IBATIS2.0 instructions (2) - Configuration articles (1) [original]

xiaoxiao2021-03-06  106

First, SQL MAP XML configuration file SQL MAP uses different setup properties, including DataSource's detailed configuration information, SQL MAP, and other optional properties, such as thread management, etc.

The following is an example of a SQL Map configuration file: sqlmapconfig.xml <-! These settings control SqlMapClient configuration details, primarily to do with transactionmanagement They are all optional (more detail later in this document) -..> <-! Type aliases allow you to use a shorter name for long fully qualified class "-> <-! Configure a datasource to use with this SQL Map using SimpleDataSource.Notice the use of the properties from the above resource -> <

property name = "JDBC.Password" value = "$ {password}" /> < property name = "Pool.PingConnectionsNotUsedFor" value = "1" /> <-! Identify all SQL Map XML files to be loaded by this SQL map Notice the pathsare relative to the classpath For.. Now, We Only Have ONE ... -> The components of the SQL Map profile are discussed in detail. (1) Element SQL MAP configuration file has unique elements for using standard Java property files (name = value) in the configuration file. The properties defined in the properties file can be referenced as variables in the SQL MAP profile and all SQL MAP mapping files therebetween. For example, if the property file contains properties: driver = org.hsqldb.jdbcdriver

SQL MAP configuration files and each mapping file can be used to represent values ​​org.hsqldb.jdbcdriver.

For example:

This element is useful in development, testing and deployment. It makes it easy to reconfigure applications in multiple different environments and use automatic build tools such as Ant.

The Java property file can be imported through class paths, or by valid URL import.

For example: (2) element element is used to configure and optimize the SQLMAPClient instance created with an XML configuration file. elements and all its properties are optional. The properties and features supported by elements are listed below:

1. MaxExecute also executes a maximum number of SQL Statement, which is greater than the thread of this value will block until another thread exits. Different DBMs have different limits. Example: maxexecute = "256" Default: 512

Under normal circumstances, this value is greater than 10, and the value is larger than the value set by the maxsessions and the maxTransactions. Typically, reduced maximum number of access can improve the efficiency of execution.

2. MAXSESSIONS refers to the number of session (or clients) in active status within a given time. This value is generally greater than or equal to the parameter value of the maxTransactions, and is less than the parameter value of maxRequests: maxsessions = "64" default: 128

3. MaxTransaction simultaneously enters the maximum number of threads of SQLMAPClient.StartTransaction (). Threads greater than this value will block until another thread exits. Different DBMs have different limits. This value should always be less than or equal to MAXSESSIONS, and more than maxRequests. Normally, reduce this value can improve the efficiency of the execution. Example: MaxTransaction = "16" Default: 32

4. Cachemodelsenabled is enabled or disables all Cache Models for SQLMapClient. Useful when debugging the program. Example: cachemodelsenabled = "true" Default: TRUE

5. LazyLoadInableD is enabled or disables all Lazy Loading for SQLMapClient. Useful when debugging the program. Example: lazyloadinagenabled = "true" Default: TRUE

6. enhancementEnabledThis setting enables runtime bytecode enhancement to facilitate optimized JavaBean property access as well as enhanced lazy loading example enhancementEnabled = "true" Default:. False (disabled)

7. UsestatementNamespaces This option This option is enabled, you must use full-qualified names to reference mapped statements, this full name consists of Sqlmap's name and Statement's name. For example: QueryForObject ("SQLMapName.StatementName");

Example: USSTATEMENTNAMESPACES = "false" Default: false (Disabled)

(3) Elements Allows you to specify an alias. This way you can replace the lengthy name through the short name you specified. For example: below is predefined alias in SQLMap: 1. Transaction Manager aliasesjdbc com.ibatis.sqlmap.Engine.Transaction.jdbc .JdbcTransactionConfigJTA com.ibatis.sqlmap.engine.transaction.jta.JtaTransactionConfigEXTERNAL com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig2. Data Source Factory AliasesSIMPLE com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactoryDBCP com.ibatis.sqlmap. Engine.DataSource.dbcpdataSourceFactoryjndi com.ibatis.sqlmap.Engine.DataSource.jndidatasourceFactory

(4) Element Note: In SQL Map 1.0 versions, multiple data sources are allowed simultaneously, which will cause some problems. So starting from version 2.0, only one data source is configured, if you have the need to configure multiple data sources, it is recommended that you use multiple different configuration files, or when you build SQL Map, as a parameter .

element allows you to configure transaction management services for SQL MAP. The TYPE property is used to specify which transaction management used, the value can be a class name or an alias.

In the framework already includes three transaction management: JDBC, JTA, and External 1. JDBC allows you to control your transactions with a CONNECTION's commit () and rollback () methods.

2. JTA This transaction management uses a JTA's global transaction to include SQL MAP's Activities as part of a WiDER Scope transaction, which may contain other databases or transactions. This configuration requires a UserTransaction property to set local User Transaction through JNDI Resource.

3. External allows you to manage your own business. You can still configure a data source, but transactions will not be submitted or rolled in the framework life cycle. This means that you have to use your own program to control your transaction. This setting is very useful for non-transactional databases.

(5) Element Tag and its properties are part of the configuration of , which is also used to configure the data source used by your SQL Map. At present, this framework provides three data source plants, but you can write one yourself. Below is a configuration example of each data source plant:

1. SimpleDataSourceFactorySimpleDataSourceFactory provides a basic implementation for Pihua DataSource for use in the case where there is no container to provide data sources.

2. DBCPDataSourceFactoryDbcpdataSourceFactory implements the connection pool service using the DataSourceAPI of Jakarta DBCP (Database Connection Pool). Suitable for WEB containers do not provide DataSource services, or perform a separate application. The parameters of the parameters that must be configured in DBCPDataSourceFactory are as follows:

3. JNDIDASourceFactoryjndidASourceFactory looks for DataSource from JNDI Context in the container of the application server. When using the application server, and the server provides the connection pool of the container and the associated DataSource implementation, JNDIDATASOSOSOURCEFAACTORY can be used. The standard method using JDBC DataSource is to find through JNDI.

JNDIDASOSOURCEFAACTORY The properties must be configured as follows: Note: The above configuration is to use standard JDBC management. However, in a container-managed data source, you may also want to configure the following: Note: Usertransaction property points to a JNDI location, You can find a UserTransaction instance through this jndi. This is needed in JTA's transaction management, which allows you to participate in transactions that contain other databases and transaction sources.

(6) Element SQLMAP elements are used to include SQL Map mapping files and other SQL MAP profiles. The SQL MAP mapping files used by each SQLMAPClient object are now declared. The mapping file is read as a STREAM Resource from classpath or URL. You must specify all SQL MAP files relative to class paths or URLs. Here are a few examples:

转载请注明原文地址:https://www.9cbs.com/read-124829.html

New Post(0)