How to change database in Liferay?
Often encountered someone asked Liferay how to change the database, how to modify the database connection. The first time we start Liferay, there will be a configuration wizard where we can select the database and configure the database connection information. What if I now select the PostgreSQL database in the wizard, but what do I want to change to Oracle later?
After you finish the Configuration Wizard, a file portal-setup-wizard.properties is generated under the Liferay directory. We open this file and can see the following database connection information in it.
jdbc.default.driverclassname=org.postgresql.driverjdbc.default.url=jdbc:postgresql://localhost:5432/ Liferay62jdbc.default.username=postgresjdbc.default.password=postgres
These lines we know is the database connection information, configured for the JDBC Connection driver name, JDBC connection string, database user name, database password and so on a few information, we need to replace the database, here to modify the database as we want.
Why do you see some tutorials or articles that are modified in the Root/web-inf/classes/portal-ext.properties file? Please refer to "Liferay in portal.properties Common configuration parameters" this blog in front of a small part, in these two files are can be modified, see oneself like.
What does the Liferay do with database connections?
The liferay underlying is the use of database operations in Hibernate,liferay through Hibernate. The default is to use the C3PO connection pool. We can also make connection pooling adjustments by portla-ext.properties, Portal-setup-wizard.properties, or other *.properties files.
Portal-setup-wizard.properties
JDBC.DEFAULT.LIFERAY.POOL.PROVIDER=C3PO #jdbc. DEFAULT.LIFERAY.POOL.PROVIDER=DBCP # Jdbc.default.liferay.pool.provider=tomcat
The default configuration, as above, can be adjusted to the connection pool we need. There are also many configuration parameters about the connection pool (can be found in the source Portal.properties file)
Jdbc.default.acquireincrement=5 jdbc.default.acquireretryattempts=3 jdbc.default.acquireretrydelay=1000 Jdbc.default.connectioncustomizerclassname=com.liferay.portal.dao.jdbc.pool.c3p0.portalconnectioncustomizer jdbc.default.idleconnectiontestperiod=60 jdbc.default.maxidletime=3600 jdbc.default.maxpoolsize=100 jdbc.default.minpoolsize=10 jdbc.default.numhelperthreads=10 #jdbc. default.transactionisolation=1
#jdbc. default.defaulttransactionisolation=read_uncommitted jdbc.default.maxactive=100 jdbc.default.minIdle=10 jdbc.default.removeabandonedtimeout=3600
Jdbc.default.jdbcinterceptors=org.apache.tomcat.jdbc.pool.interceptor.connectionstate jdbc.default.jmxEnabled= True Jdbc.default.fairqueue=true jdbc.default.timebetweenevictionrunsmillis=30000 Jdbc.default.useEquals=false
We can adjust and optimize the above parameters according to our own actual situation. Liferay the underlying configuration of the hibernate,hibernate is also available, for example, we want to print out the executed SQL statement in the console. You only need to configure the following parameters:
Hibernate.show_sql=true
The default is False. For more Hibernate default configuration information, you can search for hibernate within portal.properties. Found.
Data sources that let Liferay use the middleware
Sometimes we don't want to use a JDBC connection pool to manage our database connections, and we want to use middleware data sources, such as Tomcat's data sources, WebLogic data sources. At this point we only need to add the following configuration in Portla-ext.properties or portal-setup-wizard.properties
Jdbc.default.jndi.name=jdbc/liferaypool
So we're going to let Liferay go to the middleware data source to find the database connection. Of course, the Jndi name of the data source must be configured as Jdbc/liferaypool, and the configuration of those JDBC connections in front of you is not required. You can delete it at this time.
What databases does Liferay support?
One might think that Liferay is using hibernate at the bottom, is that not hibernate-backed database Liferay supported? This should theoretically be the case, but it is not, the database supported by Liferay is as follows:
DB2, Derby, Hypersonic (HSQL), Ingres, Mysql, Oracle, P6spy, PostgreSQL, SQL Server, Sybase, etc.
Other databases By default do not provide direct support, as long as the database is hibernate support, if you want to let Liferay support, need to make some changes to the source code, the changes are not complicated. Specific can refer to the Liferay source directory under the portal-impl/src/com/liferay/portal/dao/db of the following polygons related classes.
How to get the JDBC connection string in code connection
Sometimes maybe for this reason, we are going to get JDBC Connection connection, what do we do? It is certainly possible to use normal JDBC to read the configured parameters, but Liferay has provided us with such an API:
Dataaccess.getconnection ().
Some additional information about the database connection, such as the current database, can be obtained by DBFACTORYUTIL.GETDB () and obtaining the relevant method.
http://www.huqiwen.com/2014/01/15/liferay-6-study-26-about-liferay-database-connection/
Liferay 6 Development Learning (26): Database Connectivity related issues