Search in sources :

Example 1 with DataManager

use of com.haulmont.cuba.core.global.DataManager 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)

Example 2 with DataManager

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

the class SoftDeleteMany2ManyTest method setUp.

@Before
public void setUp() throws Exception {
    DataManager dataManager = AppBeans.get(DataManager.class);
    many2ManyA = cont.metadata().create(Many2ManyA.class);
    many2ManyB = cont.metadata().create(Many2ManyB.class);
    many2ManyA.setCollectionOfB(new HashSet<>());
    many2ManyA.getCollectionOfB().add(many2ManyB);
    dataManager.commit(new CommitContext(many2ManyA, many2ManyB));
    many2ManyA2 = cont.metadata().create(Many2ManyA.class);
    many2ManyB2 = cont.metadata().create(Many2ManyB.class);
    many2ManyA2.setCollectionOfB2(new HashSet<>());
    many2ManyA2.getCollectionOfB2().add(many2ManyB2);
    dataManager.commit(new CommitContext(many2ManyA2, many2ManyB2));
    a1 = cont.metadata().create(Many2ManyA.class);
    a2 = cont.metadata().create(Many2ManyA.class);
    b1 = cont.metadata().create(Many2ManyB.class);
    b2 = cont.metadata().create(Many2ManyB.class);
    b3 = cont.metadata().create(Many2ManyB.class);
    a1.setCollectionOfB(new HashSet<>());
    a1.getCollectionOfB().add(b1);
    a1.getCollectionOfB().add(b2);
    a2.setCollectionOfB(new HashSet<>());
    a2.getCollectionOfB().add(b3);
    dataManager.commit(new CommitContext(a1, a2, b1, b2, b3));
}
Also used : Many2ManyB(com.haulmont.cuba.testmodel.many2many.Many2ManyB) CommitContext(com.haulmont.cuba.core.global.CommitContext) DataManager(com.haulmont.cuba.core.global.DataManager) Many2ManyA(com.haulmont.cuba.testmodel.many2many.Many2ManyA) Before(org.junit.Before)

Example 3 with DataManager

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

the class SoftDeleteNotFoundDeletedTest method setUp.

@Before
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 4 with DataManager

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

the class HsqlLikeNullFailTest method testLoadListCaseInsensitive.

@Test
public void testLoadListCaseInsensitive() {
    LoadContext<User> loadContext = LoadContext.create(User.class);
    loadContext.setQueryString("select u from sec$User u " + "where u.name like :custom_searchString or u.login like :custom_searchString").setParameter("custom_searchString", null);
    DataManager dataManager = AppBeans.get(DataManager.NAME);
    List<User> list = dataManager.loadList(loadContext);
    assertEquals(0, list.size());
}
Also used : User(com.haulmont.cuba.security.entity.User) DataManager(com.haulmont.cuba.core.global.DataManager) Test(org.junit.Test)

Example 5 with DataManager

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

the class QueryCacheTestClass method dataManager_getResultListUserByLoginNamed.

protected User dataManager_getResultListUserByLoginNamed() {
    DataManager dataManager = AppBeans.get(DataManager.NAME);
    LoadContext<User> loadContext = new LoadContext<>(User.class).setView("user.browse");
    loadContext.setQueryString("select u from sec$User u where u.login = :login").setParameter("login", "ECTest-" + this.user.getId()).setCacheable(true);
    return dataManager.load(loadContext);
}
Also used : DataManager(com.haulmont.cuba.core.global.DataManager)

Aggregations

DataManager (com.haulmont.cuba.core.global.DataManager)7 User (com.haulmont.cuba.security.entity.User)3 EntityManager (com.haulmont.cuba.core.EntityManager)2 Transaction (com.haulmont.cuba.core.Transaction)2 LoadContext (com.haulmont.cuba.core.global.LoadContext)2 Before (org.junit.Before)2 CommitContext (com.haulmont.cuba.core.global.CommitContext)1 Group (com.haulmont.cuba.security.entity.Group)1 Many2ManyA (com.haulmont.cuba.testmodel.many2many.Many2ManyA)1 Many2ManyB (com.haulmont.cuba.testmodel.many2many.Many2ManyB)1 SeveralFetchGroups_Tariff (com.haulmont.cuba.testmodel.severalfetchgroups.SeveralFetchGroups_Tariff)1 SeveralFetchGroups_TariffVersion (com.haulmont.cuba.testmodel.severalfetchgroups.SeveralFetchGroups_TariffVersion)1 SoftDelete_Project (com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Project)1 SoftDelete_Service (com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Service)1 SoftDelete_Task (com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_Task)1 SoftDelete_TaskValue (com.haulmont.cuba.testmodel.softdelete_notfounddeleted.SoftDelete_TaskValue)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1