Simplify classes by creating an inheritance hierarchy of the JDBC classes.

pull/6/head
Brett Wooldridge 11 years ago
parent dea09c0654
commit 66a6e8052f

@ -263,7 +263,7 @@ public class HikariClassTransformer implements ClassFileTransformer
{
ConstPool constPool = targetClassFile.getConstPool();
for (CtMethod method : srcClass.getDeclaredMethods())
for (CtMethod method : srcClass.getMethods())
{
if (method.getAnnotation(HikariInject.class) == null)
{
@ -287,7 +287,7 @@ public class HikariClassTransformer implements ClassFileTransformer
Annotation annotation = new Annotation("com.zaxxer.hikari.javassist.HikariOverride", constPool);
attr.setAnnotation(annotation);
for (CtMethod method : srcClass.getDeclaredMethods())
for (CtMethod method : srcClass.getMethods())
{
if (method.getAnnotation(HikariOverride.class) == null)
{
@ -377,7 +377,8 @@ public class HikariClassTransformer implements ClassFileTransformer
for (CtMethod method : targetClass.getDeclaredMethods())
{
if ((method.getModifiers() & Modifier.PUBLIC) != Modifier.PUBLIC || // only public methods
method.getAnnotation(HikariInject.class) != null) // ignore methods we've injected, they already try..catch
method.getAnnotation(HikariInject.class) != null ||
method.getAnnotation(HikariOverride.class) != null) // ignore methods we've injected, they already try..catch
{
continue;
}

@ -17,51 +17,21 @@
package com.zaxxer.hikari.proxy;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.zaxxer.hikari.javassist.HikariInject;
import com.zaxxer.hikari.javassist.HikariOverride;
/**
*
* @author Brett Wooldridge
*/
public class CallableStatementProxy implements IHikariStatementProxy
public abstract class CallableStatementProxy extends PreparedStatementProxy implements IHikariStatementProxy, CallableStatement
{
private static ProxyFactory PROXY_FACTORY;
@HikariInject protected IHikariConnectionProxy _connection;
protected Statement delegate;
static
{
__static();
}
protected CallableStatementProxy(ConnectionProxy connection, CallableStatement statement)
{
this._connection = connection;
this.delegate = statement;
super(connection, statement);
}
@HikariInject
public void _setConnectionProxy(IHikariConnectionProxy connection)
{
this._connection = connection;
}
@HikariInject
public SQLException _checkException(SQLException e)
{
return _connection._checkException(e);
}
// **********************************************************************
// Overridden java.sql.CallableStatement Methods
// **********************************************************************
@ -80,71 +50,6 @@ public class CallableStatementProxy implements IHikariStatementProxy
}
}
public ResultSet executeQuery() throws SQLException
{
try
{
ResultSet rs = ((PreparedStatement) delegate).executeQuery();
if (rs == null)
{
return null;
}
IHikariResultSetProxy resultSet = (IHikariResultSetProxy) PROXY_FACTORY.getProxyResultSet(this, rs);
resultSet._setProxyStatement(this);
return (ResultSet) resultSet;
}
catch (SQLException e)
{
throw _checkException(e);
}
}
public ResultSet executeQuery(String sql) throws SQLException
{
try
{
ResultSet rs = delegate.executeQuery(sql);
if (rs == null)
{
return null;
}
ResultSet resultSet = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) resultSet)._setProxyStatement(this);
return (ResultSet) resultSet;
}
catch (SQLException e)
{
throw _checkException(e);
}
}
public ResultSet getGeneratedKeys() throws SQLException
{
try
{
ResultSet rs = delegate.getGeneratedKeys();
if (rs == null)
{
return null;
}
ResultSet resultSet = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) resultSet)._setProxyStatement(this);
return resultSet;
}
catch (SQLException e)
{
throw _checkException(e);
}
}
public Connection getConnection()
{
return (Connection) _connection;
}
// ***********************************************************************
// These methods contain code we do not want injected into the actual
// java.sql.Connection implementation class. These methods are only
@ -152,21 +57,4 @@ public class CallableStatementProxy implements IHikariStatementProxy
// delegating proxies are used.
// ***********************************************************************
private static void __static()
{
if (PROXY_FACTORY == null)
{
PROXY_FACTORY = JavassistProxyFactoryFactory.getProxyFactory();
}
}
public void __close() throws SQLException
{
if (delegate.isClosed())
{
return;
}
delegate.close();
}
}

@ -47,7 +47,7 @@ import com.zaxxer.hikari.javassist.HikariOverride;
*
* @author Brett Wooldridge
*/
public class ConnectionProxy implements IHikariConnectionProxy
public abstract class ConnectionProxy implements IHikariConnectionProxy, Connection
{
private static ProxyFactory PROXY_FACTORY;

@ -8,5 +8,7 @@ public interface IHikariStatementProxy
void _setConnectionProxy(IHikariConnectionProxy connectionProxy);
void _releaseResultSet(IHikariResultSetProxy resultSet);
SQLException _checkException(SQLException e);
}

@ -141,7 +141,10 @@ public final class JavassistProxyFactoryFactory
Set<String> superSigs = new HashSet<String>();
for (CtMethod method : superClassCt.getMethods())
{
superSigs.add(method.getName() + method.getSignature());
if ((method.getModifiers() & Modifier.ABSTRACT) != Modifier.ABSTRACT)
{
superSigs.add(method.getName() + method.getSignature());
}
}
methodBody = methodBody.replace("cast", primaryInterface.getName());

@ -16,68 +16,25 @@
package com.zaxxer.hikari.proxy;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.zaxxer.hikari.javassist.HikariInject;
import com.zaxxer.hikari.javassist.HikariOverride;
/**
*
* @author Brett Wooldridge
*/
public class PreparedStatementProxy implements IHikariStatementProxy
public abstract class PreparedStatementProxy extends StatementProxy implements IHikariStatementProxy, PreparedStatement
{
private static ProxyFactory PROXY_FACTORY;
@HikariInject protected IHikariConnectionProxy _connection;
protected Statement delegate;
static
{
__static();
}
protected PreparedStatementProxy(ConnectionProxy connection, PreparedStatement statement)
{
this._connection = connection;
this.delegate = statement;
}
@HikariInject
public void _setConnectionProxy(IHikariConnectionProxy connection)
{
this._connection = connection;
}
@HikariInject
public SQLException _checkException(SQLException e)
{
return ((IHikariConnectionProxy) getConnection())._checkException(e);
super(connection, statement);
}
// **********************************************************************
// Overridden java.sql.PreparedStatement Methods
// **********************************************************************
@HikariOverride
public void close() throws SQLException
{
((IHikariConnectionProxy) getConnection())._unregisterStatement(this);
try
{
__close();
}
catch (SQLException e)
{
throw _checkException(e);
}
}
public ResultSet executeQuery() throws SQLException
{
try
@ -98,51 +55,6 @@ public class PreparedStatementProxy implements IHikariStatementProxy
}
}
public ResultSet executeQuery(String sql) throws SQLException
{
try
{
ResultSet rs = delegate.executeQuery(sql);
if (rs == null)
{
return null;
}
ResultSet resultSet = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) resultSet)._setProxyStatement(this);
return (ResultSet) resultSet;
}
catch (SQLException e)
{
throw _checkException(e);
}
}
public ResultSet getGeneratedKeys() throws SQLException
{
try
{
ResultSet rs = delegate.getGeneratedKeys();
if (rs == null)
{
return null;
}
ResultSet resultSet = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) resultSet)._setProxyStatement(this);
return resultSet;
}
catch (SQLException e)
{
throw _checkException(e);
}
}
public Connection getConnection()
{
return (Connection) _connection;
}
// ***********************************************************************
// These methods contain code we do not want injected into the actual
// java.sql.Connection implementation class. These methods are only
@ -150,22 +62,4 @@ public class PreparedStatementProxy implements IHikariStatementProxy
// delegating proxies are used.
// ***********************************************************************
private static void __static()
{
if (PROXY_FACTORY == null)
{
PROXY_FACTORY = JavassistProxyFactoryFactory.getProxyFactory();
}
}
public void __close() throws SQLException
{
if (delegate.isClosed())
{
return;
}
delegate.close();
}
}

@ -25,9 +25,9 @@ import com.zaxxer.hikari.javassist.HikariInject;
/**
* @author Brett Wooldridge
*/
public class ResultSetProxy implements IHikariResultSetProxy
public abstract class ResultSetProxy implements IHikariResultSetProxy, ResultSet
{
private IHikariStatementProxy _statement;
@HikariInject protected IHikariStatementProxy _statement;
protected final ResultSet delegate;

@ -27,12 +27,11 @@ import com.zaxxer.hikari.javassist.HikariOverride;
/**
* @author Brett Wooldridge
*/
public class StatementProxy implements IHikariStatementProxy
public abstract class StatementProxy implements IHikariStatementProxy, Statement
{
private static ProxyFactory PROXY_FACTORY;
protected static ProxyFactory PROXY_FACTORY;
@HikariInject
protected IHikariConnectionProxy _connection;
@HikariInject protected IHikariConnectionProxy _connection;
protected Statement delegate;
@ -59,6 +58,11 @@ public class StatementProxy implements IHikariStatementProxy
return _connection._checkException(e);
}
@HikariInject
public void _releaseResultSet(IHikariResultSetProxy resultSet)
{
}
// **********************************************************************
// Overridden java.sql.Statement Methods
// **********************************************************************
@ -84,12 +88,30 @@ public class StatementProxy implements IHikariStatementProxy
ResultSet rs = delegate.executeQuery(sql);
if (rs == null)
{
return null;
rs = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) rs)._setProxyStatement(this);
}
return rs;
}
catch (SQLException e)
{
throw _checkException(e);
}
}
public ResultSet getResultSet() throws SQLException
{
try
{
ResultSet rs = delegate.getResultSet();
if (rs != null)
{
rs = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) rs)._setProxyStatement(this);
}
ResultSet resultSet = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) resultSet)._setProxyStatement(this);
return resultSet;
return rs;
}
catch (SQLException e)
{
@ -104,12 +126,11 @@ public class StatementProxy implements IHikariStatementProxy
ResultSet rs = delegate.getGeneratedKeys();
if (rs == null)
{
return null;
rs = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) rs)._setProxyStatement(this);
}
ResultSet resultSet = PROXY_FACTORY.getProxyResultSet(this, rs);
((IHikariResultSetProxy) resultSet)._setProxyStatement(this);
return resultSet;
return rs;
}
catch (SQLException e)
{
@ -129,7 +150,7 @@ public class StatementProxy implements IHikariStatementProxy
// delegating proxies are used.
// ***********************************************************************
private static void __static()
protected static void __static()
{
if (PROXY_FACTORY == null)
{

Loading…
Cancel
Save