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
相關文章
- 使用xml檔案配置SSM整合XMLSSM
- 前端如何處理xml配置檔案?前端XML
- Maven的settings.xml檔案配置MavenXML
- springboot yml 配置檔案注入Map,ListSpring Boot
- 【SSM框架整合】專案xml檔案、properties等檔案的配置SSM框架XML
- springMVC---配置檔案解析(web.xml)SpringMVCWebXML
- Struts-config.xml配置檔案講解XML
- xml檔案XML
- Mybatis 學習筆記(一)——配置檔案SqlMapConfig.xml和對映檔案Mapper.xmlMyBatis筆記SQLXMLAPP
- Hadoop配置core-site.xml檔案詳解HadoopXML
- SSM整合之使用配置類替換xml配置檔案(2)SSMXML
- eclipse配置Maven Settings.xml檔案報錯:Could not read settings.xmlEclipseMavenXML
- mybatis的全域性配置檔案SqlMapConfig.xml解析MyBatisSQLXML
- Logback簡介及配置檔案logback.xml詳解XML
- 在web.xml檔案中配置Servlet時,主要配置哪些資訊?WebXMLServlet
- AndroidMainfest.xml檔案AndroidAIXML
- python XML 檔案解析PythonXML
- jdom解析xml檔案XML
- xml是什麼格式的檔案 xml檔案怎麼開啟XML
- java 語音用xml檔案實現圖形介面 xml檔案JavaXML
- SpringBoot通過yml和xml檔案配置日誌輸出Spring BootXML
- 解決properties、xml等配置檔案無法找到問題XML
- mybatis原始碼配置檔案解析之五:解析mappers標籤(解析XML對映檔案)MyBatis原始碼APPXML
- 使用 Java 解析XML檔案JavaXML
- Go xml檔案處理GoXML
- mybatis之sql查詢配置檔案resultType和resultMapMyBatisSQL
- Python解析XML檔案生成HTMLPythonXMLHTML
- nodejs xmlreader 讀寫xml檔案NodeJSXML
- C#讀取Xml檔案C#XML
- ajax與XML檔案互動XML
- 給XML檔案定義DTDXML
- 清單檔案 AndroidManifest.xmlAndroidXML
- Java系列:讀取XML檔案JavaXML
- Linux shell格式化XML檔案LinuxXML
- 使用C#讀寫xml檔案C#XML
- XML 檔案解析實踐 (DOM 解析)XML
- 匹配 XML 檔案正規表示式XML
- php獲取xml檔案內容PHPXML
- Git配置配置檔案Git