@@ -325,22 +325,6 @@ public static Object executeQuery(Class<?> resultType, String connectionStr, Str
325325 public static Object executeStoredProcedure (Class <?> resultType , SProcAPI sproc , Object ... parms ) {
326326 Objects .requireNonNull (resultType , "[resultType] argument must be non-null" );
327327
328- int typesCount = sproc .getArgCount ();
329- int parmsCount = parms .length ;
330-
331- if (parmsCount != typesCount ) {
332- String message ;
333-
334- if (typesCount == 0 ) {
335- message = "No arguments expected for " + sproc .getEnum ().name ();
336- } else {
337- message = String .format ("Incorrect argument count for %s%s: expect: %d; actual: %d" ,
338- sproc .getEnum ().name (), Arrays .toString (sproc .getArgTypes ()), typesCount , parmsCount );
339- }
340-
341- throw new IllegalArgumentException (message );
342- }
343-
344328 String sprocName ;
345329 String [] args = {};
346330 String signature = sproc .getSignature ();
@@ -358,31 +342,47 @@ public static Object executeStoredProcedure(Class<?> resultType, SProcAPI sproc,
358342 }
359343
360344 int argsCount = args .length ;
345+ int typesCount = sproc .getArgCount ();
346+
347+ // if unbalanced args/types
361348 if (argsCount != typesCount ) {
362349 String message = String .format ("Signature argument count differs from declared type count for %s%s: "
363350 + "signature: %d; declared: %d" ,
364351 sproc .getEnum ().name (), Arrays .toString (sproc .getArgTypes ()), argsCount , typesCount );
365352 throw new IllegalArgumentException (message );
366353 }
367354
355+ int parmsCount = parms .length ;
356+
357+ // if parms specified with no matching types
358+ if ((parmsCount > 0 ) && (typesCount == 0 )) {
359+ throw new IllegalArgumentException ("No arguments expected for " + sproc .getEnum ().name ());
360+ }
361+
362+ // if fewer parms than types
363+ if (parmsCount < typesCount ) {
364+ String message = String .format ("Insufficient arguments count for %s%s: minimum: %d; actual: %d" ,
365+ sproc .getEnum ().name (), Arrays .toString (sproc .getArgTypes ()), typesCount , parmsCount );
366+ throw new IllegalArgumentException (message );
367+ }
368+
368369 int [] argTypes = sproc .getArgTypes ();
369- Param [] parmArray = Param .array (typesCount );
370- for (int i = 0 ; i < typesCount ; i ++) {
371- int type = argTypes [i ];
372- Mode mode = Mode .fromChar (args [i ].charAt (0 ));
373- switch (mode ) {
374- case IN :
375- parmArray [i ] = Param .in (parms [i ], type );
376- break ;
377-
378- case OUT :
379- parmArray [i ] = Param .out (type );
380- break ;
381-
382- case INOUT :
383- parmArray [i ] = Param .inOut (parms [i ], type );
384- break ;
385- }
370+ Param [] parmArray = Param .array (parmsCount );
371+
372+ int i = 0 ;
373+ int type = 0 ;
374+ Mode mode = Mode .IN ;
375+
376+ // process declared parameters
377+ for (i = 0 ; i < typesCount ; i ++) {
378+ type = argTypes [i ];
379+ mode = Mode .fromChar (args [i ].charAt (0 ));
380+ parmArray [i ] = Param .create (mode , type , parms [i ]);
381+ }
382+
383+ // handle varargs parameters
384+ for (; i < parmsCount ; i ++) {
385+ parmArray [i ] = Param .create (mode , type , parms [i ]);
386386 }
387387
388388 return executeStoredProcedure (resultType , sproc .getConnection (), sprocName , parmArray );
0 commit comments