TypedQueryBuilder { <U extends T> Predicate createPredicate(SqlPredicate sqlPredicate, Root<U> root) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); String operator = sqlPredicate.getOperator(); String leftExpression = sqlPredicate.getLeftExpression(); String attributeName = leftExpression.split("\\.")[1]; Object rightExpression = sqlPredicate.getRightExpression(); Predicate predicate = null; switch (operator) { case "=": predicate = criteriaBuilder.equal(root.get(attributeName), rightExpression); break; case "<": predicate = getLTPredicateFromExpression(attributeName, rightExpression, root); break; case "<=": predicate = getLTEPredicateFromExpression(attributeName, rightExpression, root); break; case ">": predicate = getGTPredicateFromExpression(attributeName, rightExpression, root); break; case ">=": predicate = getGTEPredicateFromExpression(attributeName, rightExpression, root); break; default: LOGGER.warn("Criteria equivalent of SQL operator '{}' is not yet supported", operator); } return predicate; } TypedQueryBuilder(OpaCompilerResponse opaCompilerResponse, EntityManager entityManager); TypedQuery<S> getTypedQuery(Class<S> domainClass, Sort sort);  }
@Test void shouldCreatePredicateEqualOperatorStringType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "=", "alice"); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateEqualOperatorBooleanType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "=", true); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateEqualOperatorIntegerType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "=", 5); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateEqualOperatorLongType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "=", 5L); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateEqualOperatorDoubleType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "=", 3.145); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateLTOperatorWithIntegerType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "<", 6); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateLTOperatorWithLongType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "<", 6L); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateLTOperatorWithDoubleType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "<", 4.12); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateLTEOperatorWithIntegerType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "<=", 6); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateLTEOperatorWithLongType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "<=", 2L); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateLTEOperatorWithDoubleType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "<=", 3.1354695); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateGTOperatorWithIntegerType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", ">", 405); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateGTOperatorWithLongType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", ">", 405L); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateGTOperatorWithDoubleType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", ">", 4.34); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateGTEOperatorIntegerType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", ">=", 3); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateGTEOperatorWithLongType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", ">=", 3L); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }
@Test void shouldCreatePredicateGTEOperatorWithDoubleType() { Root<PetEntity> root = getPetEntityRoot(); SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", ">=", 21.4535); Predicate result = target.createPredicate(sqlPredicate1, root); assertThat(result, is(notNullValue())); }