1010import com .fasterxml .jackson .databind .node .ObjectNode ;
1111import com .marklogic .client .document .DocumentWriteOperation ;
1212import com .marklogic .client .document .DocumentWriteSet ;
13+ import com .marklogic .client .io .Format ;
14+ import com .marklogic .client .io .StringHandle ;
1315import com .marklogic .client .expression .*;
1416import com .marklogic .client .impl .BaseTypeImpl .BaseArgImpl ;
1517import com .marklogic .client .io .marker .AbstractWriteHandle ;
@@ -843,6 +845,7 @@ static class PlanSubImpl
843845
844846 private Map <PlanParamBase ,BaseTypeImpl .ParamBinder > params = null ;
845847 private List <ContentParam > contentParams ;
848+ private Map <String ,CtsQueryExpr > queryBindings ;
846849
847850 PlanSubImpl (PlanBuilderBaseImpl .PlanBaseImpl prior , String fnPrefix , String fnName , Object [] fnArgs ) {
848851 super (prior , fnPrefix , fnName , fnArgs );
@@ -854,10 +857,12 @@ static class PlanSubImpl
854857 private PlanSubImpl (
855858 PlanBuilderBaseImpl .PlanBaseImpl prior , String fnPrefix , String fnName , Object [] fnArgs ,
856859 Map <PlanParamBase ,BaseTypeImpl .ParamBinder > params ,
857- List <ContentParam > contentParams ) {
860+ List <ContentParam > contentParams ,
861+ Map <String ,CtsQueryExpr > queryBindings ) {
858862 this (prior , fnPrefix , fnName , fnArgs );
859863 this .params = params ;
860864 this .contentParams = contentParams ;
865+ this .queryBindings = queryBindings ;
861866 }
862867
863868 @ Override
@@ -930,6 +935,30 @@ public Plan bindParam(PlanParamExpr param, String literal) {
930935 return bindParam (param , new XsValueImpl .StringValImpl (literal ));
931936 }
932937 @ Override
938+ public Plan bindParam (String paramName , CtsQueryExpr query ) {
939+ if (paramName == null ) {
940+ throw new IllegalArgumentException ("paramName for cts query binding cannot be null" );
941+ }
942+ if (query == null ) {
943+ throw new IllegalArgumentException ("query for cts query binding cannot be null" );
944+ }
945+
946+ Map <String ,CtsQueryExpr > nextQueryBindings = new HashMap <>();
947+ if (this .queryBindings != null ) {
948+ nextQueryBindings .putAll (this .queryBindings );
949+ }
950+ nextQueryBindings .put (paramName , query );
951+
952+ return new PlanSubImpl (
953+ this .prior , this .fnPrefix , this .fnName , this .fnArgs ,
954+ this .params , this .contentParams , nextQueryBindings
955+ );
956+ }
957+ @ Override
958+ public Plan bindParam (CtsParamExpr param , CtsQueryExpr query ) {
959+ return bindParam (BaseTypeImpl .getCtsParamName (param ), query );
960+ }
961+ @ Override
933962 public Plan bindParam (PlanParamExpr param , PlanParamBindingVal literal ) {
934963 if (!(param instanceof PlanParamBase )) {
935964 throw new IllegalArgumentException ("param must be an instance of PlanParamBase" );
@@ -950,7 +979,7 @@ public Plan bindParam(PlanParamExpr param, PlanParamBindingVal literal) {
950979 throw new IllegalArgumentException ("cannot set value with unknown implementation" );
951980 }
952981
953- return new PlanSubImpl (this .prior , this .fnPrefix , this .fnName , this .fnArgs , nextParams , this .contentParams );
982+ return new PlanSubImpl (this .prior , this .fnPrefix , this .fnName , this .fnArgs , nextParams , this .contentParams , this . queryBindings );
954983 }
955984
956985 @ Override
@@ -968,7 +997,7 @@ public Plan bindParam(PlanParamExpr param, DocumentWriteSet writeSet) {
968997 nextContentParams .addAll (this .contentParams );
969998 }
970999 nextContentParams .add (ContentParam .fromDocumentWriteSet ((PlanParamBase ) param , writeSet ));
971- return new PlanSubImpl (this .prior , this .fnPrefix , this .fnName , this .fnArgs , this .params , nextContentParams );
1000+ return new PlanSubImpl (this .prior , this .fnPrefix , this .fnName , this .fnArgs , this .params , nextContentParams , this . queryBindings );
9721001 }
9731002
9741003 @ Override
@@ -992,7 +1021,17 @@ public Plan bindParam(PlanParamExpr param, AbstractWriteHandle content, Map<Stri
9921021 nextContentParams .addAll (this .contentParams );
9931022 }
9941023 nextContentParams .add (new ContentParam (baseParam , content , columnAttachments ));
995- return new PlanSubImpl (this .prior , this .fnPrefix , this .fnName , this .fnArgs , this .params , nextContentParams );
1024+ return new PlanSubImpl (this .prior , this .fnPrefix , this .fnName , this .fnArgs , this .params , nextContentParams , this .queryBindings );
1025+ }
1026+
1027+ @ Override
1028+ public AbstractWriteHandle getHandle () {
1029+ if (queryBindings == null || queryBindings .isEmpty ()) {
1030+ return super .getHandle ();
1031+ }
1032+
1033+ String boundAst = BaseTypeImpl .bindCtsQueryParamsInAst (getAst (), queryBindings );
1034+ return new StringHandle (boundAst ).withFormat (Format .JSON );
9961035 }
9971036 @ Override
9981037 public List <ContentParam > getContentParams () {
0 commit comments