Skip to content

Commit

Permalink
#67 - Added descriptor factory
Browse files Browse the repository at this point in the history
  • Loading branch information
starnowski committed Dec 19, 2023
1 parent 829657f commit a4de0c0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<T extends AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptor> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlainToTSQueryFunction>{
public class PlainToTSQueryFunctionDescriptor extends AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptor<PlainToTSQueryFunction> {
public PlainToTSQueryFunctionDescriptor() {
super(PLAINTO_TSQUERY_FUNCTION_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.starnowski.posjsonhelper.text.hibernate6.descriptor;

public class PlainToTSQueryFunctionDescriptorRegister extends AbstractFunctionWithConfigurationAndTextQueryFunctionDescriptorRegister<PlainToTSQueryFunctionDescriptor>{
public PlainToTSQueryFunctionDescriptorRegister(boolean shouldOverrideFunctionIfAlreadyRegistered) {
super(shouldOverrideFunctionIfAlreadyRegistered, new PlainToTSQueryFunctionDescriptor());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit a4de0c0

Please sign in to comment.