SQL Map XML配置檔案。
SQL Map使用XML配置檔案統一配置不同的屬性,包括DataSource的詳細配置資訊,SQL Map和其他可選屬性,如執行緒管理等。以下是SQL Map配置檔案的一個例子:
SqlMapConfig.xml
<?xml version ="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap Config PUBLIC "_//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<!-- Always ensure to use the correct XML headers as above! -->
<sqlMapConfig>
<!-- The properties (name = value) in the file specified here can be used placeholders in this config file (e.g."${driver}". The file is relative to the classpath and is completely optional.) -->
<properties resource = "examples/sqlmap/maps/SqlMapConfigExample.properties" />
<!-- These settings control SqlMapClient configuration details, primarily to do with transaction management. They are all optional(more detail later in this document). -->
<settings
cacheModelsEnabled = "true"
enhancementEnabled = "true"
lazyLoadingEnabled = "true"
maxRequests = "32"
maxSessions = "10"
maxTransactions = "5"
useStatementNamespaces = "false"
/>
<!-- Type alias allow you to use a shorter name for long fully qualified class names. -->
<typeAlias alias = "order" type ="testdomain.Order" />
<!-- Configure a datasource to use with this SQL Map using SimpleDataSource. Notice the use of the properties from the above resource -->
<transactionManager type = "JDBC">
<dataSource type = "SIMPLE">
<property name = "JDBC.Driver" value ="${driver}" />
<property name = "JDBC.ConnectionURL" value = "${url}" />
<property name = "JDBC.Username" value ="${username}" />
<property name = "JDBC.Password" value = "${password}" />
<property name = "JDBC.DefaultAutoCommit" value = "true" />
<property name = "Pool.MaximumActiveConnections" value ="10" />
<property name = "Pool.MaximumldleConnections" value = "5" />
<property name = "Pool.MaximumCheckoutTime" value = "120000" />
<property name = "Pool.TimeToWait" value = "500" />
<property name = "Pool.PingQuery" value = "select 1 from ACCOUNT" />
<property name = "Pool.PingEnabled" value = "false" />
<property name = "Pool.PingConnectionsOlderThan" value = "1" />
<property name = "Pool.PingConnectionsNotUsedFor" value = "1" />
</dataSource>
</transactionManager>
<!-- Identify all SQL Map XML files to be loaded by this SQL map. Notice the paths are relative to the classpath. For now,we only have one... -->
<sqlMap resource = "examples/sqlmap/maps/Person.xml"/>
</sqlMapConfig>
以下詳細討論SQL Map配置檔案的各組成部分。
<properties>元素
SQL Map配置檔案擁有唯一的<properties>元素,用於在配置檔案中使用標準的Java屬性檔案(name = value)。這樣做後,在屬性檔案中定義的屬性可以作為變數在SQL Map配置檔案及其包含的所有SQL Map對映檔案中引用。例如,如果屬性檔案中包含屬性:
driver = org.hsqldb.jdbcDriver
SQL Map配置檔案及其每個對映檔案都可以使用佔位符${driver}來代表值org.hsqldb.jdbcDriver。例如:
<property name = "JDBC.Driver" value = "${driver}" />
這個元素在開發,測試和部署各階段都很有用。他可以使在多個不同的環境重新配置應用和使用自動生成工具(如ANT)變得容易。屬性檔案可以從類路徑中載入(使用resource屬性),也可以從合法的URL中載入(使用url屬性)。例如,要載入固定路徑的屬性檔案,使用:
<properties url = "file:///c:/config/my.properties" />
<setting>元素
<setting>元素用於配置和優化SqlMapClient例項的各選項。<setting>元素本身及其所有的屬性都是可選的。以下列出了<setting>元素支援的屬性及其功能:
- maxRequests
- maxSessions
- maxTransactions
- cacheModelsEnabled
- lazyLoadingEnabled
- enhancementEnabled
- useStatementNamespaces
- 事務管理器別名:
- Data Source Factory別名
- JDBC:
- JTA:
- EXTERNAL:
- SimpleDataSourceFactory
<transactionManager type = "JDBC">
<dataSource type = "SIMPLE">
<property name = "JDBC.Driver" value ="org.postgresql.Driver" />
<property name = "JDBC.ConnectionURL" value = "jdbc:postgresql://server:5432/dbname" />
<property name = "JDBC.Username" value ="user" />
<property name = "JDBC.Password" value = "password" />
<!-- OPTIONAL PROPERTIES BELOW -->
<property name = "Pool.MaximumActiveConnections" value ="10" />
<property name = "Pool.MaximumldleConnections" value = "5" />
<property name = "Pool.MaximumCheckoutTime" value = "120000" />
<property name = "Pool.TimeToWait" value = "10000" />
<property name = "Pool.PingQuery" value = "select * from dual" />
<property name = "Pool.PingEnabled" value = "false" />
<property name = "Pool.PingConnectionsOlderThan" value = "0" />
<property name = "Pool.PingConnectionsNotUsedFor" value = "0" />
</dataSource>
</transactionManager>
- DbcpDataSourceFactory
<transactionManager type = "JDBC">
<dataSource type = "DBCP">
<property name = "JDBC.Driver" value =${driver}" />
<property name = "JDBC.ConnectionURL" value = "${url}" />
<property name = "JDBC.Username" value ="${username}" />
<property name = "JDBC.Password" value = "${password}" />
<!-- OPTIONAL PROPERTIES BELOW -->
<property name = "Pool.MaximumActiveConnections" value ="10" />
<property name = "Pool.MaximumldleConnections" value = "5" />
<property name = "Pool.MaximumWait" value = "60000" />
<! -- Use of the validation query can be problematic. IF you have difficulty, try without it. -->
<property name = "Pool.ValidationQuery" value = "select * from ACCOUNT" />
<property name = "Pool.LogAbandoned" value = "false" />
<property name = "Pool.RemoveAbandoned" value = "false" />
<property name = "Pool.RemoveAbandonedTimeout" value = "50000" />
</dataSource>
</transactionManager>
- JndiDataSourceFactory
相關文章
- Spring中注入List,Set,Map,Properties的xml檔案配置方法SpringXML
- Sql server:從XML檔案中讀取配置資訊SQLServerXML
- 使用xml檔案配置SSM整合XMLSSM
- springmvc基於xml配置檔案SpringMVCXML
- 【SSM框架整合】專案xml檔案、properties等檔案的配置SSM框架XML
- Maven的settings.xml檔案配置MavenXML
- Maven pom.xml檔案配置詳解MavenXML
- web.xml檔案配置的說明WebXML
- springboot yml 配置檔案注入Map,ListSpring Boot
- xml檔案XML
- springMVC---配置檔案解析(web.xml)SpringMVCWebXML
- 【Mycat】schmea.xml配置檔案學習XML
- SSM框架ApplicationContext.xml檔案配置SSM框架APPContextXML
- applicationContext.xml最基本配置檔案APPContextXML
- android manifest.xml 配置檔案 雜AndroidXML
- 詳解Tomcat 配置檔案server.xmlTomcatServerXML
- AndroidManifest.xml配置檔案詳解 .AndroidXML
- 關於 Pentaho 的配置檔案 pentaho.xmlXML
- 文摘:在EJB中讀取XML配置檔案XML
- web.xml 檔案 配置載入順序WebXML
- SSM整合之使用配置類替換xml配置檔案(2)SSMXML
- Maven之pom.xml與setting.xml配置檔案詳解MavenXML
- 匯入xml檔案到SQL Server 2005XMLSQLServer
- Struts-config.xml配置檔案講解XML
- Tomcat 7 server.xml 配置檔案詳解TomcatServerXML
- DWR幫助文件-dwr.xml檔案的配置XML
- Hadoop配置core-site.xml檔案詳解HadoopXML
- 在web.xml檔案中配置Servlet時,主要配置哪些資訊?WebXMLServlet
- SQL Server解除安裝配置檔案SQLServer
- Mybatis 學習筆記(一)——配置檔案SqlMapConfig.xml和對映檔案Mapper.xmlMyBatis筆記SQLXMLAPP
- SQL Server中讀取XML檔案的簡單做法SQLServerXML
- spring applicationContext.xml 配置檔案 詳解SpringAPPContextXML
- spring application.xml中載入配置檔案SpringAPPXML
- 通過xml配置檔案定義及佈局元件XML元件
- Structs的配置檔案都在一個檔案(struct-config.xml)中嗎?StructXML
- jdom解析xml檔案XML
- [XML與properties檔案]XML
- GData解析XML檔案XML