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


Java EntityManager类代码示例

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


EntityManager类属于com.haulmont.cuba.core包,在下文中一共展示了EntityManager类的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: testNotLoadingJoinB

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Test
public void testNotLoadingJoinB() throws Exception {
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.persistence().getEntityManager();

        View fView = new View(JoinF.class).addProperty("name");
        View eView = new View(JoinE.class).addProperty("name").addProperty("f", fView, FetchMode.JOIN);
        View dView = new View(JoinD.class).addProperty("name");
        View cView = new View(JoinC.class).addProperty("name")
                .addProperty("d", dView, FetchMode.JOIN)
                .addProperty("e", eView, FetchMode.JOIN);
        View bView = new View(JoinB.class).addProperty("name")
                .addProperty("c", cView, FetchMode.JOIN);
        View aView = new View(JoinA.class).addProperty("name")
                .addProperty("b", bView, FetchMode.JOIN);

        JoinA loadedA = em.find(JoinA.class, joinA.getId(), aView);
        assertNotNull(loadedA);
        assertNotNull(loadedA.getB().getC().getD());
        assertNotNull(loadedA.getB().getC().getE());
        assertNotNull(loadedA.getB().getC().getE().getF());
        tx.commit();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:FetchJoinTest.java

示例3: loadUser

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Nullable
protected User loadUser(String login) throws LoginException {
    if (login == null) {
        throw new IllegalArgumentException("Login is null");
    }

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

    Query q = em.createQuery(queryStr);
    q.setParameter(1, login.toLowerCase());

    List list = q.getResultList();
    if (list.isEmpty()) {
        log.debug("Unable to find user: {}", login);
        return null;
    } else {
        //noinspection UnnecessaryLocalVariable
        User user = (User) list.get(0);
        return user;
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:AbstractAuthenticationProvider.java

示例4: storeAccessTokenToDatabase

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
protected void storeAccessTokenToDatabase(String tokenValue,
                                          byte[] accessTokenBytes,
                                          String authenticationKey,
                                          byte[] authenticationBytes,
                                          Date tokenExpiry,
                                          String userLogin,
                                          @Nullable Locale locale,
                                          @Nullable String refreshTokenValue) {
    try (Transaction tx = persistence.getTransaction()) {
        EntityManager em = persistence.getEntityManager();
        AccessToken accessToken = metadata.create(AccessToken.class);
        accessToken.setCreateTs(timeSource.currentTimestamp());
        accessToken.setTokenValue(tokenValue);
        accessToken.setTokenBytes(accessTokenBytes);
        accessToken.setAuthenticationKey(authenticationKey);
        accessToken.setAuthenticationBytes(authenticationBytes);
        accessToken.setExpiry(tokenExpiry);
        accessToken.setUserLogin(userLogin);
        accessToken.setLocale(locale != null ? locale.toString() : null);
        accessToken.setRefreshTokenValue(refreshTokenValue);
        em.persist(accessToken);
        tx.commit();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:ServerTokenStoreImpl.java

示例5: storeRefreshTokenToDatabase

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
protected void storeRefreshTokenToDatabase(String tokenValue,
                                          byte[] tokenBytes,
                                          byte[] authenticationBytes,
                                          Date tokenExpiry,
                                          String userLogin) {
    try (Transaction tx = persistence.getTransaction()) {
        EntityManager em = persistence.getEntityManager();
        RefreshToken refreshToken = metadata.create(RefreshToken.class);
        refreshToken.setCreateTs(timeSource.currentTimestamp());
        refreshToken.setTokenValue(tokenValue);
        refreshToken.setTokenBytes(tokenBytes);
        refreshToken.setAuthenticationBytes(authenticationBytes);
        refreshToken.setExpiry(tokenExpiry);
        refreshToken.setUserLogin(userLogin);
        em.persist(refreshToken);
        tx.commit();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:ServerTokenStoreImpl.java

示例6: testNormalMode

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

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

        Role role = em.find(Role.class, role2Id);
        assertNull(role);

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

示例7: createRole

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
public UUID createRole() {
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        User user = em.find(User.class, UUID.fromString("60885987-1b61-4247-94c7-dff348347f93"));

        Role role = new Role();
        role.setName("RelationTest");
        em.persist(role);

        UserRole userRole = new UserRole();
        userRole.setUser(user);
        userRole.setRole(role);
        em.persist(userRole);

        tx.commit();

        return role.getId();
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:24,代码来源:RelationsTest.java

示例8: 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

示例9: getAvailableUsers

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Override
public List<String> getAvailableUsers() {
    List<String> result = new ArrayList<>();

    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        Query query = em.createQuery("select u from sec$User u");
        List<User> userList = query.getResultList();
        for (User user : userList) {
            result.add(user.getLogin());
        }
        tx.commit();
    } finally {
        tx.end();
    }

    return result;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:SchedulingServiceBean.java

示例10: testFind

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Test
public void testFind() throws Exception {

    View view = new View(User.class, false)
            .addProperty("name")
            .addProperty("login")
            .addProperty("group", new View(Group.class)
                    .addProperty("name"));

    User user;

    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.persistence().getEntityManager();
        user = em.find(User.class, userId, view);

        tx.commit();
    }
    user = reserialize(user);

    assertNotNull(user.getCreatedBy());
    assertNotNull(user.getGroup());
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:EntityManagerTest.java

示例11: testOneToOneLazy

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Test
public void testOneToOneLazy() {
    System.out.println("===================== BEGIN testOneToOneLazy =====================");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id);
        assertNotNull(oneToOneA);
        assertNotNull(oneToOneA.getB());
        assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToOneLazy =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:SoftDeleteTest.java

示例12: registerExecutionStart

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
protected ScheduledExecution registerExecutionStart(ScheduledTask task, long now) {
    if (!BooleanUtils.isTrue(task.getLogStart()) && !BooleanUtils.isTrue(task.getSingleton()) && task.getSchedulingType() != SchedulingType.FIXED_DELAY)
        return null;

    log.trace("{}: registering execution start", task);

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

        ScheduledExecution execution = metadata.create(ScheduledExecution.class);
        execution.setTask(em.getReference(ScheduledTask.class, task.getId()));
        execution.setStartTime(new Date(now));
        execution.setServer(serverInfo.getServerId());

        em.persist(execution);
        tx.commit();

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

示例13: testEntityListenerOnUpdate

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Test
public void testEntityListenerOnUpdate() throws Exception {
    EntityListenerManager entityListenerManager = AppBeans.get(EntityListenerManager.class);
    entityListenerManager.addListener(CascadeEntity.class, UpdateCascadeEntityListener.class);
    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.persistence().getEntityManager();
        CascadeEntity loadedThird =  em.find(CascadeEntity.class, third.getId());
        CascadeEntity loadedSecond = em.find(CascadeEntity.class, second.getId());
        loadedThird.setName("third#1");
        tx.commit();
    }
    entityListenerManager.removeListener(CascadeEntity.class, UpdateCascadeEntityListener.class);
    assertEquals(2, UpdateCascadeEntityListener.updatedEvents.size());
    assertTrue(UpdateCascadeEntityListener.updatedEvents.contains(second.getId().toString()));
    assertTrue(UpdateCascadeEntityListener.updatedEvents.contains(third.getId().toString()));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:CascadeDeleteTest.java

示例14: testNew

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Test
public void testNew() {
    createGroups();

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Group group2 = em.find(Group.class, group2Id);
        for (GroupHierarchy hierarchy : group2.getHierarchyList()) {
            assertEquals(group2, hierarchy.getGroup());
            if (hierarchy.getLevel() == 0)
                assertEquals(rootId, hierarchy.getParent().getId());
            else if (hierarchy.getLevel() == 1)
                assertEquals(group1Id, hierarchy.getParent().getId());
        }
        tx.commit();
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:GroupTest.java

示例15: 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


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