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