Author: cbegin
Date: Sat May 16 13:57:37 2009
New Revision: 775466
URL: http://svn.apache.org/viewvc?rev=775466&view=rev
Log:
refactored key generator configuration
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/SequentialMapperBuilder.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationParser.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementParser.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/BatchExecutor.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/KeyGenerator.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/SelectKeyGenerator.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/BaseStatementHandler.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/PreparedStatementHandler.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/SimpleStatementHandler.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/MappedStatement.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parsing/NodeletContext.java
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/SequentialMapperBuilder.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/SequentialMapperBuilder.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/SequentialMapperBuilder.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/SequentialMapperBuilder.java
Sat May 16 13:57:37 2009
@@ -4,6 +4,7 @@
import org.apache.ibatis.cache.decorators.LruCache;
import org.apache.ibatis.cache.impl.PerpetualCache;
import org.apache.ibatis.executor.ErrorContext;
+import org.apache.ibatis.executor.keygen.KeyGenerator;
import org.apache.ibatis.mapping.*;
import org.apache.ibatis.reflection.MetaClass;
import org.apache.ibatis.type.*;
@@ -200,27 +201,25 @@
public void statement(
String id,
SqlSource sqlSource,
- Integer fetchSize,
+ StatementType statementType, SqlCommandType sqlCommandType, Integer
fetchSize,
Integer timeout,
String parameterMap,
Class parameterType,
String resultMap,
Class resultType,
ResultSetType resultSetType,
- boolean isSelect,
boolean flushCache,
boolean useCache,
- StatementType statementType,
- SqlCommandType sqlCommandType,
- boolean useGeneratedKeys,
+ KeyGenerator keyGenerator,
String keyProperty) {
id = applyNamespace(id);
+ boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
MappedStatement.Builder statementBuilder = new
MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType);
statementBuilder.resource(resource);
statementBuilder.fetchSize(fetchSize);
statementBuilder.statementType(statementType);
- statementBuilder.useGeneratedKeys(useGeneratedKeys);
+ statementBuilder.keyGenerator(keyGenerator);
statementBuilder.keyProperty(keyProperty);
setStatementTimeout(timeout, statementBuilder);
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationParser.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationParser.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationParser.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationParser.java
Sat May 16 13:57:37 2009
@@ -8,6 +8,7 @@
import org.apache.ibatis.builder.xml.XMLMapperParser;
import org.apache.ibatis.reflection.MetaClass;
import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.executor.keygen.*;
import java.io.*;
import java.lang.annotation.Annotation;
@@ -169,7 +170,6 @@
if (sqlSource != null) {
Options options = method.getAnnotation(Options.class);
final String mappedStatementId = method.getDeclaringClass().getName() +
"." + method.getName();
- boolean isSelect = method.getAnnotation(Select.class) != null;
boolean flushCache = false;
boolean useCache = true;
Integer fetchSize = null;
@@ -177,7 +177,8 @@
StatementType statementType = StatementType.PREPARED;
ResultSetType resultSetType = ResultSetType.FORWARD_ONLY;
SqlCommandType sqlCommandType = getSqlCommandType(method);
- boolean useGeneratedKeys = configuration.isUseGeneratedKeys() &&
SqlCommandType.INSERT.equals(sqlCommandType);
+ KeyGenerator keyGenerator = configuration.isUseGeneratedKeys()
+ && SqlCommandType.INSERT.equals(sqlCommandType) ? new
Jdbc3KeyGenerator() : null;
String keyProperty = "id";
if (options != null) {
flushCache = options.flushCache();
@@ -186,25 +187,22 @@
timeout = options.timeout() > -1 ? options.timeout() : null;
statementType = options.statementType();
resultSetType = options.resultSetType();
- useGeneratedKeys = options.useGeneratedKeys();
+ keyGenerator = options.useGeneratedKeys() ? new Jdbc3KeyGenerator() :
null;
keyProperty = options.keyProperty();
}
sequentialBuilder.statement(
mappedStatementId,
sqlSource,
- fetchSize,
+ statementType, sqlCommandType, fetchSize,
timeout,
- null, // ParameterMapID
+ null, // ParameterMapID
getParameterType(method),
- generateResultMapName(method), // ResultMapID
+ generateResultMapName(method), // ResultMapID
getReturnType(method),
resultSetType,
- isSelect, // IsSelectStatement
flushCache,
useCache,
- statementType,
- sqlCommandType,
- useGeneratedKeys,
+ keyGenerator,
keyProperty);
}
}
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementParser.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementParser.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementParser.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementParser.java
Sat May 16 13:57:37 2009
@@ -4,9 +4,9 @@
import org.apache.ibatis.builder.BaseParser;
import org.apache.ibatis.builder.ParserException;
import org.apache.ibatis.builder.SequentialMapperBuilder;
-import org.apache.ibatis.builder.SqlSourceParser;
import org.apache.ibatis.builder.xml.dynamic.*;
import org.apache.ibatis.parsing.NodeletContext;
+import org.apache.ibatis.executor.keygen.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -30,9 +30,6 @@
String id = context.getStringAttribute("id");
Integer fetchSize = context.getIntAttribute("fetchSize", null);
Integer timeout = context.getIntAttribute("timeout", null);
- boolean isSelect = "select".equals(context.getNode().getNodeName());
- boolean flushCache = context.getBooleanAttribute("flushCache", !isSelect);
- boolean useCache = context.getBooleanAttribute("useCache", isSelect);
String parameterMap = context.getStringAttribute("parameterMap");
String parameterType = context.getStringAttribute("parameterType");
Class parameterTypeClass = resolveClass(parameterType);
@@ -49,13 +46,17 @@
SqlSource sqlSource = new DynamicSqlSource(configuration, rootSqlNode);
String nodeName = context.getNode().getNodeName();
SqlCommandType sqlCommandType =
SqlCommandType.valueOf(nodeName.toUpperCase());
+ boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
+ boolean flushCache = context.getBooleanAttribute("flushCache", !isSelect);
+ boolean useCache = context.getBooleanAttribute("useCache", isSelect);
String keyProperty = context.getStringAttribute("keyProperty");
- boolean useGeneratedKeys = context.getBooleanAttribute("useGeneratedKeys",
- configuration.isUseGeneratedKeys() &&
SqlCommandType.INSERT.equals(sqlCommandType));
+ KeyGenerator keyGenerator = context.getBooleanAttribute("useGeneratedKeys",
+ configuration.isUseGeneratedKeys() &&
SqlCommandType.INSERT.equals(sqlCommandType))
+ ? new Jdbc3KeyGenerator() : null;
- sequentialBuilder.statement(id, sqlSource, fetchSize, timeout,
parameterMap, parameterTypeClass,
- resultMap, resultTypeClass, resultSetTypeEnum, isSelect, flushCache,
useCache, statementType, sqlCommandType,useGeneratedKeys,keyProperty);
+ sequentialBuilder.statement(id, sqlSource, statementType, sqlCommandType,
fetchSize, timeout, parameterMap, parameterTypeClass,
+ resultMap, resultTypeClass, resultSetTypeEnum, flushCache, useCache,
keyGenerator,keyProperty);
}
@@ -102,36 +103,33 @@
private class SelectKeyHandler implements NodeHandler {
public void handleNode(NodeletContext nodeToHandle, List<SqlNode>
targetContents) {
- String id = nodeToHandle.getStringAttribute("id");
- Integer fetchSize = nodeToHandle.getIntAttribute("fetchSize", null);
- Integer timeout = nodeToHandle.getIntAttribute("timeout", null);
- boolean isSelect = "select".equals(nodeToHandle.getNode().getNodeName());
- boolean flushCache = nodeToHandle.getBooleanAttribute("flushCache",
!isSelect);
- boolean useCache = nodeToHandle.getBooleanAttribute("useCache",
isSelect);
- String parameterMap = nodeToHandle.getStringAttribute("parameterMap");
- String parameterType = nodeToHandle.getStringAttribute("parameterType");
- Class parameterTypeClass = resolveClass(parameterType);
- String resultMap = nodeToHandle.getStringAttribute("resultMap");
+ NodeletContext parent = nodeToHandle.getParent();
+ String id = parent.getStringAttribute("id") +
SelectKeyGenerator.SELECT_KEY_SUFFIX;
String resultType = nodeToHandle.getStringAttribute("resultType");
-
Class resultTypeClass = resolveClass(resultType);
- String resultSetType = nodeToHandle.getStringAttribute("resultSetType");
StatementType statementType =
StatementType.valueOf(nodeToHandle.getStringAttribute("statementType",
StatementType.PREPARED.toString()));
- ResultSetType resultSetTypeEnum = resolveResultSetType(resultSetType);
+ String keyProperty = nodeToHandle.getStringAttribute("keyProperty");
+ String parameterType = parent.getStringAttribute("parameterType");
+ Class parameterTypeClass = resolveClass(parameterType);
+
+ //defaults
+ boolean useCache = false;
+ KeyGenerator keyGenerator = null;
+ Integer fetchSize = null;
+ Integer timeout = null;
+ boolean flushCache = false;
+ String parameterMap = null;
+ String resultMap = null;
+ ResultSetType resultSetTypeEnum = null;
List<SqlNode> contents = parseDynamicTags(nodeToHandle);
MixedSqlNode rootSqlNode = new MixedSqlNode(contents);
SqlSource sqlSource = new DynamicSqlSource(configuration, rootSqlNode);
- String nodeName = nodeToHandle.getNode().getNodeName();
- SqlCommandType sqlCommandType =
SqlCommandType.valueOf(nodeName.toUpperCase());
-
- String keyProperty = nodeToHandle.getStringAttribute("keyProperty");
- boolean useGeneratedKeys =
nodeToHandle.getBooleanAttribute("useGeneratedKeys",
- configuration.isUseGeneratedKeys() &&
SqlCommandType.INSERT.equals(sqlCommandType));
-
- sequentialBuilder.statement(id, sqlSource, fetchSize, timeout,
parameterMap, parameterTypeClass,
- resultMap, resultTypeClass, resultSetTypeEnum, isSelect, flushCache,
useCache, statementType, sqlCommandType,useGeneratedKeys,keyProperty);
+ SqlCommandType sqlCommandType = SqlCommandType.SELECT;
+ sequentialBuilder.statement(id, sqlSource, statementType,
sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass,
+ resultMap, resultTypeClass, resultSetTypeEnum, flushCache, useCache,
+ keyGenerator,keyProperty);
}
}
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/BatchExecutor.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/BatchExecutor.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/BatchExecutor.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/BatchExecutor.java
Sat May 16 13:57:37 2009
@@ -2,11 +2,9 @@
import org.apache.ibatis.executor.result.ResultHandler;
import org.apache.ibatis.executor.statement.StatementHandler;
-import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
+import org.apache.ibatis.executor.keygen.*;
import org.apache.ibatis.mapping.*;
import org.apache.ibatis.transaction.Transaction;
-import org.apache.ibatis.reflection.MetaObject;
-import org.apache.ibatis.type.*;
import java.sql.*;
import java.util.*;
@@ -66,7 +64,8 @@
batchResult.setUpdateCounts(stmt.executeBatch());
MappedStatement ms = batchResult.getMappedStatement();
Object parameter = batchResult.getParameterObject();
- new Jdbc3KeyGenerator().processGeneratedKeys(ms, stmt, parameter);
+ KeyGenerator keyGenerator = new Jdbc3KeyGenerator();
+ keyGenerator.processGeneratedKeys(this, ms, stmt, parameter);
} catch (BatchUpdateException e) {
StringBuffer message = new StringBuffer();
message.append(batchResult.getMappedStatement().getId())
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java
Sat May 16 13:57:37 2009
@@ -3,17 +3,17 @@
import org.apache.ibatis.mapping.*;
import org.apache.ibatis.type.*;
import org.apache.ibatis.reflection.MetaObject;
-import org.apache.ibatis.executor.ExecutorException;
+import org.apache.ibatis.executor.*;
import java.sql.*;
public class Jdbc3KeyGenerator implements KeyGenerator {
- public void processGeneratedKeys(MappedStatement ms, Statement stmt, Object
parameter) {
+ public void processGeneratedKeys(Executor executor, MappedStatement ms,
Statement stmt, Object parameter) {
try {
final Configuration configuration = ms.getConfiguration();
final TypeHandlerRegistry typeHandlerRegistry =
configuration.getTypeHandlerRegistry();
- if (parameter != null && ms.isUseGeneratedKeys()) {
+ if (parameter != null) {
String keyProperty = ms.getKeyProperty();
final MetaObject metaParam = MetaObject.forObject(parameter);
if (keyProperty != null && metaParam.hasSetter(keyProperty)) {
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/KeyGenerator.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/KeyGenerator.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/KeyGenerator.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/KeyGenerator.java
Sat May 16 13:57:37 2009
@@ -1,12 +1,13 @@
package org.apache.ibatis.executor.keygen;
import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.executor.Executor;
import java.sql.*;
public interface KeyGenerator {
- void processGeneratedKeys(MappedStatement ms, Statement stmt, Object
parameter);
+ void processGeneratedKeys(Executor executor, MappedStatement ms, Statement
stmt, Object parameter);
}
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/SelectKeyGenerator.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/SelectKeyGenerator.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/SelectKeyGenerator.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/keygen/SelectKeyGenerator.java
Sat May 16 13:57:37 2009
@@ -1,49 +1,36 @@
package org.apache.ibatis.executor.keygen;
+import org.apache.ibatis.executor.*;
import org.apache.ibatis.mapping.*;
-import org.apache.ibatis.type.*;
import org.apache.ibatis.reflection.MetaObject;
-import org.apache.ibatis.executor.ExecutorException;
-import java.sql.*;
+import java.sql.Statement;
public class SelectKeyGenerator implements KeyGenerator {
+ public static final String SELECT_KEY_SUFFIX = "!selectKey";
- public void processGeneratedKeys(MappedStatement ms, Statement stmt, Object
parameter) {
+ public void processGeneratedKeys(Executor executor, MappedStatement ms,
Statement stmt, Object parameter) {
try {
final Configuration configuration = ms.getConfiguration();
- final TypeHandlerRegistry typeHandlerRegistry =
configuration.getTypeHandlerRegistry();
-
- if (parameter != null && ms.isUseGeneratedKeys()) {
- String keyProperty = ms.getKeyProperty();
- final MetaObject metaParam = MetaObject.forObject(parameter);
- if (keyProperty != null && metaParam.hasSetter(keyProperty)) {
- Class keyPropertyType = metaParam.getSetterType(keyProperty);
- TypeHandler th =
typeHandlerRegistry.getTypeHandler(keyPropertyType);
- if (th != null) {
- ResultSet rs = stmt.getGeneratedKeys();
- try {
- ResultSetMetaData rsmd = rs.getMetaData();
- int colCount = rsmd.getColumnCount();
- if (colCount > 0) {
- String colName = rsmd.getColumnName(1);
- while (rs.next()) {
- Object value = th.getResult(rs,colName);
- metaParam.setValue(keyProperty,value);
- }
- }
- } finally {
- try {
- if (rs != null) rs.close();
- } catch (Exception e) {
- //ignore
- }
+ if (parameter != null) {
+ String keyStatementName = ms.getId() + SELECT_KEY_SUFFIX;
+ if (configuration.hasStatement(keyStatementName)) {
+ MappedStatement keyStatement =
configuration.getMappedStatement(keyStatementName);
+ if (keyStatement != null) {
+ String keyProperty = keyStatement.getKeyProperty();
+ final MetaObject metaParam = MetaObject.forObject(parameter);
+ if (keyProperty != null && metaParam.hasSetter(keyProperty)) {
+ // Do not close keyExecutor.
+ // The transaction will be closed by parent executor.
+ Executor keyExecutor =
configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
+ Object value = keyExecutor.query(ms, parameter,
Executor.NO_ROW_OFFSET, Executor.NO_ROW_LIMIT, Executor.NO_RESULT_HANDLER);
+ metaParam.setValue(keyProperty, value);
}
}
}
}
} catch (Exception e) {
- throw new ExecutorException("Error getting generated key or setting
result to parameter object. Cause: " + e, e);
+ throw new ExecutorException("Error selecting key or setting result to
parameter object. Cause: " + e, e);
}
}
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/BaseStatementHandler.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/BaseStatementHandler.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/BaseStatementHandler.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/BaseStatementHandler.java
Sat May 16 13:57:37 2009
@@ -12,6 +12,7 @@
public abstract class BaseStatementHandler implements StatementHandler {
+ protected final Configuration configuration;
protected final ObjectFactory objectFactory;
protected final TypeHandlerRegistry typeHandlerRegistry;
protected final ResultSetHandler resultSetHandler;
@@ -25,12 +26,12 @@
protected final BoundSql boundSql;
protected BaseStatementHandler(Executor executor, MappedStatement
mappedStatement, Object parameterObject, int rowOffset, int rowLimit,
ResultHandler resultHandler) {
+ this.configuration = mappedStatement.getConfiguration();
this.executor = executor;
this.mappedStatement = mappedStatement;
this.rowOffset = rowOffset;
this.rowLimit = rowLimit;
- Configuration configuration = mappedStatement.getConfiguration();
this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
this.objectFactory = configuration.getObjectFactory();
@@ -72,7 +73,7 @@
protected void setStatementTimeout(Statement stmt)
throws SQLException {
Integer timeout = mappedStatement.getTimeout();
- Integer defaultTimeout =
mappedStatement.getConfiguration().getDefaultStatementTimeout();
+ Integer defaultTimeout = configuration.getDefaultStatementTimeout();
if (timeout != null) {
stmt.setQueryTimeout(timeout);
} else if (defaultTimeout != null) {
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/PreparedStatementHandler.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/PreparedStatementHandler.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/PreparedStatementHandler.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/PreparedStatementHandler.java
Sat May 16 13:57:37 2009
@@ -1,7 +1,7 @@
package org.apache.ibatis.executor.statement;
import org.apache.ibatis.executor.Executor;
-import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
+import org.apache.ibatis.executor.keygen.*;
import org.apache.ibatis.executor.result.ResultHandler;
import org.apache.ibatis.mapping.MappedStatement;
@@ -20,7 +20,10 @@
ps.execute();
int result = ps.getUpdateCount();
Object parameterObject = boundSql.getParameterObject();
- new Jdbc3KeyGenerator().processGeneratedKeys(mappedStatement, ps,
parameterObject);
+ KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
+ if (keyGenerator != null) {
+ keyGenerator.processGeneratedKeys(executor, mappedStatement, ps,
parameterObject);
+ }
return result;
}
@@ -39,7 +42,7 @@
protected Statement instantiateStatement(Connection connection) throws
SQLException {
String sql = boundSql.getSql();
- if (mappedStatement.isUseGeneratedKeys()) {
+ if (mappedStatement.getKeyGenerator() instanceof Jdbc3KeyGenerator) {
return connection.prepareStatement(sql,
PreparedStatement.RETURN_GENERATED_KEYS);
} else if (mappedStatement.getResultSetType() != null) {
return connection.prepareStatement(sql,
mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/SimpleStatementHandler.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/SimpleStatementHandler.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/SimpleStatementHandler.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/statement/SimpleStatementHandler.java
Sat May 16 13:57:37 2009
@@ -1,7 +1,7 @@
package org.apache.ibatis.executor.statement;
import org.apache.ibatis.executor.Executor;
-import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
+import org.apache.ibatis.executor.keygen.*;
import org.apache.ibatis.executor.result.ResultHandler;
import org.apache.ibatis.mapping.*;
@@ -18,13 +18,14 @@
throws SQLException {
String sql = boundSql.getSql();
Object parameterObject = boundSql.getParameterObject();
- if (mappedStatement.isUseGeneratedKeys()) {
+ if (mappedStatement.getKeyGenerator() instanceof Jdbc3KeyGenerator) {
statement.execute(sql, Statement.RETURN_GENERATED_KEYS);
} else {
statement.execute(sql);
}
int result = statement.getUpdateCount();
- new Jdbc3KeyGenerator().processGeneratedKeys(mappedStatement, statement,
parameterObject);
+ KeyGenerator keyGenerator = new Jdbc3KeyGenerator();
+ keyGenerator.processGeneratedKeys(executor, mappedStatement, statement,
parameterObject);
return result;
}
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java
Sat May 16 13:57:37 2009
@@ -8,6 +8,7 @@
import org.apache.ibatis.datasource.pooled.PooledDataSourceFactory;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
import org.apache.ibatis.executor.*;
+import org.apache.ibatis.executor.keygen.*;
import org.apache.ibatis.executor.parameter.*;
import org.apache.ibatis.executor.result.ResultHandler;
import org.apache.ibatis.executor.resultset.*;
@@ -281,6 +282,10 @@
return mapperRegistry.hasMapper(type);
}
+ public boolean hasStatement(String statementName) {
+ return mappedStatements.containsKey(statementName);
+ }
+
private static class StrictMap<J, K> extends HashMap<J, K> {
private String name;
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/MappedStatement.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/MappedStatement.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/MappedStatement.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/MappedStatement.java
Sat May 16 13:57:37 2009
@@ -1,6 +1,7 @@
package org.apache.ibatis.mapping;
import org.apache.ibatis.cache.Cache;
+import org.apache.ibatis.executor.keygen.*;
import java.util.*;
@@ -20,7 +21,7 @@
private boolean flushCacheRequired;
private boolean useCache;
private SqlCommandType sqlCommandType;
- private boolean useGeneratedKeys;
+ private KeyGenerator keyGenerator;
private String keyProperty;
private MappedStatement() {
@@ -38,8 +39,8 @@
mappedStatement.resultMaps = new ArrayList<ResultMap>();
mappedStatement.timeout = configuration.getDefaultStatementTimeout();
mappedStatement.sqlCommandType = sqlCommandType;
- mappedStatement.useGeneratedKeys = configuration.isUseGeneratedKeys()
- && SqlCommandType.INSERT.equals(sqlCommandType);
+ mappedStatement.keyGenerator = configuration.isUseGeneratedKeys()
+ && SqlCommandType.INSERT.equals(sqlCommandType) ? new
Jdbc3KeyGenerator() : null;
}
public Builder resource(String resource) {
@@ -96,8 +97,8 @@
return this;
}
- public Builder useGeneratedKeys(boolean useGeneratedKeys) {
- mappedStatement.useGeneratedKeys = useGeneratedKeys;
+ public Builder keyGenerator (KeyGenerator keyGenerator) {
+ mappedStatement.keyGenerator = keyGenerator;
return this;
}
@@ -120,8 +121,8 @@
return keyProperty;
}
- public boolean isUseGeneratedKeys() {
- return useGeneratedKeys;
+ public KeyGenerator getKeyGenerator() {
+ return keyGenerator;
}
public SqlCommandType getSqlCommandType() {
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parsing/NodeletContext.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parsing/NodeletContext.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parsing/NodeletContext.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parsing/NodeletContext.java
Sat May 16 13:57:37 2009
@@ -196,6 +196,15 @@
return properties;
}
+ public NodeletContext getParent() {
+ final Node parent = node.getParentNode();
+ if (parent == null) {
+ return null;
+ } else {
+ return new NodeletContext(parent, variables);
+ }
+ }
+
private Properties parseAttributes(Node n) {
Properties attributes = new Properties();
NamedNodeMap attributeNodes = n.getAttributes();
Modified:
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java?rev=775466&r1=775465&r2=775466&view=diff
==============================================================================
---
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java
(original)
+++
ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java
Sat May 16 13:57:37 2009
@@ -7,6 +7,7 @@
import org.apache.ibatis.mapping.*;
import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.type.*;
+import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
import java.util.*;
@@ -58,7 +59,7 @@
}
}).build())
.cache(authorCache)
- .useGeneratedKeys(true)
+ .keyGenerator(new Jdbc3KeyGenerator())
.keyProperty("id")
.build();
return ms;