-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major
-
Affects Version/s: None
-
Component/s: None
-
None
アノテーションが付いたメソッドの戻り値がCollection(または、その子)だった場合に、
ResultSetを戻り値として返す(ResultSetHandlerでハンドリングして、Listにして)
機能です。
(isAssignableFromメソッドの使い方が間違っていたようなので変更してあります。)
出来れば早々にリリースして欲しいです。
以下、新規クラスとパッチです。
/*
- Copyright 2004-2006 the Seasar Foundation and the Others.
* - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
* - http://www.apache.org/licenses/LICENSE-2.0
* - Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- either express or implied. See the License for the specific language
- governing permissions and limitations under the License.
*/
package org.seasar.dao.handler;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.seasar.extension.jdbc.ResultSetHandler;
import org.seasar.extension.jdbc.StatementFactory;
import org.seasar.extension.jdbc.impl.BasicStatementFactory;
import org.seasar.framework.exception.SQLRuntimeException;
import org.seasar.framework.exception.SRuntimeException;
import org.seasar.framework.util.ResultSetUtil;
import org.seasar.framework.util.StatementUtil;
public class ListBasicProcedureHandler extends AbstractBasicProcedureHandler {
public ListBasicProcedureHandler(DataSource ds, String procedureName,
ResultSetHandler handler)
public ListBasicProcedureHandler(DataSource ds, String procedureName,
StatementFactory statementFactory, ResultSetHandler handler) {
setDataSource(ds);
setProcedureName(procedureName);
setStatementFactory(statementFactory);
setResultSetHandler(handler);
if (initTypes() > 1)
}
protected Object execute(Connection connection, Object[] args) {
CallableStatement cs = null;
ResultSet rs = null;
try
catch (SQLException e)
{ throw new SQLRuntimeException(e); } finally {
try
finally
{ StatementUtil.close(cs); } }
}
}
Index: s2dao/s2-dao/src/main/java/org/seasar/dao/impl/DaoMetaDataImpl.java
===================================================================
— s2dao/s2-dao/src/main/java/org/seasar/dao/impl/DaoMetaDataImpl.java (revision 288)
+++ s2dao/s2-dao/src/main/java/org/seasar/dao/impl/DaoMetaDataImpl.java (working copy)
@@ -23,6 +23,7 @@
import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -41,6 +42,7 @@
import org.seasar.dao.IllegalSignatureRuntimeException;
import org.seasar.dao.SqlCommand;
import org.seasar.dao.dbms.DbmsManager;
+import org.seasar.dao.handler.ListBasicProcedureHandler;
import org.seasar.dao.handler.MapBasicProcedureHandler;
import org.seasar.dao.handler.ObjectBasicProcedureHandler;
import org.seasar.extension.jdbc.PropertyType;
@@ -193,25 +195,31 @@
}
}
- protected void setupMethodByAnnotation(Class daoInterface, Method method) {
- String sql = annotationReader_.getSQL(method, dbms_.getSuffix());
- if (sql != null) { - setupMethodByManual(method, sql); - }
- String procedureName = annotationReader_.getStoredProcedureName(method);
- if(procedureName != null){
- Class returnType = method.getReturnType();
- if(returnType.isAssignableFrom(Map.class))
{
- sqlCommands_.put(method.getName(),
- new StaticStoredProcedureCommand(
- new MapBasicProcedureHandler(dataSource_,procedureName)));
- }
else
{ - sqlCommands_.put(method.getName(), - new StaticStoredProcedureCommand( - new ObjectBasicProcedureHandler(dataSource_,procedureName))); - } - }
- }
+ protected void setupMethodByAnnotation(Class daoInterface, Method method) {
+ String sql = annotationReader_.getSQL(method, dbms_.getSuffix());
+ if (sql != null) { + setupMethodByManual(method, sql); + }+ String procedureName = annotationReader_.getStoredProcedureName(method);
+ if (procedureName != null)Unknown macro: {+ Class returnType = method.getReturnType();+ SqlCommand command;+ if (Map.class.isAssignableFrom(returnType)) { + command = new StaticStoredProcedureCommand( + new MapBasicProcedureHandler(dataSource_, procedureName)); + } else if (Collection.class.isAssignableFrom(returnType)) { + command = new StaticStoredProcedureCommand( + new ListBasicProcedureHandler(dataSource_, + procedureName, createResultSetHandler(method))); + } else { + command = new StaticStoredProcedureCommand( + new ObjectBasicProcedureHandler(dataSource_, + procedureName)); + }+ sqlCommands_.put(method.getName(), command);+ }+ }
{ InputStream is = ResourceUtil.getResourceAsStream(path); Reader reader = InputStreamReaderUtil.create(is,encoding); Index: s2dao/s2-dao/src/main/java/org/seasar/dao/handler/AbstractBasicProcedureHandler.java =================================================================== --- s2dao/s2-dao/src/main/java/org/seasar/dao/handler/AbstractBasicProcedureHandler.java (revision 419) +++ s2dao/s2-dao/src/main/java/org/seasar/dao/handler/AbstractBasicProcedureHandler.java (working copy) @@ -27,6 +27,7 @@ import javax.sql.DataSource; +import org.seasar.extension.jdbc.ResultSetHandler; import org.seasar.extension.jdbc.StatementFactory; import org.seasar.extension.jdbc.ValueType; import org.seasar.extension.jdbc.impl.BasicStatementFactory; @@ -51,6 +52,8 @@ protected String procedureName_; + protected ResultSetHandler resultSetHandler_; + protected String sql_; protected Integer[] columnInOutTypes_; @@ -85,6 +88,14 @@ statementFactory_ = statementFactory; }
+
protected String readText(String path)
+ public ResultSetHandler getResultSetHandler()
{ + return resultSetHandler_; + }+
+ public void setResultSetHandler(ResultSetHandler handler)
+
protected Connection getConnection() {
if (dataSource_ == null) {
throw new EmptyRuntimeException("dataSource");