1 package org.andromda.cartridges.ejb3.metafacades;
2
3 import java.util.Collection;
4 import java.util.Iterator;
5 import java.util.List;
6 import org.andromda.metafacades.uml.AssociationEndFacade;
7 import org.andromda.metafacades.uml.Entity;
8 import org.andromda.metafacades.uml.MetafacadeUtils;
9 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
10 import org.andromda.metafacades.uml.UMLProfile;
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.commons.lang.StringUtils;
13
14
15
16
17
18
19 public class EJB3AssociationFacadeLogicImpl
20 extends EJB3AssociationFacadeLogic
21 {
22 private static final long serialVersionUID = 34L;
23
24
25
26
27
28
29 public EJB3AssociationFacadeLogicImpl(final Object metaObject, final String context)
30 {
31 super(metaObject, context);
32 }
33
34
35
36
37
38
39
40
41
42 @Override
43 public String getTableName()
44 {
45 String tableName = null;
46 final List<AssociationEndFacade> ends = this.getAssociationEnds();
47 if (ends != null && !ends.isEmpty())
48 {
49 for (AssociationEndFacade facade : ends)
50 {
51 final EJB3AssociationEndFacade end = (EJB3AssociationEndFacade)facade;
52 if ((end.isMany2Many() && end.isOwning()) ||
53 (end.isOne2Many() && !end.isNavigable() && end.getOtherEnd().isNavigable()))
54 {
55
56
57 if (Entity.class.isAssignableFrom(end.getType().getClass()))
58 {
59 final String prefixProperty = UMLMetafacadeProperties.TABLE_NAME_PREFIX;
60 final String tableNamePrefix =
61 this.isConfiguredProperty(prefixProperty)
62 ? ObjectUtils.toString(this.getConfiguredProperty(prefixProperty)) : null;
63 tableName =
64 EJB3MetafacadeUtils.getSqlNameFromTaggedValue(
65 tableNamePrefix,
66 this,
67 UMLProfile.TAGGEDVALUE_PERSISTENCE_TABLE,
68 ((Entity)end.getType()).getMaxSqlNameLength(),
69 null,
70 this.getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR),
71 this.getConfiguredProperty(UMLMetafacadeProperties.SHORTEN_SQL_NAMES_METHOD));
72 }
73 break;
74 }
75 }
76 }
77
78
79
80
81
82
83 return tableName;
84 }
85
86
87
88
89
90 @Override
91 public String getName()
92 {
93 String name = (super.getName().equalsIgnoreCase(super.getRelationName()) ? null : super.getName());
94
95
96 if (StringUtils.isBlank(name))
97 {
98 name = this.getRelationName();
99 }
100 return name;
101 }
102
103
104
105
106
107
108 @Override
109 public String getRelationName()
110 {
111 final Collection<AssociationEndFacade> ends = this.getAssociationEnds();
112 final Iterator endIt = ends.iterator();
113 final EJB3AssociationEndFacade firstEnd = (EJB3AssociationEndFacade)endIt.next();
114 final EJB3AssociationEndFacade secondEnd = (EJB3AssociationEndFacade)endIt.next();
115 final String separator = String.valueOf(
116 this.getConfiguredProperty(UMLMetafacadeProperties.RELATION_NAME_SEPARATOR));
117
118 if (secondEnd.isOwning())
119 {
120 return secondEnd.getName() + separator + firstEnd.getName();
121 }
122 else if (firstEnd.isOwning())
123 {
124 return firstEnd.getName() + separator + secondEnd.getName();
125 }
126 else
127 {
128 return MetafacadeUtils.toRelationName(
129 firstEnd.getName(),
130 secondEnd.getName(),
131 separator);
132 }
133 }
134 }