| 
      
      
      From: <fu...@us...> - 2010-01-06 21:21:52
      
     | 
| Revision: 1012
          http://cishell.svn.sourceforge.net/cishell/?rev=1012&view=rev
Author:   fugu13
Date:     2010-01-06 21:21:45 +0000 (Wed, 06 Jan 2010)
Log Message:
-----------
Make this truly delete all non-system tables.
Modified Paths:
--------------
    trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java
Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java
===================================================================
--- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java	2010-01-06 21:18:10 UTC (rev 1011)
+++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java	2010-01-06 21:21:45 UTC (rev 1012)
@@ -170,28 +170,28 @@
 	//(removes all non-system tables from the provided databases)
 	private void removeAllNonSystemDatabaseTables(Connection dbConnection) throws SQLException  {
 		   DatabaseMetaData dbMetadata = dbConnection.getMetaData();
-		   ResultSet allTableNames = dbMetadata.getTables(null, null, null, null);
+		   //using the TABLE type means we get no system tables.
+		   ResultSet allTableNames = dbMetadata.getTables(null, null, null, new String[]{"TABLE"});
 		   
 		   Statement removeTables = dbConnection.createStatement();
 		   
 		   while (allTableNames.next()) {
-			   if (!hasSystemSchema(allTableNames.getString(SCHEMA_NAME_INDEX))) {
-					 String dropTableQuery = formDropTableQuery(allTableNames.getString(TABLE_NAME_INDEX));
-					 removeTables.addBatch(dropTableQuery);
-			   }
+				String dropTableQuery = formDropTableQuery(allTableNames.getString(SCHEMA_NAME_INDEX),
+											allTableNames.getString(TABLE_NAME_INDEX));
+				removeTables.addBatch(dropTableQuery);
 		   }
 		   
 		   removeTables.executeBatch();	   
 	}
 	
-	private boolean hasSystemSchema(String tableSchemaName) {
-		return tableSchemaName.indexOf(NONSYSTEM_SCHEMA_NAME) == -1;
-	}
-	
-	private String formDropTableQuery(String tableName) {
+	private String formDropTableQuery(String schema, String tableName) {
+		String schemaPrefix = "";
+		if(schema != null && !"".equals(schema)) {
+			schemaPrefix = schema + ".";
+		}
 		String removeTableSQL = 
 			  "DROP TABLE " 
-			  + NONSYSTEM_SCHEMA_NAME + "." + tableName;
+			  + schemaPrefix + "." + tableName;
 		return removeTableSQL;
 	}
 }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |