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());
}
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();
}
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();
}
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);
}
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();
}
Aggregations