Java Code Examples for org.apache.calcite.avatica.AvaticaStatement#close()

The following examples show how to use org.apache.calcite.avatica.AvaticaStatement#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoteMetaTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void testRemoteExecuteMaxRowCount() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    final AvaticaStatement statement = conn.createStatement();
    prepareAndExecuteInternal(conn, statement,
        "select * from (values ('a', 1), ('b', 2))", 0);
    ResultSet rs = statement.getResultSet();
    int count = 0;
    while (rs.next()) {
      count++;
    }
    assertEquals("Check maxRowCount=0 and ResultSets is 0 row", count, 0);
    assertEquals("Check result set meta is still there",
        rs.getMetaData().getColumnCount(), 2);
    rs.close();
    statement.close();
    conn.close();
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
Example 2
Source File: RemoteMetaTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
private void checkLargeQuery(int n) throws Exception {
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    final AvaticaStatement statement = conn.createStatement();
    final String frenchDisko = "It said human existence is pointless\n"
        + "As acts of rebellious solidarity\n"
        + "Can bring sense in this world\n"
        + "La resistance!\n";
    final String sql = "select '"
        + longString(frenchDisko, n)
        + "' as s from (values 'x')";
    prepareAndExecuteInternal(conn, statement, sql, -1);
    ResultSet rs = statement.getResultSet();
    int count = 0;
    while (rs.next()) {
      count++;
    }
    assertThat(count, is(1));
    rs.close();
    statement.close();
    conn.close();
  }
}
 
Example 3
Source File: RemoteMetaTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void testUnicodeCharacters() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    final AvaticaStatement statement = conn.createStatement();
    ResultSet rs = statement.executeQuery(
        "select * from (values ('您好', 'こんにちは', '안녕하세요'))");
    assertThat(rs.next(), is(true));
    assertEquals("您好", rs.getString(1));
    assertEquals("こんにちは", rs.getString(2));
    assertEquals("안녕하세요", rs.getString(3));
    rs.close();
    statement.close();
    conn.close();
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
Example 4
Source File: AlternatingRemoteMetaTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void testRemoteExecuteMaxRowCount() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    final AvaticaStatement statement = conn.createStatement();
    prepareAndExecuteInternal(conn, statement,
        "select * from (values ('a', 1), ('b', 2))", 0);
    ResultSet rs = statement.getResultSet();
    int count = 0;
    while (rs.next()) {
      count++;
    }
    assertEquals("Check maxRowCount=0 and ResultSets is 0 row", count, 0);
    assertEquals("Check result set meta is still there",
        rs.getMetaData().getColumnCount(), 2);
    rs.close();
    statement.close();
    conn.close();
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
Example 5
Source File: AlternatingRemoteMetaTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
private void checkLargeQuery(int n) throws Exception {
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    final AvaticaStatement statement = conn.createStatement();
    final String frenchDisko = "It said human existence is pointless\n"
        + "As acts of rebellious solidarity\n"
        + "Can bring sense in this world\n"
        + "La resistance!\n";
    final String sql = "select '"
        + longString(frenchDisko, n)
        + "' as s from (values 'x')";
    prepareAndExecuteInternal(conn, statement, sql, -1);
    ResultSet rs = statement.getResultSet();
    int count = 0;
    while (rs.next()) {
      count++;
    }
    assertThat(count, is(1));
    rs.close();
    statement.close();
    conn.close();
  }
}
 
Example 6
Source File: RemoteMetaTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1301">[CALCITE-1301]
 * Add cancel flag to AvaticaStatement</a>. */
@Test public void testCancel() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    final AvaticaStatement statement = conn.createStatement();
    final String sql = "select * from (values ('a', 1), ('b', 2))";
    final ResultSet rs = statement.executeQuery(sql);
    int count = 0;
  loop:
    for (;;) {
      switch (count++) {
      case 0:
        assertThat(rs.next(), is(true));
        break;
      case 1:
        rs.getStatement().cancel();
        try {
          boolean x = rs.next();
          fail("expected exception, got " + x);
        } catch (SQLException e) {
          assertThat(e.getMessage(), is("Statement canceled"));
        }
        break loop;
      default:
        fail("count: " + count);
      }
    }
    assertThat(count, is(2));
    assertThat(statement.isClosed(), is(false));
    rs.close();
    assertThat(statement.isClosed(), is(false));
    statement.close();
    assertThat(statement.isClosed(), is(true));
    statement.close();
    assertThat(statement.isClosed(), is(true));
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
Example 7
Source File: JdbcRemoteTest.java    From Quicksql with MIT License 4 votes vote down vote up
private void close( ResultSet rs, AvaticaStatement statement,AvaticaConnection conn) throws SQLException {
    rs.close();
    statement.close();
    conn.close();
}