Search in sources :

Example 1 with BooleanExpression

use of com.querydsl.core.types.dsl.BooleanExpression in project Settler by EmhyrVarEmreis.

the class PermissionManagerImplementation method isAuthorized.

@Override
public boolean isAuthorized(PrivilegeObject source, PrivilegeObject target, OperationType operationType) {
    BooleanExpression expression = jTBObjectHierarchy.objectFrom.id.eq(jTBObjectPrivilege.objectTo.id).and(jTBObjectHierarchy.objectTo.id.eq(target.getId()));
    expression = expression.or(jTBObjectPrivilege.objectTo.id.eq(target.getId()));
    expression = expression.or(jTBObjectPrivilege.objectTo.isNull());
    return new JPAQuery<Void>(entityManager).select(Expressions.ONE).from(jTBObjectPrivilege, jTBObjectHierarchy).where(jTBObjectPrivilege.objectFrom.id.eq(source.getId()), (jTBObjectPrivilege.operationType.eq(operationType)), expression).fetchFirst() != null;
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression)

Example 2 with BooleanExpression

use of com.querydsl.core.types.dsl.BooleanExpression in project JavaForFun by gumartinm.

the class AdDescriptionServiceImpl method queryDslExample.

// Extending CrudServiceImpl when we need some business logic. Otherwise we would be using
// the JPA repositories and nothing else :)
// In this case there is any business logic, but this is just an example.
/**
 * Using Querydsl. Giving some business logic to this service :)
 *
 * Querydsl: fluent interface done easy. There is no effort because it is already implemented.
 *
 * Criteria using Specifications requires some effort.
 *
 * See: de.spring.example.services.impl.AdServiceImpl
 */
@Override
public Page<AdDescription> queryDslExample(Pageable pageRequest) {
    final QAdDescription adDescription = QAdDescription.adDescription1;
    final BooleanExpression adDescriptionHasAdLink = adDescription.adLink.contains("gumartinm");
    final BooleanExpression adDescriptionHasDescription = adDescription.adDescription.contains("babucha");
    /**
     * https://github.com/spring-projects/spring-data-envers/pull/45
     * return repository.findAll(adDescriptionHasAdLink.and(adDescriptionHasDescription), pageRequest);
     */
    return null;
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) QAdDescription(de.spring.example.persistence.domain.QAdDescription)

Example 3 with BooleanExpression

use of com.querydsl.core.types.dsl.BooleanExpression in project tutorials by eugenp.

the class UserController method findAllByQuerydsl.

@RequestMapping(method = RequestMethod.GET, value = "/myusers")
@ResponseBody
public Iterable<MyUser> findAllByQuerydsl(@RequestParam(value = "search") String search) {
    MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder();
    if (search != null) {
        Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),");
        Matcher matcher = pattern.matcher(search + ",");
        while (matcher.find()) {
            builder.with(matcher.group(1), matcher.group(2), matcher.group(3));
        }
    }
    BooleanExpression exp = builder.build();
    return myUserRepository.findAll(exp);
}
Also used : Pattern(java.util.regex.Pattern) BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) MyUserPredicatesBuilder(org.baeldung.persistence.dao.MyUserPredicatesBuilder) Matcher(java.util.regex.Matcher) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with BooleanExpression

use of com.querydsl.core.types.dsl.BooleanExpression in project modesti by jlsalmon.

the class Predicate method getStringPredicate.

private BooleanExpression getStringPredicate(PathBuilder<T> entityPath, String argument) {
    StringPath path = entityPath.getString(criteria.getKey());
    BooleanExpression expression;
    if (argument.startsWith("*") && argument.endsWith("*")) {
        expression = path.containsIgnoreCase(argument.substring(1, argument.length() - 1));
    } else if (argument.startsWith("*")) {
        expression = path.endsWithIgnoreCase(argument.substring(1, argument.length()));
    } else if (argument.endsWith("*")) {
        expression = path.startsWithIgnoreCase(argument.substring(0, argument.length() - 1));
    } else {
        expression = path.equalsIgnoreCase(argument);
    }
    if (RSQLOperators.EQUAL.equals(criteria.getOperation())) {
        return expression;
    } else {
        return expression.not();
    }
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) StringPath(com.querydsl.core.types.dsl.StringPath)

Example 5 with BooleanExpression

use of com.querydsl.core.types.dsl.BooleanExpression in project querydsl by querydsl.

the class JPABase method subquery_uniqueResult.

@Test
// isn't a valid JPQL query
@Ignore
public void subquery_uniqueResult() {
    QCat cat2 = new QCat("cat2");
    BooleanExpression exists = selectOne().from(cat2).where(cat2.eyecolor.isNotNull()).exists();
    assertNotNull(query().from(cat).where(cat.breed.eq(0).not()).select(new QCatSummary(cat.breed.count(), exists)).fetchOne());
}
Also used : BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

BooleanExpression (com.querydsl.core.types.dsl.BooleanExpression)30 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)4 StringPath (com.querydsl.core.types.dsl.StringPath)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 Predicate (com.querydsl.core.types.Predicate)2 Field (java.lang.reflect.Field)2 LinkedList (java.util.LinkedList)2 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 RelationalValueSearchQuery (com.evolveum.midpoint.schema.RelationalValueSearchQuery)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 LookupTableRowType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Tuple (com.querydsl.core.Tuple)1 Expression (com.querydsl.core.types.Expression)1 OrderSpecifier (com.querydsl.core.types.OrderSpecifier)1 ComparableExpressionBase (com.querydsl.core.types.dsl.ComparableExpressionBase)1 EntityPathBase (com.querydsl.core.types.dsl.EntityPathBase)1 StringExpression (com.querydsl.core.types.dsl.StringExpression)1 QAdDescription (de.spring.example.persistence.domain.QAdDescription)1