Source Code Cross Referenced for TableRelationshipsReader.java in  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » loader » generator » 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 JDBC Connection Pool » octopus » org.webdocwf.util.loader.generator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:
004:
005:         Copyright (C) 2003  Together
006:
007:         This library is free software; you can redistribute it and/or
008:         modify it under the terms of the GNU Lesser General Public
009:         License as published by the Free Software Foundation; either
010:         version 2.1 of the License, or (at your option) any later version.
011:
012:         This library is distributed in the hope that it will be useful,
013:         but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         Lesser General Public License for more details.
016:
017:         You should have received a copy of the GNU Lesser General Public
018:         License along with this library; if not, write to the Free Software
019:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:
022:        package org.webdocwf.util.loader.generator;
023:
024:        import java.sql.Connection;
025:        import java.sql.ResultSet;
026:        import java.util.ArrayList;
027:        import java.util.Arrays;
028:        import java.util.Hashtable;
029:        import java.util.List;
030:
031:        import org.webdocwf.util.loader.LoaderException;
032:        import org.webdocwf.util.loader.logging.Logger;
033:        import org.webdocwf.util.loader.logging.StandardLogger;
034:
035:        /**
036:         *
037:         * TableRelationshipsReader class read the data which describe database relationships
038:         * between the tables.
039:         * @author Radoslav Dutina
040:         * @version 1.0
041:         */
042:        public class TableRelationshipsReader {
043:
044:            private static List listPrimaryKeys = null;
045:            private static List listIndexVariables = null;
046:            private static List listForeignVariables = null;
047:            private Hashtable htIndexAndReplacement = new Hashtable();
048:            private RelationshipsAttributes relationshipsAttributes = new RelationshipsAttributes();
049:            private Logger logger;
050:
051:            /**
052:             * Construct object TableRelationshipsReader with associated parameters.
053:             * @param tableName is name of the table form which we retrieve data.
054:             * @param conn is the named connection.
055:             * @param catalogName is the name of the current database.
056:             */
057:            public TableRelationshipsReader(Connection conn, String tableName,
058:                    String catalogName, InputParameters generatorParameters,
059:                    int constraintCount) throws LoaderException {
060:                setLogger();
061:                this .logger.write("full",
062:                        "TableRelationshipsReader is started.");
063:                listPrimaryKeys = new ArrayList();
064:                listIndexVariables = new ArrayList();
065:                listForeignVariables = new ArrayList();
066:                String maxConstraintLenght = generatorParameters
067:                        .getMaxConstraintLength();
068:                int maxConstraintInt = 0;
069:                if (!maxConstraintLenght.equalsIgnoreCase("")
070:                        && !maxConstraintLenght.equalsIgnoreCase("-1")) {
071:                    maxConstraintInt = Integer.parseInt(maxConstraintLenght);
072:                }
073:                //    int constraintCount=0;
074:
075:                try {
076:                    boolean unique = false;
077:                    boolean app = false;
078:                    if (generatorParameters.getSourceType() != null
079:                            && (generatorParameters.getSourceType().equals(
080:                                    "Hsqldb")
081:                                    || generatorParameters.getSourceType()
082:                                            .equals("HypersonicSQL") || generatorParameters
083:                                    .getSourceType().equals("DB2"))) {
084:                        catalogName = null;
085:                    }
086:                    //read meta data
087:                    ResultSet rs2 = conn.getMetaData().getIndexInfo(
088:                            catalogName, null, tableName, false, true);
089:                    ResultSet rs3 = conn.getMetaData().getPrimaryKeys(
090:                            catalogName, null, tableName);
091:                    ResultSet rs5 = conn.getMetaData().getImportedKeys(
092:                            catalogName, null, tableName);
093:
094:                    //            read primary keys
095:                    while (rs3.next()) {
096:                        //primaryKeys
097:                        String primaryKeyName = rs3.getString(6);
098:                        if (maxConstraintInt > 0
099:                                && primaryKeyName.length() > maxConstraintInt) {
100:                            String newName = primaryKeyName.substring(0,
101:                                    maxConstraintInt
102:                                            - String.valueOf(constraintCount)
103:                                                    .length());
104:                            primaryKeyName = newName
105:                                    + String.valueOf(constraintCount);
106:                            constraintCount++;
107:                        }
108:                        listPrimaryKeys.add(primaryKeyName);
109:                        //columnName
110:                        listPrimaryKeys.add(rs3.getString(4));
111:                    }
112:                    rs3.close();
113:
114:                    //            read indexes
115:                    while (rs2.next()) {
116:                        if (rs2.getString(6) != null) {
117:                            //zoran comment this line,this was restrictive and preventing
118:                            //      creating index on column that is primary key also
119:                            //                        if (!rs2.getString(9).equalsIgnoreCase(rs3.getString(4))) {
120:                            //unique
121:                            listIndexVariables.add(rs2.getString(4));
122:                            //index
123:                            String indexName = rs2.getString(6);
124:                            //ZK Added next line
125:                            String keyIndexName = indexName;
126:                            if (maxConstraintInt > 0
127:                                    && indexName.length() > maxConstraintInt) {
128:                                String newName = indexName.substring(0,
129:                                        maxConstraintInt
130:                                                - String.valueOf(
131:                                                        constraintCount)
132:                                                        .length());
133:                                indexName = newName
134:                                        + String.valueOf(constraintCount);
135:                                //constraintCount++;
136:                                //ZK 9.7 2004 Added next block of code.Fixed problem with generation of index on few columns. 
137:                                if (!htIndexAndReplacement
138:                                        .containsKey(keyIndexName)) {
139:                                    htIndexAndReplacement.put(keyIndexName,
140:                                            indexName);
141:                                    constraintCount++;
142:                                } else {
143:                                    indexName = htIndexAndReplacement.get(
144:                                            keyIndexName).toString();
145:                                }
146:                                //end
147:                            }
148:                            //index name
149:                            listIndexVariables.add(indexName);
150:                            //columnName
151:                            listIndexVariables.add(rs2.getString(9));
152:                            //                        }
153:                        }
154:                    }
155:                    rs2.close();
156:
157:                    //            read imported keys
158:                    while (rs5.next()) {
159:                        //ForeignKeyTable
160:                        listForeignVariables.add(rs5.getString(7));
161:                        //foreing key restrictions (lenght)
162:                        String foreignKeyName = rs5.getString(12);
163:                        if (maxConstraintInt > 0
164:                                && foreignKeyName.length() > maxConstraintInt) {
165:                            String newName = foreignKeyName.substring(0,
166:                                    maxConstraintInt
167:                                            - String.valueOf(constraintCount)
168:                                                    .length());
169:                            foreignKeyName = newName
170:                                    + String.valueOf(constraintCount);
171:                            constraintCount++;
172:                        }
173:                        //RelationShipName
174:                        listForeignVariables.add(foreignKeyName);
175:                        //ForeignKeyValue
176:                        listForeignVariables.add(rs5.getString(8));
177:                        //PrimaryKeyTable
178:                        listForeignVariables.add(rs5.getString(3));
179:                        //PrimariKeyValue
180:                        listForeignVariables.add(rs5.getString(4));
181:                    }
182:                    rs5.close();
183:
184:                    RelationshipsAttributes.setTableName(tableName);
185:                    RelationshipsAttributes.setPrimaryKeys(getPrimaryKeys());
186:                    RelationshipsAttributes
187:                            .setIndexVariables(getIndexVariables());
188:                    RelationshipsAttributes
189:                            .setForeignVariables(getForeignVariables());
190:
191:                } catch (Exception e) {
192:                    LoaderException le = new LoaderException("Exception:", e);
193:                    this .logger.write("full",
194:                            "Exception in class TableRelationshipsReader."
195:                                    + "\n" + le.getStackTraceAsString());
196:                    throw le;
197:                }
198:                this .logger.write("full",
199:                        "TableRelationshipsReader is finished.");
200:            }
201:
202:            /**
203:             * This method sets the value of listPrimaryKeys parameters.
204:             * @param primary_Keys is value of parameter.
205:             */
206:            public static void setPrimaryKeys(String[] primary_Keys) {
207:                listPrimaryKeys = Arrays.asList(primary_Keys);
208:            }
209:
210:            /**
211:             * This method read the value of listPrimaryKeys parameters.
212:             * @return value of parameter.
213:             */
214:            public static String[] getPrimaryKeys() {
215:                String[] ret = new String[listPrimaryKeys.size()];
216:                listPrimaryKeys.toArray(ret);
217:                return ret;
218:            }
219:
220:            /**
221:             * This method sets the value of listIndexVariables parameters.
222:             * @param index_Variables is value of parameter.
223:             */
224:            public static void setIndexVariables(String[] index_Variables) {
225:                listIndexVariables = Arrays.asList(index_Variables);
226:            }
227:
228:            /**
229:             * This method read the value of listIndexVariables parameters.
230:             * @return value of parameter.
231:             */
232:            public static String[] getIndexVariables() {
233:                String[] ret = new String[listIndexVariables.size()];
234:                listIndexVariables.toArray(ret);
235:                return ret;
236:            }
237:
238:            /**
239:             * This method sets the value of listForeignVariables parameters.
240:             * @param foreign_Variables is the value of parameter.
241:             */
242:            public static void setForeignVariables(String[] foreign_Variables) {
243:                listForeignVariables = Arrays.asList(foreign_Variables);
244:            }
245:
246:            /**
247:             * This method read the value of listForeignVariables parameters.
248:             * @return value of parameter.
249:             */
250:            public static String[] getForeignVariables() {
251:                String[] ret = new String[listForeignVariables.size()];
252:                listForeignVariables.toArray(ret);
253:                return ret;
254:            }
255:
256:            /**
257:             * This method read the value of RelationshipsAttributes parameters.
258:             * @return references to RelationshipsAttributes objects.
259:             */
260:            public RelationshipsAttributes getRelationshipsAttributes() {
261:
262:                return relationshipsAttributes;
263:            }
264:
265:            /**
266:             * This method will set logger object
267:             * @param logger
268:             */
269:            private void setLogger() {
270:                this.logger = StandardLogger.getCentralLogger();
271:            }
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.