KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > database > CPStandAlone


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

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 JavaDoc xmlPoolFile) {
23     if (myPool == null) {
24       try {
25         myPool = new ConnectionProviderImpl(xmlPoolFile);
26       } catch (Exception JavaDoc e) {
27         e.printStackTrace();
28       }
29     }
30   }
31
32   /* Database access utilities
33   */

34   private ObjectPool getPool(String JavaDoc 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 JavaDoc 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 JavaDoc poolName, String JavaDoc strSql) throws Exception JavaDoc {
69     return myPool.getPreparedStatement(poolName, strSql);
70   }
71
72   public PreparedStatement getPreparedStatement(String JavaDoc strSql) throws Exception JavaDoc {
73     return myPool.getPreparedStatement(strSql);
74   }
75
76   public PreparedStatement getPreparedStatement(Connection conn, String JavaDoc 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 JavaDoc poolName) throws Exception JavaDoc {
85     return myPool.getStatement(poolName);
86   }
87
88   public Statement getStatement() throws Exception JavaDoc {
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 JavaDoc poolName, String JavaDoc strSql) throws Exception JavaDoc {
109     return myPool.getCallableStatement(poolName, strSql);
110   }
111
112   public CallableStatement getCallableStatement(String JavaDoc strSql) throws Exception JavaDoc {
113     return myPool.getCallableStatement(strSql);
114   }
115
116   public CallableStatement getCallableStatement(Connection conn, String JavaDoc 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 JavaDoc ex) {
129     }
130   }
131 }
132
Popular Tags