• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EntityManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



EntityManager类属于com.haulmont.cuba.core包,在下文中一共展示了EntityManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: computeSecurityState

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Override
public SecurityState computeSecurityState(Entity entity) {
    Preconditions.checkNotNullArgument(entity, "entity is null");

    SecurityState state;
    String storeName = metadataTools.getStoreName(metadata.getClassNN(entity.getClass()));
    Transaction tx = persistence.createTransaction(storeName);
    try {
        EntityManager em = persistence.getEntityManager(storeName);
        Entity managedEntity = em.merge(entity);
        support.setupAttributeAccess(managedEntity);
        state = BaseEntityInternalAccess.getSecurityState(managedEntity);
        // do not commit the transaction
    } finally {
        tx.end();
    }
    return state;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:AttributeAccessServiceBean.java


示例17: executeScript

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
protected Object executeScript(String domain, String sqlScript) {
    EntityManager em = persistence.getEntityManager(getDataStore(domain));
    StrTokenizer tokenizer = new StrTokenizer(sqlScript, SequenceSupport.SQL_DELIMITER);
    Object value = null;
    Connection connection = em.getConnection();
    while (tokenizer.hasNext()) {
        String sql = tokenizer.nextToken();
        try {
            PreparedStatement statement = connection.prepareStatement(sql);
            try {
                if (statement.execute()) {
                    ResultSet rs = statement.getResultSet();
                    if (rs.next())
                        value = rs.getLong(1);
                }
            } finally {
                DbUtils.closeQuietly(statement);
            }
        } catch (SQLException e) {
            throw new IllegalStateException("Error executing SQL for getting next number", e);
        }
    }
    return value;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:UniqueNumbers.java


示例18: clearScheduledTasks

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

        Query query = em.createNativeQuery("delete from SYS_SCHEDULED_EXECUTION");
        query.executeUpdate();

        query = em.createNativeQuery("delete from SYS_SCHEDULED_TASK");
        query.executeUpdate();

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


示例19: executeScript

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
protected Object executeScript(String entityName, String sqlScript) {
    EntityManager em = persistence.getEntityManager(getDataStore(entityName));
    StrTokenizer tokenizer = new StrTokenizer(sqlScript, SequenceSupport.SQL_DELIMITER);
    Object value = null;
    Connection connection = em.getConnection();
    while (tokenizer.hasNext()) {
        String sql = tokenizer.nextToken();
        try {
            PreparedStatement statement = connection.prepareStatement(sql);
            try {
                if (statement.execute()) {
                    ResultSet rs = statement.getResultSet();
                    if (rs.next())
                        value = rs.getLong(1);
                }
            } finally {
                DbUtils.closeQuietly(statement);
            }
        } catch (SQLException e) {
            throw new IllegalStateException("Error executing SQL for getting next number", e);
        }
    }
    return value;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:NumberIdWorker.java


示例20: getSnapshots

import com.haulmont.cuba.core.EntityManager; //导入依赖的package包/类
@Override
public List<EntitySnapshot> getSnapshots(MetaClass metaClass, Object id) {
    metaClass = extendedEntities.getOriginalOrThisMetaClass(metaClass);
    Entity entity = dataManager.load(new LoadContext<>(metaClass).setId(id).setView(View.LOCAL));
    checkCompositePrimaryKey(entity);
    List<EntitySnapshot> resultList = null;
    View view = metadata.getViewRepository().getView(EntitySnapshot.class, "entitySnapshot.browse");
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        TypedQuery<EntitySnapshot> query = em.createQuery(format(
                "select s from sys$EntitySnapshot s where s.entity.%s = :entityId and s.entityMetaClass = :metaClass " +
                        "order by s.snapshotDate desc", referenceToEntitySupport.getReferenceIdPropertyName(metaClass)), EntitySnapshot.class);
        query.setParameter("entityId", referenceToEntitySupport.getReferenceId(entity));
        query.setParameter("metaClass", metaClass.getName());
        query.setView(view);
        resultList = query.getResultList();

        tx.commit();
    } finally {
        tx.end();
    }

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Validator类代码示例发布时间:2022-05-22
下一篇:
Java ElementNSImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap