Package org.pjdbc.sql
Class ProxyConnection
java.lang.Object
org.pjdbc.sql.AbstractWrapper
org.pjdbc.sql.AbstractConnection
org.pjdbc.sql.ProxyConnection
- All Implemented Interfaces:
AutoCloseable,Connection,Wrapper
Base class for proxy connections that automatically delegates statement creation
to the driver's proxy methods. This eliminates ~60 lines of boilerplate per driver.
Usage
Extend this class in your driver and implement any custom behavior:
private class MyConnection extends ProxyConnection {
private final MyConfig config;
MyConnection(Connection conn, AbstractProxyDriver driver, String url, Properties info) throws SQLException {
super(conn, driver, url, info);
this.config = new MyConfig(url);
}
public MyConfig getConfig() { return config; }
}
The driver must override the proxy methods (proxyStatement, proxyPreparedStatement, proxyCallableStatement) to provide custom statement wrappers.
- See Also:
-
Field Summary
Fields inherited from class org.pjdbc.sql.AbstractConnection
connectionDelegates, driver, info, urlFields inherited from class org.pjdbc.sql.AbstractWrapper
delegatesFields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE -
Constructor Summary
ConstructorsConstructorDescriptionProxyConnection(Connection conn, AbstractProxyDriver driver, String url, Properties info) Create a proxy connection. -
Method Summary
Modifier and TypeMethodDescriptioncreateStatement(int resultSetType, int resultSetConcurrency) createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) protected AbstractProxyDriverGet the proxy driver for subclass access.prepareCall(String sql) prepareCall(String sql, int resultSetType, int resultSetConcurrency) prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement(String sql) prepareStatement(String sql, int autoGeneratedKeys) prepareStatement(String sql, int[] columnIndexes) prepareStatement(String sql, int resultSetType, int resultSetConcurrency) prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) prepareStatement(String sql, String[] columnNames) Methods inherited from class org.pjdbc.sql.AbstractConnection
abort, clearWarnings, close, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStruct, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getConnections, getDelegate, getDriver, getHoldability, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getURL, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, wrap, wrap, wrap, wrap, wrap, wrapMethods inherited from class org.pjdbc.sql.AbstractWrapper
isWrapperFor, unwrapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValidMethods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
Constructor Details
-
ProxyConnection
public ProxyConnection(Connection conn, AbstractProxyDriver driver, String url, Properties info) throws SQLException Create a proxy connection.- Parameters:
conn- the underlying connectiondriver- the proxy driver (must be AbstractProxyDriver)url- the JDBC URLinfo- connection properties- Throws:
SQLException- if connection setup fails
-
-
Method Details
-
getProxyDriver
Get the proxy driver for subclass access. -
createStatement
- Specified by:
createStatementin interfaceConnection- Overrides:
createStatementin classAbstractConnection- Throws:
SQLException
-
createStatement
- Specified by:
createStatementin interfaceConnection- Overrides:
createStatementin classAbstractConnection- Throws:
SQLException
-
createStatement
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
createStatementin interfaceConnection- Overrides:
createStatementin classAbstractConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classAbstractConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classAbstractConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classAbstractConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classAbstractConnection- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classAbstractConnection- Throws:
SQLException
-
prepareStatement
- Specified by:
prepareStatementin interfaceConnection- Overrides:
prepareStatementin classAbstractConnection- Throws:
SQLException
-
prepareCall
- Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classAbstractConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException - Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classAbstractConnection- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException - Specified by:
prepareCallin interfaceConnection- Overrides:
prepareCallin classAbstractConnection- Throws:
SQLException
-