Example usage for javax.persistence.criteria CriteriaBuilder parameter

List of usage examples for javax.persistence.criteria CriteriaBuilder parameter

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder parameter.

Prototype

<T> ParameterExpression<T> parameter(Class<T> paramClass, String name);

Source Link

Document

Create a parameter expression with the given name.

Usage

From source file:com.expressui.sample.dao.query.ProfileQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Profile> query,
        Root<Profile> profile) {/*  w w w  .  ja  va  2 s . c  o m*/
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(loginName)) {
        ParameterExpression<String> loginNameExp = builder.parameter(String.class, "loginName");
        predicates.add(
                builder.like(builder.upper(profile.<User>get("user").<String>get("loginName")), loginNameExp));
    }

    return predicates;
}

From source file:com.expressui.core.dao.security.query.RelatedPermissionsQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Permission> query,
        Root<Permission> permission) {
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(role)) {
        ParameterExpression<Role> roleExp = builder.parameter(Role.class, "role");
        predicates.add(builder.equal(permission.get("role"), roleExp));
    }/*from  w ww  .  j  a  v  a2 s.c  o  m*/

    return predicates;
}

From source file:com.expressui.sample.dao.query.RelatedContactsQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Contact> query,
        Root<Contact> contact) {//w w w. ja v a  2s.co m
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(account)) {
        ParameterExpression<Account> accountExp = builder.parameter(Account.class, "account");
        predicates.add(builder.equal(contact.get("account"), accountExp));
    }

    return predicates;
}

From source file:com.expressui.sample.dao.query.RelatedOpportunitiesQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Opportunity> query,
        Root<Opportunity> opportunity) {
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(account)) {
        ParameterExpression<Account> accountExp = builder.parameter(Account.class, "account");
        predicates.add(builder.equal(opportunity.get("account"), accountExp));
    }/*  ww w .  jav  a2 s .  c  om*/

    return predicates;
}

From source file:com.expressui.core.dao.security.query.RelatedUsersQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<User> query, Root<User> user) {
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(role)) {
        ParameterExpression<Role> roleExp = builder.parameter(Role.class, "role");
        predicates.add(builder.equal(user.join("userRoles").get("role"), roleExp));
    }/*from w  w w .  ja v a2s.  co m*/

    if (hasValue(doesNotBelongToRole)) {
        Subquery<User> subquery = query.subquery(User.class);
        Root userRole = subquery.from(UserRole.class);
        ParameterExpression<Role> roleExp = builder.parameter(Role.class, "doesNotBelongToRole");
        subquery.select(userRole.get("user")).where(builder.equal(userRole.get("role"), roleExp));
        predicates.add(builder.not(user.in(subquery)));
    }

    return predicates;
}

From source file:com.expressui.core.dao.security.query.RoleQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Role> query, Root<Role> role) {
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(name)) {
        ParameterExpression<String> nameExp = builder.parameter(String.class, "name");
        predicates.add(builder.like(builder.upper(role.<String>get("name")), nameExp));
    }/* w w  w .j av a  2 s . c o  m*/

    if (hasValue(doesNotBelongToUser)) {
        Subquery<Role> subquery = query.subquery(Role.class);
        Root<UserRole> userRole = subquery.from(UserRole.class);
        ParameterExpression<User> userExp = builder.parameter(User.class, "doesNotBelongToUser");
        subquery.select(userRole.<Role>get("role")).where(builder.equal(userRole.get("user"), userExp));
        predicates.add(builder.not(role.in(subquery)));
    }

    return predicates;
}

From source file:com.expressui.sample.dao.query.ContactQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Contact> query,
        Root<Contact> contact) {/*from w w w .  ja v a2s .  com*/
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(lastName)) {
        ParameterExpression<String> lastNameExp = builder.parameter(String.class, "lastName");
        predicates.add(builder.like(builder.upper(contact.<String>get("lastName")), lastNameExp));
    }
    if (hasValue(account)) {
        ParameterExpression<Account> accountExp = builder.parameter(Account.class, "account");
        predicates.add(builder.equal(contact.get("account"), accountExp));
    }

    return predicates;
}

From source file:com.expressui.core.dao.security.query.UserQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<User> query, Root<User> user) {
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(loginName)) {
        ParameterExpression<String> loginNameExp = builder.parameter(String.class, "loginName");
        predicates.add(builder.like(builder.upper(user.<String>get("loginName")), loginNameExp));
    }//w  ww . jav  a  2  s .c  o  m

    if (hasValue(doesNotBelongToRole)) {
        Subquery<User> subquery = query.subquery(User.class);
        Root userRole = subquery.from(UserRole.class);
        ParameterExpression<Role> role = builder.parameter(Role.class, "doesNotBelongToRole");
        subquery.select(userRole.get("user")).where(builder.equal(userRole.get("role"), role));
        predicates.add(builder.not(user.in(subquery)));
    }

    return predicates;
}

From source file:com.expressui.sample.dao.query.AccountQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Account> query,
        Root<Account> account) {/*  w  w  w .ja v  a2  s .  co m*/
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(name)) {
        ParameterExpression<String> nameExp = builder.parameter(String.class, "name");
        predicates.add(builder.like(builder.upper(account.<String>get("name")), nameExp));
    }
    if (hasValue(states)) {
        ParameterExpression<Set> statesExp = builder.parameter(Set.class, "states");
        predicates.add(builder.in(account.get("billingAddress").get("state")).value(statesExp));
    }
    if (hasValue(country)) {
        ParameterExpression<Country> countryExp = builder.parameter(Country.class, "country");
        predicates.add(builder.equal(account.get("billingAddress").get("country"), countryExp));
    }

    return predicates;
}

From source file:com.expressui.sample.dao.query.OpportunityQuery.java

@Override
public List<Predicate> buildCriteria(CriteriaBuilder builder, CriteriaQuery<Opportunity> query,
        Root<Opportunity> opportunity) {
    List<Predicate> predicates = new ArrayList<Predicate>();

    if (hasValue(accountName)) {
        ParameterExpression<String> accountNameExp = builder.parameter(String.class, "accountName");
        predicates.add(/*from   w  w w  . j a v a2 s. co  m*/
                builder.like(builder.upper(opportunity.get("account").<String>get("name")), accountNameExp));
    }
    if (hasValue(salesStages)) {
        ParameterExpression<Set> salesStagesExp = builder.parameter(Set.class, "salesStages");
        predicates.add(builder.in(opportunity.get("salesStage")).value(salesStagesExp));
    }

    return predicates;
}