Search in sources :

Example 31 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class SchedulingServiceBean method getAvailableUsers.

@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;
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) User(com.haulmont.cuba.security.entity.User) Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query) ArrayList(java.util.ArrayList)

Example 32 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class Emailer method migrateAttachmentsBatch.

protected int migrateAttachmentsBatch() {
    List<SendingAttachment> resultList;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        String qstr = "select a from sys$SendingAttachment a where a.content is not null";
        TypedQuery<SendingAttachment> query = em.createQuery(qstr, SendingAttachment.class);
        query.setMaxResults(50);
        query.setViewName(View.MINIMAL);
        resultList = query.getResultList();
        tx.commit();
    } finally {
        tx.end();
    }
    if (!resultList.isEmpty()) {
        emailer.migrateAttachmentsToFileStorage(resultList);
    }
    return resultList.size();
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) SendingAttachment(com.haulmont.cuba.core.entity.SendingAttachment) Transaction(com.haulmont.cuba.core.Transaction)

Example 33 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class RelationsTest method createRole.

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();
    }
}
Also used : Role(com.haulmont.cuba.security.entity.Role) UserRole(com.haulmont.cuba.security.entity.UserRole) EntityManager(com.haulmont.cuba.core.EntityManager) User(com.haulmont.cuba.security.entity.User) Transaction(com.haulmont.cuba.core.Transaction) UserRole(com.haulmont.cuba.security.entity.UserRole)

Example 34 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class UserSettingServiceTest method tearDown.

@After
public void tearDown() throws Exception {
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Query q = em.createNativeQuery("delete from SEC_USER_SETTING where USER_ID = ?");
        q.setParameter(1, TestUserSessionSource.USER_ID);
        q.executeUpdate();
        tx.commit();
    } finally {
        tx.end();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query) After(org.junit.After)

Example 35 with Transaction

use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.

the class SeveralFetchGroupsTest method setUp.

@Before
public void setUp() {
    metadata = cont.metadata();
    persistence = cont.persistence();
    dataManager = AppBeans.get(DataManager.class);
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        SeveralFetchGroups_Tariff tariff1 = metadata.create(SeveralFetchGroups_Tariff.class);
        tariffId1 = tariff1.getId();
        tariff1.setName("tariff1");
        em.persist(tariff1);
        SeveralFetchGroups_Tariff tariff2_1 = metadata.create(SeveralFetchGroups_Tariff.class);
        tariffId2_1 = tariff2_1.getId();
        tariff2_1.setName("tariff2_1");
        tariff2_1.setParent(tariff1);
        em.persist(tariff2_1);
        SeveralFetchGroups_Tariff tariff3_1 = metadata.create(SeveralFetchGroups_Tariff.class);
        tariffId3_1 = tariff3_1.getId();
        tariff3_1.setName("tariff3_1");
        tariff3_1.setParent(tariff1);
        em.persist(tariff3_1);
        SeveralFetchGroups_Tariff tariff4_2 = metadata.create(SeveralFetchGroups_Tariff.class);
        tariffId4_2 = tariff4_2.getId();
        tariff4_2.setName("tariff4");
        tariff4_2.setParent(tariff2_1);
        em.persist(tariff4_2);
        SeveralFetchGroups_TariffVersion tariffVersion1 = metadata.create(SeveralFetchGroups_TariffVersion.class);
        tariffVersionId1 = tariffVersion1.getId();
        tariffVersion1.setName("1");
        tariffVersion1.setDescription("tariffVersionDescription1");
        tariffVersion1.setParent(tariff1);
        tariff1.setActiveVersion(tariffVersion1);
        em.persist(tariffVersion1);
        SeveralFetchGroups_TariffVersion tariffVersion2 = metadata.create(SeveralFetchGroups_TariffVersion.class);
        tariffVersionId2 = tariffVersion2.getId();
        tariffVersion2.setName("2");
        tariffVersion2.setDescription("tariffVersionDescription2");
        tariffVersion2.setParent(tariff4_2);
        tariff4_2.setActiveVersion(tariffVersion2);
        em.persist(tariffVersion2);
        SeveralFetchGroups_TariffVersion tariffVersion3 = metadata.create(SeveralFetchGroups_TariffVersion.class);
        tariffVersionId3 = tariffVersion3.getId();
        tariffVersion3.setName("3");
        tariffVersion3.setDescription("tariffVersionDescription3");
        tariffVersion3.setParent(tariff2_1);
        tariff2_1.setActiveVersion(tariffVersion3);
        em.persist(tariffVersion3);
        tx.commit();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) SeveralFetchGroups_Tariff(com.haulmont.cuba.testmodel.severalfetchgroups.SeveralFetchGroups_Tariff) Transaction(com.haulmont.cuba.core.Transaction) SeveralFetchGroups_TariffVersion(com.haulmont.cuba.testmodel.severalfetchgroups.SeveralFetchGroups_TariffVersion) DataManager(com.haulmont.cuba.core.global.DataManager)

Aggregations

Transaction (com.haulmont.cuba.core.Transaction)211 EntityManager (com.haulmont.cuba.core.EntityManager)138 Test (org.junit.Test)44 User (com.haulmont.cuba.security.entity.User)30 Query (com.haulmont.cuba.core.Query)26 View (com.haulmont.cuba.core.global.View)21 Before (org.junit.Before)15 Group (com.haulmont.cuba.security.entity.Group)13 TypedQuery (com.haulmont.cuba.core.TypedQuery)11 MetaClass (com.haulmont.chile.core.model.MetaClass)9 SendingMessage (com.haulmont.cuba.core.entity.SendingMessage)8 Entity (com.haulmont.cuba.core.entity.Entity)7 List (java.util.List)6 Role (com.haulmont.cuba.security.entity.Role)5 UserRole (com.haulmont.cuba.security.entity.UserRole)5 SoftDeleteOneToOneA (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA)5 UUID (java.util.UUID)5 Nullable (javax.annotation.Nullable)5 AppFolder (com.haulmont.cuba.core.entity.AppFolder)4 IdentityEntity (com.haulmont.cuba.testmodel.primary_keys.IdentityEntity)4