From 87020d0532749fb0040c0da308153a92d9672da4 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Mon, 9 Dec 2024 16:55:15 +0200 Subject: [PATCH] Improve JPA Provider portability - RSQL Signed-off-by: Avgustin Marinov --- .../SoftwareModuleTypeManagement.java | 8 +- .../management/JpaControllerManagement.java | 22 ++--- .../jpa/model/AbstractJpaBaseEntity.java | 14 +-- .../SoftwareModuleTypeRepository.java | 18 ++-- .../jpa/rsql/JpaQueryRsqlVisitorG2.java | 90 +++++++++++-------- .../jpa/rsql/RSQLActionFieldsTest.java | 2 - .../rsql/RSQLDistributionSetFieldTest.java | 12 +-- .../jpa/rsql/RSQLRolloutGroupFieldTest.java | 2 - .../jpa/rsql/RSQLSoftwareModuleFieldTest.java | 2 - .../RSQLSoftwareModuleTypeFieldsTest.java | 2 - .../jpa/rsql/RSQLTargetFieldTest.java | 2 - .../rsql/RSQLTargetFilterQueryFieldsTest.java | 2 - .../repository/jpa/rsql/RSQLUtilityTest.java | 13 ++- 13 files changed, 87 insertions(+), 102 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeManagement.java index 2a73a11c7d..c5a11b24e9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeManagement.java @@ -27,17 +27,15 @@ public interface SoftwareModuleTypeManagement /** * @param key to search for - * @return {@link SoftwareModuleType} in the repository with given - * {@link SoftwareModuleType#getKey()} + * @return {@link SoftwareModuleType} in the repository with given {@link SoftwareModuleType#getKey()} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Optional getByKey(@NotEmpty String key); /** * @param name to search for - * @return all {@link SoftwareModuleType}s in the repository with given - * {@link SoftwareModuleType#getName()} + * @return all {@link SoftwareModuleType}s in the repository with given {@link SoftwareModuleType#getName()} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Optional getByName(@NotEmpty String name); -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java index 0ffbcd6bd9..1317ea8c85 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java @@ -64,6 +64,7 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.InvalidTargetAttributeException; +import org.eclipse.hawkbit.repository.jpa.Jpa; import org.eclipse.hawkbit.repository.jpa.acm.AccessController; import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusCreate; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; @@ -748,24 +749,17 @@ private Void updateLastTargetQueries(final String tenant, final List } /** - * Sets {@link Target#getLastTargetQuery()} by native SQL in order to avoid - * raising opt lock revision as this update is not mission critical and in - * fact only written by {@link ControllerManagement}, i.e. the target - * itself. + * Sets {@link Target#getLastTargetQuery()} by native SQL in order to avoid raising opt lock revision as this update is not mission-critical + * and in fact only written by {@link ControllerManagement}, i.e. the target itself. */ private void setLastTargetQuery(final String tenant, final long currentTimeMillis, final List chunk) { - final Map paramMapping = new HashMap<>(chunk.size()); - - for (int i = 0; i < chunk.size(); i++) { - paramMapping.put("cid" + i, chunk.get(i)); - } - final Query updateQuery = entityManager.createNativeQuery( - "UPDATE sp_target SET last_target_query = #last_target_query WHERE controller_id IN (" - + formatQueryInStatementParams(paramMapping.keySet()) + ") AND tenant = #tenant"); + "UPDATE sp_target SET last_target_query = " + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "last_target_query " + + "WHERE controller_id IN (" + Jpa.formatNativeQueryInClause("cid", chunk) + ")" + + " AND tenant = " + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "tenant"); - paramMapping.forEach(updateQuery::setParameter); updateQuery.setParameter("last_target_query", currentTimeMillis); + Jpa.setNativeQueryInParameter(updateQuery, "cid", chunk); updateQuery.setParameter("tenant", tenant); final int updated = updateQuery.executeUpdate(); @@ -1108,4 +1102,4 @@ public boolean equals(final Object obj) { } } -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java index 90bb9ede71..3109eccbd9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java @@ -104,6 +104,12 @@ public void setCreatedAt(final long createdAt) { } } + @Column(name = "created_at", updatable = false, nullable = false) + @Access(AccessType.PROPERTY) + public long getCreatedAt() { + return createdAt; + } + @LastModifiedBy public void setLastModifiedBy(final String lastModifiedBy) { if (isController()) { @@ -113,13 +119,7 @@ public void setLastModifiedBy(final String lastModifiedBy) { this.lastModifiedBy = lastModifiedBy; } - // maybe needed to have correct createdAt value in the database - @Access(AccessType.PROPERTY) - public long getCreatedAt() { - return createdAt; - } - - // seems needed to have correct lastModifiedBy value in the database + @Column(name = "last_modified_by", nullable = false, length = USERNAME_FIELD_LENGTH) @Access(AccessType.PROPERTY) public String getLastModifiedBy() { return lastModifiedBy; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/SoftwareModuleTypeRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/SoftwareModuleTypeRepository.java index 8e6535d996..1c6ec02f7f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/SoftwareModuleTypeRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/SoftwareModuleTypeRepository.java @@ -25,28 +25,24 @@ * Repository for {@link SoftwareModuleType}. */ @Transactional(readOnly = true) -public interface SoftwareModuleTypeRepository - extends BaseEntityRepository { +public interface SoftwareModuleTypeRepository extends BaseEntityRepository { /** * @param key to search for - * @return all {@link SoftwareModuleType}s in the repository with given - * {@link SoftwareModuleType#getKey()} + * @return all {@link SoftwareModuleType}s in the repository with given {@link SoftwareModuleType#getKey()} */ Optional findByKey(String key); /** * @param name to search for - * @return all {@link SoftwareModuleType}s in the repository with given - * {@link SoftwareModuleType#getName()} + * @return all {@link SoftwareModuleType}s in the repository with given {@link SoftwareModuleType#getName()} */ Optional findByName(String name); /** - * Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety - * reasons (this is a "delete everything" query after all) we add the tenant - * manually to query even if this will by done by {@link EntityManager} - * anyhow. The DB should take care of optimizing this away. + * Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety reasons (this is a "delete everything" query + * after all) we add the tenant manually to query even if this is done by {@link EntityManager} anyhow. The DB should take + * care of optimizing this away. * * @param tenant to delete data from */ @@ -54,4 +50,4 @@ public interface SoftwareModuleTypeRepository @Transactional @Query("DELETE FROM JpaSoftwareModuleType t WHERE t.tenant = :tenant") void deleteByTenant(@Param("tenant") String tenant); -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java index 61e2f004a3..ac50e01505 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java @@ -17,11 +17,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.function.Function; -import java.util.stream.Collectors; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; -import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.JoinType; import jakarta.persistence.criteria.MapJoin; import jakarta.persistence.criteria.Path; @@ -185,7 +183,7 @@ private Predicate mapToMapPredicate(final QuertPath queryField, final Path fi final String keyValue = graph[graph.length - 1]; if (fieldPath instanceof MapJoin) { // Currently we support only string key. So below cast is safe. - return equal((Expression) (((MapJoin) fieldPath).key()), keyValue); + return equal((Path) (((MapJoin) fieldPath).key()), keyValue); } final String keyFieldName = queryField.getEnumValue().getSubEntityMapTuple().map(Entry::getKey) @@ -225,7 +223,7 @@ private Predicate getEqualToPredicate(final Path fieldPath, final Object tran return cb.or(cb.isNull(fieldPath), cb.equal(pathOfString(fieldPath), "")); } - final Expression stringExpression = pathOfString(fieldPath); + final Path stringExpression = pathOfString(fieldPath); if (isPattern(transformedValueStr)) { // a pattern, use like return like(stringExpression, toSQL(transformedValueStr)); } else { @@ -311,14 +309,10 @@ private Path getPath(final Root root, final String fieldNameSplit) { } } - private Object convertValueIfNecessary( - final ComparisonNode node, final A fieldName, final Path fieldPath, final String value) { - // in case the value of an RSQL query e.g. type==application is an - // enum we need to handle it separately because JPA needs the - // correct java-type to build an expression. So String and numeric - // values JPA can do it by its own but not for classes like enums. - // So we need to transform the given value string into the enum - // class. + private Object convertValueIfNecessary(final ComparisonNode node, final A fieldName, final Path fieldPath, final String value) { + // in case the value of an RSQL query e.g. type==application is an enum we need to handle it separately because JPA needs the + // correct java-type to build an expression. So String and numeric values JPA can do it by its own but not for classes like enums. + // So we need to transform the given value string into the enum class. final Class javaType = fieldPath.getJavaType(); if (javaType != null && javaType.isEnum()) { return transformEnumValue(node, javaType, value); @@ -327,7 +321,7 @@ private Object convertValueIfNecessary( return convertFieldConverterValue(node, fieldName, value); } - if (Boolean.TYPE.equals(javaType)) { + if (Boolean.TYPE.equals(javaType) || Boolean.class.equals(javaType)) { return convertBooleanValue(node, javaType, value); } @@ -368,7 +362,7 @@ private Predicate toNullOrNotEqualPredicate(final Path fieldPath, final Objec @SuppressWarnings({ "unchecked", "rawtypes" }) private Predicate toNotExistsSubQueryPredicate(final QuertPath queryField, final Path fieldPath, - final Function, Predicate> subQueryPredicateProvider) { + final Function, Predicate> subQueryPredicateProvider) { // if a subquery the field's parent joins are not actually used if (!inOr) { // so, if not in or (hence not reused) we remove them. Parent shall be a Join @@ -383,24 +377,27 @@ private Predicate toNotExistsSubQueryPredicate(final QuertPath queryField, final .where(cb.and( cb.equal(root.get(queryField.getEnumValue().identifierFieldName()), subqueryRoot.get(queryField.getEnumValue().identifierFieldName())), - subQueryPredicateProvider.apply(getExpressionToCompare(queryField.getEnumValue(), - getFieldPath(subqueryRoot, queryField))))))); + subQueryPredicateProvider.apply( + getExpressionToCompare(queryField.getEnumValue(), + getFieldPath(subqueryRoot, queryField))))))); } @SuppressWarnings({ "rawtypes", "unchecked" }) - private Expression getExpressionToCompare(final A enumField, final Path fieldPath) { + private Path getExpressionToCompare(final A enumField, final Path fieldPath) { if (!enumField.isMap()) { return pathOfString(fieldPath); } if (fieldPath instanceof MapJoin) { // Currently we support only string key. So below cast is safe. - return (Expression) (((MapJoin) fieldPath).value()); + return (Path) (((MapJoin) fieldPath).value()); } return enumField.getSubEntityMapTuple() .map(Entry::getValue) .map(valueFieldName -> fieldPath. get(valueFieldName)) - .orElseThrow(() -> new UnsupportedOperationException( - "For the fields, defined as Map, only Map java type or tuple in the form of SimpleImmutableEntry are allowed. Neither of those could be found!")); + .orElseThrow(() -> + new UnsupportedOperationException( + "For the fields, defined as Map, only Map java type or tuple in the form of SimpleImmutableEntry are allowed." + + " Neither of those could be found!")); } private String toSQL(final String transformedValue) { @@ -437,33 +434,50 @@ private List acceptChildren(final LogicalNode node) { return children; } - private Predicate equal(final Expression expressionToCompare, final String sqlValue) { - return cb.equal(caseWise(cb, expressionToCompare), caseWise(sqlValue)); - } - - private Predicate notEqual(final Expression expressionToCompare, String transformedValueStr) { - return cb.notEqual(caseWise(cb, expressionToCompare), caseWise(transformedValueStr)); + private Predicate equal(final Path expressionToCompare, final String sqlValue) { + if (caseWise(expressionToCompare)) { + return cb.equal(cb.upper(expressionToCompare), sqlValue.toUpperCase()); + } else { + return cb.equal(expressionToCompare, sqlValue); + } } - private Predicate like(final Expression expressionToCompare, final String sqlValue) { - return cb.like(caseWise(cb, expressionToCompare), caseWise(sqlValue), ESCAPE_CHAR); + private Predicate notEqual(final Path expressionToCompare, String transformedValueStr) { + if (caseWise(expressionToCompare)) { + return cb.notEqual(cb.upper(expressionToCompare), transformedValueStr.toUpperCase()); + } else { + return cb.notEqual(expressionToCompare, transformedValueStr); + } } - private Predicate notLike(final Expression expressionToCompare, final String sqlValue) { - return cb.notLike(caseWise(cb, expressionToCompare), caseWise(sqlValue), ESCAPE_CHAR); + private Predicate like(final Path expressionToCompare, final String sqlValue) { + if (caseWise(expressionToCompare)) { + return cb.like(cb.upper(expressionToCompare), sqlValue.toUpperCase(), ESCAPE_CHAR); + } else { + return cb.like(expressionToCompare, sqlValue, ESCAPE_CHAR); + } } - private Predicate in(final Expression expressionToCompare, final List transformedValues) { - final List inParams = transformedValues.stream().filter(String.class::isInstance) - .map(String.class::cast).map(this::caseWise).collect(Collectors.toList()); - return inParams.isEmpty() ? expressionToCompare.in(transformedValues) : caseWise(cb, expressionToCompare).in(inParams); + private Predicate notLike(final Path expressionToCompare, final String sqlValue) { + if (caseWise(expressionToCompare)) { + return cb.notLike(cb.upper(expressionToCompare), sqlValue.toUpperCase(), ESCAPE_CHAR); + } else { + return cb.notLike(expressionToCompare, sqlValue, ESCAPE_CHAR); + } } - private Expression caseWise(final CriteriaBuilder cb, final Expression expression) { - return ensureIgnoreCase ? cb.upper(expression) : expression; + private Predicate in(final Path expressionToCompare, final List transformedValues) { + if (ensureIgnoreCase && expressionToCompare.getJavaType() == String.class) { + final List inParams = transformedValues.stream() + .filter(String.class::isInstance) + .map(String.class::cast).map(String::toUpperCase).toList(); + return inParams.isEmpty() ? expressionToCompare.in(transformedValues) : cb.upper(expressionToCompare).in(inParams); + } else { + return expressionToCompare.in(transformedValues); + } } - private String caseWise(final String str) { - return ensureIgnoreCase ? str.toUpperCase() : str; + private boolean caseWise(final Path fieldPath) { + return ensureIgnoreCase && fieldPath.getJavaType() == String.class; } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java index 7ea5b6583f..d2f0e05d7a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java @@ -63,8 +63,6 @@ public void testFilterByParameterId() { return; } - assertRSQLQuery(ActionFields.ID.name() + "==*", 11); - assertRSQLQuery(ActionFields.ID.name() + "==noexist*", 0); assertRSQLQuery(ActionFields.ID.name() + "=in=(" + action.getId() + ",10000000)", 1); assertRSQLQuery(ActionFields.ID.name() + "=out=(" + action.getId() + ",10000000)", 10); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java index 0daa761c18..3671109503 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java @@ -81,8 +81,6 @@ public void testFilterByParameterId() { return; } - assertRSQLQuery(DistributionSetFields.ID.name() + "==*", 5); - assertRSQLQuery(DistributionSetFields.ID.name() + "==noexist*", 0); assertRSQLQuery(DistributionSetFields.ID.name() + "=in=(" + ds.getId() + ",10000000)", 1); assertRSQLQuery(DistributionSetFields.ID.name() + "=out=(" + ds.getId() + ",10000000)", 4); } @@ -104,8 +102,8 @@ public void testFilterBySoftwareModule() { assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.NAME.name() + "==" + sm.getName(), 1); assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "==" + sm.getId(), 1); assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.NAME.name() + "==noExist", 0); - assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "=in=(" + sm.getId() + ", noExist)", 1); - assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "=out=(" + sm.getId() + ", noExist)", 4); + assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "=in=(" + sm.getId() + ", -1)", 1); + assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "=out=(" + sm.getId() + ", -1)", 4); } @Test @@ -128,10 +126,8 @@ public void testFilterByParameterDescription() { public void testFilterByParameterVersion() { assertRSQLQuery(DistributionSetFields.VERSION.name() + "==" + TestdataFactory.DEFAULT_VERSION, 1); assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=" + TestdataFactory.DEFAULT_VERSION, 4); - assertRSQLQuery( - DistributionSetFields.VERSION.name() + "=in=(" + TestdataFactory.DEFAULT_VERSION + ",1.0.0,1.0.1)", 3); - assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(" + TestdataFactory.DEFAULT_VERSION + ",error)", - 4); + assertRSQLQuery(DistributionSetFields.VERSION.name() + "=in=(" + TestdataFactory.DEFAULT_VERSION + ",1.0.0,1.0.1)", 3); + assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(" + TestdataFactory.DEFAULT_VERSION + ",error)", 4); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFieldTest.java index d92ff5b164..3d20dac13a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFieldTest.java @@ -58,8 +58,6 @@ public void testFilterByParameterId() { return; } - assertRSQLQuery(RolloutGroupFields.ID.name() + "==*", 4); - assertRSQLQuery(RolloutGroupFields.ID.name() + "==noexist*", 0); assertRSQLQuery(RolloutGroupFields.ID.name() + "=in=(" + rolloutGroupId + ",10000000)", 1); assertRSQLQuery(RolloutGroupFields.ID.name() + "=out=(" + rolloutGroupId + ",10000000)", 3); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java index 399d0e0c91..e7d3e031cb 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java @@ -71,8 +71,6 @@ public void testFilterByParameterId() { return; } - assertRSQLQuery(SoftwareModuleFields.ID.name() + "==*", 6); - assertRSQLQuery(SoftwareModuleFields.ID.name() + "==noexist*", 0); assertRSQLQuery(SoftwareModuleFields.ID.name() + "=in=(" + ah.getId() + ",1000000)", 1); assertRSQLQuery(SoftwareModuleFields.ID.name() + "=out=(" + ah.getId() + ",1000000)", 5); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java index 5c27267f21..f8d4afa546 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java @@ -40,8 +40,6 @@ public void testFilterByParameterId() { return; } - assertRSQLQuery(SoftwareModuleTypeFields.ID.name() + "==*", 3); - assertRSQLQuery(SoftwareModuleTypeFields.ID.name() + "==noexist*", 0); assertRSQLQuery(SoftwareModuleTypeFields.ID.name() + "=in=(" + osType.getId() + ",1000000)", 1); assertRSQLQuery(SoftwareModuleTypeFields.ID.name() + "=out=(" + osType.getId() + ",1000000)", 2); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java index 1f062d5b31..dd2cceac5d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java @@ -104,8 +104,6 @@ void setupBeforeTest() { @Description("Test filter target by (controller) id") void testFilterByParameterId() { assertRSQLQuery(TargetFields.ID.name() + "==targetId123", 1); - assertRSQLQuery(TargetFields.ID.name() + "==target*", 5); - assertRSQLQuery(TargetFields.ID.name() + "==noExist*", 0); assertRSQLQuery(TargetFields.ID.name() + "!=targetId123", 4); assertRSQLQuery(TargetFields.ID.name() + "=in=(targetId123,notexist)", 1); assertRSQLQuery(TargetFields.ID.name() + "=out=(targetId123,notexist)", 4); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFilterQueryFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFilterQueryFieldsTest.java index 0e6e10fd8b..dfb71bb20f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFilterQueryFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFilterQueryFieldsTest.java @@ -65,8 +65,6 @@ public void testFilterByParameterId() { return; } - assertRSQLQuery(TargetFilterQueryFields.ID.name() + "==*", 3); - assertRSQLQuery(TargetFilterQueryFields.ID.name() + "==noexist*", 0); assertRSQLQuery(TargetFilterQueryFields.ID.name() + "=in=(" + filter1.getId() + ",10000000)", 1); assertRSQLQuery(TargetFilterQueryFields.ID.name() + "=out=(" + filter1.getId() + ",10000000)", 2); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java index 929b99bb82..26430c2d26 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java @@ -270,7 +270,7 @@ public void correctRsqlBuildsSimpleNotEqualPredicate() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name!=abc"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); - when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class); + when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class); when(criteriaBuilderMock.isNull(any(Expression.class))).thenReturn(mock(Predicate.class)); when(criteriaBuilderMock.notEqual(any(Expression.class), anyString())) @@ -285,8 +285,7 @@ public void correctRsqlBuildsSimpleNotEqualPredicate() { // verification verify(criteriaBuilderMock, times(1)).or(any(Predicate.class), any(Predicate.class)); verify(criteriaBuilderMock, times(1)).isNull(eq(pathOfString(baseSoftwareModuleRootMock))); - verify(criteriaBuilderMock, times(1)).notEqual(eq(pathOfString(baseSoftwareModuleRootMock)), - eq("abc".toUpperCase())); + verify(criteriaBuilderMock, times(1)).notEqual(eq(pathOfString(baseSoftwareModuleRootMock)), eq("abc".toUpperCase())); } @Test @@ -294,7 +293,7 @@ public void correctRsqlBuildsSimpleNotLikePredicate() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name!=abc*"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); - when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class); + when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class); when(criteriaBuilderMock.isNull(any(Expression.class))).thenReturn(mock(Predicate.class)); when(criteriaBuilderMock.notLike(any(Expression.class), anyString(), eq('\\'))) @@ -346,7 +345,7 @@ public void correctRsqlBuildsEqualPredicateWithPercentage() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name==a%"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); - when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class); + when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class); when(criteriaBuilderMock.equal(any(Expression.class), anyString())).thenReturn(mock(Predicate.class)); when(criteriaBuilderMock. greaterThanOrEqualTo(any(Expression.class), any(String.class))) .thenReturn(mock(Predicate.class)); @@ -367,7 +366,7 @@ public void correctRsqlBuildsLikePredicateWithPercentage() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name==a%*"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); - when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class); + when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class); when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class)); when(criteriaBuilderMock. greaterThanOrEqualTo(any(Expression.class), any(String.class))) .thenReturn(mock(Predicate.class)); @@ -388,7 +387,7 @@ public void correctRsqlBuildsLikePredicateWithPercentageSQLServer() { reset0(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); final String correctRsql = "name==a%*"; when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock); - when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class); + when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class); when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock)))) .thenReturn(pathOfString(baseSoftwareModuleRootMock)); when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));