Example usage for java.sql Statement getClass

List of usage examples for java.sql Statement getClass

Introduction

In this page you can find the example usage for java.sql Statement getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.jolbox.bonecp.spring.BoneCPNativeJdbcExtractor.java

/**
 * @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter#getNativeStatement(java.sql.Statement)
 *///from w w  w .  j  a v a 2 s  .c  om
@Override
public Statement getNativeStatement(Statement stmt) throws SQLException {
    if (this.statementHandleClass.isAssignableFrom(stmt.getClass())) {
        return (Statement) ReflectionUtils.invokeJdbcMethod(this.getInternalStatementMethod, stmt);
    }
    return stmt;
}

From source file:net.big_oh.common.jdbc.JdbcObserverProxyStatementInvocationHandler.java

private String getSqlStringForMethodInvocation(Statement stmnt, Object[] args) {

    String sqlString = null;//from  ww  w  .  ja v a 2s .  co m

    if (PreparedStatement.class.isAssignableFrom(stmnt.getClass())) {
        sqlString = populatePreparedStatementSQLString((PreparedStatement) stmnt, preparedSQLTemplate);
    } else if (args != null && args.length > 0) {
        sqlString = args[0].toString();
    } else {
        sqlString = "Failed to derive an appropriate SQL statement :(";
    }

    return sqlString;

}

From source file:net.big_oh.common.jdbc.JdbcObserverProxyConnectionInvocationHandler.java

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

    // intercept calls that create statements
    if (Statement.class.isAssignableFrom(method.getReturnType())) {

        StatementInstantiationEvent event = new StatementInstantiationEvent((Connection) proxy);

        for (JDBCEventListener listener : listeners) {
            try {
                listener.statementRequested(event);
            } catch (RuntimeException rte) {
                logger.error(rte);/*w w w .ja v  a 2s.  co m*/
            }
        }

        Statement newStatement = (Statement) method.invoke(originalConnection, args);

        // Create proxy for the returned statement object
        String hardCodedSqlForStatement = (newStatement instanceof PreparedStatement && args != null
                && args.length > 0 && args[0] instanceof String) ? args[0].toString() : null;
        boolean newStatementInterfacesContainsMethodReturnTypeClass = Arrays
                .asList(newStatement.getClass().getInterfaces()).contains(method.getReturnType());
        Class<?>[] interfaces = new Class<?>[(newStatement.getClass().getInterfaces().length
                + ((newStatementInterfacesContainsMethodReturnTypeClass) ? 0 : 1))];
        System.arraycopy(newStatement.getClass().getInterfaces(), 0, interfaces, 0,
                newStatement.getClass().getInterfaces().length);
        if (!newStatementInterfacesContainsMethodReturnTypeClass) {
            interfaces[newStatement.getClass().getInterfaces().length] = method.getReturnType();
        }
        Statement statementProxy = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(),
                interfaces, new JdbcObserverProxyStatementInvocationHandler(newStatement, listeners,
                        hardCodedSqlForStatement));

        for (JDBCEventListener listener : listeners) {
            try {
                listener.statementInstantiated(event, statementProxy);
            } catch (RuntimeException rte) {
                logger.error(rte);
            }
        }

        return statementProxy;
    }

    // otherwise, just invoke the method on the underlying
    // originalConnection
    return method.invoke(originalConnection, args);

}

From source file:org.hlc.quickdb.executor.statement.CallableStatementHandler.java

@Override
public int update(Statement statement) throws SQLException {

    if (statement instanceof CallableStatement) {
        parameterize((CallableStatement) statement);
        return ((CallableStatement) statement).execute() ? 1 : -1;
    }//  www.  j a  va 2  s.  c  om
    throw new PersistenceException(statement.getClass() + "?CallableStatement");
}

From source file:org.hlc.quickdb.executor.statement.PreparedStatementHandler.java

@Override
public int[] batch(Statement statement) throws SQLException {
    if (statement instanceof PreparedStatement) {
        batchParameterize(statement);/* w  w w .  j  a  v a2s.c o m*/
        return ((PreparedStatement) statement).executeBatch();
    }
    throw new PersistenceException(statement.getClass() + "?PreparedStatement");
}

From source file:org.hlc.quickdb.executor.statement.PreparedStatementHandler.java

@Override
public int update(Statement statement) throws SQLException {

    if (statement instanceof PreparedStatement) {
        parameterize(statement);/*from  w w w.  j ava 2 s  . c  om*/
        return ((PreparedStatement) statement).executeUpdate();
    }
    throw new PersistenceException(statement.getClass() + "?PreparedStatement");
}

From source file:org.hlc.quickdb.executor.statement.PreparedStatementHandler.java

@Override
public <E> List<E> query(Statement statement, ResultHandler<E> resultHandler) throws SQLException {

    if (statement instanceof PreparedStatement) {
        parameterize(statement);/* ww w.  j ava2s .com*/
        ResultSet resultSet = ((PreparedStatement) statement).executeQuery();
        return resultHandler.handleResult(resultSet);
    }
    throw new PersistenceException(statement.getClass() + "?PreparedStatement");
}

From source file:org.jboss.dashboard.database.NonPooledDataSource.java

protected Statement createStatementProxy(Statement stmt) throws SQLException {
    return (Statement) Proxy.newProxyInstance(stmt.getClass().getClassLoader(),
            getClassInterfaces(stmt.getClass()), new StatementInvocationHandler(stmt));
}