- 浏览: 114240 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (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 3311/* * Copyright 2004 Clinton B ... -
SqlMapConfiguration
2011-01-14 14:49 1098package com.ibatis.sqlmap.engin ... -
XmlParserState
2011-01-14 12:52 893package com.ibatis.sqlmap.engin ... -
SqlMapClientBuilder
2011-01-14 12:45 3192/* * Copyright 2004 Clinton B ... -
NodeletParser
2011-01-14 09:59 1493package com.ibatis.common.xml; ...
相关推荐
它通过SqlMapConfigParser解析SqlMapConfig.xml文件,创建SqlMap实例。SqlMap则包含了对数据库操作的具体配置,包括数据源、事务管理等。对于SQL语句的执行,SqlMapClient使用Executor接口,该接口定义了不同类型的...
- **Spring与MyBatis的集成**:使用Spring的MyBatisNamespaceHandler和SqlMapConfigParser处理MyBatis的配置,使Spring能够管理MyBatis的生命周期。 4. **SpringMVCIbatisSmartClient**: - 这个文件名可能指的是...
基于springboot教育资源共享平台源码数据库文档.zip
linux开发篇,配套视频:https://www.bilibili.com/list/474327672?sid=4493702&spm_id_from=333.999.0.0&desc=1
ReadEra 这个阅读应用能够打开下列任何格式的文档: EPUB, PDF, DOC, RTF, TXT, DJVU, FB2, MOBI, 和 CHM. 基本上来说,你可以用它阅读你的设备内存中的任何书籍或者文本文档。 这个应用与划分成章节的文档兼。,有一个书签功能,可以在你阅读的时候,自动保存你的进度。另外,它让你更改页面模式,从几种不同的主题中进行挑选(夜间,白天,棕黑色调,还有控制台)。
软件环境:KEIL4 硬件环境:STM32单片机+舵机 控制原理:通过控制输出信号的占空比调节舵机旋转的角度
基于springboot仓库管理系统源码数据库文档.zip
酒店管理系统源码C++实现的毕业设计项目源码.zip,个人大四的毕业设计、经导师指导并认可通过的高分设计项目,评审分98.5分。主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。 酒店管理系统源码C++实现的毕业设计项目源码.zip,酒店管理系统源码C++实现的毕业设计项目源码.zip个人大四的毕业设计、经导师指导并认可通过的高分设计项目,评审分98.5分。主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。酒店管理系统源码C++实现的毕业设计项目源码.zip酒店管理系统源码C++实现的毕业设计项目源码.zip酒店管理系统源码C++实现的毕业设计项目源码.zip,个人大四的毕业设计、经导师指导并认可通过的高分设计项目,评审分98.5分。主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。酒店管理系统源码C++实现的毕业设计项目源码.zip,个人大四的毕业设计、经导师指导并认可通过的高分设计项目,评审分98.5分。主要针对计算机相关专业的正在做毕
58商铺全新UI试客试用平台网站源码
springboot vue3前后端分离 基于SpringBoot+Vue的轻量级定时任务管理系统.zip
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过严格测试运行成功才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
4D毫米波雷达点云数据处理方法研究.caj
S M 2 2 5 8 X T 量产工具供大家下载使用
基于springboot的文物管理系统源码数据库文档.zip
基于springboot的电影院售票管理系统源码数据库文档.zip
基于Java web 实现的仓库管理系统源码,适用于初学者了解Java web的开发过程以及仓库管理系统的实现。
美容美发项目,使用django框架,前后端一体化项目
在线票务:2023年中国在线票务行业市场规模约为24.99亿元,挖掘市场蓝海新机遇 在数字浪潮的席卷下,传统的票务销售模式正经历着前所未有的变革。纸质门票逐渐淡出人们的视野,取而代之的是便捷、高效的数字和移动票务。这一转变不仅为消费者带来了前所未有的购票体验,更为在线票务平台开辟了广阔的发展空间和市场机遇。随着国民经济的持续增长和文体娱乐行业的蓬勃发展,中国在线票务行业正站在时代的风口浪尖,等待着每一位有志之士的加入。那么,这片蓝海市场究竟蕴藏着怎样的潜力?又该如何把握机遇,实现突破?让我们一同探索。 市场概况: 近年来,中国在线票务行业市场规模持续扩大,展现出强劲的增长势头。据QYResearch数据显示,2023年中国在线票务行业市场规模约为24.99亿元,尽管受到宏观经济的影响,市场规模增速放缓,但整体趋势依然向好。这一增长主要得益于国民人均收入的不断提高、电影及演出行业的快速发展以及政府政策的支持。例如,2023年财政部、国家电影局发布的《关于阶段性免征国家电影事业发展专项资金政策的公告》,为电影行业注入了强劲动力,进而推动了在线票务市场规模的扩大。 技术创新与趋势: 技术进步
基于SpringBoot的养老院管理系统源码数据库文档.zip
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过严格测试运行成功才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。