KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > database > ConnectionWrapper


1 package org.jahia.services.database;
2
3 import java.sql.CallableStatement JavaDoc;
4 import java.sql.Connection JavaDoc;
5 import java.sql.DatabaseMetaData JavaDoc;
6 import java.sql.PreparedStatement JavaDoc;
7 import java.sql.SQLException JavaDoc;
8 import java.sql.SQLWarning JavaDoc;
9 import java.sql.Savepoint JavaDoc;
10 import java.sql.Statement JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Map JavaDoc;
14
15 public class ConnectionWrapper implements Connection JavaDoc{
16
17     Connection JavaDoc connection;
18
19         private HashMap JavaDoc cachedStatements;
20
21     public ConnectionWrapper(Connection JavaDoc c) {
22         cachedStatements = new HashMap JavaDoc();
23         connection = c;
24     }
25     public void clearWarnings() throws SQLException JavaDoc {connection.clearWarnings();}
26     public void close() throws SQLException JavaDoc {
27     }
28     public void realClose() throws SQLException JavaDoc {
29 // try {
30
// for (Iterator ite = cachedStatements.keySet().iterator(); ite.hasNext();) {
31
// StatementWrapper eps = (StatementWrapper)cachedStatements.get(ite.next());
32
// eps.closeReally();
33
// }
34
// } finally {
35
connection.close();
36 // }
37
}
38     public void commit() throws SQLException JavaDoc {connection.commit();}
39     public Statement JavaDoc createStatement() throws SQLException JavaDoc {
40         return connection.createStatement();
41     }
42     public Statement JavaDoc createStatement(int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc {
43         return connection.createStatement(resultSetType, resultSetConcurrency);
44     }
45     public Statement JavaDoc createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException JavaDoc {
46         return connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
47     }
48     public boolean getAutoCommit() throws SQLException JavaDoc {
49         return connection.getAutoCommit();
50     }
51     public String JavaDoc getCatalog() throws SQLException JavaDoc {
52         return connection.getCatalog();
53     }
54     public DatabaseMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
55         return connection.getMetaData();
56     }
57     public int getTransactionIsolation() throws SQLException JavaDoc {
58         return connection.getTransactionIsolation();
59     }
60     public Map JavaDoc getTypeMap() throws SQLException JavaDoc {
61         return connection.getTypeMap();
62     }
63     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
64         return connection.getWarnings();
65     }
66     public boolean isClosed() throws SQLException JavaDoc {
67         return connection.isClosed();
68     }
69     public boolean isReadOnly() throws SQLException JavaDoc {
70         return connection.isReadOnly();
71     }
72     public String JavaDoc nativeSQL(String JavaDoc sql) throws SQLException JavaDoc {
73         return connection.nativeSQL(sql);
74     }
75     public CallableStatement JavaDoc prepareCall(String JavaDoc sql) throws SQLException JavaDoc {
76         return connection.prepareCall(sql);
77     }
78     public CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc {
79         return connection.prepareCall(sql, resultSetType, resultSetConcurrency);
80     }
81     public CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException JavaDoc {
82         return connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
83     }
84     /**
85      * EP Specific : caching preparedStatement for performance enhancement
86      */

87     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql) throws SQLException JavaDoc {
88 // PreparedStatement ps = (PreparedStatement)cachedStatements.get(sql);
89
// if (ps == null) {
90
// ps = new PreparedStatementWrapper(connection.prepareStatement(sql));
91
// cachedStatements.put(sql, ps);
92
// }
93
return connection.prepareStatement(sql);
94     }
95     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc {
96         return connection.prepareStatement(sql, autoGeneratedKeys);
97     }
98     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int[] columnIndexes) throws SQLException JavaDoc {
99         return connection.prepareStatement(sql, columnIndexes);
100     }
101     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc {
102         return connection.prepareStatement(sql, resultSetType, resultSetConcurrency);
103     }
104     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException JavaDoc {
105         return connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
106     }
107     public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, String JavaDoc[] columnNames) throws SQLException JavaDoc {
108         return connection.prepareStatement(sql, columnNames);
109     }
110     public void rollback() throws SQLException JavaDoc {connection.rollback();}
111     public void rollback(Savepoint JavaDoc savepoint) throws SQLException JavaDoc {connection.rollback(savepoint);}
112     public void releaseSavepoint(Savepoint JavaDoc savepoint) throws SQLException JavaDoc {connection.releaseSavepoint(savepoint);}
113     public void setAutoCommit(boolean autoCommit) throws SQLException JavaDoc {connection.setAutoCommit(autoCommit);}
114     public void setCatalog(String JavaDoc catalog) throws SQLException JavaDoc {connection.setCatalog(catalog);}
115     public void setReadOnly(boolean readOnly) throws SQLException JavaDoc {connection.setReadOnly(readOnly);}
116     public void setTransactionIsolation(int level) throws SQLException JavaDoc {connection.setTransactionIsolation(level);}
117     public void setTypeMap(Map JavaDoc map) throws SQLException JavaDoc {connection.setTypeMap(map);}
118     public int getHoldability() throws SQLException JavaDoc {
119         return connection.getHoldability();
120     }
121     public void setHoldability(int holdability) throws SQLException JavaDoc {connection.setHoldability(holdability);}
122     public Savepoint JavaDoc setSavepoint() throws SQLException JavaDoc {
123         return connection.setSavepoint();
124     }
125     public Savepoint JavaDoc setSavepoint(String JavaDoc name) throws SQLException JavaDoc {
126         return connection.setSavepoint(name);
127     }
128 }
Popular Tags