Those who follow Liferay is aware of the fact that the Community Edition version 7 of Liferay, were eliminated quite a bit of components App Server, Database & Clustering Support. For more detail information you can read the blog post by Bryan Cheung published on April 7, 2016.
The Liferay 7 CE no more support OOTB (Out Of The Box):
- Application Server: Oracle WebLogic, IBM WebSphere
- Clustering
- MultiVM Cache
- Oracle Database, Microsoft SQL Server, IBM DB2, Sybase DB
This project add support to the Oracle Database, SQL Server and IBM DB2 database. Liferay has performed refactorting the code so that it is possible and easy to add support for databases no longer supported OOTB (out-of-the-box)
Attention update: The last version (1.1.4) of the driver works with the Liferay 7.2.1 CE GA2.
I invite you to read the article How to build a Docker Liferay 7.2 image with the Oracle Database support which may be interesting for you.
In the following video, I will guide you step-by-step instructions on how to add support for Oracle Database to Liferay 7 Community Edition in the bundled version of Wildfly.
To extend support to other databases, Liferay has decided to refactory code to use Java SPI (Service Provider Interface). SPI is the mechanism that allows you to extend/change the behavior within a system without changing the source. It includes interfaces, classes or methods that the user extends or implements in order to obtain a certain functionality.
In short we must:
- Implement the SPI interface com.liferay.portal.kernel.dao.db.DBFactory
- Implement the abstract class com.liferay.portal.dao.db.BaseDB
The following code shows how service providers are loaded via SPI.
public DBManagerImpl() {
ServiceLoader<DBFactory> serviceLoader = ServiceLoader.load(
DBFactory.class, DBManagerImpl.class.getClassLoader());
for (DBFactory dbFactory : serviceLoader) {
_dbFactories.put(dbFactory.getDBType(), dbFactory);
}
}
Source Code 1 - Shows how service providers are loaded via SPI
To register your service provider, you create a provider configuration file, which is stored in the META-INF/services directory of the service provider's JAR file. The name of the configuration file is the fully qualified class name of the service provider, in which each component of the name is separated by a period (.), and nested classes are separated by a dollar sign ($).
The provider configuration file contains the fully qualified class names (FQCN) of your service providers, one name per line. The file must be UTF-8 encoded. Additionally, you can include comments in the file by beginning the comment line with the number sign (#).
Our file (inside META-INF/services
directory) is called com.liferay.portal.kernel.dao.db.DBFactory
and contain the
FQCN of this class:
- it.dontesta.labs.liferay.portal.dao.db.OracleDBFactory
- it.dontesta.labs.liferay.portal.dao.db.SQLServerDBFactory
- it.dontesta.labs.liferay.portal.dao.db.DB2DBFactory
The class diagrams of each database driver are shown below.
Figure 1 - Class diagram of the SQLServerDB driver
Figure 2 - Class diagram of the DB2DB driver
Figure 3 - Class diagram of the OracleDB driver
Requirements for build the project
- Sun/Oracle JDK 1.8
- Maven 3.x (for build project)
The driver that adds support for Oracle, SQLServer and DB2 database
is a jar artifact (liferay-portal-database-all-in-one-support-${version}.jar) which
then will be installed in ROOT/WEB-INF/lib
(for the Apache Tomcat).
To generate the all in one driver just follow the instructions below.
You can download the latest version binary jar from Maven Central Repository liferay-portal-database-all-in-one-support, by doing so you can avoid doing the build.
$ git clone https://github.com/amusarra/liferay-portal-database-all-in-one-support.git
$ cd liferay-portal-database-all-in-one-support
$ mvn package
Console 1 - Clone the source project from GitHub and run package goal
The build process create the jar
liferay-portal-database-all-in-one-support-${version}.jar
inside the (maven)
target directory.
Below you can see the portal-ext.properties
. In the sample file are shown JDBC
configurations sample for Oracle, SQL Server, and DB2.
##
## JDBC
##
#
# Oracle
#
# jdbc.default.driverClassName=oracle.jdbc.OracleDriver
# jdbc.default.username=liferayce7
# jdbc.default.password=liferay12345
# jdbc.default.url=jdbc:oracle:thin:@oracledb.vm.local:1521:xe
#
# DB2
#
# jdbc.default.driverClassName=com.ibm.db2.jcc.DB2Driver
# jdbc.default.url=jdbc:db2://db2.vm.local:50001/lportal:deferPrepares=false;fullyMaterializeInputStreams=true;fullyMaterializeLobData=true;progresssiveLocators=2;progressiveStreaming=2;
# jdbc.default.username=db2inst1
# jdbc.default.password=system
#
# SQL Server
#
# jdbc.default.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
# jdbc.default.username=liferay
# jdbc.default.password=liferay12345
# jdbc.default.url=jdbc:sqlserver://sqlserverdb.vm.local;databaseName=liferayce7
Source Code 2 - Sample JDBC connection strings for Oracle, SQL Server and DB2 database
You could also configure database access as a JNDI resource and specify the resource name in configuration.
##
## JDBC
##
#
# Set the JNDI name to lookup the JDBC data source. If none is set,
# then the portal will attempt to create the JDBC data source based on the
# properties prefixed with "jdbc.default.".
#
jdbc.default.jndi.name=java:jdbc/LiferayPool
Source Code 3 - Configure the JDBC connection via JNDI
In order for Liferay to be able to connect to the database, it is necessary to install the JDBC driver compatible with the version of the specific database and JVM. Here are the links to the resources to download the JDBC driver.
The following documents (see database section) provide details of the configurations that are certified by Liferay. You can see the complete documents on Liferay Portal.
- How to build a Docker Liferay 7.2 image with the Oracle Database support
- How to build a Docker Liferay 7.2 image with the SQL Server 2017 Database support
- Liferay 7.1: How to add support for Oracle DB
- Come installare Liferay 7 su JBOSS EAP con il supporto Oracle Database
- Liferay 7 Wildfly: How to add support for Oracle DB (video on Antonio Musarra's Blog YouTube Channel)
- Liferay 7 Community Edition GA5 & Oracle 12c via Docker Composer (video on Antonio Musarra's Blog YouTube Channel)
- Come installare Liferay 7 su JBoss EAP con il supporto per Oracle Database (video on Antonio Musarra's Blog YouTube Channel)