Skip to content

Commit

Permalink
Merge branch 'master' into feature/84_text_index
Browse files Browse the repository at this point in the history
  • Loading branch information
starnowski committed Dec 29, 2023
2 parents cfe8941 + 2443503 commit 9bb9a88
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 70 deletions.
2 changes: 1 addition & 1 deletion hibernate6-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<artifactId>hibernate6-core</artifactId>

<properties>
<org.hibernate.hibernate.core.version>6.1.5.Final</org.hibernate.hibernate.core.version>
<org.hibernate.hibernate.core.version>6.4.0.Final</org.hibernate.hibernate.core.version>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CastOperatorFunctionDescriptor(HibernateContext hibernateContext) {
}

@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> translator) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, ReturnableType<?> returnableType, SqlAstTranslator<?> translator) {
//TODO Check if sqlAstArguments has two arguments only!
boolean firstPass = true;
for (Iterator var11 = sqlAstArguments.iterator(); var11.hasNext(); firstPass = false) {
Expand All @@ -52,7 +52,7 @@ public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArg
}

@Override
protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine, TypeConfiguration typeConfiguration) {
protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine) {
List<SqmExpression<String>> args = new ArrayList<>();
//TODO Check if arguments has two arguments only!
for (int i = 0; i < arguments.size(); i++) {
Expand Down
9 changes: 0 additions & 9 deletions hibernate6-tests/hibernate6-tests-native-support-1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.hibernate.hibernate.core.version>6.2.5.Final</org.hibernate.hibernate.core.version>
</properties>

<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${org.hibernate.hibernate.core.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
10 changes: 2 additions & 8 deletions hibernate6-tests/hibernate6-tests-native-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.hibernate.hibernate.core.version>6.2.0.Final</org.hibernate.hibernate.core.version>
</properties>

<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${org.hibernate.hibernate.core.version}</version>
</dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-62</artifactId>
<version>3.4.1</version>
<artifactId>hypersistence-utils-hibernate-63</artifactId>
<version>3.7.0</version>
</dependency>
</dependencies>

Expand Down
7 changes: 7 additions & 0 deletions hibernate6-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.hibernate.hibernate.core.version>6.4.0.Final</org.hibernate.hibernate.core.version>
</properties>

<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${org.hibernate.hibernate.core.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.starnowski.posjsonhelper</groupId>
<artifactId>hibernate6</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion hibernate6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<artifactId>hibernate6</artifactId>

<properties>
<org.hibernate.hibernate.core.version>6.1.5.Final</org.hibernate.hibernate.core.version>
<org.hibernate.hibernate.core.version>6.4.0.Final</org.hibernate.hibernate.core.version>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
package com.github.starnowski.posjsonhelper.hibernate6;

import jakarta.persistence.criteria.Path;
import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.function.FunctionRenderingSupport;
import org.hibernate.query.sqm.function.FunctionRenderer;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
import org.hibernate.query.sqm.tree.SqmTypedNode;
Expand Down Expand Up @@ -65,7 +66,7 @@ public AbstractJsonBExtractPath(Path referencedPathSource, NodeBuilder nodeBuild

public AbstractJsonBExtractPath(Path referencedPathSource, List<? extends SqmTypedNode<?>> path, NodeBuilder nodeBuilder, String functionName) {
super(nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(functionName),
(FunctionRenderingSupport) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(functionName),
(FunctionRenderer) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(functionName),
contactParameters(referencedPathSource, (List<? extends SqmTypedNode<?>>) path),
null,
null,
Expand All @@ -79,7 +80,7 @@ private static List<? extends SqmTypedNode<?>> mapPathParameters(NodeBuilder nod
throw new IllegalArgumentException("Path argument can not be null or empty list");
}
List<SqmTypedNode<?>> result = new ArrayList<>();
result.addAll(path.stream().map(p -> nodeBuilder.value(p)).collect(Collectors.toList()));
result.addAll(path.stream().map(p -> (SqmTypedNode<String>)nodeBuilder.value(p)).collect(Collectors.toList()));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public AbstractJsonBExtractPathDescriptor(String functionName) {

abstract protected T generateAbstractJsonBExtractPathImpl(Path referencedPathSource, List<SqmTypedNode<?>> pathArguments, NodeBuilder nodeBuilder);

protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine, TypeConfiguration typeConfiguration) {
protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine) {
List<SqmTypedNode<?>> pathArguments = new ArrayList<>();
for (int i = 1; i < arguments.size(); i++) {
pathArguments.add(arguments.get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public AbstractJsonbArrayStringsExistPredicateDescriptor(String name, HibernateC
abstract public String getSqmFunction();

@Override
protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine, TypeConfiguration typeConfiguration) {
protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine) {
return generateJsonbArrayStringsExistPredicate(this.hibernateContext, queryEngine.getCriteriaBuilder(), (JsonBExtractPath) arguments.get(0), (JsonArrayFunction) arguments.get(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.github.starnowski.posjsonhelper.core.HibernateContext;
import com.github.starnowski.posjsonhelper.hibernate6.operators.JsonArrayFunction;
import org.hibernate.query.ReturnableType;
import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
Expand Down Expand Up @@ -64,7 +65,7 @@ public JsonArrayFunctionDescriptor(HibernateContext hibernateContext) {
}

@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> translator) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, ReturnableType<?> returnableType, SqlAstTranslator<?> translator) {
sqlAppender.appendSql(this.getName());
sqlAppender.appendSql("[");

Expand All @@ -81,7 +82,7 @@ public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArg
}

@Override
protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine, TypeConfiguration typeConfiguration) {
protected <T> SelfRenderingSqmFunction<T> generateSqmFunctionExpression(List<? extends SqmTypedNode<?>> arguments, ReturnableType<T> impliedResultType, QueryEngine queryEngine) {
List<SqmExpression<String>> args = new ArrayList<>();
for (int i = 0; i < arguments.size(); i++) {
args.add((SqmExpression<String>) arguments.get(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
package com.github.starnowski.posjsonhelper.hibernate6.operators;

import com.github.starnowski.posjsonhelper.core.HibernateContext;
import org.hibernate.query.criteria.JpaExpression;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.function.FunctionRenderer;
import org.hibernate.query.sqm.function.FunctionRenderingSupport;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
Expand All @@ -41,7 +43,7 @@ public class JsonArrayFunction extends SelfRenderingSqmFunction<String> implemen

public JsonArrayFunction(NodeBuilder nodeBuilder, List<SqmExpression<String>> arguments, HibernateContext hibernateContext) {
super(nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(hibernateContext.getJsonFunctionJsonArrayOperator()),
(FunctionRenderingSupport) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(hibernateContext.getJsonFunctionJsonArrayOperator()),
(FunctionRenderer) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(hibernateContext.getJsonFunctionJsonArrayOperator()),
arguments,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
/**
* Posjsonhelper library is an open-source project that adds support of
* Hibernate query for https://www.postgresql.org/docs/10/functions-json.html)
*
* Copyright (C) 2023 Szymon Tarnowski
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
* Posjsonhelper library is an open-source project that adds support of
* Hibernate query for https://www.postgresql.org/docs/10/functions-json.html)
* <p>
* Copyright (C) 2023 Szymon Tarnowski
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package com.github.starnowski.posjsonhelper.hibernate6.predicates;

import com.github.starnowski.posjsonhelper.core.HibernateContext;
import com.github.starnowski.posjsonhelper.hibernate6.JsonBExtractPath;
import com.github.starnowski.posjsonhelper.hibernate6.operators.JsonArrayFunction;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.function.FunctionRenderingSupport;
import org.hibernate.query.sqm.function.FunctionRenderer;
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.expression.SqmExpression;
import org.hibernate.type.StandardBasicTypes;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -70,7 +71,7 @@ public AbstractJsonbArrayStringsExistPredicate(HibernateContext context, NodeBui

public AbstractJsonbArrayStringsExistPredicate(HibernateContext context, NodeBuilder nodeBuilder, JsonBExtractPath jsonBExtractPath, JsonArrayFunction arrayFunction, String functionName) {
super(nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(functionName),
(FunctionRenderingSupport) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(functionName),
(FunctionRenderer) nodeBuilder.getQueryEngine().getSqmFunctionRegistry().findFunctionDescriptor(functionName),
parameters(jsonBExtractPath, arrayFunction),
null,
null,
Expand All @@ -94,7 +95,7 @@ private static JsonArrayFunction mapArrayValues(NodeBuilder nodeBuilder, Hiberna
throw new IllegalArgumentException("Values can not be null or empty list");
}
List<SqmExpression<String>> arrayArguments = new ArrayList<>();
arrayArguments.addAll(Stream.of(values).map(p -> nodeBuilder.value(p)).collect(Collectors.toList()));
arrayArguments.addAll(Stream.of(values).map(p -> (SqmExpression<String>)nodeBuilder.value(p)).collect(Collectors.toList()));
JsonArrayFunction jsonArrayFunction = new JsonArrayFunction(nodeBuilder, arrayArguments, context);
return jsonArrayFunction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.starnowski.posjsonhelper.hibernate6
import jakarta.persistence.criteria.Path
import org.hibernate.query.spi.QueryEngine
import org.hibernate.query.sqm.NodeBuilder
import org.hibernate.query.sqm.function.FunctionRenderer
import org.hibernate.query.sqm.function.FunctionRenderingSupport
import org.hibernate.query.sqm.function.SqmFunctionDescriptor
import org.hibernate.query.sqm.function.SqmFunctionRegistry
Expand Down Expand Up @@ -90,5 +91,5 @@ abstract class AbstractJsonBExtractPathTest <T extends AbstractJsonBExtractPath>

protected abstract String expectedFunctionName()

private static interface TestInterfaceThatImplementsSqmFunctionDescriptorAndFunctionRenderingSupport extends SqmFunctionDescriptor, FunctionRenderingSupport {}
private static interface TestInterfaceThatImplementsSqmFunctionDescriptorAndFunctionRenderingSupport extends SqmFunctionDescriptor, FunctionRenderer {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class AbstractJsonBExtractPathDescriptorTest<T extends AbstractJsonBExt
org.hibernate.type.BasicType basicType = Mock(org.hibernate.type.BasicType)

when:
def result = tested.generateSqmFunctionExpression(arguments, null, queryEngine, null)
def result = tested.generateSqmFunctionExpression(arguments, null, queryEngine)

then:
queryEngine.getCriteriaBuilder() >> sqmCriteriaNodeBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class AbstractJsonbArrayStringsExistPredicateDescriptorTest <T extends
org.hibernate.type.BasicType basicType = Mock(org.hibernate.type.BasicType)

when:
def result = tested.generateSqmFunctionExpression(arguments, null, queryEngine, null)
def result = tested.generateSqmFunctionExpression(arguments, null, queryEngine)

then:
queryEngine.getCriteriaBuilder() >> sqmCriteriaNodeBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class JsonArrayFunctionDescriptorTest extends Specification {
hibernateContext.getJsonFunctionJsonArrayOperator() >> method

when:
def result = jsonArrayFunctionDescriptor.generateSqmFunctionExpression(arguments, null, queryEngine, null)
def result = jsonArrayFunctionDescriptor.generateSqmFunctionExpression(arguments, null, queryEngine)

then:
queryEngine.getCriteriaBuilder() >> criteriaBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.starnowski.posjsonhelper.hibernate6.operators.JsonArrayFunctio
import jakarta.persistence.criteria.Path
import org.hibernate.query.spi.QueryEngine
import org.hibernate.query.sqm.NodeBuilder
import org.hibernate.query.sqm.function.FunctionRenderer
import org.hibernate.query.sqm.function.FunctionRenderingSupport
import org.hibernate.query.sqm.function.SqmFunctionDescriptor
import org.hibernate.query.sqm.function.SqmFunctionRegistry
Expand Down Expand Up @@ -99,5 +100,5 @@ abstract class AbstractJsonbArrayStringsExistPredicateTest <T extends AbstractJs

protected abstract String expectedFunctionName()

private static interface TestInterfaceThatImplementsSqmFunctionDescriptorAndFunctionRenderingSupport extends SqmFunctionDescriptor, FunctionRenderingSupport {}
private static interface TestInterfaceThatImplementsSqmFunctionDescriptorAndFunctionRenderingSupport extends SqmFunctionDescriptor, FunctionRenderer {}
}
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<module>json-core</module>
<module>hibernate6-core</module>
<module>text</module>
<module>text/hibernate6-text</module>
</modules>

<properties>
Expand Down
1 change: 0 additions & 1 deletion text/hibernate6-text-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${org.hibernate.hibernate.core.version}</version>
</dependency>
<dependency>
<groupId>com.github.starnowski.posjsonhelper.text</groupId>
Expand Down
6 changes: 1 addition & 5 deletions text/hibernate6-text/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.starnowski.posjsonhelper</groupId>
<groupId>com.github.starnowski.posjsonhelper.text</groupId>
<artifactId>parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<groupId>com.github.starnowski.posjsonhelper.text</groupId>
<artifactId>hibernate6-text</artifactId>

<properties>
<org.hibernate.hibernate.core.version>6.1.5.Final</org.hibernate.hibernate.core.version>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand All @@ -25,8 +23,6 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${org.hibernate.hibernate.core.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.starnowski.posjsonhelper</groupId>
Expand Down
Loading

0 comments on commit 9bb9a88

Please sign in to comment.