Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / tools / org / apache / derby / impl / tools / dblook / DB_Schema.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/tools/org/apache/derby/impl/tools/dblook/DB_Schema.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/tools/org/apache/derby/impl/tools/dblook/DB_Schema.java
new file mode 100644 (file)
index 0000000..83fe7f4
--- /dev/null
@@ -0,0 +1,84 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.tools.dblook.DB_Schema\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.tools.dblook;\r
+\r
+import java.sql.Connection;\r
+import java.sql.Statement;\r
+import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
+\r
+import java.util.HashMap;\r
+\r
+import org.apache.derby.tools.dblook;\r
+\r
+public class DB_Schema {\r
+\r
+       /* ************************************************\r
+        * Generate the DDL for all schemas in a given\r
+        * database.\r
+        * @param conn Connection to the source database.\r
+        * @param tablesOnly true if we're only generating objects\r
+        *  specific to a particular table (in which case\r
+        *  we don't generate schemas).\r
+        * @return The DDL for the schemas has been written\r
+        *  to output via Logs.java.\r
+        ****/\r
+\r
+       public static void doSchemas(Connection conn,\r
+               boolean tablesOnly) throws SQLException\r
+       {\r
+\r
+               Statement stmt = conn.createStatement();\r
+               ResultSet rs = stmt.executeQuery("SELECT SCHEMANAME, SCHEMAID " +\r
+                       "FROM SYS.SYSSCHEMAS");\r
+\r
+               boolean firstTime = true;\r
+               while (rs.next()) {\r
+\r
+                       String sName = dblook.addQuotes(\r
+                               dblook.expandDoubleQuotes(rs.getString(1)));\r
+                       if (tablesOnly || dblook.isIgnorableSchema(sName))\r
+                               continue;\r
+\r
+                       if (sName.equals("\"APP\""))\r
+                       // don't have to create this one.\r
+                               continue;\r
+\r
+                       if (firstTime) {\r
+                               Logs.reportString("----------------------------------------------");\r
+                               Logs.reportMessage("DBLOOK_SchemasHeader");\r
+                               Logs.reportString("----------------------------------------------\n");\r
+                       }\r
+\r
+                       Logs.writeToNewDDL("CREATE SCHEMA " + sName);\r
+                       Logs.writeStmtEndToNewDDL();\r
+                       Logs.writeNewlineToNewDDL();\r
+                       firstTime = false;\r
+\r
+               }\r
+\r
+               rs.close();\r
+               stmt.close();\r
+\r
+       }\r
+\r
+}\r