Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tx="http://www.springframework.org/schema/tx" xmlns="http://www.springframework.org/schema/beans"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- <bean id="myDataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
- <property name="url" value="${db.url}" />
- <property name="username" value="${db.username}" />
- <property name="password" value="${db.password}" />
- <!-- Added this additional line to share the connection Pool -->
- <!-- <property name="initialSize" value="1000" /> <property name="maxActive"
- value="1000" /> <property name="maxIdle" value="10" /> -->
- </bean>
- <!-- This is the new Properties for the new DB of aadhaar vault -->
- <bean id="myDataSource1"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
- <property name="url" value="${db1.url}" />
- <property name="username" value="${db1.username}" />
- <property name="password" value="${db1.password}" />
- <!-- Added this additional line to share the connection Pool -->
- <!-- <property name="initialSize" value="1000" /> <property name="maxActive"
- value="1000" /> <property name="maxIdle" value="10" /> -->
- </bean>
- <!-- This is the new DB table, which is being initialized for the aadhaar
- vault -->
- <bean id="mySessionFactory1"
- class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
- <property name="dataSource" ref="myDataSource1" />
- <property name="configLocation" value="classpath:hibernateNew.cfg.xml" />
- <property name="namingStrategy" ref="namingStrategy" />
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.show_sql">false</prop>
- <prop key="hibernate.hbm2ddl.auto">create</prop>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
- <!-- Specify session context -->
- <!-- <prop key="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</prop> -->
- </props>
- </property>
- </bean>
- <!-- This is the new DB table, which is being initialized for the
- remote , ends here -->
- <bean id="mySessionFactory"
- class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
- <property name="dataSource" ref="myDataSource" />
- <property name="configLocation" value="classpath:hibernate.cfg.xml" />
- <property name="namingStrategy" ref="namingStrategy" />
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.show_sql">false</prop>
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
- <!-- Specify session context -->
- <!-- <prop key="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</prop> -->
- </props>
- </property>
- </bean>
- <tx:annotation-driven />
- <bean id="transactionManager"
- class="org.springframework.orm.hibernate4.HibernateTransactionManager">
- <property name="sessionFactory" ref="mySessionFactory" />
- </bean>
- <bean id="transactionManagerNew"
- class="org.springframework.orm.hibernate4.HibernateTransactionManager">
- <property name="sessionFactory" ref="mySessionFactory1" />
- </bean>
- <bean id="namingStrategy" class="org.hibernate.cfg.ImprovedNamingStrategy" />
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://www.jboss.org/dtd/hibernate/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <mapping class="com.abc.def.model.User"></mapping>
- </session-factory>
- </hibernate-configuration>
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://www.jboss.org/dtd/hibernate/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <mapping class="com.abc.def.model.User1"></mapping>
- </session-factory>
- </hibernate-configuration>
- db1.url=jdbc:mysql://localhost:3306/new_db?useUnicode=yes&characterEncoding=UTF-8
- db1.username=root
- db1.password=password
- db1.url=jdbc:mysql://localhost:3306/old_db?useUnicode=yes&characterEncoding=UTF-8
- db1.username=root
- db1.password=root
- @Service
- public class ABCServiceImpl implements ABCService {
- @Autowired
- ABCDao abcDao;
- @Override
- @Transactional("transactionManagerNew")
- public ABC getByForeignKey(Long refid,Long customerEntityId) {
- return abcDao.getByForeignKey(refid,customerEntityId);
- }
- @Autowired
- @Qualifier("mySessionFactory1")
- protected SessionFactory sessionFactory;
- @SuppressWarnings("unchecked")
- @Override
- public ABC getByForeignKey(Long refId,Long customerEntityId) {
- Query query = sessionFactory.getCurrentSession().createQuery(" from ABC where RefId = " + refId + " and customerEntityId = "+customerEntityId);
- List<ABC> abcs = query.list();
- if(abcs.size()>0) {
- return abcs.get(0);
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment