Skip to content

Commit

Permalink
#67 - Added constructor with configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
starnowski committed Dec 20, 2023
1 parent 8e8bd04 commit 14d4779
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,36 @@
import org.hibernate.type.StandardBasicTypes;

import java.io.Serializable;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

import static com.github.starnowski.posjsonhelper.core.Constants.TO_TSVECTOR_FUNCTION_NAME;

public class TSVectorFunction extends SelfRenderingSqmFunction<String> implements Serializable {
public TSVectorFunction(Path referencedPathSource, NodeBuilder nodeBuilder) {
this(referencedPathSource, null, nodeBuilder);
}

public TSVectorFunction(Path referencedPathSource, String configuration, NodeBuilder nodeBuilder) {
super(nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(TO_TSVECTOR_FUNCTION_NAME),
(FunctionRenderingSupport) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(TO_TSVECTOR_FUNCTION_NAME),
//TODO Add configuration
Arrays.asList((SqmTypedNode<?>) referencedPathSource),
contactParameters(referencedPathSource, configuration, nodeBuilder),
null,
null,
StandardFunctionReturnTypeResolvers.invariant(nodeBuilder.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.STRING)),
nodeBuilder,
TO_TSVECTOR_FUNCTION_NAME);
}

private static List<? extends SqmTypedNode<?>> contactParameters(Path referencedPathSource, String configuration, NodeBuilder nodeBuilder) {
if (referencedPathSource == null) {
throw new IllegalArgumentException("ReferencedPathSource argument can not be null");
}
List<SqmTypedNode<?>> result = new ArrayList<>();
if (configuration != null) {
result.add(nodeBuilder.value(configuration));
}
result.add((SqmTypedNode<?>) referencedPathSource);
return result;
}
}

0 comments on commit 14d4779

Please sign in to comment.