Search in sources :

Example 16 with PreparedStatementKey

use of com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey in project druid by alibaba.

the class DruidPooledConnection method prepareStatement.

@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
    checkState();
    PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M5, columnNames);
    PreparedStatementHolder stmtHolder = null;
    boolean poolPreparedStatements = holder.isPoolPreparedStatements();
    if (poolPreparedStatements) {
        stmtHolder = holder.getStatementPool().get(key);
    }
    if (stmtHolder == null) {
        try {
            stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, columnNames));
            holder.getDataSource().incrementPreparedStatementCount();
        } catch (SQLException ex) {
            handleException(ex);
        }
    }
    initStatement(stmtHolder);
    DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
    holder.addTrace(rtnVal);
    return rtnVal;
}
Also used : SQLException(java.sql.SQLException) PreparedStatementKey(com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)

Example 17 with PreparedStatementKey

use of com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey in project druid by alibaba.

the class PoolablePreparedStatementTest method setUp.

protected void setUp() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    MockConnection mockConn = new MockConnection();
    DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn, 0);
    DruidPooledConnection conn = new DruidPooledConnection(connHolder);
    raw = new MockPreparedStatement(null, null);
    stmt = new DruidPooledPreparedStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {

        protected SQLException checkException(Throwable error) throws SQLException {
            if (error instanceof SQLException) {
                return (SQLException) error;
            }
            return new SQLException(error);
        }
    };
}
Also used : PreparedStatementHolder(com.alibaba.druid.pool.PreparedStatementHolder) SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) DruidPooledPreparedStatement(com.alibaba.druid.pool.DruidPooledPreparedStatement) DruidConnectionHolder(com.alibaba.druid.pool.DruidConnectionHolder) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatementKey(com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 18 with PreparedStatementKey

use of com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey in project druid by alibaba.

the class DruidPooledConnection method prepareStatement.

@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
    checkState();
    PreparedStatementHolder stmtHolder = null;
    PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M2, resultSetType, resultSetConcurrency);
    boolean poolPreparedStatements = holder.isPoolPreparedStatements();
    if (poolPreparedStatements) {
        stmtHolder = holder.getStatementPool().get(key);
    }
    if (stmtHolder == null) {
        try {
            stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, resultSetType, resultSetConcurrency));
            holder.getDataSource().incrementPreparedStatementCount();
        } catch (SQLException ex) {
            handleException(ex);
        }
    }
    initStatement(stmtHolder);
    DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
    holder.addTrace(rtnVal);
    return rtnVal;
}
Also used : SQLException(java.sql.SQLException) PreparedStatementKey(com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)

Example 19 with PreparedStatementKey

use of com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey in project druid by alibaba.

the class DruidPooledConnection method prepareCall.

@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    checkState();
    PreparedStatementHolder stmtHolder = null;
    PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_2, resultSetType, resultSetConcurrency, resultSetHoldability);
    boolean poolPreparedStatements = holder.isPoolPreparedStatements();
    if (poolPreparedStatements) {
        stmtHolder = holder.getStatementPool().get(key);
    }
    if (stmtHolder == null) {
        try {
            stmtHolder = new PreparedStatementHolder(key, conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
            holder.getDataSource().incrementPreparedStatementCount();
        } catch (SQLException ex) {
            handleException(ex);
        }
    }
    initStatement(stmtHolder);
    DruidPooledCallableStatement rtnVal = new DruidPooledCallableStatement(this, stmtHolder);
    holder.addTrace(rtnVal);
    return rtnVal;
}
Also used : SQLException(java.sql.SQLException) PreparedStatementKey(com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)

Aggregations

PreparedStatementKey (com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)19 SQLException (java.sql.SQLException)8 MockConnection (com.alibaba.druid.mock.MockConnection)3 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)3 PreparedStatementHolder (com.alibaba.druid.pool.PreparedStatementHolder)3 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)2 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)2 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)1 DruidPooledCallableStatement (com.alibaba.druid.pool.DruidPooledCallableStatement)1 DruidPooledPreparedStatement (com.alibaba.druid.pool.DruidPooledPreparedStatement)1 PreparedStatementPool (com.alibaba.druid.pool.PreparedStatementPool)1