1 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 import java.sql.CallableStatement ; 28 import java.io.File ; 29 import org.apache.derby.tools.ij; 30 31 47 48 public class BackupPathTests 49 { 50 51 public static void main(String [] argv) throws Throwable 52 { 53 try { 54 55 ij.getPropertyArg(argv); 56 Connection conn = ij.startJBMS(); 57 conn.setAutoCommit(true); 58 59 Statement stmt = conn.createStatement(); 60 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 derbyHome = System.getProperty("derby.system.home"); 69 String 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 sqle) { 75 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 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 absBackupPath = 96 new File ("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 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 conn, 111 String backupPath) 112 throws SQLException 113 { 114 CallableStatement 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 125 private static void logMsg(String str) { 126 System.out.println(str); 127 } 128 129 } 130 | Popular Tags |