use of com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey in project druid by alibaba.
the class DruidPooledConnection method prepareCall.
// ////////////////////
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
checkState();
PreparedStatementHolder stmtHolder = null;
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.Precall_1);
boolean poolPreparedStatements = holder.isPoolPreparedStatements();
if (poolPreparedStatements) {
stmtHolder = holder.getStatementPool().get(key);
}
if (stmtHolder == null) {
try {
stmtHolder = new PreparedStatementHolder(key, conn.prepareCall(sql));
holder.getDataSource().incrementPreparedStatementCount();
} catch (SQLException ex) {
handleException(ex);
}
}
initStatement(stmtHolder);
DruidPooledCallableStatement rtnVal = new DruidPooledCallableStatement(this, stmtHolder);
holder.addTrace(rtnVal);
return rtnVal;
}
use of com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey in project druid by alibaba.
the class DruidPooledConnection method prepareStatement.
// ////////////////////
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
checkState();
PreparedStatementHolder stmtHolder = null;
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M1);
boolean poolPreparedStatements = holder.isPoolPreparedStatements();
if (poolPreparedStatements) {
stmtHolder = holder.getStatementPool().get(key);
}
if (stmtHolder == null) {
try {
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql));
holder.getDataSource().incrementPreparedStatementCount();
} catch (SQLException ex) {
handleException(ex);
}
}
initStatement(stmtHolder);
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
holder.addTrace(rtnVal);
return rtnVal;
}
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[] columnIndexes) throws SQLException {
checkState();
PreparedStatementKey key = new PreparedStatementKey(sql, getCatalog(), MethodType.M4, columnIndexes);
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, columnIndexes));
holder.getDataSource().incrementPreparedStatementCount();
} catch (SQLException ex) {
handleException(ex);
}
}
initStatement(stmtHolder);
DruidPooledPreparedStatement rtnVal = new DruidPooledPreparedStatement(this, stmtHolder);
holder.addTrace(rtnVal);
return rtnVal;
}
use of com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey in project druid by alibaba.
the class PreparedStatementKeyTest method test_0.
public void test_0() throws Exception {
PreparedStatementKey k1 = new PreparedStatementKey("select 'a'", "c1", MethodType.M1, 101, 102, 103);
Assert.assertEquals(101, k1.getResultSetType());
Assert.assertEquals(102, k1.getResultSetConcurrency());
Assert.assertEquals(103, k1.getResultSetHoldability());
}
use of com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey in project druid by alibaba.
the class PoolableCallableStatementTest method setUp.
protected void setUp() throws Exception {
MockConnection mockConn = new MockConnection();
DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn, 0);
conn = new DruidPooledConnection(connHolder);
raw = new MockCallableStatement(null, null);
stmt = new DruidPooledCallableStatement(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);
}
};
Assert.assertEquals(0, raw.getOutParameters().size());
stmt.registerOutParameter(1, Types.INTEGER);
Assert.assertEquals(1, raw.getOutParameters().size());
stmt.registerOutParameter(2, Types.DECIMAL, 10);
Assert.assertEquals(2, raw.getOutParameters().size());
}
Aggregations