Example #1
0
  /**
   * Test that <code>Clob.getCharacterStream(long,long)</code> works on CLOBs that are streamed from
   * store. (DERBY-2891)
   */
  public void testGetCharacterStreamLongOnLargeClob() throws Exception {
    getConnection().setAutoCommit(false);

    // create large (>32k) clob that can be read from store
    final int size = 33000;
    StringBuilder sb = new StringBuilder(size);
    for (int i = 0; i < size; i += 10) {
      sb.append("1234567890");
    }

    final int id = BlobClobTestSetup.getID();
    PreparedStatement ps =
        prepareStatement("insert into blobclob(id, clobdata) values (?,cast(? as clob))");
    ps.setInt(1, id);
    ps.setString(2, sb.toString());
    ps.executeUpdate();
    ps.close();

    Statement s = createStatement();
    ResultSet rs = s.executeQuery("select clobdata from blobclob where id = " + id);
    assertTrue(rs.next());
    Clob c = rs.getClob(1);

    // request a small region of the clob
    BufferedReader r = new BufferedReader(c.getCharacterStream(4L, 3L));
    assertEquals("456", r.readLine());

    r.close();
    c.free();
    rs.close();
    s.close();
    rollback();
  }
Example #2
0
 protected void tearDown() throws Exception {
   if (clob != null) {
     clob.free();
     clob = null;
   }
   excludedMethodSet = null;
   super.tearDown();
 }
Example #3
0
  /**
   * Test that a lock held on the corresponding row is released when free() is called on the Clob
   * object.
   *
   * @throws java.sql.SQLException
   */
  public void testLockingAfterFree() throws SQLException {
    int id = initializeLongClob(); // Opens clob object
    executeParallelUpdate(id, true); // Test that timeout occurs

    // Test that update goes through after the clob is closed
    clob.free();
    executeParallelUpdate(id, false);

    commit();
  }
Example #4
0
  /**
   * Test that a lock held on the corresponding row is released when free() is called on the Clob
   * object if the isolation level is Read Uncommitted
   *
   * @throws java.sql.SQLException
   */
  public void testLockingAfterFreeWithDirtyReads() throws SQLException {
    getConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    int id = initializeLongClob(); // Opens clob object
    executeParallelUpdate(id, true); // Test that timeout occurs

    // Test that update goes through after the clob is closed
    clob.free();
    executeParallelUpdate(id, false);

    commit();
  }
Example #5
0
  /**
   * Test that a lock held on the corresponding row is NOT released when free() is called on the
   * Clob object if the isolation level is Repeatable Read
   *
   * @throws java.sql.SQLException
   */
  public void testLockingAfterFreeWithRR() throws SQLException {
    getConnection().setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
    int id = initializeLongClob(); // Opens clob object
    executeParallelUpdate(id, true); // Test that timeout occurs

    // Test that update still times out after the clob is closed
    clob.free();
    executeParallelUpdate(id, true);

    // Test that the update goes through after the transaction has committed
    commit();
    executeParallelUpdate(id, false);
  }
Example #6
0
  /**
   * Tests the implementation for the free() method in the Clob interface.
   *
   * @throws SQLException if an error occurs during releasing the Clob resources
   */
  public void testFreeandMethodsAfterCallingFree()
      throws IllegalAccessException, InvocationTargetException, SQLException {
    clob = BlobClobTestSetup.getSampleClob(getConnection());

    // call the buildHashSetMethod to initialize the
    // HashSet with the method signatures that are exempted
    // from throwing a SQLException after free has been called
    // on the Clob object.
    buildHashSet();

    InputStream asciiStream = clob.getAsciiStream();
    Reader charStream = clob.getCharacterStream();
    clob.free();
    // testing the idempotence of the free() method
    // the method can be called multiple times on

    // the first are treated as no-ops
    clob.free();

    // to the free method so testing calling
    // a method on this invalid object should throw
    // an SQLException
    buildMethodList(clob);
  }