How best to list JBoss AS 7 datasource properties in Java code?
benkirby Mar 15, 2012 6:53 AMI'm running JBoss AS 7.1.0.CR1b. I've got several datasources defined in my standalone.xml e.g.
{code:xml}
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:/MyDS" pool-name="MyDS_Pool" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>some-url</connection-url>
<driver>the-driver</driver>
[etc]
{code}
Everything works great.
I'm trying to access the information contained here within my code - specifically the `connection-url` and `driver` properties.
I've tried getting the Datasource from JNDI, as normal, but it doesn't appear to provide access to these properties:
{code}
// catches removed
InitialContext context;
DataSource dataSource = null;
context = new InitialContext();
dataSource = (DataSource) context.lookup(jndi);
{code}
ClientInfo and DatabaseMetadata from a Connection object from this Datasource also don't contain these granular, JBoss properties.
My code will be running inside the container with the datasource specfied, so all should be available. I've looked at the IronJacamar interface
{{org.jboss.jca.common.api.metadata.ds.DataSource}}
, and its implementing class, and these seem to have accessible hooks to the information I require, but I can't find any information on how to create such objects with these already deployed resources within the container (only constructor on impl involves inputting all properties manually).
JBoss AS 7's Command-Line Interface allows you to navigate and list the datasources as a directory system. http://www.paykin.info/java/add-datasource-programaticaly-cli-jboss-7/ provides an excellent post on how to use what I've been told is the Java Management API, but this appears to involve connecting to the target JBoss server externally:
{code}
ModelControllerClient client = ModelControllerClient.Factory.create(
InetAddress.getByName("127.0.0.1"), 9999);
{code}
My code is already running within that server, so I was hoping there was a way to achieve this without a connection. Can I inject an instance of some JBoss class which I can then query to get the populated IronJacamar objects, or similar? Or is the Management API the best way to get at them?
Hope you can help, many thanks.