1 21 22 package org.apache.derbyTesting.functionTests.tests.lang; 23 24 import java.sql.Connection ; 25 import java.sql.SQLException ; 26 import java.sql.Statement ; 27 28 import org.apache.derby.tools.ij; 29 30 39 40 public class ConcurrentImplicitCreateSchema 41 { 42 43 46 class CreateTable implements Runnable 47 { 48 49 private int myId; 50 51 private int schemaId; 52 53 private Connection conn = null; 54 55 private ConcurrentImplicitCreateSchema test; 56 57 CreateTable(int id, int schemaId, 58 ConcurrentImplicitCreateSchema test) 59 throws SQLException , IllegalAccessException , 60 ClassNotFoundException , InstantiationException 61 { 62 this.myId = id; 63 this.schemaId = schemaId; 64 this.test = test; 65 66 conn = ij.startJBMS(); 68 conn.setAutoCommit(false); 69 } 70 71 public void run() 72 { 73 try { 74 Statement s = conn.createStatement(); 75 s.execute("create table testschema" + schemaId + ".testtab" 76 + myId + "(num int, addr varchar(40))"); 77 s.execute("drop table testschema" + schemaId + ".testtab" 78 + myId); 79 } catch (SQLException e) { 80 test.failed(e); 81 } 82 83 try { 87 conn.commit(); 88 conn.close(); 89 } catch (SQLException e) { 90 test.failed(e); 91 } 92 } 94 } 95 96 100 boolean passed = true; 101 102 public static void main(String [] args) 103 { 104 new ConcurrentImplicitCreateSchema().go(args); 105 } 106 107 void go(String [] args) 108 { 109 System.out.println("Test ConcurrentImplicitCreateSchema starting"); 110 111 try { 112 ij.getPropertyArg(args); 116 Connection conn = ij.startJBMS(); 117 118 conn.setAutoCommit(true); 119 120 Statement s = conn.createStatement(); 123 124 final int NSCHEMAS = 1; 127 128 for (int i=0; i < NSCHEMAS; ++i) { 129 try { 130 s.execute("drop schema testschema" + i + " restrict"); 131 } catch (SQLException e) { 132 if (e.getSQLState().equals("42Y07")) { 133 } else { 135 throw e; 136 } 137 } 138 } 139 140 final int NTHREADS = 100; 142 143 Thread [] threads = new Thread [NTHREADS]; 145 for (int i=0; i<NTHREADS; ++i) { 146 threads[i] 147 = new Thread (new CreateTable(i, i%NSCHEMAS, this)); 148 } 149 150 for (int i=0; i<NTHREADS; ++i) { 152 threads[i].start(); 153 } 154 155 for (int i=0; i<NTHREADS; ++i) { 157 threads[i].join(); 158 } 159 160 conn.close(); 161 System.out.println("Closed connection"); 162 } catch (Throwable e) { 163 System.out.println("exception thrown:"); 164 failed(e); 165 } 166 167 System.out.print("Test ConcurrentImplicitCreateSchema "); 168 if (passed) { 169 System.out.println("PASSED"); 170 } else { 171 System.out.println("FAILED"); 172 } 173 } 174 175 void failed(Throwable e) 176 { 177 if (e instanceof SQLException ) { 178 printSQLError((SQLException ) e); 179 } else { 180 e.printStackTrace(); 181 } 182 passed = false; 183 } 184 185 void printSQLError(SQLException e) 186 { 187 while (e != null) 188 { 189 System.out.println(e.toString()); 190 e.printStackTrace(); 191 e = e.getNextException(); 192 } 193 } 194 } 195 | Popular Tags |