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_View.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/tools/org/apache/derby/impl/tools/dblook/DB_View.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/tools/org/apache/derby/impl/tools/dblook/DB_View.java
new file mode 100644 (file)
index 0000000..83eaa6e
--- /dev/null
@@ -0,0 +1,98 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.tools.dblook.DB_View\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_View {\r
+\r
+       /* ************************************************\r
+        * Generate the DDL for all views in a given\r
+        * database.\r
+        * @param conn Connection to the source database.\r
+        * @return The DDL for the views has been written\r
+        *  to output via Logs.java.\r
+        ****/\r
+\r
+       public static void doViews(Connection conn)\r
+               throws SQLException {\r
+\r
+               Statement stmt = conn.createStatement();\r
+               ResultSet rs = stmt.executeQuery("SELECT V.VIEWDEFINITION, " +\r
+                       "T.TABLENAME, T.SCHEMAID, V.COMPILATIONSCHEMAID FROM SYS.SYSVIEWS V, " +\r
+                       "SYS.SYSTABLES T WHERE T.TABLEID = V.TABLEID");\r
+\r
+               boolean firstTime = true;\r
+               while (rs.next()) {\r
+\r
+                       String viewSchema = dblook.lookupSchemaId(rs.getString(3));\r
+                       if (dblook.isIgnorableSchema(viewSchema))\r
+                               continue;\r
+\r
+                       if (!dblook.stringContainsTargetTable(rs.getString(1)))\r
+                               continue;\r
+\r
+                       if (firstTime) {\r
+                               Logs.reportString("----------------------------------------------");\r
+                               Logs.reportMessage("DBLOOK_ViewsHeader");\r
+                               Logs.reportString("----------------------------------------------\n");\r
+                       }\r
+\r
+                       // We are using the exact text that was entered by the user,\r
+                       // which means the view name that is given might not include\r
+                       // the schema in which the view was created.  So, we change\r
+                       // our schema to be the one in which the view was created\r
+                       // before we execute the create statement.\r
+                       Logs.writeToNewDDL("SET SCHEMA ");\r
+                       Logs.writeToNewDDL(dblook.lookupSchemaId(rs.getString(4)));\r
+                       Logs.writeStmtEndToNewDDL();\r
+\r
+                       // Now, go ahead and create the view.\r
+                       Logs.writeToNewDDL(dblook.removeNewlines(rs.getString(1)));\r
+                       Logs.writeStmtEndToNewDDL();\r
+                       Logs.writeNewlineToNewDDL();\r
+                       firstTime = false;\r
+\r
+               }\r
+\r
+               // Set schema back to default ("APP").\r
+               if (!firstTime) {\r
+                       Logs.reportMessage("DBLOOK_DefaultSchema");\r
+                       Logs.writeToNewDDL("SET SCHEMA \"APP\"");\r
+                       Logs.writeStmtEndToNewDDL();\r
+                       Logs.writeNewlineToNewDDL();\r
+               }\r
+\r
+               rs.close();\r
+               stmt.close();\r
+               return;\r
+\r
+       }\r
+\r
+}\r