KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.store.BackupPathTests
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 import java.sql.CallableStatement JavaDoc;
28 import java.io.File JavaDoc;
29 import org.apache.derby.tools.ij;
30
31 /*
32  * This class tests online backup with various types of paths.
33  * 1 ) backup path is same as a database directory. This should fail backup
34  * can not be made onto a database directory. (DERBY-304 bug).
35  * 2 ) backup path is a sub directory in the database.
36  * 3 ) Redo backup with same path as in second case.
37  * 4 ) backup path is absolute path.
38
39  * If the path refers to some sub directory inside a database, backup
40  * will succeed because there is no easy way to catch this weird case,
41  * especially if the backup path refers to another database directory.
42  *
43  *
44  * @author <a HREF="mailto:suresh.thalamati@gmail.com">Suresh Thalamati</a>
45  * @version 1.0
46  */

47
48 public class BackupPathTests
49 {
50     
51     public static void main(String JavaDoc[] argv) throws Throwable JavaDoc
52     {
53         try {
54
55             ij.getPropertyArg(argv);
56             Connection JavaDoc conn = ij.startJBMS();
57             conn.setAutoCommit(true);
58             
59             Statement JavaDoc stmt = conn.createStatement();
60             //install a jar, so that there is a jar directory under the db.
61
stmt.execute(
62                      "call sqlj.install_jar(" +
63                      "'extin/brtestjar.jar', 'math_routines', 0)");
64
65             stmt.close();
66
67             logMsg("Begin Backup Path Tests");
68             String JavaDoc derbyHome = System.getProperty("derby.system.home");
69             String JavaDoc dbHome = derbyHome + File.separator + "wombat" ;
70
71             logMsg("case1 : try Backup with backup path as database dir");
72             try {
73                 performBackup(conn, dbHome);
74             } catch(SQLException JavaDoc sqle) {
75                 // expected to fail with following error code.
76
if (sqle.getSQLState() != null &&
77                     sqle.getSQLState().equals("XSRSC")) {
78                     logMsg("Backup in to a database dir failed");
79                 } else {
80                     throw sqle;
81                 }
82             }
83             
84             logMsg("End test case1");
85             logMsg("case2 : Backup with backup path as database jar dir");
86             String JavaDoc jarDir = dbHome + File.separator + "jar";
87             performBackup(conn, jarDir);
88             logMsg("End test case 2");
89
90             logMsg("case 3: Backup again into the same db jar dir location");
91             performBackup(conn, jarDir);
92             logMsg("End test case 3");
93
94             logMsg("case 4: Backup using an absolute path");
95             String JavaDoc absBackupPath =
96                 new File JavaDoc("extinout/backupPathTests").getAbsolutePath();
97             performBackup(conn, absBackupPath);
98             logMsg("End test case 4");
99             conn.close();
100             logMsg("End Backup Path Tests");
101
102         } catch (SQLException JavaDoc sqle) {
103             org.apache.derby.tools.JDBCDisplayUtil.ShowSQLException(System.out,
104                                                                     sqle);
105             sqle.printStackTrace(System.out);
106         }
107     }
108
109
110     private static void performBackup(Connection JavaDoc conn,
111                                       String JavaDoc backupPath)
112         throws SQLException JavaDoc
113     {
114         CallableStatement JavaDoc backupStmt =
115             conn.prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)");
116         backupStmt.setString(1, backupPath);
117         backupStmt.execute();
118         backupStmt.close();
119     }
120
121     
122     /**
123      * Write message to the standard output.
124      */

125     private static void logMsg(String JavaDoc str) {
126         System.out.println(str);
127     }
128
129 }
130
Popular Tags