KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > recovery > TableRecoveryScenario


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.raidb1.recovery;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.PreparedStatement JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30 import java.sql.ResultSetMetaData JavaDoc;
31
32 import org.objectweb.cjdbc.scenario.templates.Raidb1RecoveryTemplate;
33 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
34
35 /**
36  * This class defines a TableRecoveryScenario
37  *
38  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
39  * @version 1.0
40  */

41 public class TableRecoveryScenario extends Raidb1RecoveryTemplate
42 {
43   private static final String JavaDoc BACKUP_LOGIN = "user";
44   private static final String JavaDoc BACKUP_PASSWORD = "";
45   private static final String JavaDoc BACKUPER = "Octopus";
46   private static final String JavaDoc BACKUP_PATH = "../backup";
47
48   /**
49    * I don't know if octopus is restoring all the tables
50    *
51    * @throws Exception if fails
52    */

53   public void testListTables() throws Exception JavaDoc
54   {
55     // Create backup
56
String JavaDoc dump = "dump" + System.currentTimeMillis();
57     mainVdb.backupBackend("localhost", BACKUP_LOGIN, BACKUP_PASSWORD, dump,
58         BACKUPER, BACKUP_PATH, null);
59
60     // Recover backends
61
String JavaDoc backendName = "localhost2";
62     mainVdb.forceDisableBackend(backendName);
63     mainVdb.restoreDumpOnBackend("localhost", BACKUP_LOGIN, BACKUP_PASSWORD,
64         dump, null);
65     mainVdb.enableBackendFromCheckpoint("localhost");
66
67     String JavaDoc[] types = new String JavaDoc[]{"TABLE", "VIEW"};
68
69     Connection JavaDoc con1 = getHypersonicConnection(9001);
70     ResultSet JavaDoc rs1 = con1.getMetaData().getTables(null, null, "%", types);
71
72     Connection JavaDoc con2 = getHypersonicConnection(9002);
73     ResultSet JavaDoc rs2 = con2.getMetaData().getTables(null, null, "%", types);
74
75     assertTrue("Metadata is different for tables", ScenarioUtility.checkEquals(
76         rs1, rs2));
77
78     // Type forward only so request the metadata again from different connection
79
ResultSet JavaDoc rs = getHypersonicConnection(9001).getMetaData().getTables(null,
80         null, "%", types);
81     while (rs.next())
82     {
83       // 1 is table catalog, 2 is table schema, 3 is table name, 4 is type
84
String JavaDoc tableName = rs.getString(3);
85       String JavaDoc sql = "Select * from " + tableName;
86       System.out.println("Checking content of table:" + tableName);
87
88       PreparedStatement JavaDoc ps1 = con1.prepareStatement(sql);
89       PreparedStatement JavaDoc ps2 = con2.prepareStatement(sql);
90
91       // ps1.setString(1, tableName);
92
// ps2.setString(1, tableName);
93

94       rs1 = ps1.executeQuery();
95       rs2 = ps2.executeQuery();
96
97       assertTrue("Data is different for table:" + tableName, ScenarioUtility
98           .checkEquals(rs1, rs2));
99
100       ResultSetMetaData JavaDoc rsmd1 = rs1.getMetaData();
101       ResultSetMetaData JavaDoc rsmd2 = rs2.getMetaData();
102       assertEquals("meta data column count are different for table:"
103           + tableName, rsmd1.getColumnCount(), rsmd2.getColumnCount());
104       int colCount = rsmd1.getColumnCount();
105       for (int i = 1; i <= colCount; i++)
106       {
107         String JavaDoc colName = rsmd1.getColumnName(i);
108         System.out.println("Checking metadata for column:" + colName);
109         assertEquals(rsmd1.getCatalogName(i), rsmd2.getCatalogName(i));
110         // assertEquals(rsmd1.getColumnClassName(i),
111
// rsmd2.getColumnClassName(i)); NOT SUPPORTED BY HSQLDB
112
assertEquals(rsmd1.getColumnDisplaySize(i), rsmd2
113             .getColumnDisplaySize(i));
114         assertEquals(rsmd1.getColumnLabel(i), rsmd2.getColumnLabel(i));
115         assertEquals(rsmd1.getColumnName(i), rsmd2.getColumnName(i));
116         assertEquals(rsmd1.getColumnType(i), rsmd2.getColumnType(i));
117         assertEquals(rsmd1.getColumnTypeName(i), rsmd2.getColumnTypeName(i));
118       }
119     }
120   }
121 }
Popular Tags