KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > store > RecoveryAfterBackupSetup


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.store.LogChecksumSetup
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (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 JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.sql.Statement JavaDoc;
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     
43     public static void main(String JavaDoc[] argv) throws Throwable JavaDoc
44     {
45         try {
46             ij.getPropertyArg(argv);
47             Connection JavaDoc conn = ij.startJBMS();
48             conn.setAutoCommit(true);
49
50             System.out.println("Connection has been opened.");
51             Statement JavaDoc s = conn.createStatement();
52             try { // Drop table if it exists
53
s.execute("DROP TABLE t1");
54             } catch (SQLException JavaDoc e) {
55                 if (e.getSQLState().equals("42Y55")) {
56                     // IGNORE. Table did not exist. That is our target.
57
} else {
58                     throw e;
59                 }
60             }
61
62             System.out.println("Creating table and inserting two records.");
63             s.execute("CREATE TABLE t1(a INT)");
64             s.execute("INSERT INTO t1 VALUES(0)");
65             s.execute("INSERT INTO t1 VALUES(1)");
66
67             System.out.println("Performing backup...");
68             s.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 JavaDoc sqle) {
71             org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(System.out,
72                                                                     sqle);
73             sqle.printStackTrace(System.out);
74         }
75     }
76 }
77
Popular Tags