1 package org.andromda.metafacades.emf.uml22;
2
3 import org.andromda.metafacades.uml.ClassifierFacade;
4 import org.andromda.metafacades.uml.EntityMetafacadeUtils;
5 import org.andromda.metafacades.uml.EnumerationFacade;
6 import org.andromda.metafacades.uml.NameMasker;
7 import org.andromda.metafacades.uml.TypeMappings;
8 import org.andromda.metafacades.uml.UMLMetafacadeProperties;
9 import org.andromda.metafacades.uml.UMLProfile;
10 import org.apache.commons.lang.ObjectUtils;
11 import org.apache.commons.lang.StringUtils;
12 import org.apache.log4j.Logger;
13
14
15
16
17
18
19
20 public class EntityAttributeLogicImpl
21 extends EntityAttributeLogic
22 {
23 private static final long serialVersionUID = 34L;
24
25
26
27
28 public EntityAttributeLogicImpl(
29 final Object metaObject,
30 final String context)
31 {
32 super(metaObject, context);
33 }
34
35
36
37
38 private static final Logger LOGGER = Logger.getLogger(EntityAttributeLogicImpl.class);
39
40
41
42
43
44
45 @Override
46 protected String handleGetName()
47 {
48 final String nameMask =
49 String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.ENTITY_PROPERTY_NAME_MASK));
50 return NameMasker.mask(
51 super.handleGetName(),
52 nameMask);
53 }
54
55
56
57
58 @Override
59 protected String handleGetColumnLength()
60 {
61 return (String)this.findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_COLUMN_LENGTH);
62 }
63
64
65
66
67 @Override
68 protected String handleGetColumnName()
69 {
70 final Short maxSqlNameLength =
71 Short.valueOf((String)this.getConfiguredProperty(UMLMetafacadeProperties.MAX_SQL_NAME_LENGTH));
72 final String columnNamePrefix =
73 this.isConfiguredProperty(UMLMetafacadeProperties.COLUMN_NAME_PREFIX)
74 ? ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.COLUMN_NAME_PREFIX)) : null;
75 return EntityMetafacadeUtils.getSqlNameFromTaggedValue(
76 columnNamePrefix,
77 this,
78 UMLProfile.TAGGEDVALUE_PERSISTENCE_COLUMN,
79 maxSqlNameLength,
80 this.getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR),
81 this.getConfiguredProperty(UMLMetafacadeProperties.SHORTEN_SQL_NAMES_METHOD));
82 }
83
84
85
86
87 @Override
88 protected org.andromda.metafacades.uml.TypeMappings handleGetJdbcMappings()
89 {
90 return this.getMappingsProperty(UMLMetafacadeProperties.JDBC_MAPPINGS_URI);
91 }
92
93
94
95
96 @Override
97 protected String handleGetJdbcType()
98 {
99 String value = null;
100 if (this.getJdbcMappings() != null)
101 {
102 final ClassifierFacade type = this.getType();
103 if (type != null)
104 {
105 final String typeName = type.getFullyQualifiedName(true);
106 value = this.getJdbcMappings().getTo(typeName);
107 }
108 }
109
110 return value;
111 }
112
113
114
115
116 @Override
117 protected org.andromda.metafacades.uml.TypeMappings handleGetSqlMappings()
118 {
119 return this.getMappingsProperty(UMLMetafacadeProperties.SQL_MAPPINGS_URI);
120 }
121
122
123
124
125 @Override
126 protected String handleGetSqlType()
127 {
128 String value = null;
129 if (this.getSqlMappings() != null)
130 {
131 final ClassifierFacade type = this.getType();
132 if (type != null)
133 {
134 String typeName = type.getFullyQualifiedName(true);
135
136
137 if (type.isEnumeration())
138 {
139 final ClassifierFacade literalType = ((EnumerationFacade)type).getLiteralType();
140 if (literalType != null)
141 {
142 typeName = literalType.getFullyQualifiedName(true);
143 }
144 }
145 value = this.getSqlMappings().getTo(typeName);
146 final String columnLength = this.getColumnLength();
147 if (StringUtils.isNotBlank(columnLength))
148 {
149 value = EntityMetafacadeUtils.constructSqlTypeName(
150 value,
151 columnLength);
152 }
153 }
154 }
155 return value;
156 }
157
158
159
160
161 @Override
162 protected boolean handleIsIdentifier()
163 {
164 return this.hasStereotype(UMLProfile.STEREOTYPE_IDENTIFIER);
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 @Override
181 protected String handleGetColumnIndex()
182 {
183 final String index = (String)this.findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_COLUMN_INDEX);
184 return index == null ? null : StringUtils.trimToEmpty(index);
185 }
186
187
188
189
190
191
192
193
194
195 private TypeMappings getMappingsProperty(final String propertyName)
196 {
197 final Object property = this.getConfiguredProperty(propertyName);
198 TypeMappings mappings = null;
199 if (property instanceof String)
200 {
201 final String uri = (String)property;
202 try
203 {
204 mappings = TypeMappings.getInstance(uri);
205 this.setProperty(
206 propertyName,
207 mappings);
208 }
209 catch (Throwable th)
210 {
211 final String errMsg = "Error getting '" + propertyName + "' --> '" + uri + '\'';
212 EntityAttributeLogicImpl.LOGGER.error(
213 errMsg,
214 th);
215
216
217 }
218 }
219 else
220 {
221 mappings = (TypeMappings)property;
222 }
223 return mappings;
224 }
225
226
227
228
229 @Override
230 protected boolean handleIsTransient()
231 {
232 return this.hasStereotype(UMLProfile.STEREOTYPE_TRANSIENT);
233 }
234
235
236
237
238 @Override
239 protected String handleGetUniqueGroup() {
240 final String group = (String)this.findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_COLUMN_UNIQUE_GROUP);
241 return group == null ? null : StringUtils.trimToEmpty(group);
242 }
243 }