Source Code Cross Referenced for SqlLoaderCtlGenerator.java in  » Database-ORM » ODAL » com » completex » objective » tools » generators » 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 ORM » ODAL » com.completex.objective.tools.generators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Objective Database Abstraction Layer (ODAL)
003:         *  Copyright (c) 2004, The ODAL Development Group
004:         *  All rights reserved.
005:         *  For definition of the ODAL Development Group please refer to LICENCE.txt file
006:         *
007:         *  Distributable under LGPL license.
008:         *  See terms of license at gnu.org.
009:         */package com.completex.objective.tools.generators;
010:
011:        import com.completex.objective.components.log.Log;
012:        import com.completex.objective.components.log.adapter.StdOutputLogAdapter;
013:        import com.completex.objective.components.persistency.JavaToMetaTypeImpl;
014:        import com.completex.objective.components.persistency.MetaTable;
015:        import com.completex.objective.components.persistency.Record;
016:        import com.completex.objective.components.persistency.core.impl.SqlLoaderPersistencyImpl;
017:        import com.completex.objective.components.persistency.meta.MetaModel;
018:        import com.completex.objective.components.persistency.meta.adapter.ModelLoaderAdapter;
019:        import com.completex.objective.components.sdl.reader.SdlReader;
020:        import com.completex.objective.components.sdl.reader.impl.SdlReaderImpl;
021:        import com.completex.objective.util.cmd.CmdLine;
022:
023:        import java.io.*;
024:        import java.sql.SQLException;
025:        import java.util.Iterator;
026:        import java.util.Map;
027:        import java.util.Properties;
028:
029:        /**
030:         * @author Gennady Krizhevsky
031:         */
032:        public class SqlLoaderCtlGenerator {
033:
034:            protected static final Log logger = StdOutputLogAdapter
035:                    .newLogInstance();
036:
037:            protected ModelLoaderAdapter modelFileLoaderAdapter;
038:            protected MetaModel model;
039:            private SdlReader reader = new SdlReaderImpl();
040:            private boolean debug = false;
041:
042:            private static PersistentObjectGenerator.LineStruct lineStruct = new PersistentObjectGenerator.LineStruct();
043:
044:            private static final String INTERNAL_DESC_PATH = "intern_path"; // Internal descriptor file path
045:            private static final String EXTERNAL_DESC_PATH = "extern_path"; // External descriptor file path
046:            private static final String OUT_DIR = "out_dir"; // Top level directory for generated classes
047:            private static final String FILTER_PATTERN = "filter_pattern";
048:
049:            String labels[] = { INTERNAL_DESC_PATH, EXTERNAL_DESC_PATH,
050:                    OUT_DIR, FILTER_PATTERN, };
051:
052:            private static final String DEBUG = "-debug";
053:            String flags[] = { DEBUG, };
054:
055:            public SqlLoaderCtlGenerator(String propertiesPath)
056:                    throws Exception {
057:                initialize(propertiesPath);
058:                setUp();
059:                process();
060:            }
061:
062:            private void process() throws FileNotFoundException {
063:
064:                for (Iterator it = model.tableIterator(); it.hasNext();) {
065:                    Map.Entry entry = (Map.Entry) it.next();
066:                    MetaTable table = (MetaTable) entry.getValue();
067:                    String dataFileName = table.getTableAlias() + "-data.txt";
068:                    String ctlFileName = table.getTableAlias() + "-ctl.txt";
069:                    File outDir = new File(lineStruct.outputPath);
070:                    boolean rc = outDir.mkdirs();
071:                    PrintWriter writer = new PrintWriter(new FileOutputStream(
072:                            lineStruct.outputPath + "/" + ctlFileName));
073:                    Record record = new Record(table);
074:                    SqlLoaderPersistencyImpl
075:                            .createControlFile(
076:                                    record,
077:                                    dataFileName,
078:                                    "|",
079:                                    writer,
080:                                    SqlLoaderPersistencyImpl.DEFAULT_ORACLE_DATE_FORMAT);
081:                    writer.close();
082:                }
083:
084:            }
085:
086:            private void initialize(String propertiesPath) throws Exception {
087:                Properties properties = new Properties();
088:                properties.load(new FileInputStream(propertiesPath));
089:                logger.debug("INPUT: " + properties);
090:                String[] args = CmdLine.properties2args(properties, labels,
091:                        flags);
092:                CmdLine cmdLine = new CmdLine(this .getClass().getName(), args,
093:                        labels, flags, null);
094:
095:                lineStruct.inFilePath = cmdLine.getParam(INTERNAL_DESC_PATH,
096:                        true);
097:                lineStruct.exFilePath = cmdLine.getParam(EXTERNAL_DESC_PATH,
098:                        true);
099:                lineStruct.outputPath = cmdLine.getParam(OUT_DIR, true);
100:                lineStruct.filterPattern = cmdLine.getParam(FILTER_PATTERN,
101:                        true);
102:
103:                debug = cmdLine.getFlag(DEBUG);
104:                System.out.println("Finished initialization ...");
105:
106:            }
107:
108:            public void setUp() throws Exception, SQLException {
109:
110:                Reader internalFileReader = new BufferedReader(new FileReader(
111:                        lineStruct.inFilePath));
112:                Reader externalFileReader = new BufferedReader(new FileReader(
113:                        lineStruct.exFilePath));
114:                JavaToMetaTypeImpl javaToMetaType = new JavaToMetaTypeImpl();
115:                modelFileLoaderAdapter = new ModelLoaderAdapter(
116:                        new ModelLoaderAdapter.InternalFileModelLoaderAdapter(
117:                                internalFileReader, lineStruct.filterPattern),
118:                        new ModelLoaderAdapter.ExternalFileModelLoaderAdapter(
119:                                externalFileReader, lineStruct.filterPattern),
120:                        javaToMetaType, logger);
121:                model = modelFileLoaderAdapter.load(null);
122:                System.out.println("Finished setup ...");
123:            }
124:
125:            //
126:            //
127:            // Util classes
128:            //
129:            //
130:            static class LineStruct {
131:                String inFilePath;
132:                String exFilePath;
133:                String outputPath;
134:                String filterPattern;
135:            }
136:
137:            /**
138:             * config/test/sql-loader-ctl.properties
139:             * @param args
140:             * @throws Exception
141:             */
142:            public static void main(String[] args) throws Exception {
143:                SqlLoaderCtlGenerator generator = new SqlLoaderCtlGenerator(
144:                        args[0]);
145:            }
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.