1 12 package org.openbravo.database; 13 14 15 import java.sql.*; 16 import org.openbravo.exception.*; 17 import org.apache.commons.pool.ObjectPool; 18 19 public class CPStandAlone implements ConnectionProvider { 20 protected ConnectionProviderImpl myPool; 21 22 public CPStandAlone (String xmlPoolFile) { 23 if (myPool == null) { 24 try { 25 myPool = new ConnectionProviderImpl(xmlPoolFile); 26 } catch (Exception e) { 27 e.printStackTrace(); 28 } 29 } 30 } 31 32 34 private ObjectPool getPool(String poolName) throws PoolNotFoundException { 35 if (myPool == null) 36 throw new PoolNotFoundException(poolName + " not found"); 37 else 38 return myPool.getPool(poolName); 39 } 40 41 private ObjectPool getPool() throws PoolNotFoundException { 42 if (myPool == null) 43 throw new PoolNotFoundException("Default pool not found"); 44 else 45 return myPool.getPool(); 46 } 47 48 public Connection getConnection() throws NoConnectionAvailableException { 49 return (myPool.getConnection()); 50 } 51 52 public String getRDBMS() { 53 return (myPool.getRDBMS()); 54 } 55 56 public Connection getTransactionConnection() throws NoConnectionAvailableException, SQLException { 57 return myPool.getTransactionConnection(); 58 } 59 60 public void releaseCommitConnection(Connection conn) throws SQLException { 61 myPool.releaseCommitConnection(conn); 62 } 63 64 public void releaseRollbackConnection(Connection conn) throws SQLException { 65 myPool.releaseRollbackConnection(conn); 66 } 67 68 public PreparedStatement getPreparedStatement(String poolName, String strSql) throws Exception { 69 return myPool.getPreparedStatement(poolName, strSql); 70 } 71 72 public PreparedStatement getPreparedStatement(String strSql) throws Exception { 73 return myPool.getPreparedStatement(strSql); 74 } 75 76 public PreparedStatement getPreparedStatement(Connection conn, String strSql) throws SQLException { 77 return myPool.getPreparedStatement(conn, strSql); 78 } 79 80 public void releasePreparedStatement(PreparedStatement preparedStatement) throws SQLException { 81 myPool.releasePreparedStatement(preparedStatement); 82 } 83 84 public Statement getStatement(String poolName) throws Exception { 85 return myPool.getStatement(poolName); 86 } 87 88 public Statement getStatement() throws Exception { 89 return myPool.getStatement(); 90 } 91 92 public Statement getStatement(Connection conn) throws SQLException { 93 return myPool.getStatement(conn); 94 } 95 96 public void releaseStatement(Statement statement) throws SQLException { 97 myPool.releaseStatement(statement); 98 } 99 100 public void releaseTransactionalStatement(Statement statement) throws SQLException { 101 myPool.releaseTransactionalStatement(statement); 102 } 103 104 public void releaseTransactionalPreparedStatement(PreparedStatement preparedStatement) throws SQLException { 105 myPool.releaseTransactionalPreparedStatement(preparedStatement); 106 } 107 108 public CallableStatement getCallableStatement(String poolName, String strSql) throws Exception { 109 return myPool.getCallableStatement(poolName, strSql); 110 } 111 112 public CallableStatement getCallableStatement(String strSql) throws Exception { 113 return myPool.getCallableStatement(strSql); 114 } 115 116 public CallableStatement getCallableStatement(Connection conn, String strSql) throws SQLException { 117 return myPool.getCallableStatement(conn, strSql); 118 } 119 120 public void releaseCallableStatement(CallableStatement callableStatement) throws SQLException { 121 myPool.releaseCallableStatement(callableStatement); 122 } 123 124 public void destroy() { 125 try { 126 myPool.destroy(); 127 myPool=null; 128 } catch (Exception ex) { 129 } 130 } 131 } 132 | Popular Tags |