Search in sources :

Example 46 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class CollectionPropertyDatasourceImpl method modifyItem.

@Override
public void modifyItem(T item) {
    checkNotNullArgument(item, "item is null");
    Collection<T> collection = getCollection();
    if (collection != null) {
        for (T t : collection) {
            if (t.equals(item)) {
                EntityCopyUtils.copyCompositionsBack(item, t);
                modified = true;
                if (cascadeProperty) {
                    final Entity parentItem = masterDs.getItem();
                    // noinspection unchecked
                    ((DatasourceImplementation) masterDs).modified(parentItem);
                } else {
                    modified(t);
                }
            }
        }
        fireCollectionChanged(Operation.UPDATE, Collections.singletonList(item));
    }
}
Also used : Entity(io.jmix.core.Entity)

Example 47 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class DataManagerTest method testLoadListCaseInsensitiveLower.

@Test
public void testLoadListCaseInsensitiveLower() {
    Server server = new Server();
    server.setName("LocalHost");
    server.setRunning(true);
    DataManager dataManager = AppBeans.get(DataManager.NAME);
    dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
    LoadContext<Server> loadContext = LoadContext.create(Server.class);
    loadContext.setQueryString("select s from test$Server s where s.name like :name").setParameter("name", "(?i)%localhost%");
    List<Server> list = dataManager.loadList(loadContext);
    assertTrue(list.size() > 0);
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) DataManager(com.haulmont.cuba.core.global.DataManager) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 48 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class DataManagerTest method testLoadList.

@Test
public void testLoadList() {
    Server server = new Server();
    server.setName("localhost");
    server.setRunning(true);
    dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
    LoadContext<Server> loadContext = LoadContext.create(Server.class);
    loadContext.setQueryString("select s from " + metadata.getClass(Server.class).getName() + " s");
    List<Server> list = dataManager.loadList(loadContext);
    assertTrue(list.size() > 0);
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 49 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class DataManagerTest method testDiscardCommitted.

@Test
public void testDiscardCommitted() throws Exception {
    Server server = new Server();
    server.setName("localhost");
    CommitContext commitContext = new CommitContext(server);
    commitContext.setDiscardCommitted(true);
    Set<Entity> committed = dataManager.commit(commitContext);
    assertTrue(committed.isEmpty());
    Server saved = dataManager.load(LoadContext.create(Server.class).setId(server.getId()));
    assertNotNull(saved);
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 50 with Entity

use of io.jmix.core.Entity in project jmix by jmix-framework.

the class DataManagerTest method test.

@Test
public void test() {
    Server server = new Server();
    UUID id = server.getId();
    server.setName("localhost");
    server.setRunning(true);
    dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
    LoadContext<Server> loadContext = LoadContext.create(Server.class).setId(id);
    server = dataManager.load(loadContext);
    assertEquals("localhost", server.getName());
    server.setName("krivopustov");
    dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Aggregations

Entity (io.jmix.core.Entity)94 MetaClass (io.jmix.core.metamodel.model.MetaClass)20 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)18 CommitContext (com.haulmont.cuba.core.global.CommitContext)10 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)10 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 Test (org.junit.jupiter.api.Test)10 Server (com.haulmont.cuba.core.model.common.Server)8 Datasource (com.haulmont.cuba.gui.data.Datasource)8 Collectors (java.util.stream.Collectors)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 FetchPlan (io.jmix.core.FetchPlan)7 Logger (org.slf4j.Logger)7 Metadata (io.jmix.core.Metadata)6 MetadataTools (io.jmix.core.MetadataTools)6 EntityValues (io.jmix.core.entity.EntityValues)6 java.util (java.util)6 ArrayList (java.util.ArrayList)6 Nullable (javax.annotation.Nullable)6 LoggerFactory (org.slf4j.LoggerFactory)6