The definition and availability of a Data source for JBoss is defined by XML files. The ones we will be creating/modifying in the following sections are:
Files |
Purpose |
.\server\default\deploy\teradata-ds.xml | Defines a Teradata Datasource |
.\server\default\conf\standardjbosscmpjdbc.xml | Required for CMP entity beans |
ejb-jar.xml | Deployment Descriptors for EJBs |
jboss.xml | JBoss Deployment Descriptor |
In all of the following examples, we
assume that the Teradata JDBC install location is C:\TeraJDBC
and JBoss is installed at C:\JBossHome
. You should modify these values
to reflect your actual installation.
terajdbc4.jar
to the directory C:\JBossHome\server\default\lib
.
With older versions of the Teradata JDBC Driver, copy files terajdbc4.jar
and tdgssconfig.jar
to the directory C:\JBossHome\server\default\lib
.
A Data source is defined in JBoss via an xml file in the deploy directory which ends with the suffix "ds.xml". A Teradata Datasource will be defined by creating a "teradata-ds.xml" file in C:\JBossHome\server\default\deploy. The following is a sample "terdata-ds.xml" file, which you can be used as a template for creating your own data source.
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>TeradataDS</jndi-name>
<connection-url>jdbc:teradata://cyclops/TMODE=ANSI</connection-url>
<driver-class>com.teradata.jdbc.TeraDriver</driver-class>
<user-name>guest</user-name>
<password>please</password>
</local-tx-datasource>
</datasources>
XML-TAG |
Description |
Example |
jndi name | Java Naming &Directory Interface designation for this Data Source. Note that this name is relative to the "java:" prefix. | TeradataDS |
connection url | Defines the URL that will be passed to the driver. | jdbc:teradata://cyclops/TMODE=ANSI |
driver-class | The name of the class that implements the java.sql.Driver interface. | com.teradata.jdbc.TeraDriver |
user-name | The username for the database. | guest |
password | The password of the user defined by "Username" | please |
The file "teradata-ds.xml" creates a data source which uses the J2EE Connector Architecture(JCA) implementation for JBoss. The JCA configuration format is described in the DTD file docs/dtd/jboss-ds_1_0.dtd. For more information on the JBoss JCA implementation refer to "JBoss Admin. and Development Guide 3.2.3" or "JBoss 4 Application Server Guide."
Note: XA-compliant data sources are not supported by Teradata.
At this point, the JNDI name of the data source can be viewed on the jmx-console web console for JBoss by using the following steps:
http://localhost:8080/jmx-console/
The JNDI name for the Teradata Data Source (i.e. TeradataDS) should appear under the java: Namespace as the screen capture above shows.
For CMP Entity Beans you need to add the following xml tags to the file
C:\JBossHome\server\default\conf\standardjbosscmp-jdbc.xml
<type-mapping>
<name>teradata</name>
<row-locking-template/>
<pk-constraint-template>CONSTRAINT ?1 PRIMARY KEY (?2)</pk-constraint-template>
<fk-constraint-template>ALTER TABLE ?1 ADD CONSTRAINT ?2 FOREIGN KEY (?3) REFERENCES ?4 (?5)</fk-constraint-template>
<alias-header-prefix>t</alias-header-prefix>
<alias-header-suffix>_</alias-header-suffix>
<alias-max-length>32</alias-max-length>
<subquery-supported>true</subquery-supported>
<true-mapping>1</true-mapping>
<false-mapping>0</false-mapping>
<function-mapping>
<function-name>count</function-name>
<function-sql>count(?1)</function-sql>
</function-mapping>
<function-mapping>
<function-name>locate</function-name>
<function-sql>locate(CAST(?1 as VARCHAR(254)),CAST(?2 as VaRCHAR(254)),?3)</function-sql>
</function-mapping>
<mapping>
<java-type>java.lang.Boolean</java-type>
<jdbc-type>BIT</jdbc-type>
<sql-type>SMALLINT</sql-type>
</mapping>
<mapping>
<java-type>java.lang.Short</java-type>
<jdbc-type>SMALLINT</jdbc-type>
<sql-type>SMALLINT</sql-type>
</mapping>
<mapping>
<java-type>java.lang.Integer</java-type>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
</mapping>
<mapping>
<java-type>java.lang.Long</java-type>
<jdbc-type>BIGINT</jdbc-type>
<sql-type>BIGINT</sql-type>
</mapping>
<mapping>
<java-type>java.lang.Float</java-type>
<jdbc-type>REAL</jdbc-type>
<sql-type>REAL</sql-type>
</mapping>
<mapping>
<java-type>java.lang.Double</java-type>
<jdbc-type>DOUBLE</jdbc-type>
<sql-type>DOUBLE PRECISION</sql-type>
</mapping>
<mapping>
<java-type>java.lang.Character</java-type>
<jdbc-type>CHAR</jdbc-type>
<sql-type>CHAR</sql-type>
</mapping>
<mapping>
<java-type>java.lang.String</java-type>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(254)</sql-type>
</mapping>
<mapping>
<java-type>java.sql.Date</java-type>
<jdbc-type>DATE</jdbc-type>
<sql-type>DATE</sql-type>
</mapping>
<mapping>
<java-type>java.sql.Time</java-type>
<jdbc-type>TIME</jdbc-type>
<sql-type>TIME</sql-type>
</mapping>
<mapping>
<java-type>java.sql.Timestamp</java-type>
<jdbc-type>TIMESTAMP</jdbc-type>
<sql-type>TIMESTAMP</sql-type>
</mapping>
<!-- this one gives errors with DB2 V8.1
and at least the NET driver
<mapping>
<java-type>java.lang.Object</java-type>
<jdbc-type>JAVA_OBJECT</jdbc-type>
<sql-type>BLOB(2000)</sql-type>
</mapping>
-->
<mapping>
<java-type>java.lang.Object</java-type>
<jdbc-type>VARBINARY</jdbc-type>
<sql-type>BLOB(2000)</sql-type>
</mapping>
</type-mapping>
The standard deployment descriptor to configure the JBoss CMP container is the standardjbosscmp-jdbc.xml file. Complete documentation of the XML tags for standardjbosscmp-jdbc.xml is in the directory C:\JBossHome\docs\dtd
Bean Managed Persistence (BMP) applications need to reference a Data source in the ejb-jar.xml file as the example below shows:
<resource-ref>
<res-ref-name>teraDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
ejb-jar.xml is the standard deployment descriptor file for enterprise java beans. Complete documentation of the XML tags for ejb-jar.xml is in the directory:
C:\JBossHome\docs\dtd
In addition, the jboss.xml file must reference the JDBC data source directly as follows:
<resource-ref>
<res-ref-name>teraDB</res-ref-name>
<jndi-name>java:/TeradataDS</jndi-name>
</resource-ref>
The jboss.xml is the deployment descriptor which has JBoss-specific information.
Complete documentation of the XML tags for jboss.xml is in the directory
C:\JBossHome\docs\dtd\
Container Managed Persistence (CMP) entity beans need a reference to the Teradata Data source in the jbosscmp-jdbc.xml file as the example below shows:
<?xml version="1.0" encoding="UTF-8"?>
<jbosscmp-jdbc>
<defaults>
<datasource>java:/TeradataDS</datasource>
<datasource-mapping>teradata</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
The jbosscmp-jdbc.xml file replaces standardjbosscmp-jdbc.xml file for a specific application. The complete documentation of the XML tags for jbosscmp-jdbc.xml file is in the directory
C:\JBossHome\docs\dtd
The following code creates the initial context:
Context ctx = new InitialContext();
To perform a JNDI lookup to obtain the DataSource, the following code can be used:
DataSource ds = (DataSource) ctx.lookup(jndiName);
To obtain a connection from the DataSource, the following code can be used:
Connection con = ds.getConnection();
Complete sample servlets are listed here.
User transactions will not work in standalone Client Applications. J2EE user transactions require the "java:comp" JNDI environment to work with JBoss. User transactions can not be run from a standalone application because standalone clients do not access to the JBoss name space "java:comp". All Servlets, Session and Entity beans can use user transactions because these components run inside the JBoss application server which has access to JNDI name space "java:comp".