1 20 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 21 import org.apache.derbyTesting.functionTests.util.TestInputStream; 22 import org.apache.derbyTesting.junit.BaseJDBCTestCase; 23 import org.apache.derbyTesting.junit.BaseJDBCTestSetup; 24 25 import junit.extensions.TestSetup; 26 import junit.framework.Test; 27 import java.sql.Connection ; 28 import java.sql.PreparedStatement ; 29 import java.sql.SQLException ; 30 import java.sql.Statement ; 31 import java.io.InputStream ; 32 33 42 final public class BLOBDataModelSetup extends BaseJDBCTestSetup 43 { 44 45 49 public BLOBDataModelSetup(Test test) 50 { 51 super(test); 52 } 53 54 59 protected final void setUp() 60 throws Exception 61 { 62 Connection con = getConnection(); 63 con.setAutoCommit(false); 64 65 final Statement statement = con.createStatement(); 67 statement.executeUpdate("CREATE TABLE " + tableName + " ("+ 68 " val INTEGER," + 69 " length INTEGER, " + 70 " data BLOB(2G) NOT NULL)"); 71 statement.close(); 72 final PreparedStatement preparedStatement = 74 con.prepareStatement 75 ("INSERT INTO " + tableName + "(val, length, data) VALUES (?,?, ?)"); 76 77 for (int i = 0; i < regularBlobs; i++) { 79 final int val = i; 80 final InputStream stream = new TestInputStream(size, val); 81 preparedStatement.setInt(1, val); 82 preparedStatement.setInt(2, size); 83 preparedStatement.setBinaryStream(3, stream, size); 84 preparedStatement.executeUpdate(); 85 } 86 87 BaseJDBCTestCase.println("Insert BLOB with size = " + bigSize); 89 preparedStatement.setInt(1, bigVal); 90 preparedStatement.setInt(2, bigSize); 91 final InputStream stream = new TestInputStream(bigSize, bigVal); 92 preparedStatement.setBinaryStream(3, stream, bigSize); 93 94 BaseJDBCTestCase.println("Execute update"); 95 preparedStatement.executeUpdate(); 96 preparedStatement.close(); 97 98 BaseJDBCTestCase.println("Commit"); 99 con.commit(); 100 } 101 102 107 protected final void tearDown() 108 throws Exception 109 { 110 try { 111 Connection con = getConnection(); 112 Statement statement = con.createStatement(); 113 statement.execute("DROP TABLE " + tableName); 114 statement.close(); 115 con.commit(); 116 } catch (SQLException e) { 117 BaseJDBCTestCase.printStackTrace(e); 118 } 119 120 super.tearDown(); 121 } 122 123 127 public static final String getBlobTableName() 128 { 129 return tableName; 130 } 131 132 133 final static int size = 1024 * 1024; 134 135 136 final static int regularBlobs = 10; 137 138 139 final static int bigSize = 64 * 1024 * 1024; 140 141 142 final static int bigVal = regularBlobs + 1; 143 144 145 private static final String tableName = "TESTBLOBTABLE"; 146 } 147 | Popular Tags |