Search in sources :

Example 21 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class PreparedStatementTest method setBinaryStreamOnBlob.

/**
 **********************************************************************
 *                 A U X I L I A R Y  M E T H O D S                     *
 ***********************************************************************
 */
/**
 * Insert data into a Blob column with setBinaryStream.
 *
 * @param id unique id for inserted row
 * @param actualLength the actual length of the stream
 * @param specifiedLength the specified length of the stream
 * @param trailingBlanks number of characters at the end that is blank
 * @param lengthLess whether to use the length less overloads or not
 */
private void setBinaryStreamOnBlob(int id, int actualLength, int specifiedLength, int trailingBlanks, boolean lengthLess) throws SQLException {
    psInsertBlob.setInt(1, id);
    if (lengthLess) {
        psInsertBlob.setBinaryStream(2, new LoopingAlphabetStream(actualLength, trailingBlanks));
    } else {
        psInsertBlob.setBinaryStream(2, new LoopingAlphabetStream(actualLength, trailingBlanks), specifiedLength);
    }
    assertEquals("Insert with setBinaryStream failed", 1, psInsertBlob.executeUpdate());
}
Also used : LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Example 22 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class PreparedStatementTest method testSetBinaryStreamLengthLess1KOnBlob.

public void testSetBinaryStreamLengthLess1KOnBlob() throws IOException, SQLException {
    int length = 1 * 1024;
    setBinaryStreamOnBlob(key, length, -1, 0, true);
    psFetchBlob.setInt(1, key);
    ResultSet rs = psFetchBlob.executeQuery();
    assertTrue("Empty resultset", rs.next());
    assertEquals(new LoopingAlphabetStream(length), rs.getBinaryStream(1));
    assertFalse("Resultset should have been exhausted", rs.next());
    rs.close();
}
Also used : ResultSet(java.sql.ResultSet) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Example 23 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class PreparedStatementTest method testSetBinaryStreamLengthLess32KOnBlob.

public void testSetBinaryStreamLengthLess32KOnBlob() throws IOException, SQLException {
    int length = 32 * 1024;
    setBinaryStreamOnBlob(key, length, -1, 0, true);
    psFetchBlob.setInt(1, key);
    ResultSet rs = psFetchBlob.executeQuery();
    assertTrue("Empty resultset", rs.next());
    assertEquals(new LoopingAlphabetStream(length), rs.getBinaryStream(1));
    assertFalse("Resultset should have been exhausted", rs.next());
    rs.close();
}
Also used : ResultSet(java.sql.ResultSet) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Example 24 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class Derby6884Test method testDerby6884ImportLargeExtfileBlob.

/*
     * Same as the prior test, but with BLOB column, not CLOB column.
     */
public void testDerby6884ImportLargeExtfileBlob() throws SQLException {
    Statement s = createStatement();
    PreparedStatement ps = prepareStatement("insert into DERBY_6884_TESTBLOB values(? , ?)");
    int id = 1;
    long byteCount = 0;
    int blobSize = 0;
    while (byteCount < Integer.MAX_VALUE) {
        ps.setInt(1, id++);
        blobSize = (50000 * 1024) + (1024 * id);
        byteCount += blobSize;
        InputStream stream = new LoopingAlphabetStream(blobSize);
        ps.setBinaryStream(2, stream, blobSize);
        ps.executeUpdate();
    }
    ps.setInt(1, id++);
    InputStream stream = new LoopingAlphabetStream(blobSize);
    ps.setBinaryStream(2, stream, blobSize);
    ps.executeUpdate();
    commit();
    doExportTableLobsToExtFile("APP", "DERBY_6884_TESTBLOB", fileName6884, null, null, null, lobFile6884);
    s.execute("TRUNCATE TABLE DERBY_6884_TESTBLOB");
    doImportTableLobsFromExtFile("APP", "DERBY_6884_TESTBLOB", fileName6884, null, null, null, 0);
    SupportFilesSetup.deleteFile(fileName6884);
    SupportFilesSetup.deleteFile(lobFile6884);
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) InputStream(java.io.InputStream) PreparedStatement(java.sql.PreparedStatement) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Example 25 with LoopingAlphabetStream

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream in project derby by apache.

the class TriggerTests method runtest2InsertTriggerTest.

/**
 * Following will do an insert into table1 which will cause insert
 * trigger to fire. The insert involves the LOB column.
 *
 * @throws SQLException
 */
public void runtest2InsertTriggerTest() throws SQLException {
    PreparedStatement ps = prepareStatement("insert into table1(id, status, bl) values(101, 0, ?)");
    ps.setBinaryStream(1, new LoopingAlphabetStream(lobsize), lobsize);
    ps.executeUpdate();
    commit();
}
Also used : LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)

Aggregations

LoopingAlphabetStream (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)61 PreparedStatement (java.sql.PreparedStatement)33 InputStream (java.io.InputStream)31 ResultSet (java.sql.ResultSet)31 Statement (java.sql.Statement)20 Blob (java.sql.Blob)10 SQLException (java.sql.SQLException)9 LoopingAlphabetReader (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)9 PositionedStoreStream (org.apache.derby.impl.jdbc.PositionedStoreStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Connection (java.sql.Connection)7 OutputStream (java.io.OutputStream)5 Reader (java.io.Reader)5 Clob (java.sql.Clob)3 Timestamp (java.sql.Timestamp)3 DataInputStream (java.io.DataInputStream)2 EOFException (java.io.EOFException)2 CallableStatement (java.sql.CallableStatement)2 Date (java.sql.Date)2 Time (java.sql.Time)2