[jboss-svn-commits] JBL Code SVN: r7160 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/persistence/format/db
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 26 21:15:20 EDT 2006
Author: daniel.brum at jboss.com
Date: 2006-10-26 21:15:18 -0400 (Thu, 26 Oct 2006)
New Revision: 7160
Added:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManager.java
Log:
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManager.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManager.java 2006-10-27 01:14:34 UTC (rev 7159)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManager.java 2006-10-27 01:15:18 UTC (rev 7160)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.persistence.format.db;
+
+import java.sql.Connection;
+
+import org.jboss.soa.esb.common.Configuration;
+
+import com.mchange.v2.c3p0.ComboPooledDataSource;
+
+
+public class DBConnectionManager {
+
+ private static DBConnectionManager instance =null;
+
+ protected ComboPooledDataSource pooledDS = null;
+
+ private static final Object foo = new Integer(0);
+
+
+ protected DBConnectionManager() {}
+
+ public static DBConnectionManager getInstance() {
+ if (null != instance) {
+ return instance;
+ } synchronized(foo) {
+ if (null != instance)
+ return instance;
+ try {
+ instance = new DBConnectionManager();
+ instance.init();
+ }catch(Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ return instance;
+ }
+
+ }
+
+ private void init() throws Exception{
+ System.out.println("Initializing DBConnectionManager2...");
+ pooledDS = new ComboPooledDataSource();
+
+ pooledDS.setDriverClass(Configuration.getStoreDriver());
+ pooledDS.setJdbcUrl(Configuration.getStoreUrl());
+ pooledDS.setUser(Configuration.getStoreUser());
+ pooledDS.setPassword(Configuration.getStorePwd());
+ pooledDS.setMinPoolSize(Integer.valueOf(Configuration.getStorePoolMinSize()));
+ pooledDS.setInitialPoolSize(Integer.valueOf(Configuration.getStorePoolInitialSize()));
+ pooledDS.setMaxPoolSize(Integer.valueOf(Configuration.getStorePoolMaxSize()));
+ pooledDS.setAutomaticTestTable(Configuration.getStorePoolTestTable());
+ pooledDS.setCheckoutTimeout(Integer.valueOf(Configuration.getStorePoolTestTable()));
+ }
+
+
+
+ public Connection getConnection() throws Exception{
+
+ Connection conn = null;
+
+ //TODO: figure out why this is neccessary - pool should never return null if DB is up and can connect
+ //testing showed null was being returned from pool in QA test MessageStoreTest
+ while (true)
+ {
+ if (null!=pooledDS)
+ if (null != (conn=pooledDS.getConnection()))
+ break;
+ else
+ System.out.println("Null pooledDS");
+ try { Thread.sleep(1000); }
+ catch(Exception e) {}
+ }
+
+ return conn;
+
+ }
+
+}
More information about the jboss-svn-commits
mailing list