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;
}
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);
}
};
}
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;
}
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;
}
Aggregations