How do I declare the data source factory to use in JBoss 7?
smccormick Nov 29, 2012 12:52 PMI am attempting to write some code that will allow me to access all DB datasources at startup for Tomcat or JBoss. To do this I want to use the org.apache.commons.dbcp.BasicDataSource class, generated by the org.apache.commons.dbcp.BasicDataSourceFactory (both from Apache in commons-dbcp). The BasicDataSource class allows me to view the number of connections and some other fun stuff we'd like to know at server startup, programmatically.
Tomcat provides a mechanism to accomplish this in the server.xml file:
<Resource name="jdbc/MYDATASOURCE" auth="Container" type="javax.sql.DataSource"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
maxActive="3" maxIdle="1" maxWait="10000"
username="USERNAME" password="MYPASSWORD" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://192.168.0.0:3310/MYDATASOURCE" validationQuery="select 1" testOnBorrow="true"/>
Unfortunately I have not found anything in JBoss standalone.xml that allows me to do this, other than the <datasource-class>:
<datasource jndi-name="java:/MYDATASOURCE" pool-name="MYDATASOURCE_DB" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://192.168.0.0:3310/MYDATASOURCE</connection-url>
<datasource-class>org.apache.commons.dbcp.BasicDataSource</datasource-class>
<driver>mysql-connector-java-5.1.21.jar</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>10</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<use-fast-fail>false</use-fast-fail>
</validation>
<statement>
<track-statements>true</track-statements>
<prepared-statement-cache-size>0</prepared-statement-cache-size>
</statement>
</datasource>
Which still results in the return of org.jboss.jca.adapters.jdbc.WrapperDataSource as a result at runtime. So my guess is there must be a way to specify the connection factory to be used...or not?
Is there a mechanism in JBoss 7 (or 5 for that matter, we are actually trying to upgrade) that will allow me to do this? I have looked through tons of Blogs without success.
Forgive me if I have posted this incorrectly...I am new to the community.
Thanks!