Source Code Cross Referenced for DB_Index.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » tools » dblook » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.impl.tools.dblook 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.tools.dblook.DB_Index
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.impl.tools.dblook;
023:
024:        import java.sql.Connection;
025:        import java.sql.Statement;
026:        import java.sql.PreparedStatement;
027:        import java.sql.ResultSet;
028:        import java.sql.SQLException;
029:
030:        import java.util.HashMap;
031:        import java.util.StringTokenizer;
032:
033:        import org.apache.derby.tools.dblook;
034:
035:        public class DB_Index {
036:
037:            /* ************************************************
038:             * Generate the DDL for all indexes in a given
039:             * database.
040:             * @param conn Connection to the source database.
041:             * @return The DDL for the indexes has been written
042:             *  to output via Logs.java.
043:             ****/
044:
045:            public static void doIndexes(Connection conn) throws SQLException {
046:
047:                Statement stmt = conn.createStatement();
048:                ResultSet rs = stmt
049:                        .executeQuery("SELECT TABLEID, CONGLOMERATENAME, "
050:                                + "DESCRIPTOR, SCHEMAID, ISINDEX, ISCONSTRAINT FROM SYS.SYSCONGLOMERATES "
051:                                + "ORDER BY TABLEID");
052:
053:                boolean firstTime = true;
054:                while (rs.next()) {
055:
056:                    if (!rs.getBoolean(5) || // (isindex == false)
057:                            rs.getBoolean(6)) // (isconstraint == true)
058:                        // then skip it.
059:                        continue;
060:
061:                    String tableId = rs.getString(1);
062:                    String tableName = dblook.lookupTableId(tableId);
063:                    if (tableName == null)
064:                        // then tableId isn't a user table, so we can skip it.
065:                        continue;
066:                    else if (dblook.isExcludedTable(tableName))
067:                        // table isn't specified in user-given list.
068:                        continue;
069:
070:                    String iSchema = dblook.lookupSchemaId(rs.getString(4));
071:                    if (dblook.isIgnorableSchema(iSchema))
072:                        continue;
073:
074:                    if (firstTime) {
075:                        Logs
076:                                .reportString("----------------------------------------------");
077:                        Logs.reportMessage("DBLOOK_IndexesHeader");
078:                        Logs
079:                                .reportString("----------------------------------------------\n");
080:                    }
081:
082:                    String iName = dblook.addQuotes(dblook
083:                            .expandDoubleQuotes(rs.getString(2)));
084:                    iName = iSchema + "." + iName;
085:
086:                    StringBuffer createIndexString = createIndex(iName,
087:                            tableName, tableId, rs.getString(3));
088:
089:                    Logs.writeToNewDDL(createIndexString.toString());
090:                    Logs.writeStmtEndToNewDDL();
091:                    Logs.writeNewlineToNewDDL();
092:                    firstTime = false;
093:
094:                }
095:
096:                rs.close();
097:                stmt.close();
098:
099:            }
100:
101:            /* ************************************************
102:             * Generate DDL for a specific index.
103:             * @param ixName Name of the index.
104:             * @param tableName Name of table on which the index exists.
105:             * @param tableId Id of table on which the index exists.
106:             * @param ixDescribe Column list for the index.
107:             * @return The DDL for the specified index, as a string
108:             *  buffer.
109:             ****/
110:
111:            private static StringBuffer createIndex(String ixName,
112:                    String tableName, String tableId, String ixDescribe)
113:                    throws SQLException {
114:
115:                StringBuffer sb = new StringBuffer("CREATE ");
116:                if (ixDescribe.indexOf("UNIQUE") != -1)
117:                    sb.append("UNIQUE ");
118:
119:                // Note: We leave the keyword "BTREE" out since it's not
120:                // required, and since it is not recognized by DB2.
121:
122:                sb.append("INDEX ");
123:                sb.append(ixName);
124:                sb.append(" ON ");
125:                sb.append(tableName);
126:                sb.append(" (");
127:                sb.append(dblook.getColumnListFromDescription(tableId,
128:                        ixDescribe));
129:                sb.append(")");
130:                return sb;
131:
132:            }
133:
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.