Skip to content

Latest commit

 

History

History
109 lines (70 loc) · 3.72 KB

configure-a-database-connection-for-the-tomee-application-container-03cfb10.md

File metadata and controls

109 lines (70 loc) · 3.72 KB

Configure a Database Connection for the TomEE Application Container

Note:

The examples below refer to TomEE 10 and SAP Java Buildpack 2.

  1. Create a resources.xml file.

    • If the data source is to be used from a Web application, you have to create the file inside the WEB-INF/ directory.

    • If the data source is to be used from Enterprise JavaBeans (EJBs), you have to create the file inside the META-INF/ directory.

    The resources.xml file has to be inside the application's WAR file, and has to contain information about the data source to be used.

    Sample Code:

    resources.xml

    <?xml version='1.0' encoding='utf-8'?>
    
    <resources>
     <Resource id="jdbc/DefaultDB" provider="xs.openejb:XS Default JDBC Database" type="javax.sql.DataSource" >
        service=${service_name_for_DefaultDB}
      </Resource>
    </resources>
    
  2. Add the default keys and their values. You need to include the data source information in directory META-INF/sap_java_buildpack/config/resource_configuration.yml of the WAR file.

    • Define a default service name for a Web application:

      Sample Code:

      resource_configuration.yml

      ---
      tomee/webapps/ROOT/WEB-INF/resources.xml:
        service_name_for_DefaultDB: di-core-hdi
      
    • Define a default service name for an EJB:

      Sample Code:

      resource_configuration.yml

      ---
      tomee/webapps/ROOT/META-INF/resources.xml:
        service_name_for_DefaultDB: di-core-hdi
      
  3. Add the key values to be updated. You need to include the data source information to be updated in the manifest.yml file.

    • Define the new service name for the look-up of the data source in a Web application:

      Sample Code:

      manifest.yml

      
      env:
        TARGET_RUNTIME: tomee
        JBP_CONFIG_RESOURCE_CONFIGURATION: "['tomee/webapps/ROOT/WEB-INF/resources.xml': {'service_name_for_DefaultDB' : 'my-local-di-core-hdi'}]"
      
    • Define the new service name for the look-up of the data source in an EJB:

      Sample Code:

      manifest.yml

      
      env:
        TARGET_RUNTIME: tomee
        JBP_CONFIG_RESOURCE_CONFIGURATION: "['tomee/webapps/ROOT/META-INF/resources.xml':{'service_name_for_DefaultDB' : 'my-local-di-core-hdi'}]"
      

As a result of this configuration, when the application starts, the com.sap.xs.jdbc.datasource.TomEEDataSourceFactory factory takes the parameters bound to the my-local-di-core-hdi service from the environment, creates a data source, and binds it under jdbc/DefaultDB. The application then uses the Java Naming and Directory Interface (JNDI) to look up how to connect with the database.

Related Information

SAP HANA HDI Data Source Usage

Database Connection Configuration Details