You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by cb...@apache.org on 2007/06/10 23:38:02 UTC
svn commit: r545948 - in /ibatis/trunk/java/mapper/mapper2:
src/com/ibatis/sqlmap/engine/builder/xml/ src/com/ibatis/sqlmap/engine/cache/
src/com/ibatis/sqlmap/engine/cache/fifo/
src/com/ibatis/sqlmap/engine/cache/lru/ src/com/ibatis/sqlmap/engine/cach...
Author: cbegin
Date: Sun Jun 10 14:38:01 2007
New Revision: 545948
URL: http://svn.apache.org/viewvc?view=rev&rev=545948
Log:
Improved type safety for cache model config
Modified:
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheController.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheModel.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/fifo/FifoCacheController.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/lru/LruCacheController.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/memory/MemoryCacheController.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/oscache/OSCacheController.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/CacheModelConfig.java
ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/SqlMapConfiguration.java
ibatis/trunk/java/mapper/mapper2/test/com/ibatis/sqlmap/engine/cache/lru/LruCacheControllerTest.java
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java Sun Jun 10 14:38:01 2007
@@ -1,9 +1,11 @@
package com.ibatis.sqlmap.engine.builder.xml;
import com.ibatis.common.xml.*;
+import com.ibatis.common.resources.*;
import com.ibatis.sqlmap.client.*;
import com.ibatis.sqlmap.engine.conifg.*;
import com.ibatis.sqlmap.engine.mapping.statement.*;
+import com.ibatis.sqlmap.engine.cache.*;
import org.w3c.dom.Node;
import java.io.*;
@@ -89,13 +91,21 @@
Boolean readOnly = readOnlyAttr == null || readOnlyAttr.length() <= 0 ? null : new Boolean("true".equals(readOnlyAttr));
String serializeAttr = attributes.getProperty("serialize");
Boolean serialize = serializeAttr == null || serializeAttr.length() <= 0 ? null : new Boolean("true".equals(serializeAttr));
- CacheModelConfig cacheConfig = state.getConfig().newCacheModelConfig(id, type, readOnly, serialize);
+ type = state.getConfig().getTypeHandlerFactory().resolveAlias(type);
+ Class clazz = Resources.classForName(type);
+ if (readOnly == null) {
+ readOnly = Boolean.TRUE;
+ }
+ if (serialize == null) {
+ serialize = Boolean.FALSE;
+ }
+ CacheModelConfig cacheConfig = state.getConfig().newCacheModelConfig(id, (CacheController) Resources.instantiate(clazz), readOnly.booleanValue(), serialize.booleanValue());
state.setCacheConfig(cacheConfig);
}
});
parser.addNodelet("/sqlMap/cacheModel/end()", new Nodelet() {
public void process(Node node) throws Exception {
- state.getCacheConfig().saveCacheModel();
+ state.getCacheConfig().setControllerProperties(state.getCacheProps());
}
});
parser.addNodelet("/sqlMap/cacheModel/property", new Nodelet() {
@@ -104,7 +114,7 @@
Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps());
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), state.getGlobalProps());
- state.getCacheConfig().setProperty(name, value);
+ state.getCacheProps().setProperty(name, value);
}
});
parser.addNodelet("/sqlMap/cacheModel/flushOnExecute", new Nodelet() {
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java Sun Jun 10 14:38:01 2007
@@ -13,6 +13,7 @@
private Properties globalProps = new Properties();
private Properties txProps = new Properties();
private Properties dsProps = new Properties();
+ private Properties cacheProps = new Properties();
private boolean useStatementNamespaces = false;
private Map sqlIncludes = new HashMap();
@@ -42,7 +43,11 @@
public Properties getDsProps() {
return dsProps;
}
-
+
+ public Properties getCacheProps() {
+ return cacheProps;
+ }
+
public void setUseStatementNamespaces(boolean useStatementNamespaces) {
this.useStatementNamespaces = useStatementNamespaces;
}
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheController.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheController.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheController.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheController.java Sun Jun 10 14:38:01 2007
@@ -61,6 +61,6 @@
*
* @param props - the properties object continaing configuration information
*/
- public void configure(Properties props);
+ public void setProperties(Properties props);
}
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheModel.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheModel.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheModel.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/CacheModel.java Sun Jun 10 14:38:01 2007
@@ -17,7 +17,6 @@
import com.ibatis.common.logging.Log;
import com.ibatis.common.logging.LogFactory;
-import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.engine.mapping.statement.ExecuteListener;
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
@@ -145,15 +144,13 @@
/**
* Sets up the controller for the cache model
*
- * @param implementation - the class (FQCN) for the controller
* @throws ClassNotFoundException - if the class cannot be found
* @throws InstantiationException - if the class cannot be instantiated
* @throws IllegalAccessException - if the classes constructor is not accessible
*/
- public void setControllerClassName(String implementation)
+ public void setCacheController(CacheController controller)
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
- Class clazz = Resources.classForName(implementation);
- controller = (CacheController) Resources.instantiate(clazz);
+ this.controller = controller;
}
/**
@@ -233,7 +230,7 @@
* @param props
*/
public void configure(Properties props) {
- controller.configure(props);
+ controller.setProperties(props);
}
/**
@@ -360,5 +357,9 @@
output.append("'");
}
log.debug(output.toString());
+ }
+
+ public void setControllerProperties(Properties cacheProps) {
+ controller.setProperties(cacheProps);
}
}
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/fifo/FifoCacheController.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/fifo/FifoCacheController.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/fifo/FifoCacheController.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/fifo/FifoCacheController.java Sun Jun 10 14:38:01 2007
@@ -43,12 +43,20 @@
this.keyList = Collections.synchronizedList(new LinkedList());
}
+ public int getCacheSize() {
+ return cacheSize;
+ }
+
+ public void setCacheSize(int cacheSize) {
+ this.cacheSize = cacheSize;
+ }
+
/**
* Configures the cache
*
* @param props Optionally can contain properties [reference-type=WEAK|SOFT|STRONG]
*/
- public void configure(Properties props) {
+ public void setProperties(Properties props) {
String size = props.getProperty("cache-size");
if (size == null) {
size = props.getProperty("size");
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/lru/LruCacheController.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/lru/LruCacheController.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/lru/LruCacheController.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/lru/LruCacheController.java Sun Jun 10 14:38:01 2007
@@ -43,12 +43,20 @@
this.keyList = Collections.synchronizedList(new LinkedList());
}
+ public int getCacheSize() {
+ return cacheSize;
+ }
+
+ public void setCacheSize(int cacheSize) {
+ this.cacheSize = cacheSize;
+ }
+
/**
* Configures the cache
*
* @param props Optionally can contain properties [reference-type=WEAK|SOFT|STRONG]
*/
- public void configure(Properties props) {
+ public void setProperties(Properties props) {
String size = props.getProperty("cache-size");
if (size == null) {
size = props.getProperty("size");
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/memory/MemoryCacheController.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/memory/MemoryCacheController.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/memory/MemoryCacheController.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/memory/MemoryCacheController.java Sun Jun 10 14:38:01 2007
@@ -30,7 +30,7 @@
*/
public class MemoryCacheController implements CacheController {
- private MemoryCacheLevel cacheLevel = MemoryCacheLevel.WEAK;
+ private MemoryCacheLevel referenceType = MemoryCacheLevel.WEAK;
private Map cache = Collections.synchronizedMap(new HashMap());
/**
@@ -38,16 +38,24 @@
*
* @param props Optionally can contain properties [reference-type=WEAK|SOFT|STRONG]
*/
- public void configure(Properties props) {
+ public void setProperties(Properties props) {
String refType = props.getProperty("reference-type");
if (refType == null) {
refType = props.getProperty("referenceType");
}
if (refType != null) {
- cacheLevel = MemoryCacheLevel.getByReferenceType(refType);
+ referenceType = MemoryCacheLevel.getByReferenceType(refType);
}
}
+ public MemoryCacheLevel getReferenceType() {
+ return referenceType;
+ }
+
+ public void setReferenceType(MemoryCacheLevel referenceType) {
+ this.referenceType = referenceType;
+ }
+
/**
* Add an object to the cache
*
@@ -57,11 +65,11 @@
*/
public void putObject(CacheModel cacheModel, Object key, Object value) {
Object reference = null;
- if (cacheLevel.equals(MemoryCacheLevel.WEAK)) {
+ if (referenceType.equals(MemoryCacheLevel.WEAK)) {
reference = new WeakReference(value);
- } else if (cacheLevel.equals(MemoryCacheLevel.SOFT)) {
+ } else if (referenceType.equals(MemoryCacheLevel.SOFT)) {
reference = new SoftReference(value);
- } else if (cacheLevel.equals(MemoryCacheLevel.STRONG)) {
+ } else if (referenceType.equals(MemoryCacheLevel.STRONG)) {
reference = new StrongReference(value);
}
cache.put(key, reference);
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/oscache/OSCacheController.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/oscache/OSCacheController.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/oscache/OSCacheController.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/cache/oscache/OSCacheController.java Sun Jun 10 14:38:01 2007
@@ -70,7 +70,7 @@
CACHE.putInCache(keyString, object, new String[]{cacheModel.getId()});
}
- public void configure(Properties props) {
+ public void setProperties(Properties props) {
}
}
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/CacheModelConfig.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/CacheModelConfig.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/CacheModelConfig.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/CacheModelConfig.java Sun Jun 10 14:38:01 2007
@@ -3,39 +3,26 @@
import com.ibatis.sqlmap.engine.cache.*;
import com.ibatis.sqlmap.engine.impl.*;
import com.ibatis.sqlmap.engine.scope.*;
-import com.ibatis.sqlmap.engine.type.*;
import java.util.Properties;
public class CacheModelConfig {
private ErrorContext errorContext;
private CacheModel cacheModel;
- private Properties properties;
- CacheModelConfig(SqlMapConfiguration config, String id, String type, Boolean readOnly, Boolean serialize) {
+ CacheModelConfig(SqlMapConfiguration config, String id, CacheController controller, boolean readOnly, boolean serialize) {
this.errorContext = config.getErrorContext();
this.cacheModel = new CacheModel();
- this.properties = new Properties();
ExtendedSqlMapClient client = config.getClient();
- TypeHandlerFactory typeHandlerFactory = config.getTypeHandlerFactory();
errorContext.setActivity("building a cache model");
- type = typeHandlerFactory.resolveAlias(type);
- if (readOnly != null) {
- cacheModel.setReadOnly(readOnly.booleanValue());
- } else {
- cacheModel.setReadOnly(true);
- }
- if (serialize != null) {
- cacheModel.setSerialize(serialize.booleanValue());
- } else {
- cacheModel.setSerialize(false);
- }
+ cacheModel.setReadOnly(readOnly);
+ cacheModel.setSerialize(serialize);
errorContext.setObjectId(id + " cache model");
errorContext.setMoreInfo("Check the cache model type.");
cacheModel.setId(id);
cacheModel.setResource(errorContext.getResource());
try {
- cacheModel.setControllerClassName(type);
+ cacheModel.setCacheController(controller);
} catch (Exception e) {
throw new RuntimeException("Error setting Cache Controller Class. Cause: " + e, e);
}
@@ -47,10 +34,6 @@
errorContext.setObjectId(null);
}
- public void setProperty(String name, String value) {
- properties.setProperty(name, value);
- }
-
public void setFlushInterval(int hours, int minutes, int seconds, int milliseconds) {
errorContext.setMoreInfo("Check the cache model flush interval.");
long t = 0;
@@ -68,8 +51,11 @@
cacheModel.addFlushTriggerStatement(statement);
}
- public void saveCacheModel() {
- cacheModel.configure(properties);
+ public CacheModel getCacheModel() {
+ return cacheModel;
}
+ public void setControllerProperties(Properties cacheProps) {
+ cacheModel.setControllerProperties(cacheProps);
+ }
}
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/SqlMapConfiguration.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/SqlMapConfiguration.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/SqlMapConfiguration.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/SqlMapConfiguration.java Sun Jun 10 14:38:01 2007
@@ -20,7 +20,6 @@
import com.ibatis.sqlmap.engine.transaction.jta.*;
import com.ibatis.sqlmap.engine.type.*;
-import javax.sql.DataSource;
import java.util.*;
public class SqlMapConfiguration {
@@ -30,7 +29,6 @@
private TypeHandlerFactory typeHandlerFactory;
private ExtendedSqlMapClient client;
private Integer defaultStatementTimeout;
- private DataSource dataSource;
public SqlMapConfiguration() {
errorContext = new ErrorContext();
@@ -131,16 +129,16 @@
errorContext.setObjectId(null);
}
+ public CacheModelConfig newCacheModelConfig(String id, CacheController controller, boolean readOnly, boolean serialize) {
+ return new CacheModelConfig(this, id, controller, readOnly, serialize);
+ }
+
public ParameterMapConfig newParameterMapConfig(String id, String parameterClassName) {
return new ParameterMapConfig(this, id, parameterClassName);
}
public ResultMapConfig newResultMapConfig(String id, String resultClassName, String groupBy, String extended, String xmlName) {
return new ResultMapConfig(this, id, resultClassName, groupBy, extended, xmlName);
- }
-
- public CacheModelConfig newCacheModelConfig(String id, String type, Boolean readOnly, Boolean serialize) {
- return new CacheModelConfig(this, id, type, readOnly, serialize);
}
public MappedStatementConfig newMappedStatementConfig(String id, GeneralStatement statement, SqlSource processor, String parameterMapName, String parameterClassName, String resultMapName, String[] additionalResultMapNames, String resultClassName, String[] additionalResultClasses, String resultSetType, String fetchSize, String allowRemapping, String timeout, String cacheModelName, String xmlResultName) {
Modified: ibatis/trunk/java/mapper/mapper2/test/com/ibatis/sqlmap/engine/cache/lru/LruCacheControllerTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/test/com/ibatis/sqlmap/engine/cache/lru/LruCacheControllerTest.java?view=diff&rev=545948&r1=545947&r2=545948
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/test/com/ibatis/sqlmap/engine/cache/lru/LruCacheControllerTest.java (original)
+++ ibatis/trunk/java/mapper/mapper2/test/com/ibatis/sqlmap/engine/cache/lru/LruCacheControllerTest.java Sun Jun 10 14:38:01 2007
@@ -21,7 +21,7 @@
String testVal = "testVal";
Properties props = new Properties();
props.setProperty("cache-size", "1");
- cc.configure(props);
+ cc.setProperties(props);
cc.putObject(null, testKey, testVal);
assertEquals(testVal, cc.getObject(null, testKey));
String testKey2 = "testKey2";