Source Code Cross Referenced for DomainObjectFactoryConfig.java in  » Database-ORM » ProjectJulp » org » julp » util » common » 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 » ProjectJulp » org.julp.util.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.julp.util.common;
002:
003:        import java.beans.PropertyDescriptor;
004:        import java.io.File;
005:        import java.io.FileOutputStream;
006:        import java.io.IOException;
007:        import java.lang.reflect.Field;
008:        import java.lang.reflect.Method;
009:        import java.util.Enumeration;
010:        import java.util.Properties;
011:        import org.julp.DataWriter;
012:        import org.julp.DomainObjectFactory;
013:        import org.julp.ExceptionHandler;
014:
015:        /**
016:         * Populate settings for DomainObjectFactory
017:         */
018:        public class DomainObjectFactoryConfig {
019:
020:            private boolean debug = false;
021:            /* Useful to send only modified objects to another tier */
022:            private boolean discardUnmodifiedObjects;
023:            /* Set sequence or disable update/insert/delete */
024:            private char[] dataModificationSequence;
025:            /* Disable DB modifications*/
026:            private boolean readOnly = false;
027:
028:            /* Optimistic lock settings ****************************************/
029:
030:            private char optimisticLock = DomainObjectFactory.KEY_COLUMNS;
031:
032:            /*
033:             Throw exception if PreparedStatement.executeUpdate() does not return 1
034:             for each DomainObject.
035:             It means that the row in DB Table most likely was modified or deleted
036:             by another user/process.
037:             */
038:            private boolean throwOptimisticLockDeleteException = true;
039:            private boolean throwOptimisticLockUpdateException = true;
040:            private boolean throwFailedInsertException = true;
041:
042:            /* END of Optimistic lock settings *********************************/
043:            /* Target DB catalog */
044:            private boolean overrideCatalogName = false;
045:
046:            /* This object generates SQL for data modification */
047:            private String dataWriter = "org.julp.DBDataWriter";
048:            /* use synchronized Collections */
049:            private boolean synchronizedAccess = false;
050:            /* If lazyLoding == true than set only original values vs. original and current */
051:            private boolean lazyLoading = false;
052:            /* Records per page */
053:            private int pageSize = 0;
054:            /* Do not execute INSERTS/UPDATES/DELETES - just generate SQL and parameters */
055:            private boolean generateSQLOnly = false;
056:            /* control if load() append objects to objectList )*/
057:            private boolean append = false;
058:            /* Some databases (like hsqdb 1.7.1) failed when UPDATE statement is
059:             using TABLE_NAME.COLUMN_NAME in SET clause. INSERT also failes */
060:            private boolean noFullColumnName = false;
061:            /* Throw Exception or ignore if DomainObject has less fields than mapping */
062:            private boolean throwMissingFieldException = false;
063:            /* if not null object should handle exceptions */
064:            private String exceptionHandler;
065:            /* If true suppress exception when call writeData on empty objectList */
066:            private boolean exceptionOnEmptyObjectList = true;
067:            /* Create and populate MetaData automatically */
068:            private boolean createDefaultMetaData = true;
069:
070:            //
071:            private Properties settings;
072:            private String path;
073:
074:            public DomainObjectFactoryConfig() {
075:            }
076:
077:            public void configure(DomainObjectFactory factory) {
078:                factory.setDebug(debug);
079:                factory.setDiscardUnmodifiedObjects(discardUnmodifiedObjects);
080:                factory.setReadOnly(readOnly);
081:                factory.setOptimisticLock(optimisticLock);
082:                factory
083:                        .setThrowFailedInsertException(throwFailedInsertException);
084:                factory
085:                        .setThrowOptimisticLockDeleteException(throwOptimisticLockDeleteException);
086:                factory
087:                        .setThrowOptimisticLockUpdateException(throwOptimisticLockUpdateException);
088:                factory.setOverrideCatalogName(overrideCatalogName);
089:                factory.setSynchronizedAccess(synchronizedAccess);
090:                factory.setPageSize(pageSize);
091:                factory.setGenerateSQLOnly(generateSQLOnly);
092:                factory.setAppend(append);
093:                factory.setNoFullColumnName(noFullColumnName);
094:                factory
095:                        .setThrowMissingFieldException(throwMissingFieldException);
096:                factory
097:                        .setExceptionOnEmptyObjectList(exceptionOnEmptyObjectList);
098:                factory.setCreateDefaultMetaData(createDefaultMetaData);
099:                if (dataModificationSequence != null
100:                        && dataModificationSequence.length > 0) {
101:                    factory
102:                            .setDataModificationSequence(dataModificationSequence);
103:                }
104:                try {
105:                    factory.setExceptionHandler((ExceptionHandler) Class
106:                            .forName(exceptionHandler).newInstance());
107:                } catch (Exception e) {
108:                    e.printStackTrace();
109:                    // ignore
110:                }
111:                try {
112:                    factory.setDataWriter((DataWriter) Class
113:                            .forName(dataWriter).newInstance());
114:                } catch (Exception e) {
115:                    e.printStackTrace();
116:                    // ignore
117:                }
118:            }
119:
120:            public void populate(Properties settings) {
121:                this .settings = settings;
122:                populate();
123:            }
124:
125:            public void populate() {
126:                Enumeration enumeration = settings.keys();
127:                while (enumeration.hasMoreElements()) {
128:                    String property = (String) enumeration.nextElement();
129:                    String value = settings.getProperty(property);
130:                    if (property.equals("dataWriter")) {
131:                        try {
132:                            //dataWriter = (DataWriter) Class.forName(value).newInstance();
133:                            dataWriter = value;
134:                        } catch (Exception e) {
135:                            e.printStackTrace();
136:                            e.printStackTrace();
137:                            //ignore
138:                        }
139:                    } else if (property.equals("exceptionHandler")) {
140:                        try {
141:                            //exceptionHandler = (ExceptionHandler) Class.forName(value).newInstance();
142:                            exceptionHandler = value;
143:                        } catch (Exception e) {
144:                            e.printStackTrace();
145:                            //ignore
146:                        }
147:                        //like DIU, UD, UI etc.
148:                    } else if (property.equals("dataModificationSequence")) {
149:                        dataModificationSequence = value.toCharArray();
150:                    } else {
151:                        try {
152:                            Method mWrite = (new PropertyDescriptor(property,
153:                                    this .getClass())).getWriteMethod();
154:                            Object[] param = new Boolean[1];
155:                            param[0] = new Boolean(value);
156:                            mWrite.invoke(this , param);
157:                        } catch (Exception e) {
158:                            e.printStackTrace();
159:                            //ignore
160:                        }
161:                    }
162:                }
163:            }
164:
165:            public void store() {
166:                if (settings == null) {
167:                    settings = new Properties();
168:                }
169:                Field[] fields = getClass().getDeclaredFields();
170:                for (int i = 0; i < fields.length; i++) {
171:                    try {
172:                        String name = fields[i].getName();
173:                        if (name.equals("exceptionHandler")) {
174:                            //settings.setProperty(name, fields[i].getType().getName());
175:                            settings.setProperty(name, fields[i].get(this )
176:                                    .toString());
177:                        } else if (name.equals("dataWriter")) {
178:                            //settings.setProperty(name, fields[i].getType().getName());
179:                            settings.setProperty(name, fields[i].get(this )
180:                                    .toString());
181:                        } else if (name.equals("dataModificationSequence")) {
182:                            settings.setProperty(name, new String(
183:                                    dataModificationSequence));
184:                        }
185:                        if (fields[i].getType().equals(boolean.class)) {
186:                            settings.setProperty(name, String.valueOf(fields[i]
187:                                    .getBoolean(this )));
188:                        }
189:                    } catch (Exception e) {
190:                        e.printStackTrace();
191:                        // ignore
192:                    }
193:                }
194:                try {
195:                    settings
196:                            .store(new FileOutputStream(path),
197:                                    "DomainObjectFactoryConfig: DomainObjectFactory settings");
198:                } catch (IOException e) {
199:                    e.printStackTrace();
200:                }
201:            }
202:
203:            public void load(String path) {
204:                this .path = path;
205:                load();
206:            }
207:
208:            public void load() {
209:                java.io.InputStream inStream = null;
210:                settings = new Properties();
211:                try {
212:                    inStream = new File(path).toURL().openStream();
213:                    settings.load(inStream);
214:                } catch (java.io.IOException ioe) {
215:                    throw new RuntimeException(ioe);
216:                } finally {
217:                    try {
218:                        inStream.close();
219:                    } catch (java.io.IOException ioe) {
220:                        throw new RuntimeException(ioe);
221:                    }
222:                }
223:            }
224:
225:            public boolean isDebug() {
226:                return debug;
227:            }
228:
229:            public void setDebug(boolean debug) {
230:                this .debug = debug;
231:            }
232:
233:            public boolean isDiscardUnmodifiedObjects() {
234:                return discardUnmodifiedObjects;
235:            }
236:
237:            public void setDiscardUnmodifiedObjects(
238:                    boolean discardUnmodifiedObjects) {
239:                this .discardUnmodifiedObjects = discardUnmodifiedObjects;
240:            }
241:
242:            public char[] getDataModificationSequence() {
243:                return dataModificationSequence;
244:            }
245:
246:            public void setDataModificationSequence(
247:                    char[] dataModificationSequence) {
248:                this .dataModificationSequence = dataModificationSequence;
249:            }
250:
251:            public boolean isReadOnly() {
252:                return readOnly;
253:            }
254:
255:            public void setReadOnly(boolean readOnly) {
256:                this .readOnly = readOnly;
257:            }
258:
259:            public char getOptimisticLock() {
260:                return optimisticLock;
261:            }
262:
263:            public void setOptimisticLock(char optimisticLock) {
264:                this .optimisticLock = optimisticLock;
265:            }
266:
267:            public boolean isThrowOptimisticLockDeleteException() {
268:                return throwOptimisticLockDeleteException;
269:            }
270:
271:            public void setThrowOptimisticLockDeleteException(
272:                    boolean throwOptimisticLockDeleteException) {
273:                this .throwOptimisticLockDeleteException = throwOptimisticLockDeleteException;
274:            }
275:
276:            public boolean isThrowOptimisticLockUpdateException() {
277:                return throwOptimisticLockUpdateException;
278:            }
279:
280:            public void setThrowOptimisticLockUpdateException(
281:                    boolean throwOptimisticLockUpdateException) {
282:                this .throwOptimisticLockUpdateException = throwOptimisticLockUpdateException;
283:            }
284:
285:            public boolean isThrowFailedInsertException() {
286:                return throwFailedInsertException;
287:            }
288:
289:            public void setThrowFailedInsertException(
290:                    boolean throwFailedInsertException) {
291:                this .throwFailedInsertException = throwFailedInsertException;
292:            }
293:
294:            public boolean isOverrideCatalogName() {
295:                return overrideCatalogName;
296:            }
297:
298:            public void setOverrideCatalogName(boolean overrideCatalogName) {
299:                this .overrideCatalogName = overrideCatalogName;
300:            }
301:
302:            public String getDataWriter() {
303:                return dataWriter;
304:            }
305:
306:            public void setDataWriter(String dataWriter) {
307:                this .dataWriter = dataWriter;
308:            }
309:
310:            public boolean isSynchronizedAccess() {
311:                return synchronizedAccess;
312:            }
313:
314:            public void setSynchronizedAccess(boolean synchronizedAccess) {
315:                this .synchronizedAccess = synchronizedAccess;
316:            }
317:
318:            public boolean isLazyLoading() {
319:                return lazyLoading;
320:            }
321:
322:            public void setLazyLoading(boolean lazyLoading) {
323:                this .lazyLoading = lazyLoading;
324:            }
325:
326:            public int getPageSize() {
327:                return pageSize;
328:            }
329:
330:            public void setPageSize(int pageSize) {
331:                this .pageSize = pageSize;
332:            }
333:
334:            public boolean isGenerateSQLOnly() {
335:                return generateSQLOnly;
336:            }
337:
338:            public void setGenerateSQLOnly(boolean generateSQLOnly) {
339:                this .generateSQLOnly = generateSQLOnly;
340:            }
341:
342:            public boolean isAppend() {
343:                return append;
344:            }
345:
346:            public void setAppend(boolean append) {
347:                this .append = append;
348:            }
349:
350:            public boolean isNoFullColumnName() {
351:                return noFullColumnName;
352:            }
353:
354:            public void setNoFullColumnName(boolean noFullColumnName) {
355:                this .noFullColumnName = noFullColumnName;
356:            }
357:
358:            public boolean isThrowMissingFieldException() {
359:                return throwMissingFieldException;
360:            }
361:
362:            public void setThrowMissingFieldException(
363:                    boolean throwMissingFieldException) {
364:                this .throwMissingFieldException = throwMissingFieldException;
365:            }
366:
367:            public String getExceptionHandler() {
368:                return exceptionHandler;
369:            }
370:
371:            public void setExceptionHandler(String exceptionHandler) {
372:                this .exceptionHandler = exceptionHandler;
373:            }
374:
375:            public boolean isExceptionOnEmptyObjectList() {
376:                return exceptionOnEmptyObjectList;
377:            }
378:
379:            public void setExceptionOnEmptyObjectList(
380:                    boolean exceptionOnEmptyObjectList) {
381:                this .exceptionOnEmptyObjectList = exceptionOnEmptyObjectList;
382:            }
383:
384:            public boolean isCreateDefaultMetaData() {
385:                return createDefaultMetaData;
386:            }
387:
388:            public void setCreateDefaultMetaData(boolean createDefaultMetaData) {
389:                this .createDefaultMetaData = createDefaultMetaData;
390:            }
391:
392:            public String getPath() {
393:                return path;
394:            }
395:
396:            public void setPath(String path) {
397:                this .path = path;
398:            }
399:
400:            //test
401:            public static void main(String[] args) {
402:                DomainObjectFactoryConfig dfc = new DomainObjectFactoryConfig();
403:                dfc
404:                        .setPath("/home/leonard/projects/ProjectJulp/julp-util/src/org/julp/util/common/settings.properties");
405:                dfc.load();
406:                dfc.populate();
407:                dfc.getSettings().list(System.out);
408:                TestFactory tf = new TestFactory();
409:                System.out.println("before configure: " + tf);
410:                dfc.configure(tf);
411:                System.out.println("after configure: " + tf);
412:                dfc.store();
413:            }
414:
415:            public Properties getSettings() {
416:                return settings;
417:            }
418:
419:            public void setSettings(Properties settings) {
420:                this .settings = settings;
421:            }
422:
423:        }
424:
425:        class TestFactory extends DomainObjectFactory {
426:
427:            /** Creates a new instance of TestFactory */
428:            public TestFactory() {
429:            }
430:
431:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.