当前位置: 首页>>代码示例>>Java>>正文


Java EntityManager.createQuery方法代码示例

本文整理汇总了Java中com.haulmont.cuba.core.EntityManager.createQuery方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.createQuery方法的具体用法?Java EntityManager.createQuery怎么用?Java EntityManager.createQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.haulmont.cuba.core.EntityManager的用法示例。


在下文中一共展示了EntityManager.createQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadUser

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Nullable
@Override
public User loadUser(String login) throws LoginException {
    // first check if login is a valid user's email, and find the corresponding login name
    // to pass to the super impl
    if (login == null)
        throw new IllegalArgumentException("Login is null");

    EntityManager em = persistence.getEntityManager();
    String queryStr = "select u.loginLowerCase from sec$User u where lower(u.email) = ?1 and (u.active = true or u.active is null)";

    Query q = em.createQuery(queryStr);
    q.setParameter(1, login.toLowerCase());
    List results = q.getResultList();
    if (!results.isEmpty())
        return super.loadUser((String) results.get(0));

    return super.loadUser(login);
}
 
开发者ID:pfurini,项目名称:cuba-component-forgot-password,代码行数:20,代码来源:NexbitLoginWorkerBean.java

示例2: onBeforeUpdate

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Override
public void onBeforeUpdate(Group entity, EntityManager entityManager) {
    if (!persistence.getTools().getDirtyFields(entity).contains("parent"))
        return;

    EntityManager em = persistence.getEntityManager();

    for (GroupHierarchy oldHierarchy : entity.getHierarchyList()) {
        em.remove(oldHierarchy);
    }
    createNewHierarchy(entity, entity.getParent());

    TypedQuery<GroupHierarchy> q = em.createQuery(
            "select h from sec$GroupHierarchy h join fetch h.group " +
                    "where h.parent.id = ?1", GroupHierarchy.class);
    q.setParameter(1, entity);
    List<GroupHierarchy> list = q.getResultList();
    for (GroupHierarchy hierarchy : list) {
        Group dependentGroup = hierarchy.getGroup();
        for (GroupHierarchy depHierarchy : dependentGroup.getHierarchyList()) {
            em.remove(depHierarchy);
        }
        em.remove(hierarchy);
        createNewHierarchy(dependentGroup, dependentGroup.getParent());
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:27,代码来源:GroupEntityListener.java

示例3: testQuery_CleanupMode

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testQuery_CleanupMode() {
    System.out.println("===================== BEGIN testQuery_CleanupMode =====================");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        em.setSoftDeletion(false);
        Query query = em.createQuery("select r from sec$Role r where r.name = ?1");
        query.setParameter(1, "roleToBeDeleted");

        List<Role> list = query.getResultList();
        assertTrue(!list.isEmpty());

        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testQuery_CleanupMode =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:SoftDeleteTest.java

示例4: migrateMessagesBatch

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected int migrateMessagesBatch() {
    List<SendingMessage> resultList;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        String qstr = "select m from sys$SendingMessage m where m.contentText is not null";
        TypedQuery<SendingMessage> query = em.createQuery(qstr, SendingMessage.class);
        query.setMaxResults(50);
        query.setViewName(View.MINIMAL);

        resultList = query.getResultList();
        tx.commit();
    } finally {
        tx.end();
    }

    if (!resultList.isEmpty()) {
        emailer.migrateEmailsToFileStorage(resultList);
    }

    return resultList.size();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:Emailer.java

示例5: testQueryWithoutConditions

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testQueryWithoutConditions() {
    System.out.println("===================== BEGIN testQueryWithoutConditions =====================");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Query query = em.createQuery("select r from sec$Role r");

        List<Role> list = query.getResultList();
        for (Role role : list) {
            if (role.getId().equals(role2Id)) {
                fail();
            }
        }

        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testQueryWithoutConditions =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:SoftDeleteTest.java

示例6: testOneToMany_Query

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testOneToMany_Query() {
    System.out.println("===================== BEGIN testOneToMany_Query =====================");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        Query q = em.createQuery("select u from sec$User u where u.id = ?1");
        q.setParameter(1, userId);
        User user = (User) q.getSingleResult();

        List<UserRole> userRoles = user.getUserRoles();
        assertEquals(1, userRoles.size());
        for (UserRole ur : userRoles) {
            assertNotNull(ur.getRole());
        }

        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToMany_Query =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:SoftDeleteTest.java

示例7: getResultListUserByLoginNamed

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected User getResultListUserByLoginNamed(User loadedUser, boolean checkView, Consumer<EntityManager> emBuilder, Consumer<Query> queryBuilder) throws Exception {
    User user;
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.entityManager();
        if (emBuilder != null) {
            emBuilder.accept(em);
        }
        TypedQuery<User> query = em.createQuery("select u from sec$User u where u.login = :login", User.class);
        query.setCacheable(true);
        query.setParameter("login", "ECTest-" + loadedUser.getId());
        query.setViewName("user.browse");
        if (queryBuilder != null) {
            queryBuilder.accept(query);
        }
        List<User> resultList = query.getResultList();
        user = resultList.isEmpty() ? null : resultList.get(0);
        tx.commit();
    }

    if (user != null && checkView) {
        assertUserBrowseView(user);
    }
    return user;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:QueryCacheTestClass.java

示例8: getEntityLogItems

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
private List<EntityLogItem> getEntityLogItems() {
    Transaction tx;
    List<EntityLogItem> items;
    tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        TypedQuery<EntityLogItem> query = em.createQuery(
                "select i from sec$EntityLog i where i.entity = ?1 and i.entityRef.entityId = ?2 order by i.eventTs desc", EntityLogItem.class);
        query.setParameter(1, "sec$User");
        query.setParameter(2, userId);
        items = query.getResultList();

        tx.commit();
    } finally {
        tx.end();
    }
    return items;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:EntityLogTest.java

示例9: testQuery

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testQuery() {
    System.out.println("===================== BEGIN testQuery =====================");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Query query = em.createQuery("select r from sec$Role r where r.name = ?1");
        query.setParameter(1, "roleToBeDeleted");

        List<Role> list = query.getResultList();
        assertTrue(list.isEmpty());

        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testQuery =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:SoftDeleteTest.java

示例10: testLoadUser

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testLoadUser() {
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        TypedQuery<User> query = em.createQuery(
                "select u from sec$User u where u.login = :userLogin", User.class);
        query.setParameter("userLogin", "admin");
        List<User> users = query.getResultList();
        tx.commit();
        assertEquals(1, users.size());
    }
}
 
开发者ID:pfurini,项目名称:cuba-component-forgot-password,代码行数:13,代码来源:SampleIntegrationTest.java

示例11: checkConditions

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
private void checkConditions(Order order, EntityManager entityManager) {
    Query query = entityManager.createQuery(
            "select count(e) from sample$Order e where e.date = ?1 and e.customer.id = ?2 and e.id <> ?3");
    query.setParameter(1, order.getDate());
    query.setParameter(2, order.getCustomer());
    query.setParameter(3, order.getId());
    Long count = (Long) query.getSingleResult();
    if (count >= 2)
        throw new TooManyOrdersException(order.getCustomer().getName(), order.getDate());
}
 
开发者ID:cuba-platform,项目名称:sample-data-manipulation,代码行数:11,代码来源:OrderEntityListener.java

示例12: compileConstraints

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void compileConstraints(UserSession session, Group group) {
    EntityManager em = persistence.getEntityManager();
    TypedQuery<Constraint> q = em.createQuery("select c from sec$GroupHierarchy h join h.parent.constraints c " +
            "where h.group.id = ?1", Constraint.class);
    q.setParameter(1, group);
    List<Constraint> constraints = q.getResultList();
    List<Constraint> list = new ArrayList<>(constraints);
    list.addAll(group.getConstraints());
    for (Constraint constraint : list) {
        if (Boolean.TRUE.equals(constraint.getIsActive())) {
            session.addConstraint(constraint);
        }
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:15,代码来源:UserSessionManager.java

示例13: loadSubstitutedUser

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected User loadSubstitutedUser(User substitutedUser, UserSession currentSession, EntityManager em) {
    TypedQuery<User> query = em.createQuery(
            "select s.substitutedUser from sec$User u join u.substitutions s " +
                    "where u.id = ?1 and s.substitutedUser.id = ?2",
            User.class
    );
    query.setParameter(1, currentSession.getUser());
    query.setParameter(2, substitutedUser);
    List<User> list = query.getResultList();
    if (list.isEmpty()) {
        throw new NoResultException("User not found");
    }

    return list.get(0);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:16,代码来源:AuthenticationManagerBean.java

示例14: queryWithFlush

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
private void queryWithFlush(Collection<Entity> managedEntities, EntityManager entityManager) {
    if (!managedEntities.stream().anyMatch(e -> e instanceof User && ((User) e).getLogin().startsWith("TxLstnrTst-")))
        return;

    TypedQuery<User> query = entityManager.createQuery("select u from sec$User u where u.login like ?1", User.class);
    query.setParameter(1, "TxLstnrTst-2-%");
    query.setFlushMode(FlushModeType.AUTO);
    User result = query.getFirstResult();
    assertNotNull(result);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:11,代码来源:TestBeforeCommitTxListener.java

示例15: loadRememberMeToken

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Nullable
protected RememberMeToken loadRememberMeToken(User user, String rememberMeToken) {
    EntityManager em = persistence.getEntityManager();
    TypedQuery<RememberMeToken> query = em.createQuery(
            "select rt from sec$RememberMeToken rt where rt.token = :token and rt.user.id = :userId",
            RememberMeToken.class);
    query.setParameter("token", rememberMeToken);
    query.setParameter("userId", user.getId());

    return query.getFirstResult();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:12,代码来源:RememberMeAuthenticationProvider.java


注:本文中的com.haulmont.cuba.core.EntityManager.createQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。