User: oberg
Date: 00/12/07 07:44:52
Modified: src/main/org/jboss/jdbc Connection.java
HypersonicDatabase.java
HypersonicDatabaseMBean.java InstantDBDatabase.java
InstantDBDatabaseMBean.java
JDBCDataSourceLoader.java
JDBCDataSourceLoaderMBean.java JdbcProvider.java
JdbcProviderMBean.java XADataSourceLoader.java
XADataSourceLoaderMBean.java
Log:
Changed configuration scheme (lots of changes to jboss.conf, jboss.jcml,
org.jboss.Main)
Added ServiceControl
Changed jBoss -> JBoss
Changed GPL -> LGPL
Added jaxp/parser
Updated services to have default constructors
Revision Changes Path
1.2 +3 -3 jboss/src/main/org/jboss/jdbc/Connection.java
Index: Connection.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/Connection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Connection.java 2000/05/15 14:33:11 1.1
+++ Connection.java 2000/12/07 15:44:50 1.2
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
@@ -12,7 +12,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface Connection
extends java.sql.Connection
1.5 +3 -3 jboss/src/main/org/jboss/jdbc/HypersonicDatabase.java
Index: HypersonicDatabase.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/HypersonicDatabase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HypersonicDatabase.java 2000/11/07 12:22:57 1.4
+++ HypersonicDatabase.java 2000/12/07 15:44:50 1.5
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
@@ -27,7 +27,7 @@
*
* @see HypersonicDatabaseMBean
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class HypersonicDatabase
extends ServiceMBeanSupport
1.3 +3 -3 jboss/src/main/org/jboss/jdbc/HypersonicDatabaseMBean.java
Index: HypersonicDatabaseMBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/HypersonicDatabaseMBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HypersonicDatabaseMBean.java 2000/11/07 12:22:57 1.2
+++ HypersonicDatabaseMBean.java 2000/12/07 15:44:50 1.3
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
@@ -12,7 +12,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public interface HypersonicDatabaseMBean
extends org.jboss.util.ServiceMBean
1.3 +3 -3 jboss/src/main/org/jboss/jdbc/InstantDBDatabase.java
Index: InstantDBDatabase.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/InstantDBDatabase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- InstantDBDatabase.java 2000/06/16 13:10:29 1.2
+++ InstantDBDatabase.java 2000/12/07 15:44:50 1.3
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
@@ -28,7 +28,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class InstantDBDatabase
extends ServiceMBeanSupport
1.2 +3 -3 jboss/src/main/org/jboss/jdbc/InstantDBDatabaseMBean.java
Index: InstantDBDatabaseMBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/InstantDBDatabaseMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InstantDBDatabaseMBean.java 2000/04/22 14:30:13 1.1
+++ InstantDBDatabaseMBean.java 2000/12/07 15:44:50 1.2
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
@@ -12,7 +12,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface InstantDBDatabaseMBean
extends org.jboss.util.ServiceMBean
1.7 +3 -3 jboss/src/main/org/jboss/jdbc/JDBCDataSourceLoader.java
Index: JDBCDataSourceLoader.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/JDBCDataSourceLoader.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JDBCDataSourceLoader.java 2000/10/05 01:36:33 1.6
+++ JDBCDataSourceLoader.java 2000/12/07 15:44:50 1.7
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jdbc;
@@ -25,7 +25,7 @@
/**
* Service that loads a JDBC 1 connection pool. The constructors are called by
* the JMX engine based on your MLET tags.
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
* @author Aaron Mulder ([EMAIL PROTECTED])
*/
public class JDBCDataSourceLoader extends ServiceMBeanSupport implements
JDBCDataSourceLoaderMBean {
1.4 +2 -2 jboss/src/main/org/jboss/jdbc/JDBCDataSourceLoaderMBean.java
Index: JDBCDataSourceLoaderMBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/JDBCDataSourceLoaderMBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JDBCDataSourceLoaderMBean.java 2000/10/05 01:36:33 1.3
+++ JDBCDataSourceLoaderMBean.java 2000/12/07 15:44:50 1.4
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jdbc;
1.2 +26 -41 jboss/src/main/org/jboss/jdbc/JdbcProvider.java
Index: JdbcProvider.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/JdbcProvider.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JdbcProvider.java 2000/04/22 14:30:13 1.1
+++ JdbcProvider.java 2000/12/07 15:44:51 1.2
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
@@ -20,39 +20,50 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class JdbcProvider
- implements JdbcProviderMBean, MBeanRegistration
+ extends org.jboss.util.ServiceMBeanSupport
+ implements JdbcProviderMBean
{
// Constants -----------------------------------------------------
public static final String OBJECT_NAME = ":service=JdbcProvider";
// Attributes ----------------------------------------------------
+ String driverList = System.getProperty("jdbc.drivers");
- Log log = new Log("JDBC");
-
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
- public void start()
- throws Exception
+ public void setDrivers(String driverList)
{
+ this.driverList = driverList;
+ System.setProperty("jdbc.drivers", driverList);
}
- public void stop()
+ public String getDrivers()
{
+ return driverList;
}
-
- public ObjectName preRegister(MBeanServer server, ObjectName name)
- throws java.lang.Exception
+ // ServiceMBeanSupport overrides ---------------------------------
+ public String getName()
{
- Log.setLog(log);
-
- StringTokenizer drivers = new
StringTokenizer(System.getProperty("jdbc.drivers"), ",");
+ return "Transaction manager";
+ }
+
+ protected ObjectName getObjectName(MBeanServer server, ObjectName name)
+ throws javax.management.MalformedObjectNameException
+ {
+ return name == null ? new ObjectName(OBJECT_NAME) : name;
+ }
+
+ protected void initService()
+ throws Exception
+ {
+ StringTokenizer drivers = new StringTokenizer(driverList, ",");
while (drivers.hasMoreTokens())
{
String driver = drivers.nextToken();
@@ -65,31 +76,5 @@
log.error("Could not load driver:"+driver);
}
}
-
- Log.unsetLog();
-
- return new ObjectName(OBJECT_NAME);
- }
-
- public void postRegister(java.lang.Boolean registrationDone)
- {
- }
-
- public void preDeregister()
- throws java.lang.Exception
- {
- Log.setLog(log);
- try
- {
- stop();
- } finally
- {
- Log.unsetLog();
- }
- }
-
- public void postDeregister()
- {
}
- // Protected -----------------------------------------------------
}
1.2 +6 -9 jboss/src/main/org/jboss/jdbc/JdbcProviderMBean.java
Index: JdbcProviderMBean.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/JdbcProviderMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JdbcProviderMBean.java 2000/04/22 14:30:13 1.1
+++ JdbcProviderMBean.java 2000/12/07 15:44:51 1.2
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
@@ -12,17 +12,14 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface JdbcProviderMBean
+ extends org.jboss.util.ServiceMBean
{
- // Constants -----------------------------------------------------
-
// Public --------------------------------------------------------
- public void start()
- throws Exception;
+ public void setDrivers(String driverList);
- public void stop();
- // Protected -----------------------------------------------------
+ public String getDrivers();
}
1.13 +360 -311 jboss/src/main/org/jboss/jdbc/XADataSourceLoader.java
Index: XADataSourceLoader.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/XADataSourceLoader.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- XADataSourceLoader.java 2000/11/07 12:20:07 1.12
+++ XADataSourceLoader.java 2000/12/07 15:44:51 1.13
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jdbc;
@@ -11,6 +11,7 @@
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Properties;
+import java.util.StringTokenizer;
import javax.management.ObjectName;
import javax.management.MBeanServer;
import javax.naming.Context;
@@ -22,321 +23,369 @@
import org.jboss.logging.LogWriter;
import org.jboss.minerva.datasource.XAPoolDataSource;
import org.jboss.util.ServiceMBeanSupport;
-import org.jboss.logging.Logger;
+import org.jboss.logging.Log;
/**
* Service that loads a JDBC 2 std. extension-compliant connection pool. This
* pool generates connections that are registered with the current Transaction
* and support two-phase commit. The constructors are called by the JMX engine
* based on your MLET tags.
- * @version $Revision: 1.12 $
+ * @version $Revision: 1.13 $
* @author Aaron Mulder ([EMAIL PROTECTED])
*/
-public class XADataSourceLoader extends ServiceMBeanSupport
- implements XADataSourceLoaderMBean {
- private XAPoolDataSource source;
- private String url;
-
-/*
-// RO: This seems like a dangerous constructor, since the instance would be
inconsistently init.-ed
- public XADataSourceLoader() {}
-*/
-
- public XADataSourceLoader(String poolName, String xaDataSourceClass) {
- source = new XAPoolDataSource();
- source.setPoolName(poolName);
- XADataSource vendorSource = null;
- try {
- Class cls = Class.forName(xaDataSourceClass);
- vendorSource = (XADataSource)cls.newInstance();
- } catch(Exception e) {
- Logger.exception(e);
- throw new RuntimeException("Unable to initialize XA database pool
'"+poolName+"': "+e);
- }
- source.setDataSource(vendorSource);
- }
-
- public void setURL(String url) {
- this.url = url == null ? "" : url; // Save URL, so it doesn't disappear
from the JCML file
- XADataSource vendorSource = (XADataSource)source.getDataSource();
- try {
- Class cls = vendorSource.getClass();
- if(url != null && url.length() > 0) {
- Method setURL = cls.getMethod("setURL", new Class[]{String.class});
- setURL.invoke(vendorSource, new Object[]{url});
- }
- } catch(Exception e) {
- throw new IllegalArgumentException("Unable to set url to '"+url+"' for
pool "+source.getPoolName()+": "+e);
- }
- }
-
- public String getURL() {
- String result = "";
- XADataSource vendorSource = (XADataSource)source.getDataSource();
- try {
- Class cls = vendorSource.getClass();
- Method getURL = cls.getMethod("getURL", new Class[0]);
- result = (String) getURL.invoke(vendorSource, new Object[0]);
- } catch(Exception e) {
- log.error("There seems to be a problem with the JDBC URL: "+e);
- }
- if(result == null || result.length() == 0)
- result = url;
- return result;
- }
-
- public void setProperties(String properties) {
- XADataSource vendorSource = (XADataSource)source.getDataSource();
- try {
- Class cls = vendorSource.getClass();
- if(properties != null && properties.length() > 0) {
- Properties props = parseProperties(properties);
- Method setProperties = cls.getMethod("setProperties", new
Class[]{Properties.class});
- setProperties.invoke(vendorSource, new Object[]{props});
- }
- } catch(Exception e) {
- throw new IllegalArgumentException("Unable to set proprties to
'"+properties+"' for pool "+source.getPoolName()+": "+e);
- }
- }
-
- public String getProperties() {
- XADataSource vendorSource = (XADataSource)source.getDataSource();
- try {
- Class cls = vendorSource.getClass();
- Method getProperties = cls.getMethod("getProperties", new Class[0]);
- Properties result = (Properties) getProperties.invoke(vendorSource, new
Object[0]);
- if(result == null)
- return "";
- else
- return buildProperties(result);
- } catch(Exception e) {
- return "";
- }
- }
-
- public void setJDBCUser(String userName) {
- if(userName != null && userName.length() > 0)
- source.setJDBCUser(userName);
- }
-
- public String getJDBCUser() {
- String user = source.getJDBCUser();
- return user;
- }
-
- public void setPassword(String password) {
- if(password != null && password.length() > 0)
- source.setJDBCPassword(password);
- }
-
- public String getPassword() {
- return source.getJDBCPassword();
- }
-
- public void setLoggingEnabled(boolean enabled) {
- PrintWriter writer = enabled ? new LogWriter(log) : null;
- try {
- source.setLogWriter(writer);
- source.getDataSource().setLogWriter(writer);
- } catch(Exception e) {
- System.out.println("Unable to set logger for Minerva XA Pool!");
- }
- }
-
- public boolean isLoggingEnabled() {
- try {
- return source.getLogWriter() != null;
- } catch(Exception e) {
- return false;
- }
- }
-
- public void setMinSize(int minSize) {
- source.setMinSize(minSize);
- }
-
- public int getMinSize() {
- return source.getMinSize();
- }
-
- public void setMaxSize(int maxSize) {
- source.setMaxSize(maxSize);
- }
-
- public int getMaxSize() {
- return source.getMaxSize();
- }
-
- public void setBlocking(boolean blocking) {
- source.setBlocking(blocking);
- }
-
- public boolean isBlocking() {
- return source.isBlocking();
- }
-
- public void setGCEnabled(boolean gcEnabled) {
- source.setGCEnabled(gcEnabled);
- }
-
- public boolean isGCEnabled() {
- return source.isGCEnabled();
- }
-
- public void setGCInterval(long interval) {
- source.setGCInterval(interval);
- }
-
- public long getGCInterval() {
- return source.getGCInterval();
- }
-
- public void setGCMinIdleTime(long idleMillis) {
- source.setGCMinIdleTime(idleMillis);
- }
-
- public long getGCMinIdleTime() {
- return source.getGCMinIdleTime();
- }
-
- public void setIdleTimeoutEnabled(boolean enabled) {
- source.setIdleTimeoutEnabled(enabled);
- }
-
- public boolean isIdleTimeoutEnabled() {
- return source.isIdleTimeoutEnabled();
- }
-
- public void setIdleTimeout(long idleMillis) {
- source.setIdleTimeout(idleMillis);
- }
-
- public long getIdleTimeout() {
- return source.getIdleTimeout();
- }
-
- public void setMaxIdleTimeoutPercent(float percent) {
- source.setMaxIdleTimeoutPercent(percent);
- }
-
- public float getMaxIdleTimeoutPercent() {
- return source.getMaxIdleTimeoutPercent();
- }
-
- public void setInvalidateOnError(boolean invalidate) {
- source.setInvalidateOnError(invalidate);
- }
-
- public boolean isInvalidateOnError() {
- return source.isInvalidateOnError();
- }
-
- public void setTimestampUsed(boolean timestamp) {
- source.setTimestampUsed(timestamp);
- }
-
- public boolean isTimestampUsed() {
- return source.isTimestampUsed();
- }
-
- public ObjectName getObjectName(MBeanServer parm1, ObjectName parm2) throws
javax.management.MalformedObjectNameException {
- return (parm2 == null) ? new
ObjectName(OBJECT_NAME+",name="+source.getPoolName()) : parm2;
- }
-
- public String getName() {
- return source.getPoolName();
- }
-
- public void startService() throws Exception {
-
- initializePool();
- }
-
- public void stopService() {
- // Unbind from JNDI
- try {
- String name = source.getPoolName();
- new InitialContext().unbind("java:/"+name);
- log.log("XA Connection pool "+name+" removed from JNDI");
- source.close();
- log.log("XA Connection pool "+name+" shut down");
- } catch (NamingException e) {
- // Ignore
- }
- }
-
- // Private -------------------------------------------------------
-
- private void initializePool() throws NamingException, SQLException {
- Context ctx = null;
- Object mgr = null;
- source.setTransactionManagerJNDIName("java:/TransactionManager");
- try {
- ctx = new InitialContext();
- mgr = ctx.lookup("java:/TransactionManager");
- } catch(NamingException e) {
- throw new IllegalStateException("Cannot start XA Connection Pool; there
is no TransactionManager in JNDI!");
- }
- source.initialize();
-
- // Bind in JNDI
- bind(new InitialContext(), "java:/"+source.getPoolName(), source);
-
- log.log("XA Connection pool "+source.getPoolName()+" bound to
java:/"+source.getPoolName());
-
- // Test database
- source.getConnection().close();
- }
-
- private void bind(Context ctx, String name, Object val) throws NamingException {
- // Bind val to name in ctx, and make sure that all intermediate contexts
exist
- Name n = ctx.getNameParser("").parse(name);
- while (n.size() > 1) {
- String ctxName = n.get(0);
- try {
- ctx = (Context)ctx.lookup(ctxName);
- } catch (NameNotFoundException e) {
- ctx = ctx.createSubcontext(ctxName);
- }
- n = n.getSuffix(1);
- }
-
- ctx.bind(n.get(0), val);
- }
-
- private static Properties parseProperties(String string) {
- Properties props = new Properties();
- if(string == null || string.length() == 0) return props;
- int lastPos = -1;
- int pos = string.indexOf(";");
- while(pos > -1) {
- addProperty(props, string.substring(lastPos+1, pos));
- lastPos = pos;
- pos = string.indexOf(";", lastPos+1);
- }
- addProperty(props, string.substring(lastPos+1));
- return props;
- }
-
- private static void addProperty(Properties props, String property) {
- int pos = property.indexOf("=");
- if(pos < 0) {
- System.err.println("Unable to parse property '"+property+"' - please
use 'name=value'");
- return;
- }
- props.setProperty(property.substring(0, pos), property.substring(pos+1));
- }
-
- private static String buildProperties(Properties props) {
- StringBuffer buf = new StringBuffer();
- Iterator it = props.keySet().iterator();
- Object key;
- while(it.hasNext()) {
- key = it.next();
- if(buf.length() > 0)
- buf.append(';');
- buf.append(key).append('=').append(props.get(key));
- }
- return buf.toString();
- }
+public class XADataSourceLoader
+ extends ServiceMBeanSupport
+ implements XADataSourceLoaderMBean
+{
+ // Settings
+ String name;
+ String dataSourceClass;
+ String url;
+ String userName;
+ String password;
+ String properties;
+ boolean loggingEnabled;
+ int minSize;
+ int maxSize;
+ boolean blocking;
+ boolean gcEnabled;
+ long gcInterval;
+ long gcMinIdleTime;
+ boolean idleTimeoutEnabled;
+ long idleTimeout;
+ float maxIdleTimeoutPercent;
+ boolean invalidateOnError;
+ boolean timestampUsed;
+
+ XAPoolDataSource source;
+
+ public XADataSourceLoader()
+ {
+ }
+
+ public XADataSourceLoader(String poolName, String xaDataSourceClass)
+ {
+ setPoolName(poolName);
+ setDataSourceClass(xaDataSourceClass);
+ }
+ public void setPoolName(String name)
+ {
+ this.name = name;
+ log = new Log(name);
+ }
+
+ public String getPoolName()
+ {
+ return name;
+ }
+
+ public void setDataSourceClass(String clazz)
+ {
+ dataSourceClass = clazz;
+ }
+
+ public String getDataSourceClass()
+ {
+ return dataSourceClass;
+ }
+
+ public void setURL(String url)
+ {
+ this.url = url;
+ }
+
+ public String getURL()
+ {
+ return url;
+ }
+
+ public void setJDBCUser(String userName)
+ {
+ this.userName = userName;
+ }
+
+ public String getJDBCUser()
+ {
+ return userName;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setProperties(String properties)
+ {
+ this.properties = properties;
+ }
+
+ public String getProperties()
+ {
+ return properties;
+ }
+
+ public void setLoggingEnabled(boolean enabled)
+ {
+ this.loggingEnabled = enabled;
+ }
+
+ public boolean getLoggingEnabled()
+ {
+ return loggingEnabled;
+ }
+
+ public void setMinSize(int minSize)
+ {
+ this.minSize = minSize;
+ }
+
+ public int getMinSize()
+ {
+ return minSize;
+ }
+
+ public void setMaxSize(int maxSize)
+ {
+ this.maxSize = maxSize;
+ }
+
+ public int getMaxSize()
+ {
+ return maxSize;
+ }
+
+ public void setBlocking(boolean blocking)
+ {
+ this.blocking = blocking;
+ }
+
+ public boolean getBlocking()
+ {
+ return blocking;
+ }
+
+ public void setGCEnabled(boolean gcEnabled)
+ {
+ this.gcEnabled = gcEnabled;
+ }
+
+ public boolean getGCEnabled()
+ {
+ return gcEnabled;
+ }
+
+ public void setGCInterval(long interval)
+ {
+ this.gcInterval = interval;
+ }
+
+ public long getGCInterval()
+ {
+ return gcInterval;
+ }
+
+ public void setGCMinIdleTime(long idleMillis)
+ {
+ this.gcMinIdleTime = idleMillis;
+ }
+
+ public long getGCMinIdleTime()
+ {
+ return gcMinIdleTime;
+ }
+
+ public void setIdleTimeoutEnabled(boolean enabled)
+ {
+ this.idleTimeoutEnabled = enabled;
+ }
+
+ public boolean getIdleTimeoutEnabled()
+ {
+ return idleTimeoutEnabled;
+ }
+
+ public void setIdleTimeout(long idleMillis)
+ {
+ this.idleTimeout = idleMillis;
+ }
+
+ public long getIdleTimeout()
+ {
+ return idleTimeout;
+ }
+
+ public void setMaxIdleTimeoutPercent(float percent)
+ {
+ this.maxIdleTimeoutPercent = percent;
+ }
+
+ public float getMaxIdleTimeoutPercent()
+ {
+ return maxIdleTimeoutPercent;
+ }
+
+ public void setInvalidateOnError(boolean invalidate)
+ {
+ this.invalidateOnError = invalidate;
+ }
+
+ public boolean getInvalidateOnError()
+ {
+ return invalidateOnError;
+ }
+
+ public void setTimestampUsed(boolean timestamp)
+ {
+ this.timestampUsed = timestamp;
+ }
+
+ public boolean getTimestampUsed()
+ {
+ return timestampUsed;
+ }
+
+ // ServiceMBeanSupport implementation ----------------------------
+ public ObjectName getObjectName(MBeanServer server, ObjectName objectName)
+ throws javax.management.MalformedObjectNameException
+ {
+ return (objectName == null) ? new
ObjectName(OBJECT_NAME+",name="+getSource().getPoolName()) : objectName;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void startService() throws Exception
+ {
+ // Transfer settings
+ getSource().setPoolName(name);
+
+ XADataSource vendorSource = null;
+ Class cls = Class.forName(dataSourceClass);
+ vendorSource = (XADataSource)cls.newInstance();
+ getSource().setDataSource(vendorSource);
+
+ cls = vendorSource.getClass();
+ if(url != null && url.length() > 0)
+ {
+ Method setURL = cls.getMethod("setURL", new Class[] { String.class });
+ setURL.invoke(vendorSource, new Object[] { url });
+ }
+
+ cls = vendorSource.getClass();
+ if(properties != null && properties.length() > 0)
+ {
+ Properties props = parseProperties(properties);
+ Method setProperties = cls.getMethod("setProperties", new Class[] {
Properties.class });
+ setProperties.invoke(vendorSource, new Object[] { props });
+ }
+
+ if(userName != null && userName.length() > 0)
+ getSource().setJDBCUser(userName);
+
+ if(password != null && password.length() > 0)
+ getSource().setJDBCPassword(password);
+
+ PrintWriter writer = loggingEnabled ? new LogWriter(log) : null;
+ getSource().setLogWriter(writer);
+ getSource().getDataSource().setLogWriter(writer);
+ getSource().setMinSize(minSize);
+ getSource().setMaxSize(maxSize);
+ getSource().setBlocking(blocking);
+ getSource().setGCEnabled(gcEnabled);
+ getSource().setGCInterval(gcInterval);
+ getSource().setGCMinIdleTime(gcMinIdleTime);
+ getSource().setIdleTimeoutEnabled(idleTimeoutEnabled);
+ getSource().setIdleTimeout(idleTimeout);
+ getSource().setMaxIdleTimeoutPercent(maxIdleTimeoutPercent);
+ getSource().setInvalidateOnError(invalidateOnError);
+ getSource().setTimestampUsed(timestampUsed);
+
+ // Initialize pool
+ Context ctx = null;
+ Object mgr = null;
+ getSource().setTransactionManagerJNDIName("java:/TransactionManager");
+ try
+ {
+ ctx = new InitialContext();
+ mgr = ctx.lookup("java:/TransactionManager");
+ } catch(NamingException e)
+ {
+ throw new IllegalStateException("Cannot start XA Connection Pool; there is
no TransactionManager in JNDI!");
+ }
+ getSource().initialize();
+
+ // Bind in JNDI
+ bind(new InitialContext(), "java:/"+getSource().getPoolName(), source);
+
+ log.log("XA Connection pool "+getSource().getPoolName()+" bound to
java:/"+getSource().getPoolName());
+
+ // Test database
+ getSource().getConnection().close();
+ }
+
+ public void stopService()
+ {
+ // Unbind from JNDI
+ try {
+ String name = getSource().getPoolName();
+ new InitialContext().unbind("java:/"+name);
+ log.log("XA Connection pool "+name+" removed from JNDI");
+ getSource().close();
+ log.log("XA Connection pool "+name+" shut down");
+ } catch (NamingException e)
+ {
+ // Ignore
+ }
+ }
+
+ // Private -------------------------------------------------------
+ private XAPoolDataSource getSource()
+ {
+ if (source == null)
+ source = new XAPoolDataSource();
+ return source;
+ }
+
+ private void bind(Context ctx, String name, Object val) throws NamingException
+ {
+ // Bind val to name in ctx, and make sure that all intermediate contexts exist
+ Name n = ctx.getNameParser("").parse(name);
+ while (n.size() > 1)
+ {
+ String ctxName = n.get(0);
+ try
+ {
+ ctx = (Context)ctx.lookup(ctxName);
+ } catch (NameNotFoundException e)
+ {
+ ctx = ctx.createSubcontext(ctxName);
+ }
+ n = n.getSuffix(1);
+ }
+
+ ctx.bind(n.get(0), val);
+ }
+
+ private static Properties parseProperties(String string)
+ {
+ Properties props = new Properties();
+
+ StringTokenizer tokens = new StringTokenizer(string, ";=");
+
+ while (tokens.hasMoreTokens())
+ {
+ String key = tokens.nextToken();
+ String value = tokens.nextToken();
+ props.put(key, value);
+ }
+ return props;
+ }
}
+
1.5 +12 -8 jboss/src/main/org/jboss/jdbc/XADataSourceLoaderMBean.java
Index: XADataSourceLoaderMBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/XADataSourceLoaderMBean.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XADataSourceLoaderMBean.java 2000/10/05 01:36:34 1.4
+++ XADataSourceLoaderMBean.java 2000/12/07 15:44:51 1.5
@@ -1,7 +1,7 @@
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource EJB server
*
- * Distributable under GPL license.
+ * Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.jdbc;
@@ -13,6 +13,10 @@
public static final String OBJECT_NAME = ":service=XADataSource";
// Public --------------------------------------------------------
+ public void setPoolName(String name);
+ public String getPoolName();
+ public void setDataSourceClass(String clazz);
+ public String getDataSourceClass();
public void setURL(String url);
public String getURL();
public void setJDBCUser(String userName);
@@ -22,27 +26,27 @@
public void setProperties(String properties);
public String getProperties();
public void setLoggingEnabled(boolean enabled);
- public boolean isLoggingEnabled();
+ public boolean getLoggingEnabled();
public void setMinSize(int minSize);
public int getMinSize();
public void setMaxSize(int maxSize);
public int getMaxSize();
public void setBlocking(boolean blocking);
- public boolean isBlocking();
+ public boolean getBlocking();
public void setGCEnabled(boolean gcEnabled);
- public boolean isGCEnabled();
+ public boolean getGCEnabled();
public void setGCInterval(long interval);
public long getGCInterval();
public void setGCMinIdleTime(long idleMillis);
public long getGCMinIdleTime();
public void setIdleTimeoutEnabled(boolean enabled);
- public boolean isIdleTimeoutEnabled();
+ public boolean getIdleTimeoutEnabled();
public void setIdleTimeout(long idleMillis);
public long getIdleTimeout();
public void setMaxIdleTimeoutPercent(float percent);
public float getMaxIdleTimeoutPercent();
public void setInvalidateOnError(boolean invalidate);
- public boolean isInvalidateOnError();
+ public boolean getInvalidateOnError();
public void setTimestampUsed(boolean timestamp);
- public boolean isTimestampUsed();
+ public boolean getTimestampUsed();
}