Source Code Cross Referenced for GetMetaDataSql.java in  » Database-Client » SQL-Workbench » workbench » db » 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 » SQL Workbench » workbench.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * GetMetaDataSql.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.db;
013:
014:        /**
015:         *
016:         * @author  support@sql-workbench.net
017:         */
018:        public class GetMetaDataSql {
019:            private String baseSql;
020:            private String schema;
021:            private String schemaField;
022:            private String catalog;
023:            private String catalogField;
024:            private String objectName;
025:            private String objectNameField;
026:            private String orderBy;
027:            private boolean useUpperCase;
028:            private boolean useLowerCase;
029:            private boolean isProcedureCall;
030:            private int schemaArgumentPos;
031:            private int catalogArgumentPos;
032:            private int objectNameArgumentPos;
033:
034:            public GetMetaDataSql() {
035:            }
036:
037:            public String getSql() {
038:                if (this .isProcedureCall)
039:                    return this .getProcedureCallSql();
040:                else
041:                    return this .getSelectSql();
042:            }
043:
044:            private String getSelectSql() {
045:                boolean needsAnd = false;
046:                boolean needsWhere = false;
047:                StringBuilder sql = new StringBuilder(baseSql);
048:                if (baseSql.toLowerCase().indexOf("where") == -1) {
049:                    needsWhere = true;
050:                } else {
051:                    needsAnd = true;
052:                }
053:
054:                if (schema != null && schemaField != null) {
055:                    if (needsWhere) {
056:                        sql.append(" WHERE ");
057:                        needsWhere = false;
058:                    }
059:
060:                    if (needsAnd)
061:                        sql.append(" AND ");
062:                    sql.append(schemaField + " = '" + getNameValue(schema)
063:                            + "'");
064:                    needsAnd = true;
065:                }
066:                if (catalog != null && catalogField != null) {
067:                    if (needsWhere) {
068:                        sql.append(" WHERE ");
069:                        needsWhere = false;
070:                    }
071:                    if (needsAnd)
072:                        sql.append(" AND ");
073:                    sql.append(catalogField + " = '" + getNameValue(catalog)
074:                            + "'");
075:                    needsAnd = true;
076:                }
077:                if (objectName != null && objectNameField != null) {
078:                    if (needsWhere) {
079:                        sql.append(" WHERE ");
080:                        needsWhere = false;
081:                    }
082:                    if (needsAnd)
083:                        sql.append(" AND ");
084:                    sql.append(objectNameField + " = '"
085:                            + getNameValue(objectName) + "'");
086:                }
087:                if (this .orderBy != null) {
088:                    sql.append(" " + this .orderBy);
089:                }
090:                return sql.toString();
091:            }
092:
093:            private String getNameValue(String value) {
094:                if (value == null)
095:                    return null;
096:                if (useLowerCase)
097:                    return value.toLowerCase();
098:                if (useUpperCase)
099:                    return value.toUpperCase();
100:                return value;
101:            }
102:
103:            private String getProcedureCallSql() {
104:                StringBuilder sql = new StringBuilder(this .baseSql);
105:                sql.append(' ');
106:                for (int i = 1; i < 4; i++) {
107:                    if (schemaArgumentPos == i && this .schema != null) {
108:                        if (i > 1)
109:                            sql.append(',');
110:                        sql.append(this .schema);
111:                    } else if (catalogArgumentPos == i && this .catalog != null) {
112:                        if (i > 1)
113:                            sql.append(',');
114:                        sql.append(this .catalog);
115:                    } else if (this .objectNameArgumentPos == i
116:                            && this .objectName != null) {
117:                        if (i > 1)
118:                            sql.append(',');
119:                        sql.append(this .objectName);
120:                    }
121:                }
122:                return sql.toString();
123:            }
124:
125:            public String getBaseSql() {
126:                return baseSql;
127:            }
128:
129:            public void setBaseSql(String sql) {
130:                this .baseSql = sql;
131:            }
132:
133:            public String getSchema() {
134:                return schema;
135:            }
136:
137:            public void setSchema(String schem) {
138:                this .schema = schem;
139:            }
140:
141:            public String getCatalog() {
142:                return catalog;
143:            }
144:
145:            public void setCatalog(String cat) {
146:                this .catalog = cat;
147:            }
148:
149:            public String getObjectName() {
150:                return objectName;
151:            }
152:
153:            public void setObjectName(String name) {
154:                this .objectName = name;
155:            }
156:
157:            public String toString() {
158:                return getSql();
159:            }
160:
161:            public String getSchemaField() {
162:                return schemaField;
163:            }
164:
165:            public void setSchemaField(String field) {
166:                this .schemaField = field;
167:            }
168:
169:            public String getCatalogField() {
170:                return catalogField;
171:            }
172:
173:            public void setCatalogField(String field) {
174:                this .catalogField = field;
175:            }
176:
177:            public String getObjectNameField() {
178:                return objectNameField;
179:            }
180:
181:            public void setObjectNameField(String field) {
182:                this .objectNameField = field;
183:            }
184:
185:            public String getOrderBy() {
186:                return orderBy;
187:            }
188:
189:            public void setOrderBy(String order) {
190:                this .orderBy = order;
191:            }
192:
193:            public boolean getUseUpperCase() {
194:                return useUpperCase;
195:            }
196:
197:            public void setUseUpperCase(boolean upperCase) {
198:                this .useUpperCase = upperCase;
199:            }
200:
201:            public boolean getUseLowerCase() {
202:                return useLowerCase;
203:            }
204:
205:            public void setUseLowerCase(boolean lowerCase) {
206:                this .useLowerCase = lowerCase;
207:            }
208:
209:            public boolean isIsProcedureCall() {
210:                return isProcedureCall;
211:            }
212:
213:            public void setIsProcedureCall(boolean isCall) {
214:                this .isProcedureCall = isCall;
215:            }
216:
217:            public int getSchemaArgumentPos() {
218:                return schemaArgumentPos;
219:            }
220:
221:            public void setSchemaArgumentPos(int pos) {
222:                this .schemaArgumentPos = pos;
223:            }
224:
225:            public int getCatalogArgumentPos() {
226:                return catalogArgumentPos;
227:            }
228:
229:            public void setCatalogArgumentPos(int pos) {
230:                this .catalogArgumentPos = pos;
231:            }
232:
233:            public int getObjectNameArgumentPos() {
234:                return objectNameArgumentPos;
235:            }
236:
237:            public void setObjectNameArgumentPos(int pos) {
238:                this.objectNameArgumentPos = pos;
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.