diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptorRegister.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptorRegister.java new file mode 100644 index 00000000..89d09a8d --- /dev/null +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptorRegister.java @@ -0,0 +1,25 @@ +package com.github.starnowski.posjsonhelper.text.hibernate6.descriptor; + +import com.github.starnowski.posjsonhelper.hibernate6.descriptor.AbstractConditionalFunctionDescriptorRegister; +import org.hibernate.query.sqm.function.SqmFunctionDescriptor; +import org.hibernate.query.sqm.function.SqmFunctionRegistry; + +public abstract class AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptorRegister extends AbstractConditionalFunctionDescriptorRegister { + + private final T descriptor; + + public AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptorRegister(boolean shouldOverrideFunctionIfAlreadyRegistered, T descriptor) { + super(shouldOverrideFunctionIfAlreadyRegistered); + this.descriptor = descriptor; + } + + @Override + protected SqmFunctionDescriptor register(SqmFunctionRegistry registry) { + return registry.register(getHqlFunctionName(), descriptor); + } + + @Override + protected String getHqlFunctionName() { + return descriptor.getName(); + } +} diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptor.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptor.java index 4c20ac61..d115b54f 100644 --- a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptor.java +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptor.java @@ -2,14 +2,13 @@ import com.github.starnowski.posjsonhelper.text.hibernate6.functions.PlainToTSQueryFunction; import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; import org.hibernate.query.sqm.tree.SqmTypedNode; import java.util.List; import static com.github.starnowski.posjsonhelper.core.Constants.PLAINTO_TSQUERY_FUNCTION_NAME; -public class PlainToTSQueryFunctionDescriptor extends AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptor{ +public class PlainToTSQueryFunctionDescriptor extends AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptor { public PlainToTSQueryFunctionDescriptor() { super(PLAINTO_TSQUERY_FUNCTION_NAME); } diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptorRegister.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptorRegister.java new file mode 100644 index 00000000..70d52334 --- /dev/null +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptorRegister.java @@ -0,0 +1,7 @@ +package com.github.starnowski.posjsonhelper.text.hibernate6.descriptor; + +public class PlainToTSQueryFunctionDescriptorRegister extends AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptorRegister{ + public PlainToTSQueryFunctionDescriptorRegister(boolean shouldOverrideFunctionIfAlreadyRegistered) { + super(shouldOverrideFunctionIfAlreadyRegistered, new PlainToTSQueryFunctionDescriptor()); + } +} diff --git a/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptorRegisterFactory.java b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptorRegisterFactory.java new file mode 100644 index 00000000..23fa009b --- /dev/null +++ b/text/hibernate6-text/src/main/java/com/github/starnowski/posjsonhelper/text/hibernate6/descriptor/PlainToTSQueryFunctionDescriptorRegisterFactory.java @@ -0,0 +1,13 @@ +package com.github.starnowski.posjsonhelper.text.hibernate6.descriptor; + +import com.github.starnowski.posjsonhelper.core.Context; +import com.github.starnowski.posjsonhelper.core.HibernateContext; +import com.github.starnowski.posjsonhelper.hibernate6.descriptor.FunctionDescriptorRegister; +import com.github.starnowski.posjsonhelper.hibernate6.descriptor.FunctionDescriptorRegisterFactory; + +public class PlainToTSQueryFunctionDescriptorRegisterFactory implements FunctionDescriptorRegisterFactory { + @Override + public FunctionDescriptorRegister get(Context context, HibernateContext hibernateContext) { + return new PlainToTSQueryFunctionDescriptorRegister(true); + } +}