Search in sources :

Example 61 with LoopingAlphabetStream

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

the class BasicSetup method atestTriggersWithLOBcolumns.

// This test creates a table with LOB column and insets large data
// into that column. There is a trigger defined on this table
// but the trigger does not need access to the LOB column. In 10.8
// and prior releases, even though we don't need the LOB column to
// execute the trigger, we still read all the columns from the
// trigger table when the trigger fired. With 10.9, only the columns
// required by the firing triggers are read from the trigger table
// and hence for our test here, LOB column will not be materialized.
// In 10.8 and prior releases, the trigger defined in this test can
// run into OOM errors depending on how much heap is available to
// the upgrade test. But in 10.9 and higher, that won't happen
// because LOB is never read into memory for the trigger being
// used by this test.
public void atestTriggersWithLOBcolumns() throws Exception {
    Statement s = createStatement();
    ResultSet rs;
    boolean modeDb2SqlOptional = oldAtLeast(10, 3);
    final int lobsize = 50000 * 1024;
    switch(getPhase()) {
        case // create with old version
        PH_CREATE:
            s.execute("create table table1LOBtest (id int, status smallint, bl blob(2G))");
            PreparedStatement ps = prepareStatement("insert into table1LOBtest values (?, 0, ?)");
            ps.setInt(1, 1);
            ps.setBinaryStream(2, new LoopingAlphabetStream(lobsize), lobsize);
            ps.executeUpdate();
            s.execute("create table table2LOBtest (id int, updates int default 0)");
            ps = prepareStatement("insert into table2LOBtest (id) values (?)");
            ps.setInt(1, 1);
            ps.executeUpdate();
            s.execute("create trigger trigger1 after update of status on table1LOBtest referencing " + "new as n_row for each row " + (modeDb2SqlOptional ? "" : "MODE DB2SQL ") + "update table2LOBtest set updates = updates + 1 where table2LOBtest.id = n_row.id");
            break;
        case PH_HARD_UPGRADE:
            // OOM in 10.8 and prior
            if ((getConnection().getMetaData().getDatabaseMajorVersion() >= 10) && (getConnection().getMetaData().getDatabaseMinorVersion() >= 9)) {
                ps = prepareStatement("update table1LOBtest set status = 1 where id = 1");
                ps.executeUpdate();
            }
            break;
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) 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