Search in sources :

Example 1 with LogicalCondition

use of com.haulmont.cuba.core.global.queryconditions.LogicalCondition in project cuba by cuba-platform.

the class QueryConditionsUsageTest method test.

@Test
public void test() {
    LogicalCondition condition = and().add(where("u.login like :login")).add(where("u.userRoles ur", "ur.role.name = :roleName")).add(or().add(where("u.foo = :foo")).add(where("u.bar = :bar")));
    LoadContext.Query query = LoadContext.createQuery("select u from sec$User u").setCondition(condition).setParameter("login", "admin");
    LoadContext<User> loadContext = LoadContext.create(User.class).setQuery(query);
    List<User> users = dataManager.loadList(loadContext);
    assertEquals(1, users.size());
    Optional<User> userOpt = dataManager.load(User.class).query("select u from sec$User u").condition(condition).parameter("login", "admin").optional();
    assertTrue(userOpt.isPresent());
}
Also used : User(com.haulmont.cuba.security.entity.User) LoadContext(com.haulmont.cuba.core.global.LoadContext) LogicalCondition(com.haulmont.cuba.core.global.queryconditions.LogicalCondition) Test(org.junit.jupiter.api.Test)

Aggregations

LoadContext (com.haulmont.cuba.core.global.LoadContext)1 LogicalCondition (com.haulmont.cuba.core.global.queryconditions.LogicalCondition)1 User (com.haulmont.cuba.security.entity.User)1 Test (org.junit.jupiter.api.Test)1