In dit artikel wordt beschreven hoe je een Jboss datasource configureerd.

 

PostgreSQL:

mkdir -p $JBOSS_HOME/modules/org/postgresql/main

kopieer postgresql-9.4-1201.jdbc4.jar naar $JBOSS_HOME/modules/org/postgresql/main

maak in $JBOSS_HOME/modules/org/postgresql/main een module.xml bestand aan met de volgende inhoud:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.postgresql">
    <resources>
        <resource-root path="postgresql-9.4-1201.jdbc4.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

 

Voeg in domain.xml of standalone.xml het volgende toe in de datasources sectie:

<datasources>

<datasource jta="true" jndi-name="java:/jdbc/DatabaseName" pool-name="DatabaseName" enabled="true" use-ccm="true" statistics-enabled="false">
  <connection-url>jdbc:postgresql://hostname:5432/databasename</connection-url>
  <driver-class>org.postgresql.Driver</driver-class>
  <driver>postgresql-driver</driver>
  <pool>
    <min-pool-size>2</min-pool-size>
    <max-pool-size>50</max-pool-size>
    <prefill>true</prefill>
    <use-strict-min>true</use-strict-min>
  </pool>
  <security>
    <user-name>username</user-name>
    <password>passwd</password>
  </security>
  <validation>
    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
    <check-valid-connection-sql>select 1</check-valid-connection-sql>
    <validate-on-match>false</validate-on-match>
    <background-validation>true</background-validation>
    <background-validation-millis>30000</background-validation-millis>
    <use-fast-fail>true</use-fast-fail>
    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>

  </validation>
  <timeout>
    <set-tx-query-timeout>false</set-tx-query-timeout>
    <blocking-timeout-millis>0</blocking-timeout-millis>
    <idle-timeout-minutes>2</idle-timeout-minutes>
    <query-timeout>0</query-timeout>
    <use-try-lock>0</use-try-lock>
    <allocation-retry>0</allocation-retry>
    <allocation-retry-wait-millis>0</allocation-retry-wait-millis>
  </timeout>
  <statement>
    <share-prepared-statements>false</share-prepared-statements>
  </statement>

<drivers>
  <driver name="postgresql-driver" module="org.postgresql">
    <driver-class>org.postgresql.Driver</driver-class>
  </driver>
</drivers>

</datasources>

Oracle:

mkdir -p $JBOSS_HOME/modules/system/layers/base/com/oracle/main

kopieer ojdbc7.jar naar $JBOSS_HOME/modules/system/layers/base/com/oracle/main

maak in $JBOSS_HOME/modules/system/layers/base/com/oracle/main een module.xml bestand aan met de volgende inhoud:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle">
  <resources>
    <resource-root path="ojdbc7.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

Voeg in domain.xml of standalone.xml het volgende toe in de datasources sectie:

<datasources>

<datasource jta="true" jndi-name="java:/jdbc/DatabaseName" pool-name="DatabaseName" enabled="true" use-ccm="true">
  <connection-url>jdbc:oracle:thin:@hostname:1521/Database_Service</connection-url>

<!-- of jdbc:oracle:thin:@hostname:1521:Database_SID  als je een SID gebruikt -->
  <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
  <driver>oracle</driver>
  <security>
    <user-name>username</user-name>
    <password>passwd</password>
  </security>
  <validation>
    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
    <check-valid-connection-sql>select sysdate from dual;</check-valid-connection-sql>
    <background-validation>true</background-validation>
    <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"/>
    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/>
  </validation>
  </datasource>
  <drivers>
    <driver name="oracle" module="com.oracle">
      <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
    </driver>

  </drivers>

 </datasources>

MSSQL:

mkdir -p $JBOSS_HOME/modules/system/layers/base/com/microsoft/sqlserver/jdbc/main

kopieer mssql-jdbc-6.2.2.jre8.jar naar $JBOSS_HOME/modules/system/layers/base/com/microsoft/sqlserver/jdbc/main

maak in $JBOSS_HOME/modules/system/layers/base/com/microsoft/sqlserver/jdbc/main een bestand module.xml aan met de volgende inhoud:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.microsoft.sqlserver.jdbc">
  <resources>
    <resource-root path="mssql-jdbc-6.2.2.jre8.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
    <module name="javax.servlet.api" optional="true"/>
    <module name="javax.xml.bind.api"/>
  </dependencies>
</module>

Voeg in domain.xml of standalone.xml het volgende toe in de datasources sectie:

<datasources>

<datasource jta="true" jndi-name="java:/jdbc/DatabaseName" pool-name="DataaseName" enabled="true" use-ccm="true">
  <connection-url>jdbc:sqlserver://hostname:1433;databaseName=DatabaseName</connection-url>
  <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
  <driver>sqljdbc</driver>
  <security>
    <user-name>username</user-name>
    <password>passwd</password>
  </security>
  <validation>
    <check-valid-connection-sql>select 1</check-valid-connection-sql>
   </validation>
</datasource>
<drivers>
  <driver name="sqljdbc" module="com.microsoft.sqlserver.jdbc">

    <driver-class>
         com.microsoft.sqlserver.jdbc.SQLServerDriver
    </driver-class>
  </driver>
</drivers>

</datasources>

 

Mysql / MariaDB:

mkdir -p $JBOSS_HOME/modules/com/mysql/main

kopieer mysql-connector-java-5.1.21.jar naar $JBOSS_HOME/modules/com/mysql/main

maak in $JBOSS_HOME/modules/com/mysql/main een bestand module.xml aan met de volgende inhoud:

 

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.0" name="com.mysql">  

<resources>  

  <resource-root path="mysql-connector-java-5.1.21.jar"/>  

</resources>  

<dependencies>  

  <module name="javax.api"/>  

</dependencies> 

</module>  

 

Voeg in domain.xml of standalone.xml het volgende toe in de datasources sectie:

<datasources>

<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS">

  <connection-url>jdbc:mysql://hostname:3306/databasename</connection-url>

  <driver>com.mysql</driver>

  <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>

  <pool>

    <min-pool-size>10</min-pool-size>

    <max-pool-size>100</max-pool-size>

    <prefill>true</prefill>

  </pool>

  <security>

    <user-name>username</user-name>

    <password>passwd</password>

  </security>

  <statement>

    <prepared-statement-cache-size>32</prepared-statement-cache-size>

    <share-prepared-statements/>

  </statement>

</datasource>

<drivers>

   <driver name="com.mysql" module="com.mysql">

      <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>

   </driver>

</drivers>

</datasources>