forked from hibernate/hibernate-orm
-
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.
HHH-17375 Introduce array_includes() and INCLUDES predicate for check…
…ing if array contains all elements of subarray as replacement to array_contains() overload
- Loading branch information
Showing
26 changed files
with
897 additions
and
172 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
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
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
39 changes: 39 additions & 0 deletions
39
...ore/src/main/java/org/hibernate/dialect/function/array/AbstractArrayIncludesFunction.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.dialect.function.array; | ||
|
||
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor; | ||
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; | ||
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers; | ||
import org.hibernate.type.spi.TypeConfiguration; | ||
|
||
/** | ||
* Encapsulates the validator, return type and argument type resolvers for the array_includes function. | ||
* Subclasses only have to implement the rendering. | ||
*/ | ||
public abstract class AbstractArrayIncludesFunction extends AbstractSqmSelfRenderingFunctionDescriptor { | ||
|
||
protected final boolean nullable; | ||
|
||
public AbstractArrayIncludesFunction(boolean nullable, TypeConfiguration typeConfiguration) { | ||
super( | ||
"array_includes" + ( nullable ? "_nullable" : "" ), | ||
StandardArgumentsValidators.composite( | ||
StandardArgumentsValidators.exactly( 2 ), | ||
ArrayIncludesArgumentValidator.INSTANCE | ||
), | ||
StandardFunctionReturnTypeResolvers.invariant( typeConfiguration.standardBasicTypeForJavaType( Boolean.class ) ), | ||
ArrayIncludesArgumentTypeResolver.INSTANCE | ||
); | ||
this.nullable = nullable; | ||
} | ||
|
||
@Override | ||
public String getArgumentListSignature() { | ||
return "(ARRAY haystackArray, OBJECT needleArray)"; | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...src/main/java/org/hibernate/dialect/function/array/ArrayIncludesArgumentTypeResolver.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.dialect.function.array; | ||
|
||
import org.hibernate.metamodel.mapping.MappingModelExpressible; | ||
import org.hibernate.metamodel.model.domain.DomainType; | ||
import org.hibernate.query.sqm.produce.function.FunctionArgumentTypeResolver; | ||
import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; | ||
import org.hibernate.query.sqm.tree.SqmTypedNode; | ||
import org.hibernate.query.sqm.tree.expression.SqmExpression; | ||
import org.hibernate.query.sqm.tree.expression.SqmFunction; | ||
import org.hibernate.type.BasicPluralType; | ||
|
||
/** | ||
* A {@link FunctionArgumentTypeResolver} that resolves the argument types for the {@code array_includes} function. | ||
*/ | ||
public class ArrayIncludesArgumentTypeResolver implements FunctionArgumentTypeResolver { | ||
|
||
public static final FunctionArgumentTypeResolver INSTANCE = new ArrayIncludesArgumentTypeResolver(); | ||
|
||
@Override | ||
public MappingModelExpressible<?> resolveFunctionArgumentType( | ||
SqmFunction<?> function, | ||
int argumentIndex, | ||
SqmToSqlAstConverter converter) { | ||
if ( argumentIndex == 0 ) { | ||
final SqmTypedNode<?> node = function.getArguments().get( 1 ); | ||
if ( node instanceof SqmExpression<?> ) { | ||
return converter.determineValueMapping( (SqmExpression<?>) node ); | ||
} | ||
} | ||
else if ( argumentIndex == 1 ) { | ||
final SqmTypedNode<?> node = function.getArguments().get( 0 ); | ||
if ( node instanceof SqmExpression<?> ) { | ||
return converter.determineValueMapping( (SqmExpression<?>) node ); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...re/src/main/java/org/hibernate/dialect/function/array/ArrayIncludesArgumentValidator.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.dialect.function.array; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.query.sqm.produce.function.ArgumentsValidator; | ||
import org.hibernate.query.sqm.produce.function.FunctionArgumentException; | ||
import org.hibernate.query.sqm.tree.SqmTypedNode; | ||
import org.hibernate.type.BasicPluralType; | ||
import org.hibernate.type.spi.TypeConfiguration; | ||
|
||
/** | ||
* A {@link ArgumentsValidator} that validates the arguments for the {@code array_includes} function. | ||
*/ | ||
public class ArrayIncludesArgumentValidator extends ArrayArgumentValidator { | ||
|
||
public static final ArgumentsValidator INSTANCE = new ArrayIncludesArgumentValidator(); | ||
|
||
protected ArrayIncludesArgumentValidator() { | ||
super( 0 ); | ||
} | ||
|
||
@Override | ||
public void validate( | ||
List<? extends SqmTypedNode<?>> arguments, | ||
String functionName, | ||
TypeConfiguration typeConfiguration) { | ||
final BasicPluralType<?, ?> haystackType = | ||
getPluralType( 0, arguments, functionName, typeConfiguration ); | ||
final BasicPluralType<?, ?> needleType = | ||
getPluralType( 1, arguments, functionName, typeConfiguration ); | ||
if ( haystackType != null && needleType != null | ||
&& !haystackType.equals( needleType ) | ||
&& !haystackType.getElementType().equals( needleType ) ) { | ||
throw new FunctionArgumentException( | ||
String.format( | ||
"Parameter 1 of function '%s()' has type %s, but argument is of type '%s'", | ||
functionName, | ||
haystackType.getJavaTypeDescriptor().getTypeName(), | ||
needleType.getTypeName() | ||
) | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.