Source Code Cross Referenced for GenerateController.java in  » Database-ORM » ebean » com » avaje » util » codegen » 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 » ebean » com.avaje.util.codegen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.avaje.util.codegen;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import java.util.Iterator;
006:        import java.util.logging.Logger;
007:        import java.util.regex.Pattern;
008:
009:        import com.avaje.lib.log.LogFactory;
010:        import com.avaje.lib.sql.DictionaryInfo;
011:        import com.avaje.lib.sql.TableInfo;
012:
013:        /**
014:         * 
015:         * <pre>
016:         * <code>
017:         * 
018:         * ## patterns for database dictionary loading
019:         * ebean.codegen.catalog
020:         * ebean.codegen.schema
021:         * ebean.codegen.table
022:         * </code>
023:         * </pre>
024:         */
025:        public class GenerateController {
026:
027:            private static final Logger logger = LogFactory
028:                    .get(GenerateController.class);
029:
030:            GenerateConfiguration config;
031:
032:            DictionaryInfo dictionaryInfo;
033:
034:            BeanWriter beanWriter;
035:
036:            TableNaming tableNaming;
037:
038:            BuildBean build;
039:
040:            SourceCodeMerger sourceMerger;
041:
042:            /**
043:             * The java source directory.
044:             */
045:            String sourceDir = "src";
046:
047:            /**
048:             * Catalog pattern for registering Dictionary.
049:             */
050:            String catalogPattern;
051:
052:            /**
053:             * Schema pattern for registering Dictionary.
054:             */
055:            String schemaPattern;
056:
057:            /**
058:             * Table pattern for registering Dictionary.
059:             */
060:            String tablePattern;
061:
062:            public GenerateController(GenerateConfiguration config) {
063:                this .config = config;
064:                this .dictionaryInfo = config.getDictionaryInfo();
065:                this .tableNaming = config.getTableNaming();
066:
067:                build = new BuildBean(config);
068:                beanWriter = new BeanWriter(config);
069:                sourceMerger = new SourceCodeMerger(config);
070:
071:                sourceDir = config.getProperty("codegen.source.directory",
072:                        "src");
073:
074:                // load the patterns for reading database meta data
075:                catalogPattern = config.getProperty("codegen.catalog", null);
076:                schemaPattern = config.getProperty("codegen.schema", null);
077:                tablePattern = config.getProperty("codegen.table", null);
078:            }
079:
080:            /**
081:             * Register the tables into the Dictionary.
082:             */
083:            private void dictionaryRegister() throws IOException {
084:
085:                // register all the tables that we will generate deployment for
086:                String m = "Dictionary registering [" + catalogPattern + "]["
087:                        + schemaPattern + "][" + tablePattern + "]";
088:                logger.info(m);
089:
090:                dictionaryInfo.registerTables(catalogPattern, schemaPattern,
091:                        tablePattern, false);
092:            }
093:
094:            public void generate(String regex) throws IOException {
095:
096:                Pattern p = Pattern.compile("[a-z_]");
097:                p.matcher("junk").matches();
098:
099:                dictionaryRegister();
100:
101:                Pattern pattern = null;
102:                if (regex != null) {
103:                    pattern = Pattern.compile(regex);
104:                } else {
105:                    Pattern p2 = Pattern.compile("[a-z_]");
106:                    p2.matcher("junk").matches();
107:                }
108:
109:                GenerateLog log = new GenerateLog();
110:
111:                config
112:                        .println("==================================================");
113:                if (config.isWriteMode()) {
114:                    config.println("Generate:");
115:                } else {
116:                    config.println("Generate: Test Mode (no files written)");
117:                }
118:                config
119:                        .println("==================================================");
120:
121:                Iterator it = dictionaryInfo.getTableInfoIterator();
122:                while (it.hasNext()) {
123:                    TableInfo tableInfo = (TableInfo) it.next();
124:                    String tableName = tableInfo.getName().toLowerCase();
125:                    if (pattern != null
126:                            && !pattern.matcher(tableName).matches()) {
127:
128:                    } else {
129:                        generate(log, tableInfo, null);
130:                    }
131:                }
132:
133:                config
134:                        .println("==================================================");
135:                config.println("Summary:");
136:                config
137:                        .println("==================================================");
138:
139:                config.println(log.summary(true));
140:                config
141:                        .println("==================================================");
142:            }
143:
144:            /**
145:             * 
146:             */
147:            private boolean generate(GenerateLog log, TableInfo tableInfo,
148:                    String beanClassName) throws IOException {
149:
150:                GenerateInfo info = new GenerateInfo(log);
151:                info.setTableInfo(tableInfo);
152:
153:                if (tableInfo.hasOnlyPrimaryKey()) {
154:                    // pure intersection table 
155:                    // no bean generated and use ManyToMany
156:                    log.addIntersection(info);
157:                    return false;
158:                }
159:
160:                String dbTableName = tableInfo.getName();
161:
162:                info.setWithAnnotations(config.isWithAnnotations());
163:
164:                if (beanClassName == null) {
165:                    beanClassName = tableNaming.toBeanClassName(dbTableName);
166:                }
167:
168:                String beanPackage = tableNaming.toPackage(dbTableName);
169:
170:                info.setTableInfo(tableInfo);
171:                info.setPackageClass(beanPackage, beanClassName);
172:
173:                build.build(info);
174:
175:                // set the full destination file name
176:                setFullFileName(info);
177:
178:                // add additional properties, methods and comments from source code
179:                sourceMerger.mergeSource(info);
180:
181:                GenerateInfo embId = info.getEmbeddedId();
182:                if (embId != null) {
183:                    // generate the EmbeddedId bean
184:                    setFullFileName(embId);
185:                    sourceMerger.mergeSource(embId);
186:                    beanWriter.write(embId);
187:                }
188:
189:                beanWriter.write(info);
190:
191:                return true;
192:            }
193:
194:            private void setFullFileName(GenerateInfo info) {
195:
196:                String beanClassName = info.getClassName();
197:                String beanPackage = info.getPackage();
198:
199:                String packageDir = sourceDir;
200:                if (beanPackage != null) {
201:                    packageDir += File.separator + beanPackage;
202:                }
203:                String beanFn = packageDir + File.separator + beanClassName;
204:
205:                packageDir = packageDir.replace('.', File.separatorChar);
206:                File packageDirFile = new File(packageDir);
207:                if (!packageDirFile.exists()) {
208:                    // create the package directory
209:                    packageDirFile.mkdirs();
210:                }
211:
212:                beanFn = beanFn.replace('.', File.separatorChar) + ".java";
213:
214:                // the full file name of the source file
215:                info.setFullFileName(beanFn);
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.