Source Code Cross Referenced for ModelLoaderAdapter.java in  » Database-ORM » ODAL » com » completex » objective » components » persistency » meta » adapter » 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.components.persistency.meta.adapter 
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.components.persistency.meta.adapter;
010:
011:        import com.completex.objective.components.log.Log;
012:        import com.completex.objective.components.persistency.ColumnType;
013:        import com.completex.objective.components.persistency.JavaToMetaType;
014:        import com.completex.objective.components.persistency.MetaColumn;
015:        import com.completex.objective.components.persistency.MetaTable;
016:        import com.completex.objective.components.persistency.UserDefinedTypeMetaModel;
017:        import com.completex.objective.components.persistency.meta.MetaModel;
018:        import com.completex.objective.components.persistency.meta.ModelLoader;
019:        import com.completex.objective.components.persistency.meta.ModelLoaderPlugin;
020:        import com.completex.objective.components.persistency.meta.impl.DatabaseModelLoaderImpl;
021:        import com.completex.objective.components.persistency.meta.impl.FileModelLoaderImpl;
022:        import com.completex.objective.components.persistency.meta.impl.NullModelLoaderImpl;
023:        import com.completex.objective.components.persistency.meta.impl.UdtBaseModelLoaderPlugin;
024:        import com.completex.objective.components.sdl.reader.SdlReader;
025:        import com.completex.objective.components.sdl.reader.impl.SdlReaderImpl;
026:
027:        import java.io.IOException;
028:        import java.io.Reader;
029:        import java.sql.Connection;
030:        import java.sql.SQLException;
031:        import java.util.Iterator;
032:        import java.util.LinkedHashMap;
033:        import java.util.Map;
034:
035:        /**
036:         * @author Gennady Krizhevsky
037:         */
038:        public class ModelLoaderAdapter implements  ModelLoader {
039:
040:            private ModelLoader internalFileModelLoader;
041:            private ModelLoader externalFileModelLoader = new NullModelLoaderImpl();
042:            private JavaToMetaType javaToMetaType;
043:            private MetaColumn.GeneratorStruct creationDateStruct;
044:            private MetaColumn.GeneratorStruct lastUpdatedStruct;
045:            private Log logger;
046:
047:            private static final SdlReader sdlReader = new SdlReaderImpl();
048:            private Map plugins = new LinkedHashMap();
049:
050:            public ModelLoaderAdapter(ModelLoader internalFileModelLoader,
051:                    ModelLoader externalFileModelLoader,
052:                    JavaToMetaType javaToMetaType, Log logger) {
053:                this (internalFileModelLoader, externalFileModelLoader,
054:                        javaToMetaType, null, null, logger);
055:            }
056:
057:            public ModelLoaderAdapter(ModelLoader internalFileModelLoader,
058:                    ModelLoader externalFileModelLoader,
059:                    JavaToMetaType javaToMetaType,
060:                    MetaColumn.GeneratorStruct creationDateStruct,
061:                    MetaColumn.GeneratorStruct lastUpdatedStruct, Log logger) {
062:                //  assert internalFileModelLoader != null;
063:                //  assert logger != null;
064:
065:                this .logger = logger;
066:                this .internalFileModelLoader = internalFileModelLoader;
067:                this .internalFileModelLoader.setJavaToMetaType(javaToMetaType);
068:                this .creationDateStruct = creationDateStruct;
069:                this .lastUpdatedStruct = lastUpdatedStruct;
070:
071:                if (externalFileModelLoader != null) {
072:                    this .externalFileModelLoader = externalFileModelLoader;
073:                    this .externalFileModelLoader
074:                            .setJavaToMetaType(javaToMetaType);
075:                }
076:                setJavaToMetaType(javaToMetaType);
077:            }
078:
079:            protected Log getLogger() {
080:                return logger;
081:            }
082:
083:            private void loadPluginsData(MetaModel model) throws Exception {
084:                //
085:                // Plugins related stuff here:
086:                //
087:                // For now - load only udt one:
088:                UserDefinedTypeMetaModel pluginModel = null;
089:                if (plugins != null) {
090:                    ModelLoaderPlugin plugin = (ModelLoaderPlugin) plugins
091:                            .get(UdtBaseModelLoaderPlugin.PLUGIN_KEY);
092:                    if (plugin != null) {
093:                        pluginModel = plugin.load(pluginModel);
094:                        model.setUserDefinedTypeMetaModel(pluginModel);
095:                    }
096:                }
097:            }
098:
099:            private MetaModel loadModel() throws Exception {
100:
101:                //
102:                // Always 1st load the internal:
103:                //
104:                MetaModel model = internalFileModelLoader.load(null);
105:                //
106:                // Load external model if exists:
107:                //
108:                if (externalFileModelLoader != null) {
109:                    model = externalFileModelLoader.load(model);
110:                }
111:                //
112:                // Populate model with extra data:
113:                //
114:                for (Iterator it = model.tableIterator(); it.hasNext();) {
115:                    Map.Entry entry = (Map.Entry) it.next();
116:                    MetaTable table = (MetaTable) entry.getValue();
117:                    for (int i = 0; i < table.size(); i++) {
118:                        MetaColumn column = table.getColumn(i);
119:                        if (lastUpdatedStruct != null) {
120:                            column.setLastUpdatedNames(lastUpdatedStruct);
121:                        }
122:                        if (creationDateStruct != null) {
123:                            column.setCreationDateNames(creationDateStruct);
124:                        }
125:                    }
126:                }
127:
128:                return model;
129:            }
130:
131:            public MetaModel load(MetaModel model) throws Exception {
132:                model = loadModel();
133:                //
134:                // Plugins related stuff here:
135:                //
136:                loadPluginsData(model);
137:                return model;
138:            }
139:
140:            public void registerPlugin(ModelLoaderPlugin plugin) {
141:                String key = plugin.getPluginKey();
142:                if (plugins.containsKey(key)) {
143:                    throw new RuntimeException(
144:                            "There is already storer plugin with key " + key);
145:                }
146:                plugins.put(key, plugin);
147:                plugin.setJavaToMetaType(javaToMetaType);
148:            }
149:
150:            public void unregisterPlugin(String key) {
151:                plugins.remove(key);
152:            }
153:
154:            public JavaToMetaType getJavaToMetaType() {
155:                return javaToMetaType;
156:            }
157:
158:            public void setJavaToMetaType(JavaToMetaType javaToMetaType) {
159:                this .javaToMetaType = javaToMetaType;
160:            }
161:
162:            //
163:            //
164:            //  Auxilliary adapters
165:            //
166:            //
167:            public static class InternalFileModelLoaderAdapter extends
168:                    FileModelLoaderImpl {
169:
170:                public InternalFileModelLoaderAdapter(String descriptorPath,
171:                        String filterPattern) {
172:                    super (descriptorPath, filterPattern);
173:                }
174:
175:                public InternalFileModelLoaderAdapter(Reader reader,
176:                        String filterPattern) {
177:                    super (reader, filterPattern);
178:                }
179:
180:                protected MetaModel toModel(MetaModel model, Map modelMap) {
181:                    model.fromInternalMap(modelMap);
182:                    return model;
183:                }
184:
185:                protected Map readModelMap(Reader reader) throws IOException {
186:                    return (Map) sdlReader.read(reader);
187:                }
188:
189:                public void setJavaToMetaType(JavaToMetaType javaToMetaType) {
190:                }
191:            }
192:
193:            public static class ExternalFileModelLoaderAdapter extends
194:                    FileModelLoaderImpl {
195:
196:                public ExternalFileModelLoaderAdapter(String descriptorPath,
197:                        String filterPattern) {
198:                    super (descriptorPath, filterPattern);
199:                }
200:
201:                public ExternalFileModelLoaderAdapter(Reader reader,
202:                        String filterPattern) {
203:                    super (reader, filterPattern);
204:                }
205:
206:                protected MetaModel toModel(MetaModel model, Map modelMap) {
207:                    model.fromExternalMap(modelMap);
208:                    return model;
209:                }
210:
211:                protected Map readModelMap(Reader reader) throws IOException {
212:                    return (Map) sdlReader.read(reader);
213:                }
214:
215:                public void setJavaToMetaType(JavaToMetaType javaToMetaType) {
216:                }
217:            }
218:
219:            public static class DatabaseModelLoaderAdapter extends
220:                    DatabaseModelLoaderImpl {
221:
222:                private Connection connection;
223:                private JavaToMetaType javaToMetaType;
224:                private Log logger;
225:
226:                public DatabaseModelLoaderAdapter(String schema,
227:                        String catalog, String filterPattern,
228:                        Connection connection, Log logger) {
229:                    this (schema, catalog, filterPattern, connection, null,
230:                            logger);
231:                }
232:
233:                DatabaseModelLoaderAdapter(String schema, String catalog,
234:                        String filterPattern, Connection connection,
235:                        JavaToMetaType javaToMetaType, Log logger) {
236:                    super (schema, catalog, filterPattern);
237:                    this .logger = logger;
238:                    this .connection = connection;
239:                    this .javaToMetaType = javaToMetaType;
240:                }
241:
242:                public void setJavaToMetaType(JavaToMetaType javaToMetaType) {
243:                    this .javaToMetaType = javaToMetaType;
244:                }
245:
246:                protected Connection getConnection() throws SQLException {
247:                    return connection;
248:                }
249:
250:                protected ColumnType columnType(String dataType,
251:                        int columnSize, int decimalDigits, boolean required) {
252:                    return javaToMetaType.dataType(dataType, columnSize,
253:                            decimalDigits, required);
254:                }
255:
256:                protected void debug(String message) {
257:                    logger.debug(message);
258:                }
259:
260:                protected void info(String message) {
261:                    logger.info(message);
262:                }
263:            }
264:
265:        }
w___w_w_.j___av__a2__s___.c___om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.