Source Code Cross Referenced for SQLSchema.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » client » session » parser » kernel » 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 Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.client.session.parser.kernel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2002 Christian Sell
003:         * csell@users.sourceforge.net
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         * created by cse, 24.09.2002 17:30:57
020:         */
021:        package net.sourceforge.squirrel_sql.client.session.parser.kernel;
022:
023:        import java.sql.SQLException;
024:        import java.util.ArrayList;
025:        import java.util.List;
026:
027:        import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
028:        import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
029:
030:        /**
031:         * requirements for objects that maintain schema information
032:         */
033:        public interface SQLSchema {
034:            /**
035:             * a descriptor which groups together information about a database table
036:             */
037:            public class Table implements  Cloneable, Comparable<Table> {
038:                public final String catalog;
039:                public final String schema;
040:                public final String name;
041:                public final String compositeName;
042:                public transient String alias;
043:
044:                private SQLDatabaseMetaData dmd;
045:                private String[] columns;
046:
047:                public static String createCompositeName(String catalog,
048:                        String schema, String name) {
049:
050:                    StringBuffer sbuf = new StringBuffer();
051:                    if (catalog != null) {
052:                        sbuf.append(catalog);
053:                        sbuf.append(".");
054:                    }
055:                    if (schema != null) {
056:                        sbuf.append(schema);
057:                        sbuf.append(".");
058:                    }
059:                    sbuf.append(name);
060:                    return sbuf.toString();
061:                }
062:
063:                public Table clone(String alias) {
064:                    try {
065:                        Table newTable = (Table) super .clone();
066:                        newTable.alias = alias;
067:                        return newTable;
068:                    } catch (CloneNotSupportedException e) {
069:                        e.printStackTrace();
070:                        return null;
071:                    }
072:                }
073:
074:                public Table(String catalog, String schema, String name,
075:                        SQLDatabaseMetaData dmd) {
076:                    this .catalog = catalog;
077:                    this .schema = schema;
078:                    this .name = name;
079:                    this .compositeName = createCompositeName(catalog, schema,
080:                            name);
081:                    this .dmd = dmd;
082:                }
083:
084:                public Table(String catalog, String schema, String name) {
085:                    this (catalog, schema, name, null);
086:                }
087:
088:                public Table(String schema, String name) {
089:                    this (null, schema, name, null);
090:                }
091:
092:                public Table(String name) {
093:                    this (null, null, name, null);
094:                }
095:
096:                public void setColumns(String[] columns) {
097:                    this .columns = columns;
098:                }
099:
100:                public void setColumns(List<String> columns) {
101:                    this .columns = columns.toArray(new String[columns.size()]);
102:                }
103:
104:                public String[] getColumns() {
105:                    if (columns == null)
106:                        loadColumns();
107:                    return columns;
108:                }
109:
110:                public String[] getColumns(String prefix) {
111:                    String[] cols = getColumns();
112:                    if (prefix == null)
113:                        return cols;
114:
115:                    List<String> list = new ArrayList<String>(cols.length);
116:                    for (int i = 0; i < cols.length; i++)
117:                        if (cols[i].startsWith(prefix))
118:                            list.add(cols[i]);
119:                    return list.toArray(new String[list.size()]);
120:                }
121:
122:                public String getCompositeName() {
123:                    return compositeName;
124:                }
125:
126:                public boolean hasAlias() {
127:                    return alias != null;
128:                }
129:
130:                public String toString() {
131:                    return alias == null ? compositeName : compositeName + " "
132:                            + alias;
133:                }
134:
135:                public int hashCode() {
136:                    return compositeName.hashCode();
137:                }
138:
139:                public boolean equals(Object other) {
140:                    if (other instanceof  Table) {
141:                        Table o = (Table) other;
142:                        if (o.compositeName.equals(compositeName)) {
143:                            return alias == o.alias || alias != null
144:                                    && alias.equals(o.alias);
145:                        } else
146:                            return false;
147:                    } else
148:                        return false;
149:                }
150:
151:                public boolean equals(String catalog, String schema,
152:                        String table) {
153:                    return (this .catalog == catalog || (this .catalog != null
154:                            && catalog != null && this .catalog.equals(catalog)))
155:                            && (this .schema == schema || (this .schema != null
156:                                    && schema != null && this .schema
157:                                    .equals(schema)))
158:                            && (this .name.equals(table));
159:                }
160:
161:                public boolean matches(String catalog, String schema,
162:                        String name) {
163:                    return (catalog == null || (this .catalog != null && this .catalog
164:                            .startsWith(catalog)))
165:                            && (schema == null || (this .schema != null && this .schema
166:                                    .startsWith(schema)))
167:                            && (name == null || this .name.startsWith(name));
168:                }
169:
170:                public int compareTo(Table other) {
171:                    if (alias != null) {
172:                        return other.alias != null ? alias
173:                                .compareTo(other.alias) : -1;
174:                    } else if (other.alias != null) {
175:                        return 1;
176:                    }
177:                    return compositeName.compareTo(other.compositeName);
178:                }
179:
180:                protected void loadColumns() {
181:                    try {
182:                        List<String> cols = new ArrayList<String>();
183:                        TableColumnInfo[] infos = dmd.getColumnInfo(catalog,
184:                                schema, name);
185:                        for (int i = 0; i < infos.length; i++) {
186:                            cols.add(infos[i].getColumnName());
187:                        }
188:                        setColumns(cols);
189:                    } catch (SQLException e) {
190:                        throw new RuntimeException(e.getMessage());
191:                    }
192:                }
193:            }
194:
195:            /**
196:             * lookup a table descriptor which exactly matches the parameters
197:             * @param catalog optional
198:             * @param schema optional
199:             * @param name required
200:             * @return the table descriptor
201:             */
202:            Table getTable(String catalog, String schema, String name);
203:
204:            /**
205:             * Return tables matching a pattern. If a <em>pattern</em> is null it is not
206:             * considered. If all patterns are null, all tables are returned
207:             * @param catalog catalog name pattern (optional)
208:             * @param schema schema name pattern (optional)
209:             * @param name name pattern (optional)
210:             * @return descriptors for tables matching the parameters
211:             */
212:            List<Table> getTables(String catalog, String schema, String name);
213:
214:            /**
215:             * @param alias an alias, possibly also the table name itself
216:             * @return the table registered under the given alias/name
217:             */
218:            Table getTableForAlias(String alias);
219:        }
w__w__w._j___av___a___2__s__.__co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.