Configure multiple databases through SSH + connection pool

Source: Internet
Author: User

Two types of databases are used in the SSH framework. Oracle and sqlserver

The specific configuration is as follows:

1. applicationContext-common.xml

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans xmlns = "http://www.springframework.org/schema/beans" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xmlns: AOP = "http://www.springframework.org/schema/aop" <br/> xmlns: tx = "http://www.springframework.org/schema/tx" <br/> xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd <br/> http://www.springfram Ework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd <br/> http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd "> <br/> <bean id =" sessionfactory "<br/> class =" org. springframework. orm. hibernate3.localsessionfactorybean "> <br/> <property name =" configlocation "> <br/> <value> classpath: hibernate. cfg. XML </value> <br/> </property> <br /> </Bean> <br/> <bean id = "transactionmanager" <br/> class = "org. springframework. orm. hibernate3.hibernatetransactionmanager "> <br/> <property name =" sessionfactory "ref =" sessionfactory "> </property> <br/> </bean> <br/> <TX: advice id = "txadvice" transaction-Manager = "transactionmanager"> <br/> <TX: Attributes> <br/> <TX: method Name = "register *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: Meth Od name = "Save *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "add *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "del *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "insert *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "Update *" propagation = "required" <br/> rollback-for =" Exception "/> <br/> <TX: method Name = "Modify *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "attach *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "Exec *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "check *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method name = "approve *" propagati On = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "process *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "init *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "*" Read-Only = "true"/> <br/> </TX: Attributes> <br/> </TX: A <MCE: script Type = "text/JavaScript" src = "http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/lan GS/Zh. JS "mce_src =" http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js "> </MCE: SCRIPT> <MCE: Script Type =" text/JavaScript "src =" http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js "mce_src =" http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js "> </MCE: SCRIPT> dvice> <br/> <AOP: config> <br/> <! -- Basic info --> <br/> <AOP: Advisor advice-ref = "txadvice" <br/> pointcut = "execution (* CN. common. SYS. service .. *. *(..)) "/> <br/> </AOP: config> <br/> <! -- Sqlserver configuration --> <br/> <bean id = "sessionfactory_sqlserver" <br/> class = "org. springframework. orm. hibernate3.localsessionfactorybean "> <br/> <property name =" configlocation "> <br/> <value> classpath: faxhibernate. cfg. XML </value> <br/> </property> <br/> </bean> <br/> <bean id = "transactionmanager_sqlserver" <br/> class = "org. springframework. orm. hibernate3.hibernatetransactionmanager "> <br/> <property name =" sessio Nfactory "<br/> ref =" sessionfactory_sqlserver "> <br/> </property> <br/> </bean> <br/> <TX: advice id = "txadvice_sqlserver" <br/> transaction-Manager = "transactionmanager_sqlserver"> <br/> <TX: Attributes> <br/> <TX: method Name = "register *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "Save *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method name = "add *" Pro Pagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "del *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "insert *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "Update *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "Modify *" propagation = "required" <br/> rollback-for = "exception"/> <br /> <TX: method name = "attach *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "Exec *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "check *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "approve *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "process *" propagation = "required" <B R/> rollback-for = "exception"/> <br/> <TX: method Name = "init *" propagation = "required" <br/> rollback-for = "exception"/> <br/> <TX: method Name = "*" Read-Only = "true"/> <br/> </TX: Attributes> <br/> </TX: advice> <br/> <AOP: config> <br/> <! -- Fax management --> <br/> <AOP: Advisor advice-ref = "txadvice_sqlserver" <br/> pointcut = "execution (* CN. common. faxserver. service .. *. *(..)) "/> <br/> </AOP: config> <br/> </beans> <br/> 

2. faxhibernate. cfg. xml

<? XML version = '1. 0' encoding = 'utf-8'?> <Br/> <! Doctype hibernate-configuration Public <br/> "-// hibernate/hibernate configuration DTD 3.0 // en" <br/> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <br/> <! -- Generated by myeclipse hibernate tools. --> <br/> <pibernate-configuration> <br/> <session-factory> <br/> <property name = "hibernate. proxool. XML "> faxproxool. XML </property> <br/> <property name = "hibernate. proxool. pool_alias "> faxdbpool </property> <br/> <property name =" hibernate. connection. provider_class "> <br/> Org. hibernate. connection. proxoolconnectionprovider <br/> </property> </P> <p> <property name = "hibe Rnate. format_ SQL "> true </property> <br/> <property name =" hibernate. show_ SQL "> true </property> <br/> <property name =" hibernate. JDBC. batch_size "> 0 </property> <br/> <property name =" hibernate. JDBC. fetch_size "> 20 </property> <br/> <property name =" hibernate. JDBC. use_streams_for_binary "> <br/> true <br/> </property> <br/> <property name =" default_schema "> DBO </property> <br/> <! -- Fax sending and receiving --> <br/> <mapping <br/> resource = "cN/common/faxserver/po/tdbifaxin. HBM. XML "/> <br/> <mapping <br/> resource =" cN/common/faxserver/po/tdbifaxout. HBM. XML "/> <br/> </session-factory> <br/> </pibernate-configuration> 

Faxproxool. xml

<? XML version = '1. 0' encoding = 'utf-8'?> <Br/> <something-else-entirely> <br/> <proxool> <br/> <alias> faxdbpool </alias> <br/> <driver-URL> JDBC: sqlserver: // 192.168.0.99: 1433; databasename = trafax </driver-URL> <br/> <driver-class> COM. microsoft. sqlserver. JDBC. sqlserverdriver </driver-class> <br/> <driver-Properties> <br/> <property name = "user" value = "faxop"/> <br/> <Property name = "password" value = "faxop"/> <br/> <property name = "autoreconnect" value = "true"/> <br/> </driver-Properties> <br/> <pouse-keeping-sleep-time> 90000 </pouse-keeping-sleep-time> <br/> <pouse-keeping-test-SQL> select getdate () </pouse-keeping-test-SQL> <br/> <prototype-count> 5 </prototype-count> <br/> <maximum-connection-count> 100 </ maximum-connection-count> <br/> <Minimum-connection-count> 5 </minimum-connection-count> <br/> </proxool> <br/> </ something-else-entirely> 

3. hibernate. cfg. xml

<! Doctype hibernate-configuration Public <br/> "-// hibernate/hibernate configuration DTD 3.0/EN" <br/> "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <br/> <pibernate-configuration> <br/> <session-factory> <br/> <property name = "hibernate. proxool. XML "> proxool. XML </property> <br/> <property name = "hibernate. proxool. pool_alias "> mypool </property> <br/> <property name =" hibernate. connection. provider_class "> <br/> Org. hibernate. connection. proxoolconnectionprovider <br/> </property> <br/> <property name = "hibernate. format_ SQL "> true </property> <br/> <property name =" hibernate. show_ SQL "> true </property> <br/> <property name =" hibernate. JDBC. batch_size "> 0 </property> <br/> <property name =" hibernate. JDBC. fetch_size "> 20 </property> <br/> <property name =" hibernate. JDBC. use_streams_for_binary "> <br/> true <br/> </property> </P> <p> <property name =" dialect "> <br/> Org. hibernate. dialect. oracle9dialect <br/> </property> <br/> <Mapping Resource = "cN/finefuture/cqwater/basetask/po/calltondutyperson. HBM. XML "/> <br/> </session-factory> <br/> </pibernate-configuration> 

Proxool. xml

<? XML version = '1. 0' encoding = 'utf-8'?> <Br/> <something-else-entirely> <br/> <proxool> <br/> <alias> mypool </alias> <br/> <driver-URL> <br/> JDBC: ORACLE: thin :@ 192.168.0.99: 1521: orcl <br/> </driver-URL> <br/> <driver-class> <br/> oracle. JDBC. driver. oracledriver <br/> </driver-class> <br/> <driver-Properties> <br/> <property name = "user" value = "cqwater"/> <br /> <property name = "password" value = "cqwater"/> <br/> <property name = "autoreconnect" value = "true"/> <br/> </ driver-Properties> <br/> <pouse-keeping-sleep-time> 90000 </pouse-keeping-sleep-time> <br/> <prototype-count> 5 </ prototype-count> <br/> <maximum-connection-count> 100 </maximum-connection-count> <br/> <Minimum-connection-count> 5 </minimum- connection-count> <br/> </proxool> <br/> </something-else-entirely>

4. The applicationContext-daos.xml introduces the corresponding sessionfactory in Dao.

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans xmlns = "http://www.springframework.org/schema/beans" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <br/> <bean id = "customerdao" <br/> class = "CN. common. platform. dao. impl. customerdaoimpl "> <br/> <property name =" sessionfactory "ref =" sessionfactor Y "> </property> <br/> </bean> <br/> <! -- Send fax Dao --> <br/> <bean id = "tdbifaxoutdao" <br/> class = "CN. common. faxserver. dao. impl. tdbifaxoutdaoimpl "> <br/> <property name =" sessionfactory "<br/> ref =" sessionfactory_sqlserver "> <br/> </property> <br/> </bean> <br/> <! -- Receive fax Dao --> <br/> <bean id = "tdbifaxindao" <br/> class = "CN. common. faxserver. dao. impl. tdbifaxindaoimpl "> <br/> <property name =" sessionfactory "<br/> ref =" sessionfactory_sqlserver "> <br/> </property> <br/> </bean> <br/> </beans> <br/> 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.