@@ -474,8 +474,20 @@ public void invoke(
474474 throw new IllegalArgumentException (
475475 "Only a method annotated with @UpdateMethod can be used to start an Update." );
476476 }
477+ result = untyped .startUpdate (mergeUpdateOptions (options , workflowMetadata , method ), args );
478+ }
479+
480+ @ Override
481+ @ SuppressWarnings ("unchecked" )
482+ public <R > R getResult (Class <R > resultClass ) {
483+ return (R ) result ;
484+ }
485+
486+ static UpdateOptions <?> mergeUpdateOptions (
487+ UpdateOptions <?> options , POJOWorkflowInterfaceMetadata workflowMetadata , Method method ) {
477488 POJOWorkflowMethodMetadata methodMetadata = workflowMetadata .getMethodMetadata (method );
478489 UpdateOptions .Builder builder = UpdateOptions .newBuilder (options );
490+
479491 if (Strings .isNullOrEmpty (options .getUpdateName ())) {
480492 builder .setUpdateName (methodMetadata .getName ());
481493 } else if (!options .getUpdateName ().equals (methodMetadata .getName ())) {
@@ -491,14 +503,7 @@ public void invoke(
491503 if (options .getResultClass () == null ) {
492504 builder .setResultClass (method .getReturnType ());
493505 }
494-
495- result = untyped .startUpdate (builder .build (), args );
496- }
497-
498- @ Override
499- @ SuppressWarnings ("unchecked" )
500- public <R > R getResult (Class <R > resultClass ) {
501- return (R ) result ;
506+ return builder .build ();
502507 }
503508 }
504509
@@ -510,7 +515,7 @@ enum State {
510515 UPDATE_RECEIVED ,
511516 }
512517
513- private final UpdateOptions <?> baseUpdateOptions ;
518+ private final UpdateOptions <?> userProvidedUpdateOptions ;
514519 private Object [] updateArgs ;
515520 private UpdateOptions updateOptions ;
516521 private final WithStartWorkflowOperation <?> startOp ;
@@ -519,8 +524,10 @@ enum State {
519524 private WorkflowStub stub ;
520525
521526 public UpdateWithStartInvocationHandler (
522- UpdateOptions <?> baseUpdateOptions , WithStartWorkflowOperation <?> startOp ) {
523- this .baseUpdateOptions = baseUpdateOptions ;
527+ UpdateOptions <?> options , WithStartWorkflowOperation <?> startOp ) {
528+ Preconditions .checkNotNull (options , "options" );
529+ Preconditions .checkNotNull (startOp , "startOp" );
530+ this .userProvidedUpdateOptions = options ;
524531 this .startOp = startOp ;
525532 }
526533
@@ -542,22 +549,19 @@ public void invoke(
542549 UpdateMethod updateMethod = method .getAnnotation (UpdateMethod .class );
543550 if (updateMethod == null ) {
544551 throw new IllegalArgumentException (
545- "Method '" + method .getName () + "' is not an UpdateMethod" );
552+ "Method '" + method .getName () + "' is not an @ UpdateMethod" );
546553 }
547554 this .setStub (untyped );
548555 this .updateArgs = args ;
549556 this .updateOptions =
550- this .baseUpdateOptions .toBuilder ()
551- .setUpdateName (methodMetadata .getName ())
552- .setResultClass (method .getReturnType ())
553- .setResultType (method .getGenericReturnType ())
554- .build ();
557+ UpdateInvocationHandler .mergeUpdateOptions (
558+ userProvidedUpdateOptions , workflowMetadata , method );
555559 state = State .UPDATE_RECEIVED ;
556560 } else if (state == State .UPDATE_RECEIVED ) {
557561 WorkflowMethod workflowMethod = method .getAnnotation (WorkflowMethod .class );
558562 if (workflowMethod == null ) {
559563 throw new IllegalArgumentException (
560- "Method '" + method .getName () + "' is not a WorkflowMethod" );
564+ "Method '" + method .getName () + "' is not a @ WorkflowMethod" );
561565 }
562566 this .setStub (untyped );
563567 this .startOp .setStub (untyped );
0 commit comments