Source Code Cross Referenced for GenerateDoml.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 org.w3c.dom.Document;
025:        import org.w3c.dom.Element;
026:        import org.webdocwf.util.loader.LoaderException;
027:        import org.webdocwf.util.loader.logging.Logger;
028:        import org.webdocwf.util.loader.logging.StandardLogger;
029:
030:        /**
031:         * GenerateDoml class creates the doml file as an output.
032:         * @author Radoslav Dutina
033:         * @version 1.0
034:         */
035:        public class GenerateDoml {
036:
037:            private Document documentDoml;
038:            private String referenceTableName = null;
039:            private String javaType = null;
040:            private String tableNameToCase = null;
041:            private String referenceTableNameToCase = null;
042:            private Logger logger;
043:
044:            /**
045:             * Construct object GenerateDoml with associated parameters.
046:             * @param documentDoml is the reference to object of the Document class.
047:             * @param rootDoml is reference to the object of Element class, which represents the root element of
048:             * the documentDoml object.
049:             * @param childRoot1 is the child of the root element, of the documentDoml object.
050:             * @param childRoot2 is the child of the root element, of the documentDoml object. The childRoot2
051:             * represent package tag.
052:             * @param importDefinitionAttributes is references to ImportDefinitionAttributes object.
053:             * @param relationshipsAttributes is references to RelationshipsAttributes object.
054:             * @param generatorParameters represents the references to InputParameter object.
055:             * @param tableName is name of the table form which we retrieve data.
056:             * @throws LoaderException
057:             */
058:
059:            public GenerateDoml(Document documentDoml, Element rootDoml,
060:                    Element childRoot1, Element childRoot2, String tableName,
061:                    ImportDefinitionAttributes importDefinitionAttributes,
062:                    RelationshipsAttributes relationshipsAttributes,
063:                    InputParameters generatorParameters) throws LoaderException {
064:
065:                setLogger();
066:                this .logger.write("full", "GenerateDoml is started.");
067:                //child1=tag database
068:                try {
069:                    boolean notUsingOid = true;
070:                    if (importDefinitionAttributes.getTagSourceColumnName().length != 0) {
071:                        for (int i = 0; i < importDefinitionAttributes
072:                                .getTagSourceColumnName().length; i++) {
073:                            if (importDefinitionAttributes
074:                                    .getTagSourceColumnName()[i]
075:                                    .equalsIgnoreCase("oid")) {
076:                                notUsingOid = false;
077:                                break;
078:                            }
079:                        }
080:                    }
081:
082:                    //Crate child (table)
083:                    Element childRoot3 = (Element) documentDoml
084:                            .createElement("table");
085:                    childRoot2.appendChild(childRoot3);
086:                    tableNameToCase = tableName.toUpperCase().substring(0, 1)
087:                            + tableName.toLowerCase().substring(1);
088:                    childRoot3.setAttribute("id", generatorParameters
089:                            .getPackageName()
090:                            + "." + tableNameToCase);
091:                    childRoot3.setAttribute("dbTableName", tableName);
092:                    //      childRoot3.setAttribute("isLazyLoading", "true");
093:                    //      childRoot3.setAttribute("caching", "none");
094:                    //      if(notUsingOid){
095:                    //        childRoot3.setAttribute("notUsingOid", "true");
096:                    //      }else{
097:                    //        childRoot3.setAttribute("notUsingOid", "false");
098:                    //      }
099:
100:                    //Crate child (column)
101:                    if (importDefinitionAttributes.getTagSourceColumnName().length != 0) {
102:                        for (int i = 0; i < importDefinitionAttributes
103:                                .getTagSourceColumnName().length; i++) {
104:                            //checking id the column is the foreign key
105:                            boolean fk = false;
106:                            if (relationshipsAttributes.getForeignVariables().length != 0
107:                                    && relationshipsAttributes != null) {
108:                                for (int j = 0; j < relationshipsAttributes
109:                                        .getForeignVariables().length; j = j + 5) {
110:                                    if (relationshipsAttributes
111:                                            .getForeignVariables()[j + 2]
112:                                            .equalsIgnoreCase(importDefinitionAttributes
113:                                                    .getTagSourceColumnName()[i])) {
114:                                        fk = true;
115:                                        referenceTableName = relationshipsAttributes
116:                                                .getForeignVariables()[j + 3];
117:                                        referenceTableNameToCase = referenceTableName
118:                                                .toUpperCase().substring(0, 1)
119:                                                + referenceTableName
120:                                                        .toLowerCase()
121:                                                        .substring(1);
122:                                        break;
123:                                    }
124:                                }
125:                            }
126:                            //checking id the column is the primary key
127:                            boolean pk = false;
128:                            if (relationshipsAttributes.getPrimaryKeys().length != 0
129:                                    && relationshipsAttributes != null) {
130:                                for (int k = 0; k < relationshipsAttributes
131:                                        .getPrimaryKeys().length; k = k + 2) {
132:                                    if (importDefinitionAttributes
133:                                            .getTagSourceColumnName()[i]
134:                                            .equalsIgnoreCase(relationshipsAttributes
135:                                                    .getPrimaryKeys()[k + 1])) {
136:                                        pk = true;
137:                                        break;
138:                                    }
139:                                }
140:                            }
141:                            if (!importDefinitionAttributes
142:                                    .getTagSourceColumnName()[i]
143:                                    .equalsIgnoreCase("oid")
144:                                    && !importDefinitionAttributes
145:                                            .getTagSourceColumnName()[i]
146:                                            .equalsIgnoreCase("version")) {
147:                                Element childRoot4 = (Element) documentDoml
148:                                        .createElement("column");
149:                                childRoot3.appendChild(childRoot4);
150:                                childRoot4.setAttribute("id",
151:                                        importDefinitionAttributes
152:                                                .getTagSourceColumnName()[i]);
153:                                childRoot4.setAttribute("usedForQuery", "true");
154:                                if (pk) {
155:                                    childRoot4.setAttribute("isPrimaryKey",
156:                                            "true");
157:                                }
158:
159:                                //this column is the foreign key
160:                                if (fk) {
161:                                    Element childRoot5 = (Element) documentDoml
162:                                            .createElement("referenceObject");
163:                                    childRoot4.appendChild(childRoot5);
164:                                    childRoot5.setAttribute("constraint",
165:                                            "true");
166:                                    childRoot5.setAttribute("reference",
167:                                            generatorParameters
168:                                                    .getPackageName()
169:                                                    + "."
170:                                                    + referenceTableNameToCase);
171:
172:                                    Element childRoot6 = (Element) documentDoml
173:                                            .createElement("type");
174:                                    childRoot4.appendChild(childRoot6);
175:                                    if (importDefinitionAttributes
176:                                            .getTagAllowNulls()[i]
177:                                            .equalsIgnoreCase("NOT NULL")) {
178:                                        childRoot6.setAttribute("canBeNull",
179:                                                "false");
180:                                    } else {
181:                                        childRoot6.setAttribute("canBeNull",
182:                                                "true");
183:                                    }
184:                                    //childRoot6.setAttribute("dbType", importDefinitionAttributes.getTagColumnType()[i]);
185:                                    childRoot6.setAttribute("dbType", "none");
186:                                    MappingJavaType mappingJavaType = new MappingJavaType(
187:                                            generatorParameters,
188:                                            importDefinitionAttributes
189:                                                    .getTagColumnType()[i]);
190:                                    javaType = mappingJavaType.getJavaType();
191:                                    //childRoot6.setAttribute("javaType", javaType);
192:                                    childRoot6.setAttribute("javaType",
193:                                            generatorParameters
194:                                                    .getPackageName()
195:                                                    + "."
196:                                                    + referenceTableNameToCase
197:                                                    + "DO");
198:                                    childRoot6.setAttribute("size",
199:                                            importDefinitionAttributes
200:                                                    .getTagColumnLenght()[i]);
201:                                    //column isn't the foreign key
202:                                } else {
203:                                    Element childRoot6 = (Element) documentDoml
204:                                            .createElement("type");
205:                                    childRoot4.appendChild(childRoot6);
206:                                    if (importDefinitionAttributes
207:                                            .getTagAllowNulls()[i]
208:                                            .equalsIgnoreCase("NOT NULL")) {
209:                                        childRoot6.setAttribute("canBeNull",
210:                                                "false");
211:                                    } else {
212:                                        childRoot6.setAttribute("canBeNull",
213:                                                "true");
214:                                    }
215:                                    childRoot6.setAttribute("dbType",
216:                                            importDefinitionAttributes
217:                                                    .getTagColumnType()[i]);
218:                                    MappingJavaType mappingJavaType1 = new MappingJavaType(
219:                                            generatorParameters,
220:                                            importDefinitionAttributes
221:                                                    .getTagColumnType()[i]);
222:                                    javaType = mappingJavaType1.getJavaType();
223:                                    childRoot6.setAttribute("javaType",
224:                                            javaType);
225:                                    childRoot6.setAttribute("size",
226:                                            importDefinitionAttributes
227:                                                    .getTagColumnLenght()[i]);
228:                                }
229:                            }
230:                        }
231:                    }
232:                    if (relationshipsAttributes.getIndexVariables().length != 0
233:                            && relationshipsAttributes != null) {
234:                        for (int i = 0; i < relationshipsAttributes
235:                                .getIndexVariables().length; i = i + 3) {
236:                            //Crate child (index)
237:                            Element childRoot7 = (Element) documentDoml
238:                                    .createElement("index");
239:                            childRoot3.appendChild(childRoot7);
240:                            childRoot7
241:                                    .setAttribute("id", relationshipsAttributes
242:                                            .getIndexVariables()[i + 1]);
243:                            if (relationshipsAttributes.getIndexVariables()[i]
244:                                    .equalsIgnoreCase("1")) {
245:                                childRoot7.setAttribute("unique", "false");
246:                            } else {
247:                                childRoot7.setAttribute("unique", "true");
248:                            }
249:                            Element childRoot8 = (Element) documentDoml
250:                                    .createElement("indexColumn");
251:                            childRoot7.appendChild(childRoot8);
252:                            childRoot8
253:                                    .setAttribute("id", relationshipsAttributes
254:                                            .getIndexVariables()[i + 2]);
255:                        }
256:                    }
257:
258:                } catch (Exception e) {
259:                    String msg = "Exception in class GenerateDoml: Error has occurred when trying to generate doml file!";
260:                    LoaderException le = new LoaderException(msg + "\n"
261:                            + e.getMessage(), (Throwable) e);
262:                    this .logger
263:                            .write(
264:                                    "full",
265:                                    "Exception in class GenerateDoml: Error has occurred when trying to generate doml file!"
266:                                            + "\n" + le.getStackTraceAsString());
267:                    throw le;
268:                }
269:                this .logger.write("full", "GenerateDoml is finished.");
270:            }
271:
272:            /**
273:             * This method will set logger object
274:             * @param logger
275:             */
276:            private void setLogger() {
277:                this.logger = StandardLogger.getCentralLogger();
278:            }
279:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.