Author: cbegin Date: Fri Mar 2 13:50:49 2007 New Revision: 513972 URL: http://svn.apache.org/viewvc?view=rev&rev=513972 Log: Reintroduced XmlParserState for XML specific builder state. This cleans up the actual configuration class quite a bit.
Added: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java Modified: ibatis/trunk/java/mapper/mapper2/build/version.properties ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.java 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/SqlStatementParser.java ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XMLSqlSource.java ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/conifg/SqlMapConfiguration.java Modified: ibatis/trunk/java/mapper/mapper2/build/version.properties URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/build/version.properties?view=diff&rev=513972&r1=513971&r2=513972 ============================================================================== --- ibatis/trunk/java/mapper/mapper2/build/version.properties (original) +++ ibatis/trunk/java/mapper/mapper2/build/version.properties Fri Mar 2 13:50:49 2007 @@ -1,5 +1,5 @@ #Build version info -#Wed Feb 28 00:05:43 MST 2007 +#Fri Mar 02 14:49:45 MST 2007 version=2.3.1 -buildDate=2007/02/28 00\:05 -buildNum=685 +buildDate=2007/03/02 14\:49 +buildNum=686 Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.java?view=diff&rev=513972&r1=513971&r2=513972 ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.java (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.java Fri Mar 2 13:50:49 2007 @@ -6,7 +6,6 @@ import com.ibatis.common.xml.NodeletUtils; import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapException; -import com.ibatis.sqlmap.engine.conifg.SqlMapConfiguration; import org.w3c.dom.Node; import java.io.InputStream; @@ -16,7 +15,7 @@ public class SqlMapConfigParser { protected final NodeletParser parser = new NodeletParser(); - private SqlMapConfiguration config = new SqlMapConfiguration(); + private XmlParserState state = new XmlParserState(); private boolean usingStreams = false; @@ -36,7 +35,7 @@ } public SqlMapClient parse(Reader reader, Properties props) { - if (props != null) config.globalProps = props; + if (props != null) state.setGlobalProps(props); return parse(reader); } @@ -45,14 +44,14 @@ usingStreams = false; parser.parse(reader); - return config.getClient(); + return state.getConfig().getClient(); } catch (Exception e) { throw new RuntimeException("Error occurred. Cause: " + e, e); } } public SqlMapClient parse(InputStream inputStream, Properties props) { - if (props != null) config.globalProps = props; + if (props != null) state.setGlobalProps(props); return parse(inputStream); } @@ -61,7 +60,7 @@ usingStreams = true; parser.parse(inputStream); - return config.getClient(); + return state.getConfig().getClient(); } catch (Exception e) { throw new RuntimeException("Error occurred. Cause: " + e, e); } @@ -70,7 +69,7 @@ private void addSqlMapConfigNodelets() { parser.addNodelet("/sqlMapConfig/end()", new Nodelet() { public void process(Node node) throws Exception { - config.wireupCacheModels(); + state.getConfig().wireupCacheModels(); } }); } @@ -78,10 +77,10 @@ private void addGlobalPropNodelets() { parser.addNodelet("/sqlMapConfig/properties", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String resource = attributes.getProperty("resource"); String url = attributes.getProperty("url"); - config.setGlobalProperties(resource, url); + state.setGlobalProperties(resource, url); } }); } @@ -89,7 +88,7 @@ private void addSettingsNodelets() { parser.addNodelet("/sqlMapConfig/settings", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String classInfoCacheEnabledAttr = attributes.getProperty("classInfoCacheEnabled"); boolean classInfoCacheEnabled = (classInfoCacheEnabledAttr == null || "true".equals(classInfoCacheEnabledAttr)); @@ -123,7 +122,8 @@ String defaultTimeoutAttr = attributes.getProperty("defaultStatementTimeout"); Integer defaultTimeout = defaultTimeoutAttr == null ? null : Integer.valueOf(defaultTimeoutAttr); - config.setSettings(classInfoCacheEnabled, lazyLoadingEnabled, statementCachingEnabled, cacheModelsEnabled, enhancementEnabled, useStatementNamespaces, maxTransactions, maxRequests, maxSessions, defaultTimeout); + state.setUseStatementNamespaces(useStatementNamespaces); + state.getConfig().setSettings(classInfoCacheEnabled, lazyLoadingEnabled, statementCachingEnabled, cacheModelsEnabled, enhancementEnabled, maxTransactions, maxRequests, maxSessions, defaultTimeout); } }); } @@ -131,10 +131,10 @@ private void addTypeAliasNodelets() { parser.addNodelet("/sqlMapConfig/typeAlias", new Nodelet() { public void process(Node node) throws Exception { - Properties prop = NodeletUtils.parseAttributes(node, config.globalProps); + Properties prop = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String alias = prop.getProperty("alias"); String type = prop.getProperty("type"); - config.addTypeAlias(alias, type); + state.getConfig().addTypeAlias(alias, type); } }); } @@ -142,11 +142,11 @@ private void addTypeHandlerNodelets() { parser.addNodelet("/sqlMapConfig/typeHandler", new Nodelet() { public void process(Node node) throws Exception { - Properties prop = NodeletUtils.parseAttributes(node, config.globalProps); + Properties prop = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String jdbcType = prop.getProperty("jdbcType"); String javaType = prop.getProperty("javaType"); String callback = prop.getProperty("callback"); - config.addGlobalTypeHandler(javaType, jdbcType, callback); + state.getConfig().addGlobalTypeHandler(javaType, jdbcType, callback); } }); } @@ -154,38 +154,38 @@ private void addTransactionManagerNodelets() { parser.addNodelet("/sqlMapConfig/transactionManager/property", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String name = attributes.getProperty("name"); - String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), config.globalProps); - config.txProps.setProperty(name, value); + String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), state.getGlobalProps()); + state.getTxProps().setProperty(name, value); } }); parser.addNodelet("/sqlMapConfig/transactionManager/end()", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String type = attributes.getProperty("type"); boolean commitRequired = "true".equals(attributes.getProperty("commitRequired")); - config.setTransactionManager(type, commitRequired, config.txProps); + state.getConfig().setTransactionManager(type, commitRequired, state.getTxProps()); } }); parser.addNodelet("/sqlMapConfig/transactionManager/dataSource/property", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String name = attributes.getProperty("name"); - String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), config.globalProps); - config.dsProps.setProperty(name, value); + String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), state.getGlobalProps()); + state.getDsProps().setProperty(name, value); } }); parser.addNodelet("/sqlMapConfig/transactionManager/dataSource/end()", new Nodelet() { public void process(Node node) throws Exception { - config.getErrorContext().setActivity("configuring the data source"); + state.getConfig().getErrorContext().setActivity("configuring the data source"); - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String type = attributes.getProperty("type"); - Properties props = config.dsProps; + Properties props = state.getDsProps(); - config.setDataSource(type, props); + state.getConfig().setDataSource(type, props); } }); } @@ -194,9 +194,9 @@ protected void addSqlMapNodelets() { parser.addNodelet("/sqlMapConfig/sqlMap", new Nodelet() { public void process(Node node) throws Exception { - config.getErrorContext().setActivity("loading the SQL Map resource"); + state.getConfig().getErrorContext().setActivity("loading the SQL Map resource"); - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String resource = attributes.getProperty("resource"); String url = attributes.getProperty("url"); @@ -204,29 +204,29 @@ if (usingStreams) { InputStream inputStream = null; if (resource != null) { - config.getErrorContext().setResource(resource); + state.getConfig().getErrorContext().setResource(resource); inputStream = Resources.getResourceAsStream(resource); } else if (url != null) { - config.getErrorContext().setResource(url); + state.getConfig().getErrorContext().setResource(url); inputStream = Resources.getUrlAsStream(url); } else { throw new SqlMapException("The <sqlMap> element requires either a resource or a url attribute."); } - new SqlMapParser(config).parse(inputStream); + new SqlMapParser(state).parse(inputStream); } else { Reader reader = null; if (resource != null) { - config.getErrorContext().setResource(resource); + state.getConfig().getErrorContext().setResource(resource); reader = Resources.getResourceAsReader(resource); } else if (url != null) { - config.getErrorContext().setResource(url); + state.getConfig().getErrorContext().setResource(url); reader = Resources.getUrlAsReader(url); } else { throw new SqlMapException("The <sqlMap> element requires either a resource or a url attribute."); } - new SqlMapParser(config).parse(reader); + new SqlMapParser(state).parse(reader); } } }); @@ -235,18 +235,18 @@ private void addResultObjectFactoryNodelets() { parser.addNodelet("/sqlMapConfig/resultObjectFactory", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String type = attributes.getProperty("type"); - config.setResultObjectFactory(type); + state.getConfig().setResultObjectFactory(type); } }); parser.addNodelet("/sqlMapConfig/resultObjectFactory/property", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String name = attributes.getProperty("name"); - String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), config.globalProps); - config.getDelegate().getResultObjectFactory().setProperty(name, value); + String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), state.getGlobalProps()); + state.getConfig().getDelegate().getResultObjectFactory().setProperty(name, value); } }); } 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=513972&r1=513971&r2=513972 ============================================================================== --- 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 Fri Mar 2 13:50:49 2007 @@ -7,7 +7,6 @@ import com.ibatis.sqlmap.client.SqlMapException; import com.ibatis.sqlmap.engine.cache.CacheModel; import com.ibatis.sqlmap.engine.mapping.statement.*; -import com.ibatis.sqlmap.engine.conifg.SqlMapConfiguration; import org.w3c.dom.Node; import java.io.InputStream; @@ -17,10 +16,10 @@ public class SqlMapParser { private final NodeletParser parser = new NodeletParser(); - private SqlMapConfiguration config; + private XmlParserState state = new XmlParserState(); - public SqlMapParser(SqlMapConfiguration config) { - this.config = config; + public SqlMapParser(XmlParserState config) { + this.state = config; parser.setValidation(true); parser.setEntityResolver(new SqlMapClasspathEntityResolver()); @@ -45,13 +44,13 @@ private void addSqlMapNodelets() { parser.addNodelet("/sqlMap", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); - config.namespace = attributes.getProperty("namespace"); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); + state.setNamespace(attributes.getProperty("namespace")); } }); parser.addNodelet("/sqlMap/end()", new Nodelet() { public void process(Node node) throws Exception { - config.bindDelegateSubMaps(); + state.getConfig().bindDelegateSubMaps(); } }); } @@ -60,15 +59,15 @@ private void addSqlNodelets() { parser.addNodelet("/sqlMap/sql", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String id = attributes.getProperty("id"); - if (config.useStatementNamespaces) { - id = config.applyNamespace(id); + if (state.isUseStatementNamespaces()) { + id = state.applyNamespace(id); } - if (config.sqlIncludes.containsKey(id)) { + if (state.getSqlIncludes().containsKey(id)) { throw new SqlMapException("Duplicate <sql>-include '" + id + "' found."); } else { - config.sqlIncludes.put(id, node); + state.getSqlIncludes().put(id, node); } } }); @@ -77,10 +76,10 @@ private void addTypeAliasNodelets() { parser.addNodelet("/sqlMap/typeAlias", new Nodelet() { public void process(Node node) throws Exception { - Properties prop = NodeletUtils.parseAttributes(node, config.globalProps); + Properties prop = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String alias = prop.getProperty("alias"); String type = prop.getProperty("type"); - config.addTypeAlias(alias, type); + state.getConfig().addTypeAlias(alias, type); } }); } @@ -88,85 +87,84 @@ private void addCacheModelNodelets() { parser.addNodelet("/sqlMap/cacheModel", new Nodelet() { public void process(Node node) throws Exception { - config.cacheModel = new CacheModel(); - config.cacheProps = new Properties(); + state.getConfig().cacheModel = new CacheModel(); + state.getConfig().cacheProps = new Properties(); } }); parser.addNodelet("/sqlMap/cacheModel/end()", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); - String id = config.applyNamespace(attributes.getProperty("id")); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); + String id = state.applyNamespace(attributes.getProperty("id")); String type = attributes.getProperty("type"); String readOnlyAttr = attributes.getProperty("readOnly"); 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)); - config.addCacheModel(id, type, readOnly, serialize, config.cacheProps); + state.getConfig().addCacheModel(id, type, readOnly, serialize, state.getConfig().cacheProps); } }); parser.addNodelet("/sqlMap/cacheModel/property", new Nodelet() { public void process(Node node) throws Exception { - config.getErrorContext().setMoreInfo("Check the cache model properties."); - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + state.getConfig().getErrorContext().setMoreInfo("Check the cache model properties."); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String name = attributes.getProperty("name"); - String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), config.globalProps); - config.cacheProps.put(name, value); + String value = NodeletUtils.parsePropertyTokens(attributes.getProperty("value"), state.getGlobalProps()); + state.getConfig().cacheProps.put(name, value); } }); parser.addNodelet("/sqlMap/cacheModel/flushOnExecute", new Nodelet() { public void process(Node node) throws Exception { - Properties childAttributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String statement = childAttributes.getProperty("statement"); - config.addFlushTriggerStatement(statement); + state.getConfig().addFlushTriggerStatement(statement); } }); parser.addNodelet("/sqlMap/cacheModel/flushInterval", new Nodelet() { public void process(Node node) throws Exception { - Properties childAttributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); try { int milliseconds = childAttributes.getProperty("milliseconds") == null ? 0 : Integer.parseInt(childAttributes.getProperty("milliseconds")); int seconds = childAttributes.getProperty("seconds") == null ? 0 : Integer.parseInt(childAttributes.getProperty("seconds")); int minutes = childAttributes.getProperty("minutes") == null ? 0 : Integer.parseInt(childAttributes.getProperty("minutes")); int hours = childAttributes.getProperty("hours") == null ? 0 : Integer.parseInt(childAttributes.getProperty("hours")); - config.setFlushInterval(hours, minutes, seconds, milliseconds); + state.getConfig().setFlushInterval(hours, minutes, seconds, milliseconds); } catch (NumberFormatException e) { - throw new RuntimeException("Error building cache '" + config.cacheModel.getId() + "' in '" + "resourceNAME" + "'. Flush interval milliseconds must be a valid long integer value. Cause: " + e, e); + throw new RuntimeException("Error building cache '" + state.getConfig().cacheModel.getId() + "' in '" + "resourceNAME" + "'. Flush interval milliseconds must be a valid long integer value. Cause: " + e, e); } } }); } - private void addParameterMapNodelets() { parser.addNodelet("/sqlMap/parameterMap/end()", new Nodelet() { public void process(Node node) throws Exception { - config.finalizeParameterMap(); + state.getConfig().finalizeParameterMap(); } }); parser.addNodelet("/sqlMap/parameterMap", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); - String id = config.applyNamespace(attributes.getProperty("id")); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); + String id = state.applyNamespace(attributes.getProperty("id")); String parameterClassName = attributes.getProperty("class"); - config.addParameterMap(id, parameterClassName); + state.getConfig().addParameterMap(id, parameterClassName); } }); parser.addNodelet("/sqlMap/parameterMap/parameter", new Nodelet() { public void process(Node node) throws Exception { - Properties childAttributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String propertyName = childAttributes.getProperty("property"); String jdbcType = childAttributes.getProperty("jdbcType"); String type = childAttributes.getProperty("typeName"); String javaType = childAttributes.getProperty("javaType"); - String resultMap = childAttributes.getProperty("resultMap"); + String resultMap = state.applyNamespace(childAttributes.getProperty("resultMap")); String nullValue = childAttributes.getProperty("nullValue"); String mode = childAttributes.getProperty("mode"); String callback = childAttributes.getProperty("typeHandler"); String numericScale = childAttributes.getProperty("numericScale"); - config.addParameterMapping(callback, javaType, resultMap, propertyName, jdbcType, type, nullValue, mode, numericScale); + state.getConfig().addParameterMapping(callback, javaType, resultMap, propertyName, jdbcType, type, nullValue, mode, numericScale); } }); @@ -176,23 +174,23 @@ private void addResultMapNodelets() { parser.addNodelet("/sqlMap/resultMap/end()", new Nodelet() { public void process(Node node) throws Exception { - config.finalizeResultMap(); + state.getConfig().finalizeResultMap(); } }); parser.addNodelet("/sqlMap/resultMap", new Nodelet() { public void process(Node node) throws Exception { - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); - String id = config.applyNamespace(attributes.getProperty("id")); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); + String id = state.applyNamespace(attributes.getProperty("id")); String resultClassName = attributes.getProperty("class"); - String extended = config.applyNamespace(attributes.getProperty("extends")); + String extended = state.applyNamespace(attributes.getProperty("extends")); String xmlName = attributes.getProperty("xmlName"); String groupBy = attributes.getProperty("groupBy"); - config.addResultMap(id, resultClassName, xmlName, groupBy, extended); + state.getConfig().addResultMap(id, resultClassName, xmlName, groupBy, extended); } }); parser.addNodelet("/sqlMap/resultMap/result", new Nodelet() { public void process(Node node) throws Exception { - Properties childAttributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String propertyName = childAttributes.getProperty("property"); String nullValue = childAttributes.getProperty("nullValue"); String jdbcType = childAttributes.getProperty("jdbcType"); @@ -203,22 +201,23 @@ String resultMapName = childAttributes.getProperty("resultMap"); String callback = childAttributes.getProperty("typeHandler"); - config.addResultMapping(callback, javaType, propertyName, jdbcType, columnName, nullValue, statementName, resultMapName, columnIndex); + state.getConfig().addResultMapping(callback, javaType, propertyName, jdbcType, columnName, nullValue, statementName, resultMapName, columnIndex); } }); parser.addNodelet("/sqlMap/resultMap/discriminator/subMap", new Nodelet() { public void process(Node node) throws Exception { - Properties childAttributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String value = childAttributes.getProperty("value"); String resultMap = childAttributes.getProperty("resultMap"); - config.addSubMap(value, resultMap); + resultMap = state.applyNamespace(resultMap); + state.getConfig().addSubMap(value, resultMap); } }); parser.addNodelet("/sqlMap/resultMap/discriminator", new Nodelet() { public void process(Node node) throws Exception { - Properties childAttributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties childAttributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String nullValue = childAttributes.getProperty("nullValue"); String jdbcType = childAttributes.getProperty("jdbcType"); String javaType = childAttributes.getProperty("javaType"); @@ -226,7 +225,7 @@ String columnIndex = childAttributes.getProperty("columnIndex"); String callback = childAttributes.getProperty("typeHandler"); - config.addDiscriminator(callback, javaType, jdbcType, columnName, nullValue, columnIndex); + state.getConfig().addDiscriminator(callback, javaType, jdbcType, columnName, nullValue, columnIndex); } }); } @@ -234,38 +233,38 @@ protected void addStatementNodelets() { parser.addNodelet("/sqlMap/statement", new Nodelet() { public void process(Node node) throws Exception { - config.currentStatement = new SqlStatementParser(config).parseGeneralStatement(node, new GeneralStatement()); - config.getDelegate().addMappedStatement(config.currentStatement); + MappedStatement statement = new SqlStatementParser(state).parseGeneralStatement(node, new GeneralStatement()); + state.getConfig().getDelegate().addMappedStatement(statement); } }); parser.addNodelet("/sqlMap/insert", new Nodelet() { public void process(Node node) throws Exception { - config.currentStatement = new SqlStatementParser(config).parseGeneralStatement(node, new InsertStatement()); - config.getDelegate().addMappedStatement(config.currentStatement); + MappedStatement statement = new SqlStatementParser(state).parseGeneralStatement(node, new InsertStatement()); + state.getConfig().getDelegate().addMappedStatement(statement); } }); parser.addNodelet("/sqlMap/update", new Nodelet() { public void process(Node node) throws Exception { - config.currentStatement = new SqlStatementParser(config).parseGeneralStatement(node, new UpdateStatement()); - config.getDelegate().addMappedStatement(config.currentStatement); + MappedStatement statement = new SqlStatementParser(state).parseGeneralStatement(node, new UpdateStatement()); + state.getConfig().getDelegate().addMappedStatement(statement); } }); parser.addNodelet("/sqlMap/delete", new Nodelet() { public void process(Node node) throws Exception { - config.currentStatement = new SqlStatementParser(config).parseGeneralStatement(node, new DeleteStatement()); - config.getDelegate().addMappedStatement(config.currentStatement); + MappedStatement statement = new SqlStatementParser(state).parseGeneralStatement(node, new DeleteStatement()); + state.getConfig().getDelegate().addMappedStatement(statement); } }); parser.addNodelet("/sqlMap/select", new Nodelet() { public void process(Node node) throws Exception { - config.currentStatement = new SqlStatementParser(config).parseGeneralStatement(node, new SelectStatement()); - config.getDelegate().addMappedStatement(config.currentStatement); + MappedStatement statement = new SqlStatementParser(state).parseGeneralStatement(node, new SelectStatement()); + state.getConfig().getDelegate().addMappedStatement(statement); } }); parser.addNodelet("/sqlMap/procedure", new Nodelet() { public void process(Node node) throws Exception { - config.currentStatement = new SqlStatementParser(config).parseGeneralStatement(node, new ProcedureStatement()); - config.getDelegate().addMappedStatement(config.currentStatement); + MappedStatement statement = new SqlStatementParser(state).parseGeneralStatement(node, new ProcedureStatement()); + state.getConfig().getDelegate().addMappedStatement(statement); } }); } Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlStatementParser.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlStatementParser.java?view=diff&rev=513972&r1=513971&r2=513972 ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlStatementParser.java (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlStatementParser.java Fri Mar 2 13:50:49 2007 @@ -2,36 +2,54 @@ import com.ibatis.common.xml.NodeletUtils; import com.ibatis.sqlmap.engine.mapping.statement.*; -import com.ibatis.sqlmap.engine.conifg.SqlMapConfiguration; import org.w3c.dom.*; import java.util.Properties; public class SqlStatementParser { - private SqlMapConfiguration config; + private XmlParserState state; - public SqlStatementParser(SqlMapConfiguration config) { - this.config = config; + public SqlStatementParser(XmlParserState config) { + this.state = config; } public MappedStatement parseGeneralStatement(Node node, GeneralStatement statement) { // get attributes - Properties attributes = NodeletUtils.parseAttributes(node, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(node, state.getGlobalProps()); String id = attributes.getProperty("id"); - String parameterMapName = config.applyNamespace(attributes.getProperty("parameterMap")); + String parameterMapName = state.applyNamespace(attributes.getProperty("parameterMap")); String parameterClassName = attributes.getProperty("parameterClass"); String resultMapName = attributes.getProperty("resultMap"); String resultClassName = attributes.getProperty("resultClass"); - String cacheModelName = config.applyNamespace(attributes.getProperty("cacheModel")); + String cacheModelName = state.applyNamespace(attributes.getProperty("cacheModel")); String xmlResultName = attributes.getProperty("xmlResultName"); String resultSetType = attributes.getProperty("resultSetType"); String fetchSize = attributes.getProperty("fetchSize"); String allowRemapping = attributes.getProperty("remapResults"); String timeout = attributes.getProperty("timeout"); - MappedStatement mappedStatement = config.prepareGeneralStatement(new XMLSqlSource(config, node), statement, id, resultMapName, parameterMapName, resultSetType, fetchSize, parameterClassName, resultClassName, allowRemapping, xmlResultName, timeout, cacheModelName); + if (state.isUseStatementNamespaces()) { + id = state.applyNamespace(id); + } + String[] additionalResultMapNames = null; + if (resultMapName != null) { + additionalResultMapNames = state.getAllButFirstToken(resultMapName); + resultMapName = state.getFirstToken(resultMapName); + resultMapName = state.applyNamespace(resultMapName); + for (int i = 0; i < additionalResultMapNames.length; i++) { + additionalResultMapNames[i] = state.applyNamespace(additionalResultMapNames[i]); + } + } + + String[] additionalResultClasses = null; + if (resultClassName != null) { + additionalResultClasses = state.getAllButFirstToken(resultClassName); + resultClassName = state.getFirstToken(resultClassName); + } + MappedStatement mappedStatement = state.getConfig().prepareGeneralStatement(new XMLSqlSource(state, node), statement, id, resultMapName, additionalResultMapNames, parameterMapName, resultSetType, fetchSize, parameterClassName, resultClassName, additionalResultClasses, allowRemapping, xmlResultName, timeout, cacheModelName); + findAndParseSelectKey(node, statement); return mappedStatement; @@ -39,7 +57,7 @@ private void findAndParseSelectKey(Node node, GeneralStatement statement) { if (statement instanceof InsertStatement) { - config.getErrorContext().setActivity("parsing select key tags"); + state.getConfig().getErrorContext().setActivity("parsing select key tags"); InsertStatement insertStatement = ((InsertStatement) statement); @@ -58,15 +76,15 @@ } } else if (child.getNodeType() == Node.ELEMENT_NODE && "selectKey".equals(child.getNodeName())) { - Properties attributes = NodeletUtils.parseAttributes(child, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(child, state.getGlobalProps()); String keyPropName = attributes.getProperty("keyProperty"); String resultClassName = attributes.getProperty("resultClass"); String type = attributes.getProperty("type"); - selectKeyStatement = config.prepareSelectKeyStatement(new XMLSqlSource(config, child), resultClassName, statement.getId(), keyPropName, foundSQLFirst, type, statement.getParameterClass()); + selectKeyStatement = state.getConfig().prepareSelectKeyStatement(new XMLSqlSource(state, child), resultClassName, statement.getId(), keyPropName, foundSQLFirst, type, statement.getParameterClass()); break; } } - config.getErrorContext().setMoreInfo(null); + state.getConfig().getErrorContext().setMoreInfo(null); insertStatement.setSelectKeyStatement(selectKeyStatement); } } Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XMLSqlSource.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XMLSqlSource.java?view=diff&rev=513972&r1=513971&r2=513972 ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XMLSqlSource.java (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XMLSqlSource.java Fri Mar 2 13:50:49 2007 @@ -16,20 +16,20 @@ private static final InlineParameterMapParser PARAM_PARSER = new InlineParameterMapParser(); - private SqlMapConfiguration config; + private XmlParserState state; private Node parentNode; - public XMLSqlSource(SqlMapConfiguration config, Node parentNode) { - this.config = config; + public XMLSqlSource(XmlParserState config, Node parentNode) { + this.state = config; this.parentNode = parentNode; } public Sql getSql() { - config.getErrorContext().setActivity("processing an SQL statement"); + state.getConfig().getErrorContext().setActivity("processing an SQL statement"); boolean isDynamic = false; StringBuffer sqlBuffer = new StringBuffer(); - DynamicSql dynamic = new DynamicSql(config.getClient().getDelegate()); + DynamicSql dynamic = new DynamicSql(state.getConfig().getClient().getDelegate()); isDynamic = parseDynamicTags(parentNode, dynamic, sqlBuffer, isDynamic, false); String sqlStatement = sqlBuffer.toString(); if (isDynamic) { @@ -40,7 +40,7 @@ } private boolean parseDynamicTags(Node node, DynamicParent dynamic, StringBuffer sqlBuffer, boolean isDynamic, boolean postParseRequired) { - config.getErrorContext().setActivity("parsing dynamic SQL tags"); + state.getConfig().getErrorContext().setActivity("parsing dynamic SQL tags"); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { @@ -50,7 +50,7 @@ || child.getNodeType() == Node.TEXT_NODE) { String data = ((CharacterData) child).getData(); - data = NodeletUtils.parsePropertyTokens(data, config.globalProps); + data = NodeletUtils.parsePropertyTokens(data, state.getGlobalProps()); SqlText sqlText; @@ -59,7 +59,7 @@ sqlText.setPostParseRequired(postParseRequired); sqlText.setText(data); } else { - sqlText = PARAM_PARSER.parseInlineParameterMap(config.getClient().getDelegate().getTypeHandlerFactory(), data, null); + sqlText = PARAM_PARSER.parseInlineParameterMap(state.getConfig().getClient().getDelegate().getTypeHandlerFactory(), data, null); sqlText.setPostParseRequired(postParseRequired); } @@ -67,19 +67,19 @@ sqlBuffer.append(data); } else if ("include".equals(nodeName)) { - Properties attributes = NodeletUtils.parseAttributes(child, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(child, state.getGlobalProps()); String refid = (String) attributes.get("refid"); - Node includeNode = (Node) config.sqlIncludes.get(refid); + Node includeNode = (Node) state.getSqlIncludes().get(refid); if (includeNode == null) { - String nsrefid = config.applyNamespace(refid); - includeNode = (Node) config.sqlIncludes.get(nsrefid); + String nsrefid = state.applyNamespace(refid); + includeNode = (Node) state.getSqlIncludes().get(nsrefid); if (includeNode == null) { throw new RuntimeException("Could not find SQL statement to include with refid '" + refid + "'"); } } isDynamic = parseDynamicTags(includeNode, dynamic, sqlBuffer, isDynamic, false); } else { - config.getErrorContext().setMoreInfo("Check the dynamic tags."); + state.getConfig().getErrorContext().setMoreInfo("Check the dynamic tags."); SqlTagHandler handler = SqlTagHandlerFactory.getSqlTagHandler(nodeName); if (handler != null) { @@ -89,7 +89,7 @@ tag.setName(nodeName); tag.setHandler(handler); - Properties attributes = NodeletUtils.parseAttributes(child, config.globalProps); + Properties attributes = NodeletUtils.parseAttributes(child, state.getGlobalProps()); tag.setPrependAttr(attributes.getProperty("prepend")); tag.setPropertyAttr(attributes.getProperty("property")); @@ -124,7 +124,7 @@ } } } - config.getErrorContext().setMoreInfo(null); + state.getConfig().getErrorContext().setMoreInfo(null); return isDynamic; } Added: 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=auto&rev=513972 ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java (added) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java Fri Mar 2 13:50:49 2007 @@ -0,0 +1,102 @@ +package com.ibatis.sqlmap.engine.builder.xml; + +import com.ibatis.common.resources.Resources; +import com.ibatis.sqlmap.engine.conifg.SqlMapConfiguration; + +import java.util.*; + +public class XmlParserState { + + private SqlMapConfiguration config = new SqlMapConfiguration(); + + private Properties globalProps = new Properties(); + private Properties txProps = new Properties(); + private Properties dsProps = new Properties(); + private boolean useStatementNamespaces = false; + private Map sqlIncludes = new HashMap(); + + private String namespace; + + public SqlMapConfiguration getConfig() { + return config; + } + + public void setGlobalProps(Properties props) { + globalProps = props; + } + + public Properties getGlobalProps() { + return globalProps; + } + + public Properties getTxProps() { + return txProps; + } + + public Properties getDsProps() { + return dsProps; + } + + public void setUseStatementNamespaces(boolean useStatementNamespaces) { + this.useStatementNamespaces = useStatementNamespaces; + } + + public boolean isUseStatementNamespaces() { + return useStatementNamespaces; + } + + public Map getSqlIncludes() { + return sqlIncludes; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public String applyNamespace(String id) { + String newId = id; + if (namespace != null && namespace.length() > 0 && id != null && id.indexOf('.') < 0) { + newId = namespace + "." + id; + } + return newId; + } + + public String getFirstToken(String s) { + return new StringTokenizer(s, ", ", false).nextToken(); + } + + public String[] getAllButFirstToken(String s) { + List strings = new ArrayList(); + StringTokenizer parser = new StringTokenizer(s, ", ", false); + parser.nextToken(); + while (parser.hasMoreTokens()) { + strings.add(parser.nextToken()); + } + return (String[]) strings.toArray(new String[strings.size()]); + } + + public void setGlobalProperties(String resource, String url) { + config.getErrorContext().setActivity("loading global properties"); + try { + Properties props; + if (resource != null) { + config.getErrorContext().setResource(resource); + props = Resources.getResourceAsProperties(resource); + } else if (url != null) { + config.getErrorContext().setResource(url); + props = Resources.getUrlAsProperties(url); + } else { + throw new RuntimeException("The " + "properties" + " element requires either a resource or a url attribute."); + } + + // Merge properties with those passed in programmatically + if (props != null) { + props.putAll(globalProps); + globalProps = props; + } + } catch (Exception e) { + throw new RuntimeException("Error loading properties. Cause: " + e, e); + } + } + +} 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=513972&r1=513971&r2=513972 ============================================================================== --- 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 Fri Mar 2 13:50:49 2007 @@ -42,8 +42,7 @@ private static final InlineParameterMapParser PARAM_PARSER = new InlineParameterMapParser(); private ErrorContext errorContext = new ErrorContext(); - private String resource = "SQL Map Config XML File"; - + private ExtendedSqlMapClient client; private SqlMapExecutorDelegate delegate; private TypeHandlerFactory typeHandlerFactory; @@ -51,33 +50,24 @@ private Integer defaultStatementTimeout; private DataSource dataSource; + // TODO: Move to ResultMapConfig private BasicResultMap resultMap; private List resultMappingList; private int resultMappingIndex; private Discriminator discriminator; + // TODO: Move to ParameterMapConfig private BasicParameterMap parameterMap; private List parameterMappingList; - public Properties globalProps = new Properties(); - public Properties txProps = new Properties(); - public Properties dsProps = new Properties(); - - public boolean useStatementNamespaces; - - public String namespace; - + // TODO: Move to CacheModelConfig public CacheModel cacheModel; public Properties cacheProps; - public Map sqlIncludes = new HashMap(); - public MappedStatement currentStatement; - public SqlMapConfiguration() { delegate = new SqlMapExecutorDelegate(); typeHandlerFactory = delegate.getTypeHandlerFactory(); client = new SqlMapClientImpl(delegate); - useStatementNamespaces = false; registerDefaultTypeAliases(); } @@ -93,6 +83,7 @@ return delegate; } + // // Utility Methods // @@ -146,13 +137,6 @@ return handler; } - public String applyNamespace(String id) { - String newId = id; - if (namespace != null && namespace.length() > 0 && id != null && id.indexOf('.') < 0) { - newId = namespace + "." + id; - } - return newId; - } private void registerDefaultTypeAliases() { // TRANSACTION ALIASES @@ -183,32 +167,9 @@ // SQL Map Config methods // - public void setGlobalProperties(String resource, String url) { - errorContext.setActivity("loading global properties"); - try { - Properties props; - if (resource != null) { - errorContext.setResource(resource); - props = Resources.getResourceAsProperties(resource); - } else if (url != null) { - errorContext.setResource(url); - props = Resources.getUrlAsProperties(url); - } else { - throw new RuntimeException("The " + "properties" + " element requires either a resource or a url attribute."); - } - - // Merge properties with those passed in programmatically - if (props != null) { - props.putAll(globalProps); - globalProps = props; - } - } catch (Exception e) { - throw new RuntimeException("Error loading properties. Cause: " + e, e); - } - } // TODO: Split into separate methods - public void setSettings(boolean classInfoCacheEnabled, boolean lazyLoadingEnabled, boolean statementCachingEnabled, boolean cacheModelsEnabled, boolean enhancementEnabled, boolean useStatementNamespaces, Integer maxTransactions, Integer maxRequests, Integer maxSessions, Integer defaultTimeout) { + public void setSettings(boolean classInfoCacheEnabled, boolean lazyLoadingEnabled, boolean statementCachingEnabled, boolean cacheModelsEnabled, boolean enhancementEnabled, Integer maxTransactions, Integer maxRequests, Integer maxSessions, Integer defaultTimeout) { errorContext.setActivity("loading settings properties"); ClassInfo.setCacheEnabled(classInfoCacheEnabled); client.getDelegate().setLazyLoadingEnabled(lazyLoadingEnabled); @@ -220,7 +181,6 @@ enhancementEnabled = false; } client.getDelegate().setEnhancementEnabled(enhancementEnabled); - this.useStatementNamespaces = useStatementNamespaces; if (maxTransactions != null && maxTransactions.intValue() > 0) { client.getDelegate().setMaxTransactions(maxTransactions.intValue()); @@ -446,7 +406,6 @@ public void addParameterMapping(String callback, String javaType, String resultMap, String propertyName, String jdbcType, String type, String nullValue, String mode, String numericScale) { callback = typeHandlerFactory.resolveAlias(callback); javaType = typeHandlerFactory.resolveAlias(javaType); - resultMap = applyNamespace(resultMap); errorContext.setObjectId(propertyName + " mapping of the " + parameterMap.getId() + " parameter map"); @@ -581,7 +540,7 @@ if (discriminator == null) { throw new RuntimeException("The discriminator is null, but somehow a subMap was reached. This is a bug."); } - discriminator.addSubMap(value, applyNamespace(resultMap)); + discriminator.addSubMap(value, resultMap); } // TODO: pass into addResultMap @@ -728,33 +687,17 @@ // SQL Statement methods // - public MappedStatement prepareGeneralStatement(final String sql, GeneralStatement statement, String id, String resultMapName, String parameterMapName, String resultSetType, String fetchSize, String parameterClassName, String resultClassName, String allowRemapping, String xmlResultName, String timeout, String cacheModelName) { - return prepareGeneralStatement(new SqlSource() { - public Sql getSql() { - return new RawSql(sql); - } - }, statement, id, resultMapName, parameterMapName, resultSetType,fetchSize, parameterClassName, resultClassName, allowRemapping, xmlResultName, timeout, cacheModelName); - } - // TODO: Clean up method signature - public MappedStatement prepareGeneralStatement(SqlSource processor, GeneralStatement statement, String id, String resultMapName, String parameterMapName, String resultSetType, String fetchSize, String parameterClassName, String resultClassName, String allowRemapping, String xmlResultName, String timeout, String cacheModelName) { + public MappedStatement prepareGeneralStatement(SqlSource processor, GeneralStatement statement, String id, String resultMapName, String[] additionalResultMapNames, String parameterMapName, String resultSetType, String fetchSize, String parameterClassName, String resultClassName, String[] additionalResultClasses, String allowRemapping, String xmlResultName, String timeout, String cacheModelName) { errorContext.setActivity("parsing a mapped statement"); - if (useStatementNamespaces) { - id = applyNamespace(id); - } - - String[] additionalResultMapNames; - errorContext.setObjectId(id + " statement"); - errorContext.setMoreInfo("Check the result map name."); - //BasicResultMap resultMap = null; if (resultMapName != null) { - additionalResultMapNames = getAllButFirstToken(resultMapName); - resultMapName = getFirstToken(resultMapName); - statement.setResultMap((BasicResultMap) client.getDelegate().getResultMap(applyNamespace(resultMapName))); - for (int i = 0; i < additionalResultMapNames.length; i++) { - statement.addResultMap((BasicResultMap) client.getDelegate().getResultMap(applyNamespace(additionalResultMapNames[i]))); + statement.setResultMap((BasicResultMap) client.getDelegate().getResultMap(resultMapName)); + if (additionalResultMapNames != null) { + for (int i = 0; i < additionalResultMapNames.length; i++) { + statement.addResultMap((BasicResultMap) client.getDelegate().getResultMap(additionalResultMapNames[i])); + } } } @@ -808,12 +751,12 @@ if (resultMap == null && resultClassName == null) { statement.setResultMap(null); } else if (resultMap == null) { - String firstResultClass = getFirstToken(resultClassName); - resultMap = buildAutoResultMap(allowRemapping, statement, firstResultClass, xmlResultName); + resultMap = buildAutoResultMap(allowRemapping, statement, resultClassName, xmlResultName); statement.setResultMap(resultMap); - String[] additionalResultClasses = getAllButFirstToken(resultClassName); - for (int i = 0; i < additionalResultClasses.length; i++) { - statement.addResultMap(buildAutoResultMap(allowRemapping, statement, additionalResultClasses[i], xmlResultName)); + if (additionalResultClasses != null) { + for (int i = 0; i < additionalResultClasses.length; i++) { + statement.addResultMap(buildAutoResultMap(allowRemapping, statement, additionalResultClasses[i], xmlResultName)); + } } } @@ -962,18 +905,5 @@ } } - private String getFirstToken(String s) { - return new StringTokenizer(s, ", ", false).nextToken(); - } - - private String[] getAllButFirstToken(String s) { - List strings = new ArrayList(); - StringTokenizer parser = new StringTokenizer(s, ", ", false); - parser.nextToken(); - while (parser.hasMoreTokens()) { - strings.add(parser.nextToken()); - } - return (String[]) strings.toArray(new String[strings.size()]); - } }