-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-17355 Smoothen some rough edges with parameter typing and PG12 su…
…pport
- Loading branch information
Showing
41 changed files
with
374 additions
and
101 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
37 changes: 37 additions & 0 deletions
37
...te-core/src/main/java/org/hibernate/dialect/function/array/AbstractArrayTrimFunction.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,37 @@ | ||
/* | ||
* 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.ArgumentTypesValidator; | ||
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators; | ||
import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers; | ||
|
||
import static org.hibernate.query.sqm.produce.function.FunctionParameterType.ANY; | ||
import static org.hibernate.query.sqm.produce.function.FunctionParameterType.INTEGER; | ||
|
||
/** | ||
* Encapsulates the validator, return type and argument type resolvers for the array_remove functions. | ||
* Subclasses only have to implement the rendering. | ||
*/ | ||
public abstract class AbstractArrayTrimFunction extends AbstractSqmSelfRenderingFunctionDescriptor { | ||
|
||
public AbstractArrayTrimFunction() { | ||
super( | ||
"array_trim", | ||
StandardArgumentsValidators.composite( | ||
new ArgumentTypesValidator( null, ANY, INTEGER ), | ||
ArrayArgumentValidator.DEFAULT_INSTANCE | ||
), | ||
ArrayViaArgumentReturnTypeResolver.DEFAULT_INSTANCE, | ||
StandardFunctionArgumentTypeResolvers.composite( | ||
StandardFunctionArgumentTypeResolvers.invariant( ANY, INTEGER ), | ||
StandardFunctionArgumentTypeResolvers.IMPLIED_RESULT_TYPE | ||
) | ||
); | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
...e-core/src/main/java/org/hibernate/dialect/function/array/CockroachArrayFillFunction.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,66 @@ | ||
/* | ||
* 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.ReturnableType; | ||
import org.hibernate.sql.ast.SqlAstTranslator; | ||
import org.hibernate.sql.ast.spi.SqlAppender; | ||
import org.hibernate.sql.ast.tree.SqlAstNode; | ||
import org.hibernate.sql.ast.tree.expression.Expression; | ||
import org.hibernate.sql.ast.tree.expression.Literal; | ||
|
||
/** | ||
* Implement the array fill function by using {@code generate_series}. | ||
*/ | ||
public class CockroachArrayFillFunction extends AbstractArrayFillFunction { | ||
|
||
public CockroachArrayFillFunction(boolean list) { | ||
super( list ); | ||
} | ||
|
||
@Override | ||
public void render( | ||
SqlAppender sqlAppender, | ||
List<? extends SqlAstNode> sqlAstArguments, | ||
ReturnableType<?> returnType, | ||
SqlAstTranslator<?> walker) { | ||
sqlAppender.append( "coalesce(case when " ); | ||
sqlAstArguments.get( 1 ).accept( walker ); | ||
sqlAppender.append( "<>0 then (select array_agg(" ); | ||
final String elementCastType; | ||
final Expression elementExpression = (Expression) sqlAstArguments.get( 0 ); | ||
if ( needsElementCasting( elementExpression ) ) { | ||
elementCastType = DdlTypeHelper.getCastTypeName( | ||
elementExpression.getExpressionType(), | ||
walker.getSessionFactory().getTypeConfiguration() | ||
); | ||
sqlAppender.append( "cast(" ); | ||
} | ||
else { | ||
elementCastType = null; | ||
} | ||
sqlAstArguments.get( 0 ).accept( walker ); | ||
if ( elementCastType != null ) { | ||
sqlAppender.append( " as " ); | ||
sqlAppender.append( elementCastType ); | ||
sqlAppender.append( ')' ); | ||
} | ||
sqlAppender.append( ") from generate_series(1," ); | ||
sqlAstArguments.get( 1 ).accept( walker ); | ||
sqlAppender.append( ",1))) end,array[])" ); | ||
} | ||
|
||
private static boolean needsElementCasting(Expression elementExpression) { | ||
// PostgreSQL needs casting of null and string literal expressions | ||
return elementExpression instanceof Literal && ( | ||
elementExpression.getExpressionType().getSingleJdbcMapping().getJdbcType().isString() | ||
|| ( (Literal) elementExpression ).getLiteralValue() == null | ||
); | ||
} | ||
} |
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
Oops, something went wrong.