[
http://jira.jboss.com/jira/browse/JBAS-1425?page=comments#action_12400110 ]
Steve Davidson commented on JBAS-1425:
--------------------------------------
Following code effectively creates connection Pool.
final String jndiURL = "jdbc/pool/" + schema;
//XaTXCM
ObjectName cmName = new ObjectName("jboss.jca:service=XaTxCM,name=" +
jndiURL);
// try to remove mbean if leftover...
if (server.isRegistered(cmName)) {
server.unregisterMBean(cmName);
}
Object cmBean =
server.createMBean("org.jboss.resource.connectionmanager.TxConnectionManager",
cmName);
assert cmBean != null : "Server never created TxConnectionManager for: "
+ schema;
assert server.isRegistered(cmName) : "Server never registered
ConnectionManager for: " + schema;
//ManagedConnection Factory
ObjectName mcfName = new
ObjectName("jboss.jca:service=ManagedConnectionFactory,name=" + jndiURL);
// try to remove mbean if leftover...
if (server.isRegistered(mcfName)) {
server.unregisterMBean(mcfName);
}
Object mbean =
server.createMBean("org.jboss.resource.connectionmanager.RARDeployment",
mcfName);
assert mbean != null : "Server never created ManagedConnectinoFactory for:
" + schema;
assert server.isRegistered(mcfName) : "Server never registered
ManagedConnectionFactory for: " + schema;
//ManagedConnectionPool
ObjectName mcpName = new
ObjectName("jboss.jca:service=ManagedConnectionPool,name=" + jndiURL);
// try to remove mbean if leftover...
if (server.isRegistered(mcpName)) {
server.unregisterMBean(mcpName);
}
Object pool =
server.createMBean("org.jboss.resource.connectionmanager.JBossManagedConnectionPool",
mcpName);
assert pool != null : "Server never created Connection Pool for: " +
schema;
assert server.isRegistered(mcpName) : "Server never registered Connection
Pool for: " + schema;
ObjectName serviceControllerName = new
ObjectName("jboss.system:service=ServiceController");
// anon block so I don't rename var al
{
AttributeList al = new AttributeList();
al.add(new Attribute("JndiName", jndiURL));
al.add(new Attribute("ManagedConnectionPool", mcpName));
al.add(new Attribute("CachedConnectionManager",
new ObjectName(
"jboss.jca:service=CachedConnectionManager")));
final ObjectName tmsName = new
ObjectName("jboss:service=TransactionManager");
al.add(new Attribute("TransactionManagerService", tmsName));
//BUG?
// al.add(new Attribute("LocalTransactions", Boolean.TRUE));
al.add(new Attribute("LocalTransactions", Boolean.FALSE));
al.add(new Attribute("TrackConnectionByTx", Boolean.TRUE));
// try to set the attributes on the bean
try {
server.setAttributes(cmName, al);
} catch (UndeclaredThrowableException e) {
final Throwable cause = e.getCause();
if (cause instanceof MBeanException) {
LOGGER.error("Exception setting Attribute on Server handle:
" + e.getMessage(), e);
throw (MBeanException) cause;
} //else
throw new HRNException(cause, ApplicationConstants.BASE_RESOURCE,
"common.error.db.connectionfailed",
new Object[] { cause.getMessage() });
}
}
// RARDeployment
{
AttributeList al = new AttributeList();
al.add(new Attribute("ManagedConnectionFactoryClass",
"org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory"));
al.add(new Attribute("ConnectionDefinition",
"javax.sql.DataSource"));
// al.add(new Attribute("LogWriter", ?));//PrintWriter
// try to set the attributes on the bean
server.setAttributes(mcfName, al);
}
// anon block so I don't rename vars
{
AttributeList al = new AttributeList();
al.add(new Attribute("PoolJndiName", jndiURL));
al.add(new Attribute("ManagedConnectionFactoryName", mcfName));
al.add(new Attribute("MinSize", new Integer(0)));
al.add(new Attribute("MaxSize", new Integer(50)));
al.add(new Attribute("BlockingTimeoutMillis", new Long(5000)));
al.add(new Attribute("IdleTimeoutMinutes", new Integer(7)));
al.add(new Attribute("Criteria", "ByNothing"));
// try to set the attributes on the bean
server.setAttributes(mcpName, al);
}
//DataSource
ObjectName dsName = new
ObjectName("jboss.jca:service=DataSourceBinding,name=" + jndiURL);
// try to remove mbean if leftover...
if (server.isRegistered(dsName)) {
server.unregisterMBean(dsName);
}
Object dsBean =
server.createMBean("org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService",
dsName);
assert dsBean != null : "Server never created DataSourceBinding for: " +
schema;
assert server.isRegistered(dsName) : "Server never registered
ConnectionManager for: " + schema;
{
AttributeList al = new AttributeList();
al.add(new Attribute("JndiName", jndiURL));
al.add(new Attribute("UseJavaContext", Boolean.TRUE));
al.add(new Attribute("ConnectionManager", cmName));
// try to set the attributes on the bean
server.setAttributes(dsName, al);
}// anon block so I don't rename var
// start the mbeans
// create and configure the ManagedConnectionFactory
/*
* //Service Controller should already be running!
* server.invoke(serviceControllerName, "create", new Object[]{mcfName},
new String[] {"javax.management.ObjectName"});
* server.invoke(serviceControllerName, "start", new Object[] {mcfName},
new String[] {"javax.management.ObjectName"});
*/
// assertTrue("State is not started",
"Started".equals(getServer().getAttribute(mcfName, "StateString")));
// Make the Connection URL
// Now set the important attributes:
final StringBuilder connectionURL = new StringBuilder("jdbc:");
final String sid = rs.getString(SID);
if (!rs.wasNull()) {
// Oracle DataBase
connectionURL.append("oracle:" + ORACLE_DRIVER_TYPE +
":@");
} else {
// There is a serious issue somewhere, or a new driver type
throw new HRNException(ApplicationConstants.BASE_RESOURCE,
"common.error.db.critical.sid", null);
}
connectionURL.append(rs.getString(MACHINE));
connectionURL.append(':');
connectionURL.append(rs.getString(PORT));
// TODO: Check to see if Oracle before adding following....
connectionURL.append(':');
connectionURL.append(sid);
// Now set the important attributes:
// create and configure the ManagedConnectionFactory
server.invoke(serviceControllerName, "create", new Object[] { mcfName
},
new String[] { "javax.management.ObjectName" });
server.invoke(serviceControllerName, "start", new Object[] { mcfName },
new String[] { "javax.management.ObjectName" });
assert "Started".equals(server.getAttribute(mcfName,
"StateString")) :
"State is not started for ManagedConnectionFactory: " + schema;
server.invoke(mcfName, "setManagedConnectionFactoryAttribute", new
Object[] { "XADataSourceClass",
java.lang.String.class,
"oracle.jdbc.xa.client.OracleXADataSource" }, new String[] {
"java.lang.String",
"java.lang.Class", "java.lang.Object" });
//BUG: JBoss currently ignoring URL, Username, etc. Instead, needs properties.
//HACK: Username, Password, URL all get ignored, UNLESS sent via properties
final StringBuilder properties = new StringBuilder(512);
properties.append("URL=");
properties.append(connectionURL);
properties.append("\nUser=");
properties.append(schema);
properties.append("\nPassword=");
properties.append(strPassword);
properties.append('\n');
server.invoke(mcfName, "setManagedConnectionFactoryAttribute", new
Object[] { "XADataSourceProperties",
java.lang.String.class, properties.toString() }, new String[] {
"java.lang.String", "java.lang.Class",
"java.lang.Object" });
// server.invoke(mcfName, "setManagedConnectionFactoryAttribute", new
Object[] { "ConnectionURL",
// java.lang.String.class, connectionURL.toString() }, new String[] {
"java.lang.String",
// "java.lang.Class", "java.lang.Object" });
// server.invoke(mcfName, "setManagedConnectionFactoryAttribute", new
Object[] { "UserName",
// java.lang.String.class, schema }, new String[] {
"java.lang.String", "java.lang.Class",
// "java.lang.Object" });
// server.invoke(mcfName, "setManagedConnectionFactoryAttribute", new
Object[] { "Password",
// java.lang.String.class, rs.getString(PASS) }, new String[] {
"java.lang.String", "java.lang.Class",
// "java.lang.Object" });
// start the pool
server.invoke(serviceControllerName, "create", new Object[] { mcpName
},
new String[] { "javax.management.ObjectName" });
server.invoke(serviceControllerName, "start", new Object[] { mcpName },
new String[] { "javax.management.ObjectName" });
// assertTrue("State is not started",
"Started".equals(getServer().getAttribute(mcpName, "StateString")));
// start the ConnectionManager
server.invoke(serviceControllerName, "create", new Object[] { cmName },
new String[] { "javax.management.ObjectName" });
server.invoke(serviceControllerName, "start", new Object[] { cmName },
new String[] { "javax.management.ObjectName" });
//Start the DataSource.
server.invoke(serviceControllerName, "create", new Object[] { dsName },
new String[] { "javax.management.ObjectName" });
server.invoke(serviceControllerName, "start", new Object[] { dsName },
new String[] { "javax.management.ObjectName" });
// Despite having gone through all of the above, we still don't have a handle
// to the dataSource, so get one and return it.
return (getDataSource(schema, false));
Programmatic Connection Definition Deployment
---------------------------------------------
Key: JBAS-1425
URL:
http://jira.jboss.com/jira/browse/JBAS-1425
Project: JBoss Application Server
Issue Type: Task
Security Level: Public(Everyone can see)
Components: JCA service
Reporter: Adrian Brock
Assigned To: Weston Price
Priority: Minor
Forums Discussion Thread:
http://www.jboss.org/index.html?module=bb&op=viewtopic&t=48673
Provide a mechanism where ConnectionFactorys/DataSources (Connection Definitions)
can be deployed/undeployed programmatically.
The basic design is as follows:
1) Provide a mechanism to instantiate MetaData for a connection factory.
This information is the same as the -ds.xml deployment format.
The MetaData can be logically divided into at least the following categories:
* RAR/ConnectionDefinition identification
* ManagedConnectionFactory
* Pool
* Security
* ConnectionManager
* Proxy/JNDI binding
2) Write an optimized version of the MetaData for the DataSource deployments
which are really a simplified version of the ConnectionFactory deployments with some
hardwiring.
3) Write a service that deploys the ConnectionFactory (creates MBeans)
from the MetaData and undeploys them based on their id (jndi binding).
4) Convert the ConnectionFactory deployer to construct the MetaData from the -ds.xml
files and invoke the service new service.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira