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();
}
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);
}
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));
}
}
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());
}
}
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();
}
Aggregations