- 浏览: 113608 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (79)
- iBATIS (6)
- MySQL (4)
- english song (4)
- 软件过程管理 (1)
- 人生大事 (1)
- ruby (7)
- JAVACC (1)
- IT生活 (1)
- jQuery (0)
- database (1)
- JVM (3)
- jQueryUI (1)
- OSCache (6)
- JCS (1)
- sip servlet (2)
- 正则表达式 (1)
- R (1)
- Java (4)
- GAE (1)
- SSH (1)
- SVN (1)
- network (1)
- 经典面试题 (1)
- CSS (1)
- Spring (4)
- Rest (0)
- SipServlet (1)
- vnc (1)
- jmx-console (1)
- JavaScript (2)
- node.js (5)
- HTML5 (1)
- Android (1)
- Hadoop (0)
最新评论
-
lb86haha:
DispatcherServlet在web.xml中的配置 -
蜀山客:
我查看源代码,知道了分页的机制:操作结果集,移动指针到指定的第 ...
SqlMapClientImpl -
蜀山客:
最近对分页查询,怎么运用产生了兴趣并遇到了困惑,希望大神帮忙
SqlMapClientImpl -
蜀山客:
public List queryForList(String ...
SqlMapClientImpl -
aoems:
请教博主。上述代码细节上有问题,比如标点,比如新版本中。另外, ...
node.js连接 mysql
package com.ibatis.sqlmap.engine.builder.xml;
import com.ibatis.common.resources.*;
import com.ibatis.common.xml.*;
import com.ibatis.sqlmap.client.*;
import com.ibatis.sqlmap.engine.config.*;
import com.ibatis.sqlmap.engine.transaction.*;
import com.ibatis.sqlmap.engine.datasource.*;
import com.ibatis.sqlmap.engine.mapping.result.*;
import org.w3c.dom.Node;
import java.io.*;
import java.util.Properties;
//璇ョ被涓昏鏄鐞嗚В鏋怱QL Map閰嶇疆鏂囦欢
public class SqlMapConfigParser {
// parser鍙橀噺鏄В鏋怷ML鐨勬牳蹇�
protected final NodeletParser parser = new NodeletParser();
// state鍙橀噺鍏呭綋涓�釜涓棿鍙橀噺鐨勫鍣紝鎴栬�鏄竴涓厤缃俊鎭殑闂ㄦ埛
private XmlParserState state = new XmlParserState();
private boolean usingStreams = false;
public SqlMapConfigParser() {
// 楠岃瘉dtd鏂囦欢锛岃缃獙璇佸弬鏁�
parser.setValidation(true);
parser.setEntityResolver(new SqlMapClasspathEntityResolver());
//杩涜鍒濆鍖栫殑璧嬪�澶勭悊
addSqlMapConfigNodelets();
addGlobalPropNodelets();
addSettingsNodelets();
addTypeAliasNodelets();
addTypeHandlerNodelets();
addTransactionManagerNodelets();
addSqlMapNodelets();
addResultObjectFactoryNodelets();
}
public SqlMapClient parse(Reader reader, Properties props) {
if (props != null)
state.setGlobalProps(props);
return parse(reader);
}
//鍩轰簬瀛楃妯″紡瑙f瀽XML閰嶇疆鏂囦欢
public SqlMapClient parse(Reader reader) {
try {
usingStreams = false;
parser.parse(reader);
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)
state.setGlobalProps(props);
return parse(inputStream);
}
// 鍩轰簬瀛楄妭妯″紡瑙f瀽XML閰嶇疆鏂囦欢
public SqlMapClient parse(InputStream inputStream) {
try {
usingStreams = true;
parser.parse(inputStream);
return state.getConfig().getClient();
} catch (Exception e) {
throw new RuntimeException("Error occurred. Cause: " + e, e);
}
}
// 澶勭悊sqlMapConfig鏍硅妭鐐逛俊鎭紝琛ㄦ槑鍏跺凡缁忕粨鏉�
private void addSqlMapConfigNodelets() {
parser.addNodelet("/sqlMapConfig/end()", new Nodelet() {
public void process(Node node) throws Exception {
state.getConfig().finalizeSqlMapConfig();
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/properties淇℃伅锛屼骇鐢熶竴涓叏灞�殑Properties
private void addGlobalPropNodelets() {
parser.addNodelet("/sqlMapConfig/properties", new Nodelet() {
public void process(Node node) throws Exception {
// 鑾峰緱/sqlMapConfig/properties鑺傜偣涓嬬殑鍏ㄩ儴灞炴�鍊硷紝骞舵妸杩欎簺灞炴�鍊艰祴鍊肩粰Properties绫诲瀷鐨勫彉閲廰ttributes
Properties attributes = NodeletUtils.parseAttributes(node,
state.getGlobalProps());
String resource = attributes.getProperty("resource");
String url = attributes.getProperty("url");
// 鐢眘tate鍙橀噺浣滀负涓棿浣撲紶閫掍俊鎭�
state.setGlobalProperties(resource, url);
}
});
}
//澶勭悊鑺傜偣/sqlMapConfig/settings淇℃伅锛屼骇鐢熷叏灞�彉閲�
private void addSettingsNodelets() {
parser.addNodelet("/sqlMapConfig/settings", new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(node,
state.getGlobalProps());
SqlMapConfiguration config = state.getConfig();
String classInfoCacheEnabledAttr = attributes
.getProperty("classInfoCacheEnabled");
boolean classInfoCacheEnabled = (classInfoCacheEnabledAttr == null || "true"
.equals(classInfoCacheEnabledAttr));
config.setClassInfoCacheEnabled(classInfoCacheEnabled);
String lazyLoadingEnabledAttr = attributes
.getProperty("lazyLoadingEnabled");
boolean lazyLoadingEnabled = (lazyLoadingEnabledAttr == null || "true"
.equals(lazyLoadingEnabledAttr));
config.setLazyLoadingEnabled(lazyLoadingEnabled);
String statementCachingEnabledAttr = attributes
.getProperty("statementCachingEnabled");
boolean statementCachingEnabled = (statementCachingEnabledAttr == null || "true"
.equals(statementCachingEnabledAttr));
config.setStatementCachingEnabled(statementCachingEnabled);
String cacheModelsEnabledAttr = attributes
.getProperty("cacheModelsEnabled");
boolean cacheModelsEnabled = (cacheModelsEnabledAttr == null || "true"
.equals(cacheModelsEnabledAttr));
config.setCacheModelsEnabled(cacheModelsEnabled);
String enhancementEnabledAttr = attributes
.getProperty("enhancementEnabled");
boolean enhancementEnabled = (enhancementEnabledAttr == null || "true"
.equals(enhancementEnabledAttr));
config.setEnhancementEnabled(enhancementEnabled);
String useColumnLabelAttr = attributes
.getProperty("useColumnLabel");
boolean useColumnLabel = (useColumnLabelAttr == null || "true"
.equals(useColumnLabelAttr));
config.setUseColumnLabel(useColumnLabel);
String forceMultipleResultSetSupportAttr = attributes
.getProperty("forceMultipleResultSetSupport");
boolean forceMultipleResultSetSupport = "true"
.equals(forceMultipleResultSetSupportAttr);
config
.setForceMultipleResultSetSupport(forceMultipleResultSetSupport);
String defaultTimeoutAttr = attributes
.getProperty("defaultStatementTimeout");
Integer defaultTimeout = defaultTimeoutAttr == null ? null
: Integer.valueOf(defaultTimeoutAttr);
config.setDefaultStatementTimeout(defaultTimeout);
String useStatementNamespacesAttr = attributes
.getProperty("useStatementNamespaces");
boolean useStatementNamespaces = "true"
.equals(useStatementNamespacesAttr);
state.setUseStatementNamespaces(useStatementNamespaces);
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/typeAlias淇℃伅锛屽鐞嗗埆鍚嶏紙typeAlias锛夎浆鍖�
private void addTypeAliasNodelets() {
parser.addNodelet("/sqlMapConfig/typeAlias", new Nodelet() {
public void process(Node node) throws Exception {
Properties prop = NodeletUtils.parseAttributes(node, state
.getGlobalProps());
String alias = prop.getProperty("alias");
String type = prop.getProperty("type");
//鑾峰彇鍒悕鍙婂叾瀵瑰簲鐨凜lass绫诲瀷锛屾敞鍐屽埌TypeHandlerFactory宸ュ巶瀵硅薄涓�
state.getConfig().getTypeHandlerFactory().putTypeAlias(alias,
type);
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/typeHandler淇℃伅锛屽鍔犳柊鐨刯dbcType
private void addTypeHandlerNodelets() {
parser.addNodelet("/sqlMapConfig/typeHandler", new Nodelet() {
public void process(Node node) throws Exception {
Properties prop = NodeletUtils.parseAttributes(node, state
.getGlobalProps());
String jdbcType = prop.getProperty("jdbcType");
String javaType = prop.getProperty("javaType");
String callback = prop.getProperty("callback");
javaType = state.getConfig().getTypeHandlerFactory()
.resolveAlias(javaType);
callback = state.getConfig().getTypeHandlerFactory()
.resolveAlias(callback);
state.getConfig().newTypeHandler(
Resources.classForName(javaType), jdbcType,
Resources.instantiate(callback));
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager淇℃伅锛屽寘鎷瑃ransactionManager鍜宒ataSource
private void addTransactionManagerNodelets() {
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager/property鐨勪俊鎭紝杞寲鍒皌ransactionManager瀵硅薄鐨勭浉鍏冲睘鎬т腑
parser.addNodelet("/sqlMapConfig/transactionManager/property",
new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(
attributes.getProperty("value"), state
.getGlobalProps());
state.getTxProps().setProperty(name, value);
}
});
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager/锛岀敓鎴恡ransactionManager瀵硅薄骞惰繘琛岀粨鏉熷鐞�
parser.addNodelet("/sqlMapConfig/transactionManager/end()",
new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String type = attributes.getProperty("type");
boolean commitRequired = "true".equals(attributes
.getProperty("commitRequired"));
state.getConfig().getErrorContext().setActivity(
"configuring the transaction manager");
type = state.getConfig().getTypeHandlerFactory()
.resolveAlias(type);
TransactionManager txManager;
try {
state.getConfig().getErrorContext().setMoreInfo(
"Check the transaction manager type or class.");
TransactionConfig config = (TransactionConfig) Resources
.instantiate(type);
config.setDataSource(state.getDataSource());
state
.getConfig()
.getErrorContext()
.setMoreInfo(
"Check the transactio nmanager properties or configuration.");
config.setProperties(state.getTxProps());
config.setForceCommit(commitRequired);
config.setDataSource(state.getDataSource());
state.getConfig().getErrorContext().setMoreInfo(
null);
txManager = new TransactionManager(config);
} catch (Exception e) {
if (e instanceof SqlMapException) {
throw (SqlMapException) e;
} else {
throw new SqlMapException(
"Error initializing TransactionManager. Could not instantiate TransactionConfig. Cause: "
+ e, e);
}
}
state.getConfig().setTransactionManager(txManager);
}
});
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager/dataSource/property锛屽鐞哾ataSource鑺傜偣鐨刾roperty鍐呭
parser.addNodelet(
"/sqlMapConfig/transactionManager/dataSource/property",
new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(
attributes.getProperty("value"), state
.getGlobalProps());
state.getDsProps().setProperty(name, value);
}
});
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager/dataSource/end()锛屽姩鎬佸疄渚嬪寲dataSource瀵硅薄锛岀劧鍚庤繘琛屽睘鎬у垵濮嬪寲
parser.addNodelet("/sqlMapConfig/transactionManager/dataSource/end()",
new Nodelet() {
public void process(Node node) throws Exception {
state.getConfig().getErrorContext().setActivity(
"configuring the data source");
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String type = attributes.getProperty("type");
Properties props = state.getDsProps();
type = state.getConfig().getTypeHandlerFactory()
.resolveAlias(type);
try {
state.getConfig().getErrorContext().setMoreInfo(
"Check the data source type or class.");
DataSourceFactory dsFactory = (DataSourceFactory) Resources
.instantiate(type);
state.getConfig().getErrorContext().setMoreInfo(
"Check the data source properties or configuration.");
dsFactory.initialize(props);
state.setDataSource(dsFactory.getDataSource());
state.getConfig().getErrorContext().setMoreInfo(
null);
} catch (Exception e) {
if (e instanceof SqlMapException) {
throw (SqlMapException) e;
} else {
throw new SqlMapException(
"Error initializing DataSource. Could not instantiate DataSourceFactory. Cause: "
+ e, e);
}
}
}
});
}
//澶勭悊鑺傜偣/sqlMapConfig/sqlMap锛屽幓鑾峰彇sqlMap鐨勬槧灏勬枃浠讹紝鐒跺悗瀵瑰悇涓槧灏勬枃浠惰繘琛岃鍙栧鐞�
protected void addSqlMapNodelets() {
parser.addNodelet("/sqlMapConfig/sqlMap", new Nodelet() {
public void process(Node node) throws Exception {
state.getConfig().getErrorContext().setActivity(
"loading the SQL Map resource");
Properties attributes = NodeletUtils.parseAttributes(node,
state.getGlobalProps());
String resource = attributes.getProperty("resource");
String url = attributes.getProperty("url");
if (usingStreams) {
//閲囩敤瀛楄妭娴佹ā寮忔潵璇诲彇鏂囦欢
InputStream inputStream = null;
if (resource != null) {
state.getConfig().getErrorContext().setResource(
resource);
inputStream = Resources.getResourceAsStream(resource);
} else if (url != null) {
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(state).parse(inputStream);
} else {
// 閲囩敤瀛楃娴佹ā寮忔潵璇诲彇鏂囦欢
Reader reader = null;
if (resource != null) {
state.getConfig().getErrorContext().setResource(
resource);
reader = Resources.getResourceAsReader(resource);
} else if (url != null) {
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(state).parse(reader);
}
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/resultObjectFactory锛屽垵濮嬪寲鏂扮殑resultObjectFactory
private void addResultObjectFactoryNodelets() {
parser.addNodelet("/sqlMapConfig/resultObjectFactory", new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(node,
state.getGlobalProps());
String type = attributes.getProperty("type");
state.getConfig().getErrorContext().setActivity(
"configuring the Result Object Factory");
ResultObjectFactory rof;
try {
rof = (ResultObjectFactory) Resources.instantiate(type);
state.getConfig().setResultObjectFactory(rof);
} catch (Exception e) {
throw new SqlMapException(
"Error instantiating resultObjectFactory: " + type,
e);
}
}
});
parser.addNodelet("/sqlMapConfig/resultObjectFactory/property",
new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(
attributes.getProperty("value"), state
.getGlobalProps());
state.getConfig().getDelegate()
.getResultObjectFactory().setProperty(name,
value);
}
});
}
}
import com.ibatis.common.resources.*;
import com.ibatis.common.xml.*;
import com.ibatis.sqlmap.client.*;
import com.ibatis.sqlmap.engine.config.*;
import com.ibatis.sqlmap.engine.transaction.*;
import com.ibatis.sqlmap.engine.datasource.*;
import com.ibatis.sqlmap.engine.mapping.result.*;
import org.w3c.dom.Node;
import java.io.*;
import java.util.Properties;
//璇ョ被涓昏鏄鐞嗚В鏋怱QL Map閰嶇疆鏂囦欢
public class SqlMapConfigParser {
// parser鍙橀噺鏄В鏋怷ML鐨勬牳蹇�
protected final NodeletParser parser = new NodeletParser();
// state鍙橀噺鍏呭綋涓�釜涓棿鍙橀噺鐨勫鍣紝鎴栬�鏄竴涓厤缃俊鎭殑闂ㄦ埛
private XmlParserState state = new XmlParserState();
private boolean usingStreams = false;
public SqlMapConfigParser() {
// 楠岃瘉dtd鏂囦欢锛岃缃獙璇佸弬鏁�
parser.setValidation(true);
parser.setEntityResolver(new SqlMapClasspathEntityResolver());
//杩涜鍒濆鍖栫殑璧嬪�澶勭悊
addSqlMapConfigNodelets();
addGlobalPropNodelets();
addSettingsNodelets();
addTypeAliasNodelets();
addTypeHandlerNodelets();
addTransactionManagerNodelets();
addSqlMapNodelets();
addResultObjectFactoryNodelets();
}
public SqlMapClient parse(Reader reader, Properties props) {
if (props != null)
state.setGlobalProps(props);
return parse(reader);
}
//鍩轰簬瀛楃妯″紡瑙f瀽XML閰嶇疆鏂囦欢
public SqlMapClient parse(Reader reader) {
try {
usingStreams = false;
parser.parse(reader);
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)
state.setGlobalProps(props);
return parse(inputStream);
}
// 鍩轰簬瀛楄妭妯″紡瑙f瀽XML閰嶇疆鏂囦欢
public SqlMapClient parse(InputStream inputStream) {
try {
usingStreams = true;
parser.parse(inputStream);
return state.getConfig().getClient();
} catch (Exception e) {
throw new RuntimeException("Error occurred. Cause: " + e, e);
}
}
// 澶勭悊sqlMapConfig鏍硅妭鐐逛俊鎭紝琛ㄦ槑鍏跺凡缁忕粨鏉�
private void addSqlMapConfigNodelets() {
parser.addNodelet("/sqlMapConfig/end()", new Nodelet() {
public void process(Node node) throws Exception {
state.getConfig().finalizeSqlMapConfig();
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/properties淇℃伅锛屼骇鐢熶竴涓叏灞�殑Properties
private void addGlobalPropNodelets() {
parser.addNodelet("/sqlMapConfig/properties", new Nodelet() {
public void process(Node node) throws Exception {
// 鑾峰緱/sqlMapConfig/properties鑺傜偣涓嬬殑鍏ㄩ儴灞炴�鍊硷紝骞舵妸杩欎簺灞炴�鍊艰祴鍊肩粰Properties绫诲瀷鐨勫彉閲廰ttributes
Properties attributes = NodeletUtils.parseAttributes(node,
state.getGlobalProps());
String resource = attributes.getProperty("resource");
String url = attributes.getProperty("url");
// 鐢眘tate鍙橀噺浣滀负涓棿浣撲紶閫掍俊鎭�
state.setGlobalProperties(resource, url);
}
});
}
//澶勭悊鑺傜偣/sqlMapConfig/settings淇℃伅锛屼骇鐢熷叏灞�彉閲�
private void addSettingsNodelets() {
parser.addNodelet("/sqlMapConfig/settings", new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(node,
state.getGlobalProps());
SqlMapConfiguration config = state.getConfig();
String classInfoCacheEnabledAttr = attributes
.getProperty("classInfoCacheEnabled");
boolean classInfoCacheEnabled = (classInfoCacheEnabledAttr == null || "true"
.equals(classInfoCacheEnabledAttr));
config.setClassInfoCacheEnabled(classInfoCacheEnabled);
String lazyLoadingEnabledAttr = attributes
.getProperty("lazyLoadingEnabled");
boolean lazyLoadingEnabled = (lazyLoadingEnabledAttr == null || "true"
.equals(lazyLoadingEnabledAttr));
config.setLazyLoadingEnabled(lazyLoadingEnabled);
String statementCachingEnabledAttr = attributes
.getProperty("statementCachingEnabled");
boolean statementCachingEnabled = (statementCachingEnabledAttr == null || "true"
.equals(statementCachingEnabledAttr));
config.setStatementCachingEnabled(statementCachingEnabled);
String cacheModelsEnabledAttr = attributes
.getProperty("cacheModelsEnabled");
boolean cacheModelsEnabled = (cacheModelsEnabledAttr == null || "true"
.equals(cacheModelsEnabledAttr));
config.setCacheModelsEnabled(cacheModelsEnabled);
String enhancementEnabledAttr = attributes
.getProperty("enhancementEnabled");
boolean enhancementEnabled = (enhancementEnabledAttr == null || "true"
.equals(enhancementEnabledAttr));
config.setEnhancementEnabled(enhancementEnabled);
String useColumnLabelAttr = attributes
.getProperty("useColumnLabel");
boolean useColumnLabel = (useColumnLabelAttr == null || "true"
.equals(useColumnLabelAttr));
config.setUseColumnLabel(useColumnLabel);
String forceMultipleResultSetSupportAttr = attributes
.getProperty("forceMultipleResultSetSupport");
boolean forceMultipleResultSetSupport = "true"
.equals(forceMultipleResultSetSupportAttr);
config
.setForceMultipleResultSetSupport(forceMultipleResultSetSupport);
String defaultTimeoutAttr = attributes
.getProperty("defaultStatementTimeout");
Integer defaultTimeout = defaultTimeoutAttr == null ? null
: Integer.valueOf(defaultTimeoutAttr);
config.setDefaultStatementTimeout(defaultTimeout);
String useStatementNamespacesAttr = attributes
.getProperty("useStatementNamespaces");
boolean useStatementNamespaces = "true"
.equals(useStatementNamespacesAttr);
state.setUseStatementNamespaces(useStatementNamespaces);
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/typeAlias淇℃伅锛屽鐞嗗埆鍚嶏紙typeAlias锛夎浆鍖�
private void addTypeAliasNodelets() {
parser.addNodelet("/sqlMapConfig/typeAlias", new Nodelet() {
public void process(Node node) throws Exception {
Properties prop = NodeletUtils.parseAttributes(node, state
.getGlobalProps());
String alias = prop.getProperty("alias");
String type = prop.getProperty("type");
//鑾峰彇鍒悕鍙婂叾瀵瑰簲鐨凜lass绫诲瀷锛屾敞鍐屽埌TypeHandlerFactory宸ュ巶瀵硅薄涓�
state.getConfig().getTypeHandlerFactory().putTypeAlias(alias,
type);
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/typeHandler淇℃伅锛屽鍔犳柊鐨刯dbcType
private void addTypeHandlerNodelets() {
parser.addNodelet("/sqlMapConfig/typeHandler", new Nodelet() {
public void process(Node node) throws Exception {
Properties prop = NodeletUtils.parseAttributes(node, state
.getGlobalProps());
String jdbcType = prop.getProperty("jdbcType");
String javaType = prop.getProperty("javaType");
String callback = prop.getProperty("callback");
javaType = state.getConfig().getTypeHandlerFactory()
.resolveAlias(javaType);
callback = state.getConfig().getTypeHandlerFactory()
.resolveAlias(callback);
state.getConfig().newTypeHandler(
Resources.classForName(javaType), jdbcType,
Resources.instantiate(callback));
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager淇℃伅锛屽寘鎷瑃ransactionManager鍜宒ataSource
private void addTransactionManagerNodelets() {
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager/property鐨勪俊鎭紝杞寲鍒皌ransactionManager瀵硅薄鐨勭浉鍏冲睘鎬т腑
parser.addNodelet("/sqlMapConfig/transactionManager/property",
new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(
attributes.getProperty("value"), state
.getGlobalProps());
state.getTxProps().setProperty(name, value);
}
});
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager/锛岀敓鎴恡ransactionManager瀵硅薄骞惰繘琛岀粨鏉熷鐞�
parser.addNodelet("/sqlMapConfig/transactionManager/end()",
new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String type = attributes.getProperty("type");
boolean commitRequired = "true".equals(attributes
.getProperty("commitRequired"));
state.getConfig().getErrorContext().setActivity(
"configuring the transaction manager");
type = state.getConfig().getTypeHandlerFactory()
.resolveAlias(type);
TransactionManager txManager;
try {
state.getConfig().getErrorContext().setMoreInfo(
"Check the transaction manager type or class.");
TransactionConfig config = (TransactionConfig) Resources
.instantiate(type);
config.setDataSource(state.getDataSource());
state
.getConfig()
.getErrorContext()
.setMoreInfo(
"Check the transactio nmanager properties or configuration.");
config.setProperties(state.getTxProps());
config.setForceCommit(commitRequired);
config.setDataSource(state.getDataSource());
state.getConfig().getErrorContext().setMoreInfo(
null);
txManager = new TransactionManager(config);
} catch (Exception e) {
if (e instanceof SqlMapException) {
throw (SqlMapException) e;
} else {
throw new SqlMapException(
"Error initializing TransactionManager. Could not instantiate TransactionConfig. Cause: "
+ e, e);
}
}
state.getConfig().setTransactionManager(txManager);
}
});
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager/dataSource/property锛屽鐞哾ataSource鑺傜偣鐨刾roperty鍐呭
parser.addNodelet(
"/sqlMapConfig/transactionManager/dataSource/property",
new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(
attributes.getProperty("value"), state
.getGlobalProps());
state.getDsProps().setProperty(name, value);
}
});
// 澶勭悊鑺傜偣/sqlMapConfig/transactionManager/dataSource/end()锛屽姩鎬佸疄渚嬪寲dataSource瀵硅薄锛岀劧鍚庤繘琛屽睘鎬у垵濮嬪寲
parser.addNodelet("/sqlMapConfig/transactionManager/dataSource/end()",
new Nodelet() {
public void process(Node node) throws Exception {
state.getConfig().getErrorContext().setActivity(
"configuring the data source");
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String type = attributes.getProperty("type");
Properties props = state.getDsProps();
type = state.getConfig().getTypeHandlerFactory()
.resolveAlias(type);
try {
state.getConfig().getErrorContext().setMoreInfo(
"Check the data source type or class.");
DataSourceFactory dsFactory = (DataSourceFactory) Resources
.instantiate(type);
state.getConfig().getErrorContext().setMoreInfo(
"Check the data source properties or configuration.");
dsFactory.initialize(props);
state.setDataSource(dsFactory.getDataSource());
state.getConfig().getErrorContext().setMoreInfo(
null);
} catch (Exception e) {
if (e instanceof SqlMapException) {
throw (SqlMapException) e;
} else {
throw new SqlMapException(
"Error initializing DataSource. Could not instantiate DataSourceFactory. Cause: "
+ e, e);
}
}
}
});
}
//澶勭悊鑺傜偣/sqlMapConfig/sqlMap锛屽幓鑾峰彇sqlMap鐨勬槧灏勬枃浠讹紝鐒跺悗瀵瑰悇涓槧灏勬枃浠惰繘琛岃鍙栧鐞�
protected void addSqlMapNodelets() {
parser.addNodelet("/sqlMapConfig/sqlMap", new Nodelet() {
public void process(Node node) throws Exception {
state.getConfig().getErrorContext().setActivity(
"loading the SQL Map resource");
Properties attributes = NodeletUtils.parseAttributes(node,
state.getGlobalProps());
String resource = attributes.getProperty("resource");
String url = attributes.getProperty("url");
if (usingStreams) {
//閲囩敤瀛楄妭娴佹ā寮忔潵璇诲彇鏂囦欢
InputStream inputStream = null;
if (resource != null) {
state.getConfig().getErrorContext().setResource(
resource);
inputStream = Resources.getResourceAsStream(resource);
} else if (url != null) {
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(state).parse(inputStream);
} else {
// 閲囩敤瀛楃娴佹ā寮忔潵璇诲彇鏂囦欢
Reader reader = null;
if (resource != null) {
state.getConfig().getErrorContext().setResource(
resource);
reader = Resources.getResourceAsReader(resource);
} else if (url != null) {
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(state).parse(reader);
}
}
});
}
// 澶勭悊鑺傜偣/sqlMapConfig/resultObjectFactory锛屽垵濮嬪寲鏂扮殑resultObjectFactory
private void addResultObjectFactoryNodelets() {
parser.addNodelet("/sqlMapConfig/resultObjectFactory", new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(node,
state.getGlobalProps());
String type = attributes.getProperty("type");
state.getConfig().getErrorContext().setActivity(
"configuring the Result Object Factory");
ResultObjectFactory rof;
try {
rof = (ResultObjectFactory) Resources.instantiate(type);
state.getConfig().setResultObjectFactory(rof);
} catch (Exception e) {
throw new SqlMapException(
"Error instantiating resultObjectFactory: " + type,
e);
}
}
});
parser.addNodelet("/sqlMapConfig/resultObjectFactory/property",
new Nodelet() {
public void process(Node node) throws Exception {
Properties attributes = NodeletUtils.parseAttributes(
node, state.getGlobalProps());
String name = attributes.getProperty("name");
String value = NodeletUtils.parsePropertyTokens(
attributes.getProperty("value"), state
.getGlobalProps());
state.getConfig().getDelegate()
.getResultObjectFactory().setProperty(name,
value);
}
});
}
}
发表评论
-
SqlMapClientImpl
2011-01-14 15:07 3304/* * Copyright 2004 Clinton B ... -
SqlMapConfiguration
2011-01-14 14:49 1089package com.ibatis.sqlmap.engin ... -
XmlParserState
2011-01-14 12:52 887package com.ibatis.sqlmap.engin ... -
SqlMapClientBuilder
2011-01-14 12:45 3183/* * Copyright 2004 Clinton B ... -
NodeletParser
2011-01-14 09:59 1488package com.ibatis.common.xml; ...
相关推荐
它通过SqlMapConfigParser解析SqlMapConfig.xml文件,创建SqlMap实例。SqlMap则包含了对数据库操作的具体配置,包括数据源、事务管理等。对于SQL语句的执行,SqlMapClient使用Executor接口,该接口定义了不同类型的...
- **Spring与MyBatis的集成**:使用Spring的MyBatisNamespaceHandler和SqlMapConfigParser处理MyBatis的配置,使Spring能够管理MyBatis的生命周期。 4. **SpringMVCIbatisSmartClient**: - 这个文件名可能指的是...
机器人路径优化:基于强化学习Q-learning算法的移动机器人路径优化MATLAB
本项目是一款支持Java、Kotlin和C++的多语言自定义控件通用库,包含176个文件,涵盖43个PNG图片、41个Java源文件、40个XML布局文件、21个Kotlin源文件、4个Gradle配置文件及其他相关文件。库提供详尽的API文档,支持持续集成与维护,旨在提供便捷、高效的自定义控件开发体验。
本项目为基于树莓派的HarmonyOS系统移植与开发设计源码,包含116个文件,涵盖20个头文件、19个Markdown文档、16个C语言源文件、7个PNG图片文件、7个PDF文件、4个二进制文件、4个ELF文件、4个gn文件、3个HCS文件,以及使用C、Shell和Python等多种编程语言编写。该源码旨在实现HarmonyOS系统在树莓派平台上的移植与应用开发。
【毕设项目】springboot校友社交系统 答辩用的 PPT
全国大学生电子设计大赛项目合集全国电赛优秀作品STM32项目(ST大赛三等奖作品)超声波自拍神器
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
全国大学生电子设计大赛项目合集全国电赛优秀作品开源基于STC15W4K61S4的微型四旋翼
微信小程序模块化开发框架-abrator
原卡GPU-Z保存下来的
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
微信小程序开发资源总结-100款精彩微信微信
ADC建模,ADC数字校准,模拟ic设计 模数转器, ADC MATLAB建模, 包含实例和说明 ADC数字校准 ,simulink模型 14bit 100MSAR ADC 12位流水线 pipelined ADC 模拟IC,ADC建模 多种sar adc和流水线的matlab模型 ADC的动态fft,静态特性inl、dnl仿真 多种 sarADCMATLAB和simulink 建模全都整合在里面了 实用SAR ADC的Matlab Simulink Model,可用于非理想效应的行为级仿真一个实用的SAR ADC的行为级模型。 对多种非理想效应都进行了建模仿真,包括非线性采样,比较器offset,以及电容适配 ADC的动态fft,静态特性inl、dnl仿真 教程,动态静态参数分析。 东西很多,就不一一介绍了。
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
微信小程序Redux与_cechat eapp Redux绑定
golang,微信小程序,电子商务系统_高国
该项目为基于Java语言的VEP视频播放器解码设计源码,总共有23个文件,其中包含7个Java源文件、4个属性文件以及必要的配置和构建文件。
微信小程序图表库,微信小程式图表_wx-Charts
该系统是一套基于Java语言的蓝旭春季后端考核题解设计源码,由24个文件组成,包括11个Java源文件、7个XML配置文件、1个Git忽略文件、1个mvnw文件、1个cmd脚本、1个Markdown文档、1个CSV文件和1个HTML文件。项目旨在提供蓝旭春季后端考核的题解实现,适合后端开发人员参考和学习使用。