@@ -122,8 +122,10 @@ public Map<Method, StoredProcedure> handle(Class c, SProcServiceAnnotationHandle
122
122
123
123
RowMapper <?> resultMapper = this .getRowMapper (scA );
124
124
125
- boolean useValidation = this .isValidationActive (scA , handlerResult );
126
- final StoredProcedure storedProcedure = this .getStoredProcedure (scA , handlerResult , method , name , sprocStrategy , resultMapper , useValidation );
125
+ final boolean useValidation = this .isValidationActive (scA , handlerResult );
126
+
127
+ final List <ShardKeyParameter > shardKeyParameters = new ArrayList <>();
128
+ final List <StoredProcedureParameter > params = new ArrayList <>();
127
129
128
130
int pos = 0 ;
129
131
for (final Annotation [] as : method .getParameterAnnotations ()) {
@@ -140,7 +142,7 @@ public Map<Method, StoredProcedure> handle(Class c, SProcServiceAnnotationHandle
140
142
}
141
143
142
144
if (a instanceof ShardKey ) {
143
- storedProcedure . addShardKeyParameter ( pos , clazz );
145
+ shardKeyParameters . add ( new ShardKeyParameter ( pos , clazz ) );
144
146
}
145
147
146
148
if (a instanceof SProcParam ) {
@@ -149,7 +151,7 @@ public Map<Method, StoredProcedure> handle(Class c, SProcServiceAnnotationHandle
149
151
final String dbTypeName = sParam .type ();
150
152
151
153
try {
152
- storedProcedure . addParam (StoredProcedureParameter .createParameter (clazz , genericType ,
154
+ params . add (StoredProcedureParameter .createParameter (clazz , genericType ,
153
155
method , dbTypeName , sParam .sqlType (), pos , sParam .sensitive ()));
154
156
} catch (final InstantiationException | IllegalAccessException e ) {
155
157
LOG .error ("Could not instantiate StoredProcedureParameter. ABORTING." , e );
@@ -160,22 +162,27 @@ public Map<Method, StoredProcedure> handle(Class c, SProcServiceAnnotationHandle
160
162
161
163
pos ++;
162
164
}
165
+ final StoredProcedure storedProcedure = createStoredProcedure (scA , handlerResult , method , name , params , sprocStrategy , shardKeyParameters , resultMapper , useValidation );
166
+
163
167
result .put (method , storedProcedure );
164
168
}
165
169
return result ;
166
170
}
167
171
168
- private StoredProcedure getStoredProcedure (SProcCall scA , SProcServiceAnnotationHandler .HandlerResult handlerResult , Method method , String name , VirtualShardKeyStrategy sprocStrategy , RowMapper <?> resultMapper , boolean useValidation ) {
172
+ private StoredProcedure createStoredProcedure (SProcCall scA , SProcServiceAnnotationHandler .HandlerResult handlerResult ,
173
+ Method method , String name , List <StoredProcedureParameter > params ,
174
+ VirtualShardKeyStrategy sprocStrategy , List <ShardKeyParameter > shardKeyParameters ,
175
+ RowMapper <?> resultMapper , boolean useValidation ) {
169
176
try {
170
177
SProcService .WriteTransaction writeTransaction = mapSprocWriteTransactionToServiceWriteTransaction (scA .shardedWriteTransaction (), handlerResult );
171
178
172
- StoredProcedure storedProcedure = new StoredProcedure (name , method .getGenericReturnType (), sprocStrategy ,
179
+ String query = !"" .equals (scA .sql ()) ? scA .sql () : null ;
180
+
181
+ StoredProcedure storedProcedure = new StoredProcedure (name , query , params , method .getGenericReturnType (), sprocStrategy , shardKeyParameters ,
173
182
scA .runOnAllShards (), scA .searchShards (), scA .parallel (), resultMapper ,
174
183
scA .timeoutInMilliSeconds (), new SProcCall .AdvisoryLock (scA .adivsoryLockName (),scA .adivsoryLockId ()), useValidation , scA .readOnly (),
175
184
writeTransaction );
176
- if (!"" .equals (scA .sql ())) {
177
- storedProcedure .setQuery (scA .sql ());
178
- }
185
+
179
186
return storedProcedure ;
180
187
} catch (final InstantiationException | IllegalAccessException e ) {
181
188
LOG .error ("Could not instantiate StoredProcedure. ABORTING." , e );
0 commit comments