Search in sources :

Example 11 with Entity

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

the class EmbeddedDatasourceImpl method committed.

@Override
public void committed(Set<Entity> entities) {
    Entity item = masterDs.getItem();
    Entity newItem = null;
    Entity previousItem = null;
    if (item != null) {
        Iterator<Entity> commitIter = entities.iterator();
        while (commitIter.hasNext() && (previousItem == null) && (newItem == null)) {
            Entity commitItem = commitIter.next();
            if (commitItem.equals(item)) {
                previousItem = item;
                newItem = commitItem;
            }
        }
        if (previousItem != null) {
            detachListener(getItem(previousItem));
        }
        if (newItem != null) {
            attachListener(getItem(newItem));
        }
    }
    modified = false;
    clearCommitLists();
}
Also used : Entity(io.jmix.core.Entity)

Example 12 with Entity

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

the class TestBeforeCommitTxListener method queryWithFlush.

private void queryWithFlush(Collection<Entity> managedEntities, EntityManager entityManager) {
    if (!managedEntities.stream().anyMatch(e -> e instanceof User && ((User) e).getLogin().startsWith("TxLstnrTst-")))
        return;
    TypedQuery<User> query = entityManager.createQuery("select u from test$User u where u.login like ?1", User.class);
    query.setParameter(1, "TxLstnrTst-2-%");
    query.setFlushMode(FlushModeType.AUTO);
    User result = query.getFirstResult();
    assertNotNull(result);
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Persistence(com.haulmont.cuba.core.Persistence) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Metadata(io.jmix.core.Metadata) FlushModeType(javax.persistence.FlushModeType) UUID(java.util.UUID) Group(com.haulmont.cuba.core.model.common.Group) TypedQuery(com.haulmont.cuba.core.TypedQuery) Component(org.springframework.stereotype.Component) EntityStates(io.jmix.core.EntityStates) Transaction(com.haulmont.cuba.core.Transaction) BeforeCommitTransactionListener(com.haulmont.cuba.core.listener.BeforeCommitTransactionListener) Entity(io.jmix.core.Entity) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) User(com.haulmont.cuba.core.model.common.User) User(com.haulmont.cuba.core.model.common.User)

Example 13 with Entity

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

the class TestSupport method deleteRecord.

public void deleteRecord(Entity... entities) {
    if (entities == null) {
        return;
    }
    for (Entity entity : entities) {
        if (entity == null) {
            continue;
        }
        MetaClass metaClass = metadata.getClass(entity.getClass());
        String table = metadataTools.getDatabaseTable(metaClass);
        String primaryKey = metadataTools.getPrimaryKeyName(metaClass);
        if (table == null || primaryKey == null) {
            throw new RuntimeException("Unable to determine table or primary key name for " + entity);
        }
        deleteRecord(table, primaryKey, EntityValues.getId(entity));
    }
}
Also used : Entity(io.jmix.core.Entity) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 14 with Entity

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

the class TestAfterCompleteTxListener method testRollback.

private void testRollback(boolean committed, Collection<Entity> detachedEntities) {
    assertFalse(committed);
    User user = null;
    for (Entity entity : detachedEntities) {
        if (entity instanceof User && ((User) entity).getLogin().startsWith("TxLstnrTst-1-"))
            user = (User) entity;
    }
    if (user != null) {
        assertEquals("updated by testRollback", user.getName());
        JdbcTemplate jdbcTemplate = new JdbcTemplate(persistence.getDataSource());
        jdbcTemplate.update("update TEST_USER set NAME = 'updated by TestAfterCompleteTxListener' where ID = ?", user.getId().toString());
    }
}
Also used : Entity(io.jmix.core.Entity) User(com.haulmont.cuba.core.model.common.User) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate)

Example 15 with Entity

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

the class LinkCellClickListener method accept.

@Override
public void accept(Table.Column.ClickEvent clickEvent) {
    if (!clickEvent.isText()) {
        return;
    }
    Table.Column<?> column = clickEvent.getSource();
    Table owner = column.getOwner();
    if (owner == null || owner.getFrame() == null) {
        return;
    }
    Object rowItem = clickEvent.getItem();
    MetaPropertyPath mpp = column.getMetaPropertyPathNN();
    Object item = EntityValues.getValueEx(rowItem, mpp);
    Entity entity;
    if (EntityValues.isEntity(item)) {
        entity = (Entity) item;
    } else {
        entity = (Entity) rowItem;
    }
    if (EntityValues.isSoftDeleted(entity)) {
        ScreenContext context = ComponentsHelper.getScreenContext(owner);
        context.getNotifications().create(Notifications.NotificationType.HUMANIZED).withCaption(applicationContext.getBean(Messages.class).getMessage("OpenAction.objectIsDeleted")).show();
        return;
    }
    entity = loadEntity(entity);
    MetaClass metaClass = applicationContext.getBean(Metadata.class).getClass(entity);
    String linkScreenId = loadLinkScreenId(column, metaClass);
    OpenMode openMode = loadLinkScreenOpenMode(column);
    Screen editor = applicationContext.getBean(ScreenBuilders.class).editor(metaClass.getJavaClass(), owner.getFrame().getFrameOwner()).withScreenId(linkScreenId).editEntity(entity).withOpenMode(openMode).build();
    editor.addAfterCloseListener(afterCloseEvent -> {
        // move focus to component
        owner.focus();
        if (afterCloseEvent.closedWith(StandardOutcome.COMMIT) && editor instanceof EditorScreen) {
            onEditScreenAfterCommit(mpp, rowItem, (EditorScreen) editor, owner);
        }
    });
    editor.show();
}
Also used : Entity(io.jmix.core.Entity) Table(io.jmix.ui.component.Table) Messages(io.jmix.core.Messages) EditorScreen(io.jmix.ui.screen.EditorScreen) Screen(io.jmix.ui.screen.Screen) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) Metadata(io.jmix.core.Metadata) OpenMode(io.jmix.ui.screen.OpenMode) ScreenContext(io.jmix.ui.screen.ScreenContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorScreen(io.jmix.ui.screen.EditorScreen) ScreenBuilders(io.jmix.ui.ScreenBuilders)

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