Search in sources :

Example 81 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 82 with Transaction

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

the class UserSettingServiceTest method tearDown.

@AfterEach
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) AfterEach(org.junit.jupiter.api.AfterEach)

Example 83 with Transaction

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

the class SoftDeleteDataManagerTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    persistence = cont.persistence();
    metadata = cont.metadata();
    try (Transaction tx = persistence.createTransaction()) {
        user = metadata.create(User.class);
        user.setGroup(persistence.getEntityManager().find(Group.class, TestSupport.COMPANY_GROUP_ID));
        user.setLogin("user-" + user.getId());
        persistence.getEntityManager().persist(user);
        tx.commit();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) User(com.haulmont.cuba.security.entity.User) Transaction(com.haulmont.cuba.core.Transaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 84 with Transaction

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

the class SoftDeleteNotFoundDeletedTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    dataManager = AppBeans.get(DataManager.class);
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        SoftDelete_Service service = new SoftDelete_Service();
        serviceId = service.getId();
        service.setName("service");
        service.setCode("serviceCode");
        em.persist(service);
        SoftDelete_Task task = new SoftDelete_Task();
        taskId = task.getId();
        task.setMessage("message");
        task.setService(service);
        em.persist(task);
        SoftDelete_TaskValue taskValue = new SoftDelete_TaskValue();
        taskValueId = taskValue.getId();
        taskValue.setTask(task);
        em.persist(taskValue);
        SoftDelete_Project project = new SoftDelete_Project();
        projectId = project.getId();
        project.setName("project");
        project.setAValue(taskValue);
        project.setTask(task);
        em.persist(project);
        tx.commitRetaining();
        em = cont.persistence().getEntityManager();
        task = em.find(SoftDelete_Task.class, taskId);
        em.remove(task);
        tx.commit();
    } finally {
        tx.end();
    }
}
Also used : SoftDelete_Task(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Task) EntityManager(com.haulmont.cuba.core.EntityManager) SoftDelete_Service(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Service) SoftDelete_TaskValue(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_TaskValue) Transaction(com.haulmont.cuba.core.Transaction) DataManager(com.haulmont.cuba.core.global.DataManager) SoftDelete_Project(com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Project)

Example 85 with Transaction

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

the class EntityLogTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    cleanup();
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Query q;
        q = em.createNativeQuery("delete from SEC_ENTITY_LOG");
        q.executeUpdate();
        LoggedEntity le = new LoggedEntity();
        le.setName("sec$User");
        le.setAuto(true);
        em.persist(le);
        LoggedAttribute la = new LoggedAttribute();
        la.setEntity(le);
        la.setName("email");
        em.persist(la);
        le = new LoggedEntity();
        le.setName("sec$Role");
        le.setAuto(true);
        em.persist(le);
        la = new LoggedAttribute();
        la.setEntity(le);
        la.setName("type");
        em.persist(la);
        tx.commit();
    } finally {
        tx.end();
    }
    entityLog = AppBeans.get(EntityLogAPI.NAME);
    entityLog.invalidateCache();
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query) TypedQuery(com.haulmont.cuba.core.TypedQuery) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Transaction (com.haulmont.cuba.core.Transaction)226 EntityManager (com.haulmont.cuba.core.EntityManager)142 Test (org.junit.jupiter.api.Test)59 Query (com.haulmont.cuba.core.Query)30 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)27 User (com.haulmont.cuba.security.entity.User)25 View (com.haulmont.cuba.core.global.View)22 BeforeEach (org.junit.jupiter.api.BeforeEach)18 TypedQuery (com.haulmont.cuba.core.TypedQuery)13 Group (com.haulmont.cuba.security.entity.Group)12 List (java.util.List)10 SendingMessage (com.haulmont.cuba.core.entity.SendingMessage)8 MetaClass (com.haulmont.chile.core.model.MetaClass)7 Entity (com.haulmont.cuba.core.entity.Entity)7 SoftDeleteOneToOneA (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA)7 ChildCachedEntity (com.haulmont.cuba.testmodel.entity_cache.ChildCachedEntity)5 ParentCachedEntity (com.haulmont.cuba.testmodel.entity_cache.ParentCachedEntity)5 UUID (java.util.UUID)5 Nullable (javax.annotation.Nullable)5 EntityManagerFactory (javax.persistence.EntityManagerFactory)5