Skip to content

Commit

Permalink
Bump hibernate.version from 6.2.7.Final to 6.3.1.Final (#3083)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-tay authored Oct 7, 2023
1 parent c84fa2a commit e9e7438
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.yahoo.elide.core.Path;
import com.yahoo.elide.core.exceptions.InvalidValueException;
import com.yahoo.elide.core.filter.predicates.FilterPredicate;
import com.yahoo.elide.core.type.ClassType;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -30,6 +31,7 @@ public class CaseAwareJPQLGenerator implements JPQLPredicateGenerator {
private Case upperOrLower;
private String jpqlTemplate;
private ArgumentCount argumentCount;
private boolean castFieldAsString;

/**
* Whether to use uppercase, lowercase, or not transformation for case insensitive queries.
Expand Down Expand Up @@ -68,9 +70,15 @@ public enum ArgumentCount {
* @param argumentCount ZERO, ONE, or MANY
*/
public CaseAwareJPQLGenerator(String jpqlTemplate, Case upperOrLower, ArgumentCount argumentCount) {
this(jpqlTemplate, upperOrLower, argumentCount, false);
}

public CaseAwareJPQLGenerator(String jpqlTemplate, Case upperOrLower, ArgumentCount argumentCount,
boolean castFieldAsString) {
this.upperOrLower = upperOrLower;
this.jpqlTemplate = jpqlTemplate;
this.argumentCount = argumentCount;
this.castFieldAsString = castFieldAsString;
}

@Override
Expand All @@ -94,6 +102,14 @@ public String generate(FilterPredicate predicate, Function<Path, String> aliasGe
}
}

if (castFieldAsString) {
// In JPQL the like operator can only be used on string operands
// @see https://github.com/hibernate/hibernate-orm/commit/935ac494dd19fc84672f64f5bd40b2b9ed7c76c3
if (!ClassType.of(String.class).isAssignableFrom(predicate.getFieldType())) {
columnAlias = "CONCAT(" + columnAlias + ",'')";
}
}

return String.format(jpqlTemplate, upperOrLower.wrap(columnAlias), parameters.stream()
.map(upperOrLower::wrap)
.collect(Collectors.joining(COMMA)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,73 +102,85 @@ public class FilterTranslator implements FilterOperation<String> {
GLOBAL_OPERATOR_GENERATORS.put(PREFIX, new CaseAwareJPQLGenerator(
"%s LIKE CONCAT(%s, '%%')",
CaseAwareJPQLGenerator.Case.NONE,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(NOT_PREFIX, new CaseAwareJPQLGenerator(
"%s NOT LIKE CONCAT(%s, '%%')",
CaseAwareJPQLGenerator.Case.NONE,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(PREFIX_CASE_INSENSITIVE, new CaseAwareJPQLGenerator(
"%s LIKE CONCAT(%s, '%%')",
CaseAwareJPQLGenerator.Case.LOWER,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(NOT_PREFIX_CASE_INSENSITIVE, new CaseAwareJPQLGenerator(
"%s NOT LIKE CONCAT(%s, '%%')",
CaseAwareJPQLGenerator.Case.LOWER,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(POSTFIX, new CaseAwareJPQLGenerator(
"%s LIKE CONCAT('%%', %s)",
CaseAwareJPQLGenerator.Case.NONE,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(NOT_POSTFIX, new CaseAwareJPQLGenerator(
"%s NOT LIKE CONCAT('%%', %s)",
CaseAwareJPQLGenerator.Case.NONE,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(POSTFIX_CASE_INSENSITIVE, new CaseAwareJPQLGenerator(
"%s LIKE CONCAT('%%', %s)",
CaseAwareJPQLGenerator.Case.LOWER,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(NOT_POSTFIX_CASE_INSENSITIVE, new CaseAwareJPQLGenerator(
"%s NOT LIKE CONCAT('%%', %s)",
CaseAwareJPQLGenerator.Case.LOWER,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(INFIX, new CaseAwareJPQLGenerator(
"%s LIKE CONCAT('%%', CONCAT(%s, '%%'))",
CaseAwareJPQLGenerator.Case.NONE,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(NOT_INFIX, new CaseAwareJPQLGenerator(
"%s NOT LIKE CONCAT('%%', CONCAT(%s, '%%'))",
CaseAwareJPQLGenerator.Case.NONE,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(INFIX_CASE_INSENSITIVE, new CaseAwareJPQLGenerator(
"%s LIKE CONCAT('%%', CONCAT(%s, '%%'))",
CaseAwareJPQLGenerator.Case.LOWER,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(NOT_INFIX_CASE_INSENSITIVE, new CaseAwareJPQLGenerator(
"%s NOT LIKE CONCAT('%%', CONCAT(%s, '%%'))",
CaseAwareJPQLGenerator.Case.LOWER,
CaseAwareJPQLGenerator.ArgumentCount.ONE)
CaseAwareJPQLGenerator.ArgumentCount.ONE,
true)
);

GLOBAL_OPERATOR_GENERATORS.put(LT, (predicate, aliasGenerator) -> {
Expand Down
7 changes: 0 additions & 7 deletions elide-datastore/elide-datastore-search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@
<artifactId>jakarta.persistence-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<!-- This override is for hibernate-search-mapper-orm-orm6 6.1 fails with 6.2.2.Final -->
<version>6.2.7.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate.search</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<graal-sdk.version>23.1.0</graal-sdk.version>
<guava.version>32.1.1-jre</guava.version>
<handlebars.version>4.3.1</handlebars.version>
<hibernate.version>6.2.7.Final</hibernate.version>
<hibernate.version>6.3.1.Final</hibernate.version>
<hibernate-validator.version>8.0.0.Final</hibernate-validator.version>
<hibernate-search.version>6.2.1.Final</hibernate-search.version>
<hjson.version>3.0.1</hjson.version>
Expand Down

0 comments on commit e9e7438

Please sign in to comment.