use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class OracleExceptionSorterTest_setSavepointWithName method test_connect.
public void test_connect() throws Exception {
String sql = "SELECT 1";
{
DruidPooledConnection conn = dataSource.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.execute();
pstmt.close();
conn.close();
assertEquals(0, dataSource.getActiveCount());
assertEquals(1, dataSource.getPoolingCount());
assertEquals(1, dataSource.getCreateCount());
}
DruidPooledConnection conn = dataSource.getConnection();
MockConnection mockConn = conn.unwrap(MockConnection.class);
assertNotNull(mockConn);
SQLException exception = new SQLException("xx", "xxx", 28);
mockConn.setError(exception);
Exception setError = null;
try {
conn.setSavepoint("xxx");
} catch (Exception ex) {
setError = ex;
}
assertNotNull(setError);
conn.close();
{
Connection conn2 = dataSource.getConnection();
conn2.close();
}
assertEquals(0, dataSource.getActiveCount());
assertTrue(dataSource.getPoolingCount() >= 1);
assertTrue(dataSource.getCreateCount() >= 2);
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class OracleExceptionSorterTest_stmt_clearWarrnings method test_connect.
public void test_connect() throws Exception {
String sql = "SELECT 1";
{
DruidPooledConnection conn = dataSource.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.execute();
pstmt.close();
conn.close();
}
DruidPooledConnection conn = dataSource.getConnection();
MockConnection mockConn = conn.unwrap(MockConnection.class);
Assert.assertNotNull(mockConn);
Statement stmt = conn.createStatement();
stmt.execute(sql);
SQLException exception = new SQLException("xx", "xxx", 28);
mockConn.setError(exception);
SQLException stmtErrror = null;
try {
stmt.clearWarnings();
} catch (SQLException ex) {
stmtErrror = ex;
}
Assert.assertNotNull(stmtErrror);
Assert.assertSame(exception, stmtErrror);
SQLException commitError = null;
try {
conn.commit();
} catch (SQLException ex) {
commitError = ex;
}
Assert.assertNotNull(commitError);
Assert.assertSame(exception, commitError.getCause());
conn.close();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class OracleExceptionSorterTest_stmt_executeQuery method test_connect.
public void test_connect() throws Exception {
String sql = "SELECT 1";
{
DruidPooledConnection conn = dataSource.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.execute();
pstmt.close();
conn.close();
}
DruidPooledConnection conn = dataSource.getConnection();
MockConnection mockConn = conn.unwrap(MockConnection.class);
Assert.assertNotNull(mockConn);
Statement stmt = conn.createStatement();
SQLException exception = new SQLException("xx", "xxx", 28);
mockConn.setError(exception);
SQLException execErrror = null;
try {
stmt.executeQuery(sql);
} catch (SQLException ex) {
execErrror = ex;
}
Assert.assertNotNull(execErrror);
Assert.assertSame(exception, execErrror);
SQLException commitError = null;
try {
conn.commit();
} catch (SQLException ex) {
commitError = ex;
}
Assert.assertNotNull(commitError);
Assert.assertSame(exception, commitError.getCause());
conn.close();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class RaspberryPiMySqlTest method test_mysql.
public void test_mysql() throws Exception {
DruidPooledConnection connection = dataSource.getConnection();
System.out.println("variables : " + connection.getVariables());
System.out.println("gloabl variables : " + connection.getGloablVariables());
connection.close();
}
use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.
the class LogFilter method dataSource_getConnection.
@Override
public DruidPooledConnection dataSource_getConnection(FilterChain chain, DruidDataSource dataSource, long maxWaitMillis) throws SQLException {
DruidPooledConnection conn = chain.dataSource_connect(dataSource, maxWaitMillis);
ConnectionProxy connection = (ConnectionProxy) conn.getConnectionHolder().getConnection();
if (connectionConnectAfterLogEnable && isConnectionLogEnabled()) {
connectionLog("{conn-" + connection.getId() + "} pool-connect");
}
return conn;
}
Aggregations