Generally we guys used to connect with the liferay default Database.
We also have requirement that Client wants there Data on Separate Schema or Separate DB.
But In Liferay how we can connect with different DB?
Don't Worry guys your problem is now solved.
Just Follow some steps as below :-
1) As you are mentioning the jdbc properties for the liferayportal in portal-ext.properties, same way mention for the external DB or seperate schema as below :-
Explanation :-
The first four line starts with the jdbc.default, it means that it was associated with the Default Data Source. So it will connect to the Default Liferay DB.
Last four line line starts with the jdbc.test, which does not belong to the Default DB. It will be connected to some other DB whose entry will be in ext-spring.xml.
2) As we are using service-builder, it means that you need new tables other than liferay default DB. So it requires for you to create new plugins project and in that you need to create service.xml under webapps/WEB-INF and with the help of ANT(ant build-service) or MAVEN (mvn liferay:build-service) you will able to create full structure for your service. But still it is pointing to the default DB.
Now you need to create a new file ext-spring.xml under WEB-INF/src/META-INF dir. Inside META-INF folder you will find couple of xml files whose entry will be there in liferay portal.properties file as below :-
If you notice the order of xml file loading in portal.properties file, then you will find that the last file is ext-spring.xml is loaded. So we will now create ext-spring.xml and putting all transaction,datasource and sessionfactory related changed on that file as below :-
3) Now the last and the final step you need to do is that you need to modify the existing service.xml as follows :-
The data-source value specifies the data source target that is set to the persistence class. The default value is the Liferay data source. This is used in conjunction with session-factory.
The session-factory value specifies the session factory that is set to the persistence class. The default value is the Liferay session factory. This is used in conjunction with data-source.
The tx-manager value specifies the transaction manager that Spring uses. The default value is the Spring Hibernate transaction manager that wraps the Liferay data source and session factory.
If the local-service value is true, then the service will generate the local interfaces for the service. The default value is false.
If the remote-service value is true, then the service will generate remote interfaces for the service. The default value is true.
You can use the local-service and remote-service attribute according to your needs.
You are now connected with your external DB.
Put your Suggestions/Comments.
Thanks for Reading !!!
We also have requirement that Client wants there Data on Separate Schema or Separate DB.
But In Liferay how we can connect with different DB?
Don't Worry guys your problem is now solved.
Just Follow some steps as below :-
1) As you are mentioning the jdbc properties for the liferayportal in portal-ext.properties, same way mention for the external DB or seperate schema as below :-
Explanation :-
The first four line starts with the jdbc.default, it means that it was associated with the Default Data Source. So it will connect to the Default Liferay DB.
Last four line line starts with the jdbc.test, which does not belong to the Default DB. It will be connected to some other DB whose entry will be in ext-spring.xml.
2) As we are using service-builder, it means that you need new tables other than liferay default DB. So it requires for you to create new plugins project and in that you need to create service.xml under webapps/WEB-INF and with the help of ANT(ant build-service) or MAVEN (mvn liferay:build-service) you will able to create full structure for your service. But still it is pointing to the default DB.
Now you need to create a new file ext-spring.xml under WEB-INF/src/META-INF dir. Inside META-INF folder you will find couple of xml files whose entry will be there in liferay portal.properties file as below :-
If you notice the order of xml file loading in portal.properties file, then you will find that the last file is ext-spring.xml is loaded. So we will now create ext-spring.xml and putting all transaction,datasource and sessionfactory related changed on that file as below :-
3) Now the last and the final step you need to do is that you need to modify the existing service.xml as follows :-
The data-source value specifies the data source target that is set to the persistence class. The default value is the Liferay data source. This is used in conjunction with session-factory.
The session-factory value specifies the session factory that is set to the persistence class. The default value is the Liferay session factory. This is used in conjunction with data-source.
The tx-manager value specifies the transaction manager that Spring uses. The default value is the Spring Hibernate transaction manager that wraps the Liferay data source and session factory.
If the local-service value is true, then the service will generate the local interfaces for the service. The default value is false.
If the remote-service value is true, then the service will generate remote interfaces for the service. The default value is true.
You can use the local-service and remote-service attribute according to your needs.
You are now connected with your external DB.
Put your Suggestions/Comments.
Thanks for Reading !!!