KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > tools > dblook > DB_Schema


1 /*
2
3    Derby - Class org.apache.derby.impl.tools.dblook.DB_Schema
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.tools.dblook;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.Statement JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28
29 import java.util.HashMap JavaDoc;
30
31 import org.apache.derby.tools.dblook;
32
33 public class DB_Schema {
34
35     /* ************************************************
36      * Generate the DDL for all schemas in a given
37      * database.
38      * @param conn Connection to the source database.
39      * @param tablesOnly true if we're only generating objects
40      * specific to a particular table (in which case
41      * we don't generate schemas).
42      * @return The DDL for the schemas has been written
43      * to output via Logs.java.
44      ****/

45
46     public static void doSchemas(Connection JavaDoc conn,
47         boolean tablesOnly) throws SQLException JavaDoc
48     {
49
50         Statement JavaDoc stmt = conn.createStatement();
51         ResultSet JavaDoc rs = stmt.executeQuery("SELECT SCHEMANAME, SCHEMAID " +
52             "FROM SYS.SYSSCHEMAS");
53
54         boolean firstTime = true;
55         while (rs.next()) {
56
57             String JavaDoc sName = dblook.addQuotes(
58                 dblook.expandDoubleQuotes(rs.getString(1)));
59             if (tablesOnly || dblook.isIgnorableSchema(sName))
60                 continue;
61
62             if (sName.equals("\"APP\""))
63             // don't have to create this one.
64
continue;
65
66             if (firstTime) {
67                 Logs.reportString("----------------------------------------------");
68                 Logs.reportMessage("DBLOOK_SchemasHeader");
69                 Logs.reportString("----------------------------------------------\n");
70             }
71
72             Logs.writeToNewDDL("CREATE SCHEMA " + sName);
73             Logs.writeStmtEndToNewDDL();
74             Logs.writeNewlineToNewDDL();
75             firstTime = false;
76
77         }
78
79         rs.close();
80         stmt.close();
81
82     }
83
84 }
85
Popular Tags