@@ -40,14 +40,8 @@ public QueryResult executeQuery(StatementMappingOptions options, Method method,
4040 i ++;
4141 }
4242
43- Annotation queryAnnotation = null ;
44- QueryAnnotation wrappedAnnotation = null ;
45- for (Annotation annotation : method .getAnnotations ()) {
46- if (QueryAnnotation .isQueryAnnotation (annotation )) {
47- queryAnnotation = annotation ;
48- wrappedAnnotation = QueryAnnotation .wrap (annotation );
49- }
50- }
43+ Annotation queryAnnotation = filterQueryAnnotation (method , args );
44+ QueryAnnotation wrappedAnnotation = QueryAnnotation .wrap (queryAnnotation );
5145
5246 if (wrappedAnnotation == null ) {
5347 throw new SQLMappingException ("No query builder found for method " + method .getName () + "! Is query annotation present?" , method , args );
@@ -56,10 +50,8 @@ public QueryResult executeQuery(StatementMappingOptions options, Method method,
5650 }
5751
5852 QueryNode <?> node = wrappedAnnotation .getQueryBuilder ().build (
59- new QueryAnnotation .DefaultMappingDetails (connection , options ),
60- queryAnnotation ,
61- method ,
62- parameters );
53+ new QueryAnnotation .DefaultMappingDetails (connection , options ), queryAnnotation ,
54+ method , parameters );
6355 if (method .isAnnotationPresent (Append .class )) {
6456 Append append = method .getAnnotation (Append .class );
6557 node .then (new PlaceholderMapper (parameters ).assignValues (append .value ()));
@@ -78,6 +70,20 @@ public QueryResult executeQuery(StatementMappingOptions options, Method method,
7870 }
7971 }
8072
73+ private static Annotation filterQueryAnnotation (Method method , Object [] args ) {
74+ Annotation queryAnnotation = null ;
75+ for (Annotation annotation : method .getAnnotations ()) {
76+ boolean isQueryAnnot = QueryAnnotation .isQueryAnnotation (annotation );
77+ if (isQueryAnnot && queryAnnotation == null ) {
78+ queryAnnotation = annotation ;
79+ } else if (isQueryAnnot ) {
80+ String errMessage = String .format ("Multiple query annotations (Select/Insert/...) found on method %s!" , method .getName ());
81+ throw new SQLMappingException (errMessage , method , args );
82+ }
83+ }
84+ return queryAnnotation ;
85+ }
86+
8187 @ Override
8288 public boolean isMappingMethod (Method method ) {
8389 for (Annotation annot : method .getAnnotations ()) {
0 commit comments