01: /*
02:
03: Derby - Class org.apache.derbyTesting.functionTests.store.LogChecksumSetup
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derbyTesting.functionTests.tests.store;
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: /*
31: * This class will do the setup for testing recovery after backup.
32: * This test will insert some records into a table, do a backup and
33: * end without shutting down the database. The succeeding test,
34: * RecoveryAfterBackup, will then do recovery of the database.
35: *
36: * @author oystein.grovlen@sun.com
37: * @see RecoveryAfterBackup
38: */
39:
40: public class RecoveryAfterBackupSetup {
41:
42: public static void main(String[] argv) throws Throwable {
43: try {
44: ij.getPropertyArg(argv);
45: Connection conn = ij.startJBMS();
46: conn.setAutoCommit(true);
47:
48: System.out.println("Connection has been opened.");
49: Statement s = conn.createStatement();
50: try { // Drop table if it exists
51: s.execute("DROP TABLE t1");
52: } catch (SQLException e) {
53: if (e.getSQLState().equals("42Y55")) {
54: // IGNORE. Table did not exist. That is our target.
55: } else {
56: throw e;
57: }
58: }
59:
60: System.out
61: .println("Creating table and inserting two records.");
62: s.execute("CREATE TABLE t1(a INT)");
63: s.execute("INSERT INTO t1 VALUES(0)");
64: s.execute("INSERT INTO t1 VALUES(1)");
65:
66: System.out.println("Performing backup...");
67: s
68: .execute("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE('extinout/mybackup', 0)");
69: System.out.println("Backup completed. Test finished.");
70: } catch (SQLException sqle) {
71: org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(
72: System.out, sqle);
73: sqle.printStackTrace(System.out);
74: }
75: }
76: }
|