01: /*
02:
03: Derby - Class org.apache.derby.impl.tools.dblook.DB_Schema
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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;
25: import java.sql.Statement;
26: import java.sql.ResultSet;
27: import java.sql.SQLException;
28:
29: import java.util.HashMap;
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 conn, boolean tablesOnly)
47: throws SQLException {
48:
49: Statement stmt = conn.createStatement();
50: ResultSet rs = stmt.executeQuery("SELECT SCHEMANAME, SCHEMAID "
51: + "FROM SYS.SYSSCHEMAS");
52:
53: boolean firstTime = true;
54: while (rs.next()) {
55:
56: String sName = dblook.addQuotes(dblook
57: .expandDoubleQuotes(rs.getString(1)));
58: if (tablesOnly || dblook.isIgnorableSchema(sName))
59: continue;
60:
61: if (sName.equals("\"APP\""))
62: // don't have to create this one.
63: continue;
64:
65: if (firstTime) {
66: Logs
67: .reportString("----------------------------------------------");
68: Logs.reportMessage("DBLOOK_SchemasHeader");
69: Logs
70: .reportString("----------------------------------------------\n");
71: }
72:
73: Logs.writeToNewDDL("CREATE SCHEMA " + sName);
74: Logs.writeStmtEndToNewDDL();
75: Logs.writeNewlineToNewDDL();
76: firstTime = false;
77:
78: }
79:
80: rs.close();
81: stmt.close();
82:
83: }
84:
85: }
|