Exemplo n.º 1
0
  public void test_prepareStatement_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    MockPreparedStatement raw = null;
    {
      PreparedStatement stmt =
          conn.prepareStatement(
              "SELECT 1",
              ResultSet.TYPE_FORWARD_ONLY,
              ResultSet.CONCUR_READ_ONLY,
              ResultSet.HOLD_CURSORS_OVER_COMMIT);
      raw = stmt.unwrap(MockPreparedStatement.class);
      stmt.close();
    }
    {
      PreparedStatement stmt =
          conn.prepareStatement(
              "SELECT 1",
              ResultSet.TYPE_FORWARD_ONLY,
              ResultSet.CONCUR_READ_ONLY,
              ResultSet.HOLD_CURSORS_OVER_COMMIT);
      Assert.assertSame(raw, stmt.unwrap(MockPreparedStatement.class));
      stmt.close();
    }

    conn.close();
  }
Exemplo n.º 2
0
  public void test_prepareStatement_4() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    MockPreparedStatement raw = null;
    {
      PreparedStatement stmt = conn.prepareStatement("SELECT 1", 0);
      raw = stmt.unwrap(MockPreparedStatement.class);
      stmt.close();
    }
    {
      PreparedStatement stmt = conn.prepareStatement("SELECT 1", 0);
      Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
      stmt.close();
    }

    conn.close();
  }
Exemplo n.º 3
0
  public void test_prepareStatement_error5() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    {
      SQLException error = null;
      try {
        conn.prepareStatement(null, new int[0]);
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }
Exemplo n.º 4
0
  public void test_handleException_4() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    conn.getConnection().close();

    {
      SQLException error = null;
      try {
        conn.prepareStatement("SELECT 1");
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    Assert.assertEquals(true, conn.isClosed());
  }
Exemplo n.º 5
0
  public void test_prepareStatement_error2() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    conn.getConnection().close();

    {
      SQLException error = null;
      try {
        conn.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      } catch (SQLException ex) {
        error = ex;
      }
      Assert.assertNotNull(error);
    }

    conn.close();
  }
  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.addBatch(sql);

    SQLException exception = new SQLException("xx", "xxx", 28);
    mockConn.setError(exception);

    SQLException stmtErrror = null;
    try {
      stmt.executeBatch();
    } 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();
  }