1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/*
Derby - Class org.apache.derbyTesting.functionTests.tests.lang.wisconsin
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.apache.derbyTesting.functionTests.tests.lang;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.derby.impl.tools.ij.utilMain;
import org.apache.derby.tools.ij;
public class wisconsin {
public static void main(String[] args) throws Throwable{
ij.getPropertyArg(args);
Connection conn = ij.startJBMS();
conn.setAutoCommit(false);
conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
createTables(conn, true);
BufferedInputStream inStream;
String resource = "org/apache/derbyTesting/functionTests/tests/" +
"lang/wisc_setup.sql";
// set input stream
URL sql = getTestResource(resource);
InputStream sqlIn = openTestResource(sql);
if (sqlIn == null ) {
throw new Exception("SQL Resource missing:" +
resource);
}
inStream = new BufferedInputStream(sqlIn,
utilMain.BUFFEREDFILESIZE);
ij.runScript(conn, inStream, "US-ASCII",
System.out, (String) null );
conn.commit();
}
public static void createTables(Connection conn, boolean compress)
throws SQLException {
createTables(conn, compress, 10000);
}
public static void createTables(Connection conn, boolean compress, int numRows)
throws SQLException {
Statement stmt = conn.createStatement();
stmt.execute("create table TENKTUP1 ( unique1 int not null, " +
"unique2 int not null, " +
"two int, " +
"four int, " +
"ten int, " +
"twenty int, " +
"onePercent int, " +
"tenPercent int, " +
"twentyPercent int, " +
"fiftyPercent int, " +
"unique3 int, " +
"evenOnePercent int, " +
"oddOnePercent int, " +
"stringu1 char(52) not null, " +
"stringu2 char(52) not null, " +
"string4 char(52) )");
//--insert numRows rows into TENKTUP1
WISCInsert wi = new WISCInsert();
wi.doWISCInsert(numRows, "TENKTUP1", conn);
stmt.execute("create unique index TK1UNIQUE1 on TENKTUP1(unique1)");
stmt.execute("create unique index TK1UNIQUE2 on TENKTUP1(unique2)");
stmt.execute("create index TK1TWO on TENKTUP1(two)");
stmt.execute("create index TK1FOUR on TENKTUP1(four)");
stmt.execute("create index TK1TEN on TENKTUP1(ten)");
stmt.execute("create index TK1TWENTY on TENKTUP1(twenty)");
stmt.execute("create index TK1ONEPERCENT on TENKTUP1(onePercent)");
stmt.execute("create index TK1TWENTYPERCENT on TENKTUP1(twentyPercent)");
stmt.execute("create index TK1EVENONEPERCENT on TENKTUP1(evenOnePercent)");
stmt.execute("create index TK1ODDONEPERCENT on TENKTUP1(oddOnePercent)");
stmt.execute("create unique index TK1STRINGU1 on TENKTUP1(stringu1)");
stmt.execute("create unique index TK1STRINGU2 on TENKTUP1(stringu2)");
stmt.execute("create index TK1STRING4 on TENKTUP1(string4)");
stmt.execute("create table TENKTUP2 (unique1 int not null, " +
"unique2 int not null, " +
"two int, " +
"four int, " +
"ten int, " +
"twenty int, " +
"onePercent int, " +
"tenPercent int, " +
"twentyPercent int, " +
"fiftyPercent int, " +
"unique3 int, " +
"evenOnePercent int, " +
"oddOnePercent int, " +
"stringu1 char(52), " +
"stringu2 char(52), " +
"string4 char(52) )");
//-- insert numRows rows into TENKTUP2
wi = new WISCInsert();
wi.doWISCInsert(numRows, "TENKTUP2", conn);
stmt.execute("create unique index TK2UNIQUE1 on TENKTUP2(unique1)");
stmt.execute("create unique index TK2UNIQUE2 on TENKTUP2(unique2)");
stmt.execute("create table ONEKTUP ( unique1 int not null, " +
"unique2 int not null, " +
"two int, " +
"four int, " +
"ten int, " +
"twenty int, " +
"onePercent int, " +
"tenPercent int, " +
"twentyPercent int, " +
"fiftyPercent int, " +
"unique3 int, " +
"evenOnePercent int, " +
"oddOnePercent int, " +
"stringu1 char(52), " +
"stringu2 char(52), " +
"string4 char(52) )");
//-- insert 1000 rows into ONEKTUP
wi = new WISCInsert();
wi.doWISCInsert(1000, "ONEKTUP", conn);
stmt.execute("create unique index ONEKUNIQUE1 on ONEKTUP(unique1)");
stmt.execute("create unique index ONEKUNIQUE2 on ONEKTUP(unique2)");
stmt.execute("create table BPRIME ( unique1 int, " +
"unique2 int, " +
"two int, " +
"four int, " +
"ten int, " +
"twenty int, " +
"onePercent int, " +
"tenPercent int, " +
"twentyPercent int, " +
"fiftyPercent int, " +
"unique3 int, " +
"evenOnePercent int, " +
"oddOnePercent int, " +
"stringu1 char(52), " +
"stringu2 char(52), " +
"string4 char(52))");
stmt.execute("insert into BPRIME select * from TENKTUP2 where TENKTUP2.unique2 < 1000");
conn.commit();
if (!compress) {
return;
}
PreparedStatement ps2 = conn.prepareStatement
("call SYSCS_UTIL.SYSCS_COMPRESS_TABLE(?, ?, ?)");
ps2.setString(1, "APP");
ps2.setString(2, "BPRIME");
ps2.setInt(3, 0);
ps2.executeUpdate();
conn.commit();
ps2.setString(1, "APP");
ps2.setString(2, "TENKTUP1");
ps2.setInt(3, 0);
ps2.executeUpdate();
conn.commit();
ps2.setString(1, "APP");
ps2.setString(2, "TENKTUP2");
ps2.setInt(3, 0);
ps2.executeUpdate();
conn.commit();
ps2.setString(1, "APP");
ps2.setString(2, "ONEKTUP");
ps2.setInt(3, 0);
ps2.executeUpdate();
conn.commit();
}
/**
* Open the URL for a a test resource, e.g. a policy
* file or a SQL script.
* @param url URL obtained from getTestResource
* @return An open stream
*/
protected static InputStream openTestResource(final URL url)
throws PrivilegedActionException
{
return AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction<InputStream>(){
public InputStream run() throws IOException {
return url.openStream();
}
}
);
}
/**
* Obtain the URL for a test resource, e.g. a policy
* file or a SQL script.
* @param name Resource name, typically - org.apache.derbyTesing.something
* @return URL to the resource, null if it does not exist.
*/
protected static URL getTestResource(final String name)
{
return AccessController.doPrivileged
(new java.security.PrivilegedAction<URL>(){
public URL run(){
return this.getClass().getClassLoader().
getResource(name);
}
}
);
}
}
|