Author: cbegin
Date: Sun Sep 20 12:55:48 2009
New Revision: 817019
URL: http://svn.apache.org/viewvc?rev=817019&view=rev
Log:
Made old multi-result test more realistic.
Added update count to cachekey
Cleaned up cachekey code in resultsethandler.
Modified:
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/DerbyProc.xml
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/SqlMapConfig.xml
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/proc/DerbyProcs.java
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/cache/CacheKey.java
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/NewResultSetHandler.java
Modified:
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/DerbyProc.xml
URL:
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/DerbyProc.xml?rev=817019&r1=817018&r2=817019&view=diff
==============================================================================
---
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/DerbyProc.xml
(original)
+++
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/DerbyProc.xml
Sun Sep 20 12:55:48 2009
@@ -9,7 +9,7 @@
<typeAlias alias="account" type="testdomain.Account"/>
<resultMap id="account-result" class="account">
- <result property="id" column="ACC_ID"/>
+ <result property="id" column="id"/>
<result property="firstName" column="ACC_FIRST_NAME"/>
<result property="lastName" column="ACC_LAST_NAME"/>
<result property="emailAddress" column="ACC_EMAIL"/>
Modified:
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/SqlMapConfig.xml
URL:
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/SqlMapConfig.xml?rev=817019&r1=817018&r2=817019&view=diff
==============================================================================
---
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/SqlMapConfig.xml
(original)
+++
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/maps/SqlMapConfig.xml
Sun Sep 20 12:55:48 2009
@@ -17,7 +17,7 @@
<settings
cacheModelsEnabled="true"
enhancementEnabled="false"
- lazyLoadingEnabled="true"
+ lazyLoadingEnabled="false"
statementCachingEnabled="false"
useStatementNamespaces="false"
/>
Modified:
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/proc/DerbyProcs.java
URL:
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/proc/DerbyProcs.java?rev=817019&r1=817018&r2=817019&view=diff
==============================================================================
---
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/proc/DerbyProcs.java
(original)
+++
ibatis/java/ibatis-3/trunk/ibatis-3-compat/src/test/java/com/ibatis/sqlmap/proc/DerbyProcs.java
Sun Sep 20 12:55:48 2009
@@ -5,11 +5,11 @@
public class DerbyProcs {
public static void selectRows(int p1, int p2, int p3, int p4, ResultSet[]
rs1, ResultSet[] rs2) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
- PreparedStatement ps1 = conn.prepareStatement("select * from account where
acc_id in (?,?)");
+ PreparedStatement ps1 = conn.prepareStatement("select acc_id as id from
account where acc_id in (?,?)");
ps1.setInt(1, p1);
ps1.setInt(2, p2);
rs1[0] = ps1.executeQuery();
- PreparedStatement ps2 = conn.prepareStatement("select * from account where
acc_id in (?,?)");
+ PreparedStatement ps2 = conn.prepareStatement("select acc_id as id from
account where acc_id in (?,?)");
ps2.setInt(1, p3);
ps2.setInt(2, p4);
rs2[0] = ps2.executeQuery();
Modified:
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/cache/CacheKey.java
URL:
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/cache/CacheKey.java?rev=817019&r1=817018&r2=817019&view=diff
==============================================================================
---
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/cache/CacheKey.java
(original)
+++
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/cache/CacheKey.java
Sun Sep 20 12:55:48 2009
@@ -25,6 +25,10 @@
updateAll(objects);
}
+ public int getUpdateCount() {
+ return updateList.size();
+ }
+
public void update(Object object) {
int baseHashCode = object == null ? 1 : object.hashCode();
Modified:
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/NewResultSetHandler.java
URL:
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/NewResultSetHandler.java?rev=817019&r1=817018&r2=817019&view=diff
==============================================================================
---
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/NewResultSetHandler.java
(original)
+++
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/NewResultSetHandler.java
Sun Sep 20 12:55:48 2009
@@ -208,7 +208,7 @@
for (ResultMapping propertyMapping : propertyMappings) {
final String column = propertyMapping.getColumn();
if (propertyMapping.isCompositeResult() || (column != null &&
mappedColumnNames.contains(column.toUpperCase()))) {
- Object value = getPropertyMappingValue(rs, metaObject, resultMap,
propertyMapping, lazyLoader);
+ Object value = getPropertyMappingValue(rs, metaObject,
propertyMapping, lazyLoader);
if (value != null) {
final String property = propertyMapping.getProperty();
metaObject.setValue(property, value);
@@ -217,10 +217,10 @@
}
}
- private Object getPropertyMappingValue(ResultSet rs, MetaObject
metaResultObject, ResultMap resultMap, ResultMapping propertyMapping,
ResultLoaderRegistry lazyLoader) throws SQLException {
+ private Object getPropertyMappingValue(ResultSet rs, MetaObject
metaResultObject, ResultMapping propertyMapping, ResultLoaderRegistry
lazyLoader) throws SQLException {
final TypeHandler typeHandler = propertyMapping.getTypeHandler();
if (propertyMapping.getNestedQueryId() != null) {
- return getNestedQueryMappingValue(rs, metaResultObject, resultMap,
propertyMapping, lazyLoader);
+ return getNestedQueryMappingValue(rs, metaResultObject, propertyMapping,
lazyLoader);
} else if (typeHandler != null) {
final String column = propertyMapping.getColumn();
return typeHandler.getResult(rs, column);
@@ -310,7 +310,7 @@
// NESTED QUERY
//
- private Object getNestedQueryMappingValue(ResultSet rs, MetaObject
metaResultObject, ResultMap resultMap, ResultMapping propertyMapping,
ResultLoaderRegistry lazyLoader) throws SQLException {
+ private Object getNestedQueryMappingValue(ResultSet rs, MetaObject
metaResultObject, ResultMapping propertyMapping, ResultLoaderRegistry
lazyLoader) throws SQLException {
final String nestedQueryId = propertyMapping.getNestedQueryId();
final String property = propertyMapping.getProperty();
final MappedStatement nestedQuery =
configuration.getMappedStatement(nestedQueryId);
@@ -458,59 +458,75 @@
private CacheKey createRowKey(ResultMap resultMap, ResultSet rs) throws
SQLException {
final CacheKey cacheKey = new CacheKey();
- List<ResultMapping> resultMappings = resultMap.getIdResultMappings();
- if (resultMappings.size() == 0) {
- resultMappings = resultMap.getPropertyResultMappings();
- }
+ List<ResultMapping> resultMappings = getResultMappingsForRowKey(resultMap);
cacheKey.update(resultMap.getId());
if (resultMappings.size() == 0) {
if (Map.class.isAssignableFrom(resultMap.getType())) {
- final ResultSetMetaData rsmd = rs.getMetaData();
- final int columnCount = rsmd.getColumnCount();
- final Set<String> mappedColumns = resultMap.getMappedColumns();
- for (int i = 1; i <= columnCount; i++) {
- final String columnName = configuration.isUseColumnLabel() ?
rsmd.getColumnLabel(i) : rsmd.getColumnName(i);
- final String value = rs.getString(columnName);
- if (value != null) {
- cacheKey.update(columnName);
- cacheKey.update(value);
- }
- }
+ createRowKeyForMap(rs, cacheKey);
} else {
- final MetaClass metaType = MetaClass.forClass(resultMap.getType());
- final List<String> mappedColumnNames = new ArrayList<String>();
- final List<String> unmappedColumnNames = new ArrayList<String>();
- loadMappedAndUnmappedColumnNames(rs, resultMap, mappedColumnNames,
unmappedColumnNames);
- for (String column : unmappedColumnNames) {
- if (metaType.findProperty(column) != null) {
- String value = rs.getString(column);
+ createRowKeyForUnmappedProperties(resultMap, rs, cacheKey);
+ }
+ } else {
+ createRowKeyForMappedProperties(rs, cacheKey, resultMappings);
+ }
+ return cacheKey;
+ }
+
+ private List<ResultMapping> getResultMappingsForRowKey(ResultMap resultMap) {
+ List<ResultMapping> resultMappings = resultMap.getIdResultMappings();
+ if (resultMappings.size() == 0) {
+ resultMappings = resultMap.getPropertyResultMappings();
+ }
+ return resultMappings;
+ }
+
+ private void createRowKeyForMappedProperties(ResultSet rs, CacheKey
cacheKey, List<ResultMapping> resultMappings) {
+ for (ResultMapping resultMapping : resultMappings) {
+ if (resultMapping.getNestedQueryId() == null &&
resultMapping.getNestedResultMapId() == null) {
+ final String column = resultMapping.getColumn();
+ final TypeHandler th = resultMapping.getTypeHandler();
+ if (column != null) {
+ try {
+ final Object value = th.getResult(rs, column);
if (value != null) {
cacheKey.update(column);
cacheKey.update(value);
}
+ } catch (Exception e) {
+ //ignore
}
}
}
- } else {
- for (ResultMapping resultMapping : resultMappings) {
- if (resultMapping.getNestedQueryId() == null &&
resultMapping.getNestedResultMapId() == null) {
- final String column = resultMapping.getColumn();
- final TypeHandler th = resultMapping.getTypeHandler();
- if (column != null) {
- try {
- final Object value = th.getResult(rs, column);
- if (value != null) {
- cacheKey.update(column);
- cacheKey.update(value);
- }
- } catch (Exception e) {
- //ignore
- }
- }
+ }
+ }
+
+ private void createRowKeyForUnmappedProperties(ResultMap resultMap,
ResultSet rs, CacheKey cacheKey) throws SQLException {
+ final MetaClass metaType = MetaClass.forClass(resultMap.getType());
+ final List<String> mappedColumnNames = new ArrayList<String>();
+ final List<String> unmappedColumnNames = new ArrayList<String>();
+ loadMappedAndUnmappedColumnNames(rs, resultMap, mappedColumnNames,
unmappedColumnNames);
+ for (String column : unmappedColumnNames) {
+ if (metaType.findProperty(column) != null) {
+ String value = rs.getString(column);
+ if (value != null) {
+ cacheKey.update(column);
+ cacheKey.update(value);
}
}
}
- return cacheKey;
+ }
+
+ private void createRowKeyForMap(ResultSet rs, CacheKey cacheKey) throws
SQLException {
+ final ResultSetMetaData rsmd = rs.getMetaData();
+ final int columnCount = rsmd.getColumnCount();
+ for (int i = 1; i <= columnCount; i++) {
+ final String columnName = configuration.isUseColumnLabel() ?
rsmd.getColumnLabel(i) : rsmd.getColumnName(i);
+ final String value = rs.getString(columnName);
+ if (value != null) {
+ cacheKey.update(columnName);
+ cacheKey.update(value);
+ }
+ }
}
}