1 package org.andromda.metafacades.emf.uml22;
2
3 import java.util.Collection;
4 import java.util.Iterator;
5 import org.andromda.core.metafacade.MetafacadeImplsException;
6 import org.andromda.metafacades.uml.AssociationEndFacade;
7 import org.andromda.metafacades.uml.ClassifierFacade;
8 import org.andromda.metafacades.uml.Entity;
9 import org.andromda.metafacades.uml.EntityMetafacadeUtils;
10 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
11 import org.andromda.metafacades.uml.UMLProfile;
12 import org.apache.commons.lang.ObjectUtils;
13 import org.apache.commons.lang.StringUtils;
14 import org.eclipse.uml2.uml.Association;
15 import org.eclipse.uml2.uml.Property;
16 import org.eclipse.uml2.uml.Type;
17
18
19
20
21
22
23
24 public class EntityAssociationLogicImpl
25 extends EntityAssociationLogic
26 {
27 private static final long serialVersionUID = -5313785900247499346L;
28
29
30
31
32
33 public EntityAssociationLogicImpl(
34 final Object metaObject,
35 final String context)
36 {
37 super(metaObject, context);
38 }
39
40
41
42
43 @Override
44 protected String handleGetTableName()
45 {
46 String tableName = null;
47 final Collection<AssociationEndFacade> ends = this.getAssociationEnds();
48 if (ends != null && !ends.isEmpty())
49 {
50 final AssociationEndFacade end = ends.iterator().next();
51 final ClassifierFacade type = end.getType();
52
53 if (type != null && type instanceof Entity)
54 {
55 final String prefixProperty = UMLMetafacadeProperties.TABLE_NAME_PREFIX;
56 final String tableNamePrefix =
57 this.isConfiguredProperty(prefixProperty)
58 ? ObjectUtils.toString(this.getConfiguredProperty(prefixProperty)) : null;
59 tableName =
60 EntityMetafacadeUtils.getSqlNameFromTaggedValue(
61 tableNamePrefix,
62 this,
63 UMLProfile.TAGGEDVALUE_PERSISTENCE_TABLE,
64 Short.valueOf(((Entity)type).getMaxSqlNameLength()),
65 this.getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR),
66 this.getConfiguredProperty(UMLMetafacadeProperties.SHORTEN_SQL_NAMES_METHOD));
67 }
68 }
69 return tableName;
70 }
71
72
73
74
75
76 @Override
77 protected String handleGetSchema()
78 {
79 String schemaName = ObjectUtils.toString(this.findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_SCHEMA));
80 if (StringUtils.isBlank(schemaName))
81 {
82 schemaName = ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.SCHEMA_NAME));
83 }
84 return schemaName;
85 }
86
87
88
89
90
91 @Override
92 protected boolean handleIsEntityAssociation()
93 {
94
95
96
97
98 if (this.metaObject == null || !(this.metaObject instanceof Association))
99 {
100 throw new MetafacadeImplsException("Incorrect metafacade mapping for " + this.toString());
101 }
102 boolean isEntityAssociation = true;
103 for (final Iterator<Property> ends = ((Association)this.metaObject).getMemberEnds().iterator(); ends.hasNext();)
104 {
105 final Property prop = ends.next();
106 final Type propertyType = prop.getType();
107 if (propertyType == null || !UmlUtilities.containsStereotype(
108 propertyType,
109 UMLProfile.STEREOTYPE_ENTITY))
110 {
111 isEntityAssociation = false;
112 }
113 }
114 return isEntityAssociation;
115 }
116 }