Creating Datasource in TomEE+

You can create DataSource in Apache TomEE+ Server.

Creating a DataSource in Apache TomEE+ server is one of the primary steps involved in the deployment of the Gateway Server on Apache TomEE+ server.

The procedure is identical for both Gateway Server for X-PDM and Gateway Server for X-PDM Connectivity.

This task shows you how to:

For Derby Database

You can use the default database provided with the installer, which can be found in folder persistance\GatewayDbDerby.

  1. Download the apache db derby jar db-derby-10.16.1.1-lib.zip file, which is supported for Java 17 and higher from https://dlcdn.apache.org/db/derby/db-derby-10.16.1.1 URL.
  2. Extract the derby jar files and copy it and paste all the following derby jar file to %TOMEE+_HOME%\lib directory.

    • derby.jar
    • derbyLocale_cs.jar
    • derbyLocale_de_DE.jar
    • derbyLocale_es.jar
    • derbyLocale_fr.jar
    • derbyLocale_hu.jar
    • derbyLocale_it.jar
    • derbyLocale_ja_JP.jar
    • derbyLocale_ko_KR.jar
    • derbyLocale_pl.jar
    • derbyLocale_pt_BR.jar
    • derbyLocale_ru.jar
    • derbyLocale_zh_CN.jar
    • derbyLocale_zh_TW.jar
    • derbyshared.jar
    • derbytools.jar

  3. Restart the Apache TOMEE application server.
  4. Navigate to %TOMEE+_HOME%\conf directory. Open TomEE.xml file in an editor.
  5. Append Resource element as shown in the below example.

    <Resource id="jdbc/gateway/3DEXPERIENCEPlatformGW" type="javax.sql.DataSource">
    JdbcDriver org.apache.derby.jdbc.EmbeddedDriver
    JdbcUrl jdbc:derby:C:/3DEXPERIENCEPlatformGW/persistance/GatewayDbDerby
    maxActive 100
    maxIdle 30
    maxWait 10000
    username
    password
    JtaManaged false
    </Resource>
    

    where,

    • C:/3DEXPERIENCEPlatformGW/persistance/GatewayDbDerby point to path of GatewayDbDerby directory in persistance directory.
    • jdbc/gateway/3DEXPERIENCEPlatformGW is the DataSource JNDI Name entered when installing Gateway Server for X-PDM.

Result: The DataSource is configured and is ready to use.

For Oracle Database

  1. Copy ojdbc6.jar located in ORACLE_HOME\jdbc\lib path to %TOMEE+_HOME%\lib folder.
  2. Create an Oracle database to be used as DataSource for Gateway.

    For example: Datasource

  3. Follow the below steps to create new database user(For example: Dsource) in Oracle:

    Open command prompt (cmd) and type following commands:

    >set ORACLE_SID=Datasource
    >sqlplus /nolog
    SQL>conn sys/sys as sysdba;

    Use command to create user as mentioned below:

    SQL>create user Dsource identified by Dsource default tablespace users;

    Give database connection and other required access to use:

    SQL>grant connect, resource to Dsource;
    SQL>grant unlimited tablespace to Dsource;
    Exit from sqlplus: SQL>quit;

  4. Create tables as per script gateway-db-oracle.sql located in folder persistance or by running the gateway-db-oracle.sql script on the database server Datasource.

    Note: It is recommended to connect with a user other than sysdba user to run the script.

    For example: Dsource

    • Open Command prompt (cmd) and type following commands:

      >set ORACLE_SID=Datasource
      >sqlplus /nolog
      SQL>conn Dsource/Dsource;
    • Create tables as per script gateway-db-oracle.sql

      SQL>@D:\Gateway\persistance\ gateway-db-oracle.sql
    • Exit from sqlplus.

      SQL>quit;

  5. Navigate to %TOMEE+_HOME%\conf directory. Open TomEE.xml file in an editor.
  6. Append Resource element as shown in the example below.

    <Resource id="jdbc/gateway/3DEXPERIENCEPlatformGW" type="DataSource">
    	JdbcDriver oracle.jdbc.driver.OracleDriver
    	JdbcUrl jdbc:oracle:thin:@mymachine:1521:Datasource
    	UserName Dsource
    	Password Dsource
    	maxActive 20
    	maxIdle 10
    	maxWait -1
    	JtaManaged false
    </Resource>
    

    Where,

    • mymachine : Oracle database machine
    • 1521 : listener port number
    • Datasource : database name
    • jdbc/gateway/3DEXPERIENCEPlatformGW is the DataSource JNDI Name entered when installing Gateway Server for X-PDM.

    Note: UserName must be the same user as for creating tables.

Result: The DataSource is now configured and ready to use.

For DB2 Database

  1. Copy and paste db2jcc.jar and db2jcc_license_cu.jar to %TOMEE+_HOME%\lib from %DB2 Installation%\IBM\SQLLIB\java.
  2. Launch db2cwadmin.bat for executing queries to create database located at <DB2_Install>\IBM\SQLLIB\BIN

    <DB2_Install>\IBM\SQLLIB\BIN>db2start

    <DB2_Install>\IBM\SQLLIB\BIN>db2 create database <db_name>

    <DB2_Install>\IBM\SQLLIB\BIN>db2 connect to <db_name>

    where, <db_name> is the name of the database.

  3. Create tables and alteration.

    <DB2_Install>\IBM\SQLLIB\BIN>db2 -tvf <GatewayInstallDir>\persistance\gateway-db-db2.db2

    where, <GatewayInstallDir> is the Gateway Server installation directory path.

    For example:

    D:\IBM\SQLLIB\BIN>db2start

    SQL1063N DB2START processing was successful.

    D:\IBM\SQLLIB\BIN>db2 create database GATEWAY

    DB20000I The CREATE DATABASE command completed successfully.

    D:\IBM\SQLLIB\BIN>db2 connect to test123

    Database Connection Information

    Database server = DB2/NT64 10.1.0

    SQL authorization ID = IKC

    Local database alias = TEST123

    D:\IBM\SQLLIB\BIN>db2 -tvf C:\DassaultSystemes\3DEXPERIENCEPlatformGW\persistance\gateway-db-db2.db2

    DB20000I The SQL command completed successfully.

  4. Add Resource element entry in tomee.xml as,

    <Resource id="jdbc/gateway/GatewayDB" type="DataSource">
         JdbcDriver com.ibm.db2.jcc.DB2Driver
          JdbcUrl jdbc:db2://<host-name>:<port>/<db-name>
          UserName <db2 admin user>
          Password <db2 admin pwd>
          maxActive 20
          maxIdle 10
          maxWait -1
          JtaManaged false
    </Resource>
    
    Notes:
    • The correct JNDI name should be present in <Resource>.
    • To know the DB2 Instance listener port number follow the below procedure:
      1. In DB2 command window, run db2 "get dbm cfg" | grep SVCENAME
      2. The DB2 service name is generated as TCP/IP Service name (SVCENAME) = db2c_DB2
        • On Windows: Open %windir%/system32/drivers/etc/services and check tcp port of ‘SVCENAME ' (For example, db2c_DB2)
        • On AIX: Open cat /etc/services and check tcp port of ‘SVCENAME ' (For example, db2c_DB2)

Result: The DataSource is now configured and ready to use.

For Microsoft SQL Database

  1. Download and paste sqljdbc4.jar to %TOMEE+_HOME%\lib from http://www.microsoft.com/en-in/download/details.aspx?id=11774.
  2. Launch Microsoft SQL Prompt by navigating cmd to below path and run below commands to create database.

    C:\Program Files\Microsoft SQL Server\110\Tools\Binn>sqlcmd -S <host_name\instanceName> -U <User> -P <Password>

    1>create database <db_name>

    2>go

    1>grant connect to [dsone\techel]

    2>go

    1>exit

    Note: go is a terminating character for an instruction/instructions like ‘;’ in SQL queries of Oracle.

  3. Create tables and alteration.

    C:\Program Files\Microsoft SQL Server\110\Tools\Binn>sqlcmd -S <hostName\instanceName> -U <user> -P <password> -d <DBName> -i <GatewayInstallDir> \persistance\gateway-db-sqlserver.sql

    where, <GatewayInstallDir> is the Gateway Server installation directory path.

    For example:

    C:\Program Files\Microsoft SQL Server\110\Tools\Binn>sqlcmd -S VDEVPRIW153plp\SQLSERVER2012 -U sa -P ****

    1>create database GATEWAY

    2>go

    1>grant connect to appUser

    2>go

    1>exit

    C:\Program Files\Microsoft SQL Server\110\Tools\Binn>sqlcmd -S VDEVPRIW153plp\SQLSERVER2012 -U sa -P passwordForSa -d GATEWAY -i C:\Gateway\persistance\gateway-db-sqlserver.sql

  4. Add Resource element entry in tomee.xml as,

    <Resource id="jdbc/gateway/GatewayDB" type="javax.sql.DataSource">
          JdbcDriver com.microsoft.sqlserver.jdbc.SQLServerDriver
          JdbcUrl jdbc:sqlserver://<host-name>:<port>;instanceName=<db-instance>;database=<db-name>;
          UserName <sql admin user>
          Password <sql admin pwd>
          maxActive 100
          maxIdle 30
          maxWait 10000
          JtaManaged false
    </Resource>
    
    Note: To have a successful connection of your application through JDBC, the TCP/IP connection should be enabled. Follow the below procedure to enable the TCP/IP connection:
    1. Go to Start > All Programs > Microsoft SQL Server 2012 > Configuration Tools > SQL Server Configuration Manager.

      The SQL Server Configuration Manager window appears.

    2. Select SQL Server Network Configuration > Protocols for DBName
    3. Right-click TCP/IP and select Enable, if its disabled.
    4. Right-click Properties.

      The Properties window appears.

    5. In IP Addresses tab, select IPALL > TCP Dynamic Port .The value should be same as the port mentioned in your resource definition of your tomee.xmlfile.

Result: The DataSource is now configured and ready to use.

DataSource Password Encryption

The TomEE.xml configuration file can be used to cipher the DataSource password.

The following is an example using the 3DES implementation with an Oracle DataSource.

<Resource id="jdbc/gateway/3DEXPERIENCEPlatformGW" type="DataSource">
      JdbcDriver oracle.jdbc.driver.OracleDriver
      JdbcUrl jdbc:oracle:thin:@mymachine:1521:Datasource
      username Dsource
      Password 2vaA5FaNp6ZtpaAri44ONw==
      maxActive 20
      maxIdle 10
      maxWait -1
      PasswordCipher Static3DES
</Resource>

For more detail, refer http://tomee.apache.org/datasource-password-encryption.html