Guest User

Untitled

a guest
Dec 24th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:tx="http://www.springframework.org/schema/tx" xmlns="http://www.springframework.org/schema/beans"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/tx
  7. http://www.springframework.org/schema/tx/spring-tx.xsd">
  8.  
  9. <bean id="myDataSource"
  10. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  11. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  12. <property name="url" value="${db.url}" />
  13. <property name="username" value="${db.username}" />
  14. <property name="password" value="${db.password}" />
  15.  
  16. <!-- Added this additional line to share the connection Pool -->
  17. <!-- <property name="initialSize" value="1000" /> <property name="maxActive"
  18. value="1000" /> <property name="maxIdle" value="10" /> -->
  19. </bean>
  20.  
  21. <!-- This is the new Properties for the new DB of aadhaar vault -->
  22. <bean id="myDataSource1"
  23. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  24. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  25. <property name="url" value="${db1.url}" />
  26. <property name="username" value="${db1.username}" />
  27. <property name="password" value="${db1.password}" />
  28.  
  29. <!-- Added this additional line to share the connection Pool -->
  30. <!-- <property name="initialSize" value="1000" /> <property name="maxActive"
  31. value="1000" /> <property name="maxIdle" value="10" /> -->
  32. </bean>
  33.  
  34. <!-- This is the new DB table, which is being initialized for the aadhaar
  35. vault -->
  36.  
  37. <bean id="mySessionFactory1"
  38. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  39. <property name="dataSource" ref="myDataSource1" />
  40. <property name="configLocation" value="classpath:hibernateNew.cfg.xml" />
  41. <property name="namingStrategy" ref="namingStrategy" />
  42. <property name="hibernateProperties">
  43. <props>
  44. <prop key="hibernate.show_sql">false</prop>
  45. <prop key="hibernate.hbm2ddl.auto">create</prop>
  46. <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  47. <!-- Specify session context -->
  48. <!-- <prop key="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</prop> -->
  49.  
  50. </props>
  51. </property>
  52. </bean>
  53.  
  54.  
  55.  
  56. <!-- This is the new DB table, which is being initialized for the
  57. remote , ends here -->
  58.  
  59.  
  60. <bean id="mySessionFactory"
  61. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  62. <property name="dataSource" ref="myDataSource" />
  63. <property name="configLocation" value="classpath:hibernate.cfg.xml" />
  64. <property name="namingStrategy" ref="namingStrategy" />
  65. <property name="hibernateProperties">
  66. <props>
  67. <prop key="hibernate.show_sql">false</prop>
  68. <prop key="hibernate.hbm2ddl.auto">update</prop>
  69. <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  70. <!-- Specify session context -->
  71. <!-- <prop key="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</prop> -->
  72.  
  73. </props>
  74. </property>
  75. </bean>
  76.  
  77. <tx:annotation-driven />
  78.  
  79. <bean id="transactionManager"
  80. class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  81. <property name="sessionFactory" ref="mySessionFactory" />
  82. </bean>
  83. <bean id="transactionManagerNew"
  84. class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  85. <property name="sessionFactory" ref="mySessionFactory1" />
  86. </bean>
  87.  
  88. <bean id="namingStrategy" class="org.hibernate.cfg.ImprovedNamingStrategy" />
  89.  
  90. <?xml version="1.0" encoding="UTF-8"?>
  91. <!DOCTYPE hibernate-configuration PUBLIC
  92. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  93. "http://www.jboss.org/dtd/hibernate/hibernate-configuration-3.0.dtd">
  94. <hibernate-configuration>
  95. <session-factory>
  96. <mapping class="com.abc.def.model.User"></mapping>
  97.  
  98. </session-factory>
  99. </hibernate-configuration>
  100.  
  101. <?xml version="1.0" encoding="UTF-8"?>
  102. <!DOCTYPE hibernate-configuration PUBLIC
  103. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  104. "http://www.jboss.org/dtd/hibernate/hibernate-configuration-3.0.dtd">
  105. <hibernate-configuration>
  106. <session-factory>
  107. <mapping class="com.abc.def.model.User1"></mapping>
  108. </session-factory>
  109. </hibernate-configuration>
  110.  
  111. db1.url=jdbc:mysql://localhost:3306/new_db?useUnicode=yes&characterEncoding=UTF-8
  112. db1.username=root
  113. db1.password=password
  114.  
  115. db1.url=jdbc:mysql://localhost:3306/old_db?useUnicode=yes&characterEncoding=UTF-8
  116. db1.username=root
  117. db1.password=root
  118.  
  119. @Service
  120. public class ABCServiceImpl implements ABCService {
  121.  
  122. @Autowired
  123. ABCDao abcDao;
  124. @Override
  125. @Transactional("transactionManagerNew")
  126. public ABC getByForeignKey(Long refid,Long customerEntityId) {
  127.  
  128. return abcDao.getByForeignKey(refid,customerEntityId);
  129. }
  130.  
  131. @Autowired
  132. @Qualifier("mySessionFactory1")
  133. protected SessionFactory sessionFactory;
  134. @SuppressWarnings("unchecked")
  135. @Override
  136. public ABC getByForeignKey(Long refId,Long customerEntityId) {
  137. Query query = sessionFactory.getCurrentSession().createQuery(" from ABC where RefId = " + refId + " and customerEntityId = "+customerEntityId);
  138. List<ABC> abcs = query.list();
  139. if(abcs.size()>0) {
  140. return abcs.get(0);
  141. }
  142.  
  143. return null;
  144. }
  145. }
Add Comment
Please, Sign In to add comment