Source Code Cross Referenced for HibernateEntityLogicImpl.java in  » UML » AndroMDA-3.2 » org » andromda » cartridges » hibernate » metafacades » 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 » UML » AndroMDA 3.2 » org.andromda.cartridges.hibernate.metafacades 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.cartridges.hibernate.metafacades;
002:
003:        import java.text.MessageFormat;
004:
005:        import java.util.ArrayList;
006:        import java.util.Collection;
007:
008:        import org.andromda.cartridges.hibernate.HibernateProfile;
009:        import org.andromda.cartridges.hibernate.HibernateUtils;
010:        import org.andromda.metafacades.uml.AssociationEndFacade;
011:        import org.andromda.metafacades.uml.Entity;
012:        import org.andromda.metafacades.uml.EntityAttribute;
013:        import org.apache.commons.collections.CollectionUtils;
014:        import org.apache.commons.collections.Predicate;
015:        import org.apache.commons.collections.Transformer;
016:        import org.apache.commons.lang.StringUtils;
017:
018:        /**
019:         * <p/> Provides support for the hibernate inheritance strategies of class
020:         * (table per hierarchy), subclass (table per subclass in hierarchy) and
021:         * concrete (table per class). With concrete the strategy can be changed lower
022:         * down. Also provides for the root class being defined as an interface and the
023:         * attributes remapped to the subclasses. This is useful in the concrete case
024:         * becuase it has limitations in the associations.
025:         * </p>
026:         * <p/> Also provides support for not generating the entity factory which is
027:         * useful when using subclass mode.
028:         * </p>
029:         *
030:         * @author Chad Brandon
031:         * @author Martin West
032:         * @author Carlos Cuenca
033:         * @author Peter Friese
034:         * @author Wouter Zoons
035:         */
036:        public class HibernateEntityLogicImpl extends HibernateEntityLogic {
037:            public HibernateEntityLogicImpl(java.lang.Object metaObject,
038:                    String context) {
039:                super (metaObject, context);
040:            }
041:
042:            /**
043:             * Value for one table per root class
044:             */
045:            private static final String INHERITANCE_STRATEGY_CLASS = "class";
046:
047:            /**
048:             * Value for joined-subclass
049:             */
050:            private static final String INHERITANCE_STRATEGY_SUBCLASS = "subclass";
051:
052:            /**
053:             * Value for one table per concrete class
054:             */
055:            private static final String INHERITANCE_STRATEGY_CONCRETE = "concrete";
056:
057:            /**
058:             * Value make entity an interface, delegate attributes to subclasses.
059:             */
060:            private static final String INHERITANCE_STRATEGY_INTERFACE = "interface";
061:
062:            /**
063:             * Value for one table per concrete class, (with union-subclass)
064:             */
065:            private static final String INHERITANCE_STRATEGY_UNION_SUBCLASS = "union-subclass";
066:
067:            /**
068:             * Stores the valid inheritance strategies.
069:             */
070:            private static final Collection inheritanceStrategies = new ArrayList();
071:
072:            static {
073:                inheritanceStrategies.add(INHERITANCE_STRATEGY_CLASS);
074:                inheritanceStrategies.add(INHERITANCE_STRATEGY_SUBCLASS);
075:                inheritanceStrategies.add(INHERITANCE_STRATEGY_CONCRETE);
076:                inheritanceStrategies.add(INHERITANCE_STRATEGY_INTERFACE);
077:                inheritanceStrategies.add(INHERITANCE_STRATEGY_UNION_SUBCLASS);
078:            }
079:
080:            /**
081:             * Stores the default hibernate inheritance strategy.
082:             */
083:            private static final String INHERITANCE_STRATEGY = "hibernateInheritanceStrategy";
084:
085:            /**
086:             * Stores the hibernate entity cache value.
087:             */
088:            private static final String HIBERNATE_ENTITY_CACHE = "hibernateEntityCache";
089:
090:            /**
091:             * The namespace property storing the hibernate default-cascade value for an
092:             * entity.
093:             */
094:            private static final String HIBERNATE_DEFAULT_CASCADE = "hibernateDefaultCascade";
095:
096:            /**
097:             * Namespace property storing the default hibernate generator class.
098:             */
099:            private static final String DEFAULT_HIBERNATE_GENERATOR_CLASS = "defaultHibernateGeneratorClass";
100:
101:            /**
102:             * Represents a <em>foreign</em> Hibernate generator class.
103:             */
104:            private static final String HIBERNATE_GENERATOR_CLASS_FOREIGN = "foreign";
105:
106:            /**
107:             * Represents an <em>assigned</em> Hibernate generator class.
108:             */
109:            private static final String HIBERNATE_GENERATOR_CLASS_ASSIGNED = "assigned";
110:            private static final String HIBERNATE_GENERATOR_CLASS_SEQUENCE = "sequence";
111:
112:            /**
113:             * The namespace property for specifying a hibernate proxy for this entity.
114:             */
115:            private static final String HIBERNATE_PROXY = "hibernateProxy";
116:
117:            /**
118:             * The "class" mapping name.
119:             */
120:            private static final String CLASS_MAPPING_NAME = "class";
121:
122:            /**
123:             * The "joined-subclass" mapping name.
124:             */
125:            private static final String JOINED_SUBCLASS_MAPPING_NAME = "joined-subclass";
126:
127:            /**
128:             * The "subclass" mapping name.
129:             */
130:            private static final String SUBCLASS_MAPPING_NAME = "subclass";
131:
132:            /**
133:             * The "union-subclass" mapping name.
134:             */
135:            private static final String UNION_SUBCLASS_MAPPING_NAME = "union-subclass";
136:
137:            /**
138:             * Return all the business operations (ones that are inherited as well as
139:             * directly on the entity).
140:             *
141:             * @return all business operations
142:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getAllBusinessOperations()
143:             */
144:            protected Collection handleGetAllBusinessOperations() {
145:                Entity super Element = (Entity) this .getGeneralization();
146:                Collection result = this .getBusinessOperations();
147:
148:                while (super Element != null) {
149:                    result.addAll(super Element.getBusinessOperations());
150:                    super Element = (Entity) super Element.getGeneralization();
151:                }
152:
153:                return result;
154:            }
155:
156:            /**
157:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getHibernateInheritanceStrategy()
158:             */
159:            protected String handleGetHibernateInheritanceStrategy() {
160:                String inheritance = HibernateEntityLogicImpl
161:                        .getInheritance(this );
162:
163:                for (HibernateEntity super Entity = this .getSuperEntity(); (super Entity != null)
164:                        && StringUtils.isBlank(inheritance);) {
165:                    inheritance = super Entity.getHibernateInheritanceStrategy();
166:                }
167:
168:                inheritance = inheritance != null ? inheritance.toLowerCase()
169:                        : null;
170:
171:                if (StringUtils.isBlank(inheritance)
172:                        || !inheritanceStrategies.contains(inheritance)) {
173:                    inheritance = this .getDefaultInheritanceStrategy();
174:                }
175:
176:                return inheritance;
177:            }
178:
179:            /**
180:             * Gets the default hibernate inhertance strategy.
181:             *
182:             * @return the default hibernate inheritance strategy.
183:             */
184:            private String getDefaultInheritanceStrategy() {
185:                return String.valueOf(this 
186:                        .getConfiguredProperty(INHERITANCE_STRATEGY));
187:            }
188:
189:            /**
190:             * Return the inheritance tagged value for for given <code>entity</code>.
191:             *
192:             * @param entity the HibernateEntity from which to retrieve the inheritance tagged
193:             *        value.
194:             * @return String inheritance tagged value.
195:             */
196:            private static String getInheritance(HibernateEntity entity) {
197:                String inheritance = null;
198:
199:                if (entity != null) {
200:                    final Object value = entity
201:                            .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_INHERITANCE);
202:
203:                    if (value != null) {
204:                        inheritance = String.valueOf(value);
205:                    }
206:                }
207:
208:                return inheritance;
209:            }
210:
211:            /**
212:             * @see org.andromda.metafacades.uml.ClassifierFacade#getProperties()
213:             */
214:            public java.util.Collection getProperties() {
215:                Collection properties = this .getAttributes();
216:                Collection connectingEnds = this .getAssociationEnds();
217:                CollectionUtils.transform(connectingEnds, new Transformer() {
218:                    public Object transform(Object object) {
219:                        return ((AssociationEndFacade) object).getOtherEnd();
220:                    }
221:                });
222:                class NavigableFilter implements  Predicate {
223:                    public boolean evaluate(Object object) {
224:                        AssociationEndFacade end = (AssociationEndFacade) object;
225:
226:                        return end.isNavigable()
227:                                || (end.getOtherEnd().isChild() && isForeignHibernateGeneratorClass());
228:                    }
229:                }
230:                CollectionUtils.filter(connectingEnds, new NavigableFilter());
231:                properties.addAll(connectingEnds);
232:
233:                return properties;
234:            }
235:
236:            /**
237:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isHibernateInheritanceClass()
238:             */
239:            protected boolean handleIsHibernateInheritanceClass() {
240:                return this .getHibernateInheritanceStrategy().equalsIgnoreCase(
241:                        INHERITANCE_STRATEGY_CLASS);
242:            }
243:
244:            /**
245:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isHibernateInheritanceInterface()
246:             */
247:            protected boolean handleIsHibernateInheritanceInterface() {
248:                return this .getHibernateInheritanceStrategy().equalsIgnoreCase(
249:                        INHERITANCE_STRATEGY_INTERFACE);
250:            }
251:
252:            /**
253:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isHibernateInheritanceSubclass()
254:             */
255:            protected boolean handleIsHibernateInheritanceSubclass() {
256:                return this .getHibernateInheritanceStrategy().equalsIgnoreCase(
257:                        INHERITANCE_STRATEGY_SUBCLASS);
258:            }
259:
260:            /**
261:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isHibernateInheritanceConcrete()
262:             */
263:            protected boolean handleIsHibernateInheritanceConcrete() {
264:                return this .getHibernateInheritanceStrategy().equalsIgnoreCase(
265:                        INHERITANCE_STRATEGY_CONCRETE);
266:            }
267:
268:            /**
269:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isHibernateInheritanceUnionSubClass()
270:             */
271:            protected boolean handleIsHibernateInheritanceUnionSubClass() {
272:                String version = (String) this 
273:                        .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION);
274:                return (version.equals(HibernateGlobals.HIBERNATE_VERSION_3))
275:                        && this .getHibernateInheritanceStrategy()
276:                                .equalsIgnoreCase(
277:                                        INHERITANCE_STRATEGY_UNION_SUBCLASS);
278:            }
279:
280:            /**
281:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isLazy()
282:             */
283:            protected boolean handleIsLazy() {
284:                String value = (String) findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_LAZY);
285:                if (StringUtils.isBlank(value)) {
286:                    String version = (String) this 
287:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION);
288:                    value = version
289:                            .equals(HibernateGlobals.HIBERNATE_VERSION_2) ? "false"
290:                            : "true";
291:                }
292:                return Boolean.valueOf(value).booleanValue();
293:            }
294:
295:            /**
296:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getHibernateCacheType()
297:             */
298:            protected String handleGetHibernateCacheType() {
299:                String cacheType = (String) findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ENTITY_CACHE);
300:
301:                if (cacheType == null) {
302:                    cacheType = String.valueOf(this 
303:                            .getConfiguredProperty(HIBERNATE_ENTITY_CACHE));
304:                }
305:
306:                return cacheType;
307:            }
308:
309:            /**
310:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getFullyQualifiedEntityName()
311:             */
312:            protected String handleGetFullyQualifiedEntityName() {
313:                return HibernateMetafacadeUtils.getFullyQualifiedName(this 
314:                        .getPackageName(), this .getEntityName(), null);
315:            }
316:
317:            /**
318:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getFullyQualifiedEntityImplementationName()
319:             */
320:            protected String handleGetFullyQualifiedEntityImplementationName() {
321:                return HibernateMetafacadeUtils.getFullyQualifiedName(this 
322:                        .getPackageName(), this .getEntityImplementationName(),
323:                        null);
324:            }
325:
326:            /**
327:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getHibernateDefaultCascade()
328:             */
329:            protected String handleGetHibernateDefaultCascade() {
330:                return StringUtils.trimToEmpty(String.valueOf(this 
331:                        .getConfiguredProperty(HIBERNATE_DEFAULT_CASCADE)));
332:            }
333:
334:            /**
335:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getHibernateGeneratorClass()
336:             */
337:            protected String handleGetHibernateGeneratorClass() {
338:                String hibernateGeneratorClass;
339:
340:                // if the entity is using a foreign identifier, then
341:                // we automatically set the identifier generator
342:                // class to be foreign
343:                if (this .isUsingForeignIdentifier()) {
344:                    hibernateGeneratorClass = HIBERNATE_GENERATOR_CLASS_FOREIGN;
345:                } else if (this .isUsingAssignedIdentifier()) {
346:                    hibernateGeneratorClass = HIBERNATE_GENERATOR_CLASS_ASSIGNED;
347:                } else {
348:                    hibernateGeneratorClass = (String) this 
349:                            .findTaggedValue(
350:                                    HibernateProfile.TAGGEDVALUE_HIBERNATE_GENERATOR_CLASS,
351:                                    false);
352:
353:                    if (StringUtils.isBlank(hibernateGeneratorClass)) {
354:                        hibernateGeneratorClass = (String) this 
355:                                .getConfiguredProperty(DEFAULT_HIBERNATE_GENERATOR_CLASS);
356:                    }
357:                }
358:                return StringUtils.trimToEmpty(hibernateGeneratorClass);
359:            }
360:
361:            /**
362:             * @see org.andromda.cartridges.spring.metafacades.SpringEntity#isForeignHibernateGeneratorClass()
363:             */
364:            protected boolean handleIsForeignHibernateGeneratorClass() {
365:                // check to see if the entity is using a foreign identifier
366:                // OR if the actual hibernate generator class is set to foreign
367:                return this .isUsingForeignIdentifier()
368:                        || this .getHibernateGeneratorClass().equalsIgnoreCase(
369:                                HIBERNATE_GENERATOR_CLASS_FOREIGN);
370:            }
371:
372:            /**
373:             * @see org.andromda.cartridges.spring.metafacades.SpringEntity#isSequenceHibernateGeneratorClass()
374:             */
375:            protected boolean handleIsSequenceHibernateGeneratorClass() {
376:                return this .getHibernateGeneratorClass().equalsIgnoreCase(
377:                        HIBERNATE_GENERATOR_CLASS_SEQUENCE);
378:            }
379:
380:            /**
381:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getEntityName()
382:             */
383:            protected String handleGetEntityName() {
384:                String entityNamePattern = (String) this 
385:                        .getConfiguredProperty(HibernateGlobals.ENTITY_NAME_PATTERN);
386:
387:                return MessageFormat
388:                        .format(entityNamePattern, new Object[] { StringUtils
389:                                .trimToEmpty(this .getName()) });
390:            }
391:
392:            /**
393:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getEntityImplementationName()
394:             */
395:            protected String handleGetEntityImplementationName() {
396:                String implNamePattern = String
397:                        .valueOf(this 
398:                                .getConfiguredProperty(HibernateGlobals.ENTITY_IMPLEMENTATION_NAME_PATTERN));
399:
400:                return MessageFormat
401:                        .format(implNamePattern, new Object[] { StringUtils
402:                                .trimToEmpty(this .getName()) });
403:            }
404:
405:            /**
406:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getHibernateDiscriminatorColumn()
407:             */
408:            protected String handleGetHibernateDiscriminatorColumn() {
409:                String column = (String) findTaggedValue(HibernateProfile.TAGGEDVALUE_ENTITY_DISCRIMINATOR_COLUMN);
410:
411:                if (column == null) {
412:                    column = String
413:                            .valueOf(this 
414:                                    .getConfiguredProperty(HibernateGlobals.ENTITY_DISCRIMINATOR_COLUMN));
415:                }
416:
417:                return column;
418:            }
419:
420:            /**
421:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getHibernateDiscriminatorType()
422:             */
423:            protected String handleGetHibernateDiscriminatorType() {
424:                String type = (String) findTaggedValue(HibernateProfile.TAGGEDVALUE_ENTITY_DISCRIMINATOR_TYPE);
425:
426:                if (type == null) {
427:                    type = String
428:                            .valueOf(this 
429:                                    .getConfiguredProperty(HibernateGlobals.ENTITY_DISCRIMINATOR_TYPE));
430:                }
431:
432:                return type;
433:            }
434:
435:            /**
436:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getHibernateDiscriminatorLength()
437:             */
438:            protected int handleGetHibernateDiscriminatorLength() {
439:                return 1;
440:            }
441:
442:            /**
443:             * Override so that we retrieve only the operations that are classifier
444:             * scope (i.e. static).
445:             *
446:             * @see org.andromda.metafacades.uml.Entity#getBusinessOperations()
447:             */
448:            public Collection getBusinessOperations() {
449:                return HibernateMetafacadeUtils.filterBusinessOperations(super 
450:                        .getBusinessOperations());
451:            }
452:
453:            /**
454:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isBusinessOperationsPresent()
455:             */
456:            protected boolean handleIsBusinessOperationsPresent() {
457:                final Collection allBusinessOperations = this 
458:                        .getAllBusinessOperations();
459:
460:                return (allBusinessOperations != null)
461:                        && !allBusinessOperations.isEmpty();
462:            }
463:
464:            /**
465:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isHibernateProxy()
466:             */
467:            protected boolean handleIsHibernateProxy() {
468:                String hibernateProxy = (String) this 
469:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_PROXY);
470:
471:                if (hibernateProxy == null) {
472:                    hibernateProxy = (String) this 
473:                            .getConfiguredProperty(HIBERNATE_PROXY);
474:                }
475:
476:                return Boolean.valueOf(hibernateProxy).booleanValue();
477:            }
478:
479:            /**
480:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getEhCacheMaxElementsInMemory()
481:             */
482:            protected int handleGetEhCacheMaxElementsInMemory() {
483:                String maxElements = null;
484:                maxElements = (String) this 
485:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_MAX_ELEMENTS);
486:
487:                if (StringUtils.isBlank(maxElements)) {
488:                    maxElements = (String) this 
489:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_MAX_ELEMENTS);
490:                }
491:
492:                return Integer.parseInt(StringUtils.trimToEmpty(maxElements));
493:            }
494:
495:            /**
496:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isEhCacheEternal()
497:             */
498:            protected boolean handleIsEhCacheEternal() {
499:                String eternal = (String) this 
500:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_ETERNAL);
501:                if (eternal == null) {
502:                    eternal = (String) this 
503:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_ETERNAL);
504:                }
505:                return Boolean.valueOf(StringUtils.trimToEmpty(eternal))
506:                        .booleanValue();
507:            }
508:
509:            /**
510:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getEhCacheTimeToIdleSeconds()
511:             */
512:            protected int handleGetEhCacheTimeToIdleSeconds() {
513:                String timeToIdle = null;
514:                timeToIdle = (String) this 
515:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_TIME_TO_IDLE);
516:
517:                if (StringUtils.isBlank(timeToIdle)) {
518:                    timeToIdle = (String) this 
519:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_TIME_TO_IDLE);
520:                }
521:
522:                return Integer.parseInt(StringUtils.trimToEmpty(timeToIdle));
523:            }
524:
525:            /**
526:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getEhCacheTimeToLiveSeconds()
527:             */
528:            protected int handleGetEhCacheTimeToLiveSeconds() {
529:                String timeToLive = null;
530:                timeToLive = (String) this 
531:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_TIME_TO_LIVE);
532:
533:                if (StringUtils.isBlank(timeToLive)) {
534:                    timeToLive = (String) this 
535:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_TIME_TO_LIVE);
536:                }
537:
538:                return Integer.parseInt(StringUtils.trimToEmpty(timeToLive));
539:            }
540:
541:            /**
542:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isEhCacheOverflowToDisk()
543:             */
544:            protected boolean handleIsEhCacheOverflowToDisk() {
545:                String eternal = (String) this 
546:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_OVERFLOW_TO_DISK);
547:
548:                if (eternal == null) {
549:                    eternal = (String) this 
550:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_OVERFLOW_TO_DISK);
551:                }
552:
553:                return Boolean.valueOf(StringUtils.trimToEmpty(eternal))
554:                        .booleanValue();
555:            }
556:
557:            /**
558:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isHibernateCacheDistributed()
559:             */
560:            protected boolean handleIsHibernateCacheDistributed() {
561:                String distributed = (String) this 
562:                        .getConfiguredProperty(HibernateGlobals.HIBERNATE_ENTITYCACHE_DISTRIBUTED);
563:                boolean distributedCachingEnabled = Boolean.valueOf(
564:                        StringUtils.trimToEmpty(distributed)).booleanValue();
565:
566:                if (distributedCachingEnabled) {
567:                    String entityCacheDistributed = (String) this 
568:                            .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ENTITYCACHE_DISTRIBUTED);
569:                    return Boolean.valueOf(
570:                            StringUtils.trimToEmpty(entityCacheDistributed))
571:                            .booleanValue();
572:                }
573:                return false;
574:            }
575:
576:            /**
577:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isTableRequired()
578:             */
579:            protected boolean handleIsTableRequired() {
580:                return !this .isHibernateInheritanceClass()
581:                        || (this .isHibernateInheritanceClass() && (this 
582:                                .getGeneralization() == null));
583:            }
584:
585:            /**
586:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getMappingClassName()
587:             */
588:            protected String handleGetMappingClassName() {
589:                String mappingClassName = CLASS_MAPPING_NAME;
590:                final HibernateEntity super Entity = this .getSuperEntity();
591:
592:                if ((super Entity != null)
593:                        && !super Entity.isHibernateInheritanceInterface()
594:                        && !super Entity.isHibernateInheritanceConcrete()) {
595:                    mappingClassName = JOINED_SUBCLASS_MAPPING_NAME;
596:
597:                    if (this .isHibernateInheritanceClass()) {
598:                        mappingClassName = SUBCLASS_MAPPING_NAME;
599:                    } else if (this .isHibernateInheritanceUnionSubClass()) {
600:                        mappingClassName = UNION_SUBCLASS_MAPPING_NAME;
601:                    }
602:                }
603:
604:                return mappingClassName;
605:            }
606:
607:            /**
608:             * Gets the super entity for this entity (if one exists). If a
609:             * generalization does not exist OR if it's not an instance of
610:             * HibernateEntity then return null.
611:             *
612:             * @return the super entity or null if one doesn't exist.
613:             */
614:            private HibernateEntity getSuperEntity() {
615:                HibernateEntity super Entity = null;
616:
617:                if ((this .getGeneralization() != null)
618:                        && this .getGeneralization() instanceof  HibernateEntity) {
619:                    super Entity = (HibernateEntity) this .getGeneralization();
620:                }
621:
622:                return super Entity;
623:            }
624:
625:            /**
626:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getSubclassKeyColumn()
627:             */
628:            protected String handleGetSubclassKeyColumn() {
629:                String column = null;
630:                final HibernateEntity super Entity = this .getSuperEntity();
631:
632:                if ((super Entity != null)
633:                        && super Entity.isHibernateInheritanceSubclass()) {
634:                    column = ((EntityAttribute) this .getIdentifiers()
635:                            .iterator().next()).getColumnName();
636:                }
637:
638:                return column;
639:            }
640:
641:            /**
642:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isRequiresMapping()
643:             */
644:            protected boolean handleIsRequiresMapping() {
645:                final HibernateEntity super Entity = this .getSuperEntity();
646:                return HibernateUtils
647:                        .mapSubclassesInSeparateFile((String) this 
648:                                .getConfiguredProperty(HibernateGlobals.HIBERNATE_MAPPING_STRATEGY))
649:                        || this .isRoot()
650:                        && (!this .isHibernateInheritanceInterface()
651:                                || this .getSpecializations().isEmpty() || (super Entity != null && super Entity
652:                                .isHibernateInheritanceInterface()));
653:            }
654:
655:            /**
656:             * Indicates if this entity is a <code>root</code> entity (meaning it
657:             * doesn't specialize anything).
658:             */
659:            private boolean isRoot() {
660:                final HibernateEntity super Entity = this .getSuperEntity();
661:                boolean abstractConcreteEntity = (this 
662:                        .isHibernateInheritanceConcrete() || this 
663:                        .isHibernateInheritanceInterface())
664:                        && this .isAbstract();
665:
666:                return (this .getSuperEntity() == null || (super Entity
667:                        .isHibernateInheritanceInterface() || super Entity
668:                        .isHibernateInheritanceConcrete()))
669:                        && !abstractConcreteEntity;
670:            }
671:
672:            /**
673:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isRequiresSpecializationMapping()
674:             */
675:            protected boolean handleIsRequiresSpecializationMapping() {
676:                return !HibernateUtils
677:                        .mapSubclassesInSeparateFile((String) this 
678:                                .getConfiguredProperty(HibernateGlobals.HIBERNATE_MAPPING_STRATEGY))
679:                        && this .isRoot()
680:                        && (this .isHibernateInheritanceSubclass()
681:                                || this .isHibernateInheritanceClass() || this 
682:                                .isHibernateInheritanceUnionSubClass());
683:            }
684:
685:            /**
686:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isDynamicInsert()
687:             */
688:            protected boolean handleIsDynamicInsert() {
689:                String dynamicInsert = (String) this 
690:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ENTITY_DYNAMIC_INSERT);
691:
692:                if (dynamicInsert == null) {
693:                    dynamicInsert = (String) this 
694:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_ENTITY_DYNAMIC_INSERT);
695:                }
696:
697:                return Boolean.valueOf(dynamicInsert).booleanValue();
698:            }
699:
700:            /**
701:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isDynamicUpdate()
702:             */
703:            protected boolean handleIsDynamicUpdate() {
704:                String dynamicUpdate = (String) this 
705:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ENTITY_DYNAMIC_UPDATE);
706:
707:                if (dynamicUpdate == null) {
708:                    dynamicUpdate = (String) this 
709:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_ENTITY_DYNAMIC_UPDATE);
710:                }
711:
712:                return Boolean.valueOf(dynamicUpdate).booleanValue();
713:            }
714:
715:            /**
716:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#isMappingRequiresSuperProperties()
717:             */
718:            protected boolean handleIsMappingRequiresSuperProperties() {
719:                return this .isHibernateInheritanceInterface()
720:                        || (this .isHibernateInheritanceConcrete() && this 
721:                                .isAbstract());
722:            }
723:
724:            /**
725:             * @see HibernateEntity#getHibernateVersionProperty()
726:             */
727:            protected String handleGetHibernateVersionProperty() {
728:                String version = (String) this 
729:                        .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_VERSION_PROPERTY);
730:                if (version == null) {
731:                    version = (String) this 
732:                            .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION_PROPERTY);
733:                }
734:                return version;
735:            }
736:
737:            /**
738:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#getVersion()
739:             */
740:            protected int handleGetVersion() {
741:                return Integer
742:                        .parseInt((String) this 
743:                                .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION));
744:            }
745:
746:            private boolean isXmlPersistenceActive() {
747:                return HibernateUtils
748:                        .isXmlPersistenceActive(
749:                                (String) this 
750:                                        .getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION),
751:                                (String) this 
752:                                        .getConfiguredProperty(HibernateGlobals.HIBERNATE_XML_PERSISTENCE));
753:            }
754:
755:            protected String handleGetXmlTagName() {
756:                String tagName = null;
757:
758:                if (isXmlPersistenceActive()) {
759:                    tagName = (String) this 
760:                            .findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_XML_TAG_NAME);
761:
762:                    if (tagName == null) {
763:                        tagName = this .getName();
764:                    }
765:                }
766:                return (StringUtils.isBlank(tagName)) ? null : tagName;
767:            }
768:
769:            /**
770:             * @see org.andromda.cartridges.hibernate.metafacades.HibernateEntity#hibernateDiscriminatorValue()
771:             */
772:            protected String handleGetHibernateDiscriminatorValue() {
773:                String value = (String) findTaggedValue(HibernateProfile.TAGGEDVALUE_ENTITY_DISCRIMINATOR_VALUE);
774:
775:                if (value == null) {
776:                    value = getEntityImplementationName();
777:                }
778:
779:                return value;
780:            }
781:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.