Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 20 package org.apache.derbyTesting.junit; 21 22 import java.sql.*; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import org.apache.derbyTesting.functionTests.tests.lang.TimeHandlingTest; 28 29 30 import junit.framework.Test; 31 32 53 public class CleanDatabaseTestSetup extends BaseJDBCTestSetup { 54 55 58 public CleanDatabaseTestSetup(Test test) { 59 super(test); 60 } 61 62 67 protected void setUp() throws Exception { 68 Connection conn = getConnection(); 69 conn.setAutoCommit(false); 70 CleanDatabaseTestSetup.cleanDatabase(conn); 71 72 Statement s = conn.createStatement(); 73 decorateSQL(s); 74 75 s.close(); 76 conn.commit(); 77 conn.close(); 78 } 79 80 92 protected void decorateSQL(Statement s) throws SQLException 93 { 94 } 96 97 100 protected void tearDown() throws Exception { 101 Connection conn = getConnection(); 102 conn.setAutoCommit(false); 103 CleanDatabaseTestSetup.cleanDatabase(conn); 104 super.tearDown(); 105 } 106 107 112 public static void cleanDatabase(Connection conn) throws SQLException { 113 DatabaseMetaData dmd = conn.getMetaData(); 114 115 List schemas = new ArrayList (); 117 ResultSet rs = dmd.getSchemas(); 118 while (rs.next()) { 119 120 String schema = rs.getString("TABLE_SCHEM"); 121 if (schema.startsWith("SYS")) 122 continue; 123 if (schema.equals("SQLJ")) 124 continue; 125 if (schema.equals("NULLID")) 126 continue; 127 128 schemas.add(schema); 129 } 130 rs.close(); 131 132 for (Iterator i = schemas.iterator(); i.hasNext();) { 134 String schema = (String ) i.next(); 135 JDBC.dropSchema(dmd, schema); 136 } 137 } 138 139 } 140
| Popular Tags
|