1
2
3
4
5 package org.andromda.cartridges.spring.metafacades;
6
7 import java.util.Collection;
8 import org.andromda.core.common.Introspector;
9 import org.andromda.core.metafacade.MetafacadeBase;
10 import org.andromda.core.metafacade.MetafacadeFactory;
11 import org.andromda.core.metafacade.ModelValidationMessage;
12 import org.andromda.metafacades.uml.ClassifierFacade;
13 import org.andromda.metafacades.uml.ConstraintFacade;
14 import org.andromda.metafacades.uml.DependencyFacade;
15 import org.andromda.metafacades.uml.EntityQueryOperation;
16 import org.andromda.metafacades.uml.ModelElementFacade;
17 import org.andromda.metafacades.uml.ModelFacade;
18 import org.andromda.metafacades.uml.OperationFacade;
19 import org.andromda.metafacades.uml.PackageFacade;
20 import org.andromda.metafacades.uml.ParameterFacade;
21 import org.andromda.metafacades.uml.StateMachineFacade;
22 import org.andromda.metafacades.uml.StereotypeFacade;
23 import org.andromda.metafacades.uml.TaggedValueFacade;
24 import org.andromda.metafacades.uml.TemplateParameterFacade;
25 import org.andromda.metafacades.uml.TypeMappings;
26 import org.andromda.translation.ocl.validation.OCLCollections;
27 import org.andromda.translation.ocl.validation.OCLIntrospector;
28 import org.andromda.translation.ocl.validation.OCLResultEnsurer;
29 import org.apache.commons.collections.Predicate;
30 import org.apache.log4j.Logger;
31
32
33
34
35
36
37
38 public abstract class SpringQueryOperationLogic
39 extends MetafacadeBase
40 implements SpringQueryOperation
41 {
42
43
44
45
46 protected Object metaObject;
47
48
49
50
51
52 protected SpringQueryOperationLogic(Object metaObjectIn, String context)
53 {
54 super(metaObjectIn, getContext(context));
55 this.superEntityQueryOperation =
56 (EntityQueryOperation)
57 MetafacadeFactory.getInstance().createFacadeImpl(
58 "org.andromda.metafacades.uml.EntityQueryOperation",
59 metaObjectIn,
60 getContext(context));
61 this.metaObject = metaObjectIn;
62 }
63
64
65
66
67 private static final Logger logger = Logger.getLogger(SpringQueryOperationLogic.class);
68
69
70
71
72
73
74 private static String getContext(String context)
75 {
76 if (context == null)
77 {
78 context = "org.andromda.cartridges.spring.metafacades.SpringQueryOperation";
79 }
80 return context;
81 }
82
83 private EntityQueryOperation superEntityQueryOperation;
84 private boolean superEntityQueryOperationInitialized = false;
85
86
87
88
89
90 private EntityQueryOperation getSuperEntityQueryOperation()
91 {
92 if (!this.superEntityQueryOperationInitialized)
93 {
94 ((MetafacadeBase)this.superEntityQueryOperation).setMetafacadeContext(this.getMetafacadeContext());
95 this.superEntityQueryOperationInitialized = true;
96 }
97 return this.superEntityQueryOperation;
98 }
99
100
101
102
103
104 @Override
105 public void resetMetafacadeContext(String context)
106 {
107 if (!this.contextRoot)
108 {
109 context = getContext(context);
110 setMetafacadeContext (context);
111 if (this.superEntityQueryOperationInitialized)
112 {
113 ((MetafacadeBase)this.superEntityQueryOperation).resetMetafacadeContext(context);
114 }
115 }
116 }
117
118
119
120
121
122 public boolean isSpringQueryOperationMetaType()
123 {
124 return true;
125 }
126
127
128
129
130
131
132
133 protected abstract boolean handleIsUseNamedParameters();
134
135 private boolean __useNamedParameters1a;
136 private boolean __useNamedParameters1aSet = false;
137
138
139
140
141
142
143 public final boolean isUseNamedParameters()
144 {
145 boolean useNamedParameters1a = this.__useNamedParameters1a;
146 if (!this.__useNamedParameters1aSet)
147 {
148
149 useNamedParameters1a = handleIsUseNamedParameters();
150
151 this.__useNamedParameters1a = useNamedParameters1a;
152 if (isMetafacadePropertyCachingEnabled())
153 {
154 this.__useNamedParameters1aSet = true;
155 }
156 }
157 return useNamedParameters1a;
158 }
159
160
161
162
163
164 protected abstract String handleGetQuery();
165
166 private String __query2a;
167 private boolean __query2aSet = false;
168
169
170
171
172
173 public final String getQuery()
174 {
175 String query2a = this.__query2a;
176 if (!this.__query2aSet)
177 {
178
179 query2a = handleGetQuery();
180
181 this.__query2a = query2a;
182 if (isMetafacadePropertyCachingEnabled())
183 {
184 this.__query2aSet = true;
185 }
186 }
187 return query2a;
188 }
189
190
191
192
193
194 protected abstract boolean handleIsCriteriaFinder();
195
196 private boolean __criteriaFinder3a;
197 private boolean __criteriaFinder3aSet = false;
198
199
200
201
202
203 public final boolean isCriteriaFinder()
204 {
205 boolean criteriaFinder3a = this.__criteriaFinder3a;
206 if (!this.__criteriaFinder3aSet)
207 {
208
209 criteriaFinder3a = handleIsCriteriaFinder();
210
211 this.__criteriaFinder3a = criteriaFinder3a;
212 if (isMetafacadePropertyCachingEnabled())
213 {
214 this.__criteriaFinder3aSet = true;
215 }
216 }
217 return criteriaFinder3a;
218 }
219
220
221
222
223
224 protected abstract ParameterFacade handleGetCriteriaArgument();
225
226 private ParameterFacade __criteriaArgument4a;
227 private boolean __criteriaArgument4aSet = false;
228
229
230
231
232
233 public final ParameterFacade getCriteriaArgument()
234 {
235 ParameterFacade criteriaArgument4a = this.__criteriaArgument4a;
236 if (!this.__criteriaArgument4aSet)
237 {
238
239 criteriaArgument4a = handleGetCriteriaArgument();
240
241 this.__criteriaArgument4a = criteriaArgument4a;
242 if (isMetafacadePropertyCachingEnabled())
243 {
244 this.__criteriaArgument4aSet = true;
245 }
246 }
247 return criteriaArgument4a;
248 }
249
250
251
252
253
254
255
256
257
258
259 protected abstract String handleGetQuery(SpringEntity entity);
260
261
262
263
264
265
266
267
268 public String getQuery(SpringEntity entity)
269 {
270
271 String returnValue = handleGetQuery(entity);
272
273 return returnValue;
274 }
275
276
277
278
279
280 public boolean isEntityQueryOperationMetaType()
281 {
282 return true;
283 }
284
285
286
287
288
289 public boolean isOperationFacadeMetaType()
290 {
291 return true;
292 }
293
294
295
296
297
298 public boolean isModelElementFacadeMetaType()
299 {
300 return true;
301 }
302
303
304
305
306
307
308
309
310 public String getQuery(String translation)
311 {
312 return this.getSuperEntityQueryOperation().getQuery(translation);
313 }
314
315
316
317
318
319 public void copyTaggedValues(ModelElementFacade element)
320 {
321 this.getSuperEntityQueryOperation().copyTaggedValues(element);
322 }
323
324
325
326
327
328
329 public Object findTaggedValue(String tagName)
330 {
331 return this.getSuperEntityQueryOperation().findTaggedValue(tagName);
332 }
333
334
335
336
337
338
339 public Collection<Object> findTaggedValues(String tagName)
340 {
341 return this.getSuperEntityQueryOperation().findTaggedValues(tagName);
342 }
343
344
345
346
347
348
349
350 public String getBindedFullyQualifiedName(ModelElementFacade bindedElement)
351 {
352 return this.getSuperEntityQueryOperation().getBindedFullyQualifiedName(bindedElement);
353 }
354
355
356
357
358
359 public Collection<ConstraintFacade> getConstraints()
360 {
361 return this.getSuperEntityQueryOperation().getConstraints();
362 }
363
364
365
366
367
368
369 public Collection<ConstraintFacade> getConstraints(String kind)
370 {
371 return this.getSuperEntityQueryOperation().getConstraints(kind);
372 }
373
374
375
376
377
378
379
380 public String getDocumentation(String indent)
381 {
382 return this.getSuperEntityQueryOperation().getDocumentation(indent);
383 }
384
385
386
387
388
389
390
391
392 public String getDocumentation(String indent, int lineLength)
393 {
394 return this.getSuperEntityQueryOperation().getDocumentation(indent, lineLength);
395 }
396
397
398
399
400
401
402
403 public String getDocumentation(String indent, int lineLength, boolean htmlStyle)
404 {
405 return this.getSuperEntityQueryOperation().getDocumentation(indent, lineLength, htmlStyle);
406 }
407
408
409
410
411
412 public String getFullyQualifiedName()
413 {
414 return this.getSuperEntityQueryOperation().getFullyQualifiedName();
415 }
416
417
418
419
420
421
422
423
424 public String getFullyQualifiedName(boolean modelName)
425 {
426 return this.getSuperEntityQueryOperation().getFullyQualifiedName(modelName);
427 }
428
429
430
431
432
433
434 public String getFullyQualifiedNamePath()
435 {
436 return this.getSuperEntityQueryOperation().getFullyQualifiedNamePath();
437 }
438
439
440
441
442
443 public String getId()
444 {
445 return this.getSuperEntityQueryOperation().getId();
446 }
447
448
449
450
451
452
453
454
455
456 public Collection<String> getKeywords()
457 {
458 return this.getSuperEntityQueryOperation().getKeywords();
459 }
460
461
462
463
464
465 public String getLabel()
466 {
467 return this.getSuperEntityQueryOperation().getLabel();
468 }
469
470
471
472
473
474 public TypeMappings getLanguageMappings()
475 {
476 return this.getSuperEntityQueryOperation().getLanguageMappings();
477 }
478
479
480
481
482
483
484 public ModelFacade getModel()
485 {
486 return this.getSuperEntityQueryOperation().getModel();
487 }
488
489
490
491
492
493 public String getName()
494 {
495 return this.getSuperEntityQueryOperation().getName();
496 }
497
498
499
500
501
502 public ModelElementFacade getPackage()
503 {
504 return this.getSuperEntityQueryOperation().getPackage();
505 }
506
507
508
509
510
511 public String getPackageName()
512 {
513 return this.getSuperEntityQueryOperation().getPackageName();
514 }
515
516
517
518
519
520
521 public String getPackageName(boolean modelName)
522 {
523 return this.getSuperEntityQueryOperation().getPackageName(modelName);
524 }
525
526
527
528
529
530 public String getPackagePath()
531 {
532 return this.getSuperEntityQueryOperation().getPackagePath();
533 }
534
535
536
537
538
539
540
541
542 public String getQualifiedName()
543 {
544 return this.getSuperEntityQueryOperation().getQualifiedName();
545 }
546
547
548
549
550
551 public PackageFacade getRootPackage()
552 {
553 return this.getSuperEntityQueryOperation().getRootPackage();
554 }
555
556
557
558
559
560 public Collection<DependencyFacade> getSourceDependencies()
561 {
562 return this.getSuperEntityQueryOperation().getSourceDependencies();
563 }
564
565
566
567
568
569
570 public StateMachineFacade getStateMachineContext()
571 {
572 return this.getSuperEntityQueryOperation().getStateMachineContext();
573 }
574
575
576
577
578
579 public Collection<String> getStereotypeNames()
580 {
581 return this.getSuperEntityQueryOperation().getStereotypeNames();
582 }
583
584
585
586
587
588 public Collection<StereotypeFacade> getStereotypes()
589 {
590 return this.getSuperEntityQueryOperation().getStereotypes();
591 }
592
593
594
595
596
597 public Collection<TaggedValueFacade> getTaggedValues()
598 {
599 return this.getSuperEntityQueryOperation().getTaggedValues();
600 }
601
602
603
604
605
606 public Collection<DependencyFacade> getTargetDependencies()
607 {
608 return this.getSuperEntityQueryOperation().getTargetDependencies();
609 }
610
611
612
613
614
615 public Object getTemplateParameter(String parameterName)
616 {
617 return this.getSuperEntityQueryOperation().getTemplateParameter(parameterName);
618 }
619
620
621
622
623
624 public Collection<TemplateParameterFacade> getTemplateParameters()
625 {
626 return this.getSuperEntityQueryOperation().getTemplateParameters();
627 }
628
629
630
631
632
633
634 public String getVisibility()
635 {
636 return this.getSuperEntityQueryOperation().getVisibility();
637 }
638
639
640
641
642
643
644 public boolean hasExactStereotype(String stereotypeName)
645 {
646 return this.getSuperEntityQueryOperation().hasExactStereotype(stereotypeName);
647 }
648
649
650
651
652
653
654 public boolean hasKeyword(String keywordName)
655 {
656 return this.getSuperEntityQueryOperation().hasKeyword(keywordName);
657 }
658
659
660
661
662
663
664
665
666
667
668
669
670
671 public boolean hasStereotype(String stereotypeName)
672 {
673 return this.getSuperEntityQueryOperation().hasStereotype(stereotypeName);
674 }
675
676
677
678
679
680
681 public boolean isBindingDependenciesPresent()
682 {
683 return this.getSuperEntityQueryOperation().isBindingDependenciesPresent();
684 }
685
686
687
688
689
690 public boolean isConstraintsPresent()
691 {
692 return this.getSuperEntityQueryOperation().isConstraintsPresent();
693 }
694
695
696
697
698
699 public boolean isDocumentationPresent()
700 {
701 return this.getSuperEntityQueryOperation().isDocumentationPresent();
702 }
703
704
705
706
707
708 public boolean isReservedWord()
709 {
710 return this.getSuperEntityQueryOperation().isReservedWord();
711 }
712
713
714
715
716
717
718 public boolean isTemplateParametersPresent()
719 {
720 return this.getSuperEntityQueryOperation().isTemplateParametersPresent();
721 }
722
723
724
725
726
727
728
729 public boolean isValidIdentifierName()
730 {
731 return this.getSuperEntityQueryOperation().isValidIdentifierName();
732 }
733
734
735
736
737
738
739
740 public String translateConstraint(String name, String translation)
741 {
742 return this.getSuperEntityQueryOperation().translateConstraint(name, translation);
743 }
744
745
746
747
748
749 public String[] translateConstraints(String translation)
750 {
751 return this.getSuperEntityQueryOperation().translateConstraints(translation);
752 }
753
754
755
756
757
758 public String[] translateConstraints(String kind, String translation)
759 {
760 return this.getSuperEntityQueryOperation().translateConstraints(kind, translation);
761 }
762
763
764
765
766
767
768 public ParameterFacade findParameter(String name)
769 {
770 return this.getSuperEntityQueryOperation().findParameter(name);
771 }
772
773
774
775
776
777
778
779 public Object findTaggedValue(String name, boolean follow)
780 {
781 return this.getSuperEntityQueryOperation().findTaggedValue(name, follow);
782 }
783
784
785
786
787
788 public String getArgumentNames()
789 {
790 return this.getSuperEntityQueryOperation().getArgumentNames();
791 }
792
793
794
795
796
797 public String getArgumentTypeNames()
798 {
799 return this.getSuperEntityQueryOperation().getArgumentTypeNames();
800 }
801
802
803
804
805
806
807
808
809
810 public Collection<ParameterFacade> getArguments()
811 {
812 return this.getSuperEntityQueryOperation().getArguments();
813 }
814
815
816
817
818
819 public String getCall()
820 {
821 return this.getSuperEntityQueryOperation().getCall();
822 }
823
824
825
826
827
828
829
830 public String getConcurrency()
831 {
832 return this.getSuperEntityQueryOperation().getConcurrency();
833 }
834
835
836
837
838
839
840 public String getExceptionList()
841 {
842 return this.getSuperEntityQueryOperation().getExceptionList();
843 }
844
845
846
847
848
849
850 public String getExceptionList(String initialExceptions)
851 {
852 return this.getSuperEntityQueryOperation().getExceptionList(initialExceptions);
853 }
854
855
856
857
858
859 public Collection<ModelElementFacade> getExceptions()
860 {
861 return this.getSuperEntityQueryOperation().getExceptions();
862 }
863
864
865
866
867
868 public String getGetterSetterReturnTypeName()
869 {
870 return this.getSuperEntityQueryOperation().getGetterSetterReturnTypeName();
871 }
872
873
874
875
876
877
878 public int getLower()
879 {
880 return this.getSuperEntityQueryOperation().getLower();
881 }
882
883
884
885
886
887 public String getMethodBody()
888 {
889 return this.getSuperEntityQueryOperation().getMethodBody();
890 }
891
892
893
894
895
896 public OperationFacade getOverriddenOperation()
897 {
898 return this.getSuperEntityQueryOperation().getOverriddenOperation();
899 }
900
901
902
903
904
905 public ClassifierFacade getOwner()
906 {
907 return this.getSuperEntityQueryOperation().getOwner();
908 }
909
910
911
912
913
914 public Collection<ParameterFacade> getParameters()
915 {
916 return this.getSuperEntityQueryOperation().getParameters();
917 }
918
919
920
921
922
923 public String getPostconditionName()
924 {
925 return this.getSuperEntityQueryOperation().getPostconditionName();
926 }
927
928
929
930
931
932 public Collection<ConstraintFacade> getPostconditions()
933 {
934 return this.getSuperEntityQueryOperation().getPostconditions();
935 }
936
937
938
939
940
941 public String getPreconditionCall()
942 {
943 return this.getSuperEntityQueryOperation().getPreconditionCall();
944 }
945
946
947
948
949
950 public String getPreconditionName()
951 {
952 return this.getSuperEntityQueryOperation().getPreconditionName();
953 }
954
955
956
957
958
959 public String getPreconditionSignature()
960 {
961 return this.getSuperEntityQueryOperation().getPreconditionSignature();
962 }
963
964
965
966
967
968 public Collection<ConstraintFacade> getPreconditions()
969 {
970 return this.getSuperEntityQueryOperation().getPreconditions();
971 }
972
973
974
975
976
977 public ParameterFacade getReturnParameter()
978 {
979 return this.getSuperEntityQueryOperation().getReturnParameter();
980 }
981
982
983
984
985
986 public ClassifierFacade getReturnType()
987 {
988 return this.getSuperEntityQueryOperation().getReturnType();
989 }
990
991
992
993
994
995
996 public String getSignature()
997 {
998 return this.getSuperEntityQueryOperation().getSignature();
999 }
1000
1001
1002
1003
1004
1005
1006
1007 public String getSignature(boolean withArgumentNames)
1008 {
1009 return this.getSuperEntityQueryOperation().getSignature(withArgumentNames);
1010 }
1011
1012
1013
1014
1015
1016
1017 public String getSignature(String argumentModifier)
1018 {
1019 return this.getSuperEntityQueryOperation().getSignature(argumentModifier);
1020 }
1021
1022
1023
1024
1025
1026 public String getTypedArgumentList()
1027 {
1028 return this.getSuperEntityQueryOperation().getTypedArgumentList();
1029 }
1030
1031
1032
1033
1034
1035
1036 public String getTypedArgumentList(String modifier)
1037 {
1038 return this.getSuperEntityQueryOperation().getTypedArgumentList(modifier);
1039 }
1040
1041
1042
1043
1044
1045
1046 public int getUpper()
1047 {
1048 return this.getSuperEntityQueryOperation().getUpper();
1049 }
1050
1051
1052
1053
1054
1055 public boolean isAbstract()
1056 {
1057 return this.getSuperEntityQueryOperation().isAbstract();
1058 }
1059
1060
1061
1062
1063
1064 public boolean isExceptionsPresent()
1065 {
1066 return this.getSuperEntityQueryOperation().isExceptionsPresent();
1067 }
1068
1069
1070
1071
1072
1073
1074 public boolean isLeaf()
1075 {
1076 return this.getSuperEntityQueryOperation().isLeaf();
1077 }
1078
1079
1080
1081
1082
1083
1084 public boolean isMany()
1085 {
1086 return this.getSuperEntityQueryOperation().isMany();
1087 }
1088
1089
1090
1091
1092
1093
1094 public boolean isOrdered()
1095 {
1096 return this.getSuperEntityQueryOperation().isOrdered();
1097 }
1098
1099
1100
1101
1102
1103
1104
1105 public boolean isOverriding()
1106 {
1107 return this.getSuperEntityQueryOperation().isOverriding();
1108 }
1109
1110
1111
1112
1113
1114 public boolean isPostconditionsPresent()
1115 {
1116 return this.getSuperEntityQueryOperation().isPostconditionsPresent();
1117 }
1118
1119
1120
1121
1122
1123 public boolean isPreconditionsPresent()
1124 {
1125 return this.getSuperEntityQueryOperation().isPreconditionsPresent();
1126 }
1127
1128
1129
1130
1131
1132 public boolean isQuery()
1133 {
1134 return this.getSuperEntityQueryOperation().isQuery();
1135 }
1136
1137
1138
1139
1140
1141
1142 public boolean isReturnTypePresent()
1143 {
1144 return this.getSuperEntityQueryOperation().isReturnTypePresent();
1145 }
1146
1147
1148
1149
1150
1151 public boolean isStatic()
1152 {
1153 return this.getSuperEntityQueryOperation().isStatic();
1154 }
1155
1156
1157
1158
1159
1160
1161 public boolean isUnique()
1162 {
1163 return this.getSuperEntityQueryOperation().isUnique();
1164 }
1165
1166
1167
1168
1169 @Override
1170 public void initialize()
1171 {
1172 this.getSuperEntityQueryOperation().initialize();
1173 }
1174
1175
1176
1177
1178
1179 @Override
1180 public Object getValidationOwner()
1181 {
1182 Object owner = this.getSuperEntityQueryOperation().getValidationOwner();
1183 return owner;
1184 }
1185
1186
1187
1188
1189
1190 @Override
1191 public String getValidationName()
1192 {
1193 String name = this.getSuperEntityQueryOperation().getValidationName();
1194 return name;
1195 }
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206 @Override
1207 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
1208 {
1209 this.getSuperEntityQueryOperation().validateInvariants(validationMessages);
1210 try
1211 {
1212 final Object contextElement = this.THIS();
1213 boolean constraintValid = OCLResultEnsurer.ensure((Boolean.valueOf(String.valueOf(!Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(contextElement,"useNamedParameters"))).booleanValue())).booleanValue()?OCLCollections.forAll(OCLIntrospector.invoke(contextElement,"arguments"),new Predicate(){public boolean evaluate(Object object){return Boolean.valueOf(String.valueOf(!Boolean.valueOf(String.valueOf(OCLIntrospector.invoke(object,"type.collectionType"))).booleanValue())).booleanValue();}}):true));
1214 if (!constraintValid)
1215 {
1216 validationMessages.add(
1217 new ModelValidationMessage(
1218 (MetafacadeBase)contextElement ,
1219 "org::andromda::cartridges::spring::metafacades::SpringQueryOperation::collection parameters must use named parameters",
1220 "A collection type argument can only be specified when using named parameters, please set the 'hibernateQueryUseNamedParameters' namespace property to 'true' when attempting to use a collection as a query argument."));
1221 }
1222 }
1223 catch (Throwable th)
1224 {
1225 Throwable cause = th.getCause();
1226 int depth = 0;
1227 while (cause != null && depth < 7)
1228 {
1229 th = cause;
1230 depth++;
1231 }
1232 logger.error("Error validating constraint 'org::andromda::cartridges::spring::metafacades::SpringQueryOperation::collection parameters must use named parameters' ON "
1233 + this.THIS().toString() + ": " + th.getMessage(), th);
1234 }
1235 }
1236
1237
1238
1239
1240 private static final String NAME_PROPERTY = "name";
1241 private static final String FQNAME_PROPERTY = "fullyQualifiedName";
1242
1243
1244
1245
1246 @Override
1247 public String toString()
1248 {
1249 final StringBuilder toString = new StringBuilder(this.getClass().getName());
1250 toString.append("[");
1251 try
1252 {
1253 toString.append(Introspector.instance().getProperty(this, FQNAME_PROPERTY));
1254 }
1255 catch (final Throwable tryAgain)
1256 {
1257 try
1258 {
1259 toString.append(Introspector.instance().getProperty(this, NAME_PROPERTY));
1260 }
1261 catch (final Throwable ignore)
1262 {
1263
1264 }
1265 }
1266 toString.append("]");
1267 return toString.toString();
1268 }
1269 }