-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dbb041
commit 8e8bd04
Showing
3 changed files
with
25 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 22 additions & 7 deletions
29
...a/com/github/starnowski/posjsonhelper/text/hibernate6/operators/TextOperatorFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,60 @@ | ||
package com.github.starnowski.posjsonhelper.text.hibernate6.operators; | ||
|
||
import com.github.starnowski.posjsonhelper.core.HibernateContext; | ||
import com.github.starnowski.posjsonhelper.text.hibernate6.functions.TSVectorFunction; | ||
import jakarta.persistence.criteria.Path; | ||
import org.hibernate.query.sqm.NodeBuilder; | ||
import org.hibernate.query.sqm.function.FunctionRenderingSupport; | ||
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; | ||
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; | ||
import org.hibernate.query.sqm.tree.SqmCopyContext; | ||
import org.hibernate.query.sqm.tree.SqmTypedNode; | ||
import org.hibernate.query.sqm.tree.expression.SqmExpression; | ||
import org.hibernate.type.StandardBasicTypes; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class TextOperatorFunction extends SelfRenderingSqmFunction<Boolean> implements Serializable { | ||
|
||
private final HibernateContext context; | ||
private final List<? extends SqmExpression<String>> arguments; | ||
private final TSVectorFunction tsVectorFunction; | ||
private final SqmExpression<String> argument; | ||
|
||
public TextOperatorFunction(NodeBuilder nodeBuilder, List<? extends SqmExpression<String>> arguments, HibernateContext hibernateContext) { | ||
public TextOperatorFunction(NodeBuilder nodeBuilder, TSVectorFunction tsVectorFunction, SqmExpression<String> argument, HibernateContext hibernateContext) { | ||
super(nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(hibernateContext.getTextFunctionOperator()), | ||
(FunctionRenderingSupport) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(hibernateContext.getTextFunctionOperator()), | ||
//TODO Check if only two arguments are being passed! | ||
//TODO First should be TSVector type | ||
arguments, | ||
contactParameters(tsVectorFunction, argument), | ||
null, | ||
null, | ||
StandardFunctionReturnTypeResolvers.invariant(nodeBuilder.getTypeConfiguration().getBasicTypeRegistry().resolve(StandardBasicTypes.BOOLEAN)), | ||
nodeBuilder, | ||
hibernateContext.getTextFunctionOperator()); | ||
this.context = hibernateContext; | ||
this.arguments = arguments; | ||
this.tsVectorFunction = tsVectorFunction; | ||
this.argument = argument; | ||
} | ||
|
||
public TextOperatorFunction copy(SqmCopyContext context) { | ||
TextOperatorFunction existing = (TextOperatorFunction) context.getCopy(this); | ||
if (existing != null) { | ||
return existing; | ||
} else { | ||
TextOperatorFunction predicate = (TextOperatorFunction) context.registerCopy(this, new TextOperatorFunction(nodeBuilder(), this.arguments, this.context)); | ||
TextOperatorFunction predicate = (TextOperatorFunction) context.registerCopy(this, new TextOperatorFunction(nodeBuilder(), this.tsVectorFunction, this.argument, this.context)); | ||
this.copyTo(predicate, context); | ||
return predicate; | ||
} | ||
} | ||
|
||
private static List<? extends SqmExpression<String>> contactParameters(TSVectorFunction tsVectorFunction, SqmExpression<String> argument) { | ||
if (tsVectorFunction == null) { | ||
throw new IllegalArgumentException("TSVectorFunction argument can not be null"); | ||
} | ||
List<SqmExpression<String>> result = new ArrayList<>(); | ||
result.add(tsVectorFunction); | ||
result.add(argument); | ||
return result; | ||
} | ||
} |