use of io.jmix.core.Entity in project jmix-docs by Haulmont.
the class EntityData method onInit.
@Subscribe
protected void onInit(InitEvent event) {
ListDataProvider dataProvider = new ListDataProvider();
dataProvider.addItem(new EntityDataItem((Entity) valueDescription(75, "Sky")));
dataProvider.addItem(new EntityDataItem((Entity) valueDescription(7, "Shady side of pyramid")));
dataProvider.addItem(new EntityDataItem((Entity) valueDescription(18, "Sunny side of pyramid")));
chart.setDataProvider(dataProvider);
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class DatasourceImpl method commit.
@SuppressWarnings("unchecked")
@Override
public void commit() {
backgroundWorker.checkUIAccess();
if (!allowCommit) {
return;
}
if (getCommitMode() == CommitMode.DATASTORE) {
final DataSupplier supplier = getDataSupplier();
Entity committedItem = supplier.commit(item, getView());
committed(Collections.singleton(committedItem));
} else if (getCommitMode() == CommitMode.PARENT) {
if (parentDs == null) {
throw new IllegalStateException("parentDs is null while commitMode=PARENT");
}
if (parentDs instanceof CollectionDatasource) {
CollectionDatasource ds = (CollectionDatasource) parentDs;
if (ds.containsItem(EntityValues.getId(item))) {
ds.modifyItem(item);
} else {
ds.addItem(item);
// This is necessary for nested property datasources to work correctly
ds.setItem(item);
}
} else {
parentDs.setItem(item);
if (AppBeans.get(EntityStates.class).isNew(item)) {
((DatasourceImplementation) parentDs).modified(item);
}
}
clearCommitLists();
modified = false;
} else {
throw new UnsupportedOperationException("Unsupported commitMode: " + getCommitMode());
}
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class DsContextImpl method createCommitContext.
protected CommitContext createCommitContext(DataSupplier dataservice, Map<DataSupplier, Collection<Datasource<Entity>>> commitData) {
CommitContext context = new CommitContext();
context.setDiscardCommitted(discardCommitted);
for (Datasource<Entity> datasource : commitData.get(dataservice)) {
if (datasource instanceof DatasourceImplementation) {
DatasourceImplementation<Entity> implementation = (DatasourceImplementation) datasource;
boolean listenersEnabled = implementation.enableListeners(false);
try {
for (Entity entity : implementation.getItemsToCreate()) {
addToContext(entity, datasource, context.getEntitiesToSave(), context.getFetchPlans());
}
for (Entity entity : implementation.getItemsToUpdate()) {
addToContext(entity, datasource, context.getEntitiesToSave(), context.getFetchPlans());
}
for (Entity entity : implementation.getItemsToDelete()) {
addToContext(entity, datasource, context.getEntitiesToRemove(), context.getFetchPlans());
}
} finally {
implementation.enableListeners(listenersEnabled);
}
}
}
repairReferences(context);
return context;
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class DsContextImpl method replaceMasterCopies.
// Replace the reference to master entity with actual entity containing in the master datasource,
// because in case of nested property datasources there may be references to cloned master entities.
protected void replaceMasterCopies(Entity entity, NestedDatasource datasource) {
Datasource masterDs = datasource.getMaster();
MetaProperty metaProperty = datasource.getProperty();
if (masterDs != null && metaProperty != null) {
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null && !inverseProp.getRange().getCardinality().isMany()) {
MetaClass metaClass = metadata.getExtendedEntities().getEffectiveMetaClass(inverseProp.getDomain());
if (metaClass.equals(datasource.getMetaClass()) && (PersistenceHelper.isLoaded(entity, inverseProp.getName()) && // replace master only if it's already set
EntityValues.getValue(entity, inverseProp.getName()) != null)) {
Object masterItem = null;
if (masterDs instanceof CollectionDatasource) {
Entity value = EntityValues.getValue(entity, inverseProp.getName());
if (value != null) {
Object id = EntityValues.getId(value);
// noinspection unchecked
masterItem = ((CollectionDatasource) masterDs).getItem(id);
}
} else {
masterItem = masterDs.getItem();
}
if (masterItem != null) {
// CAUTION need to rework this mechanism in case of two or more nested collection datasources
EntityValues.setValue(entity, inverseProp.getName(), masterItem, false);
}
}
}
}
}
use of io.jmix.core.Entity in project jmix by jmix-framework.
the class DsContextImpl method commit.
@Override
public boolean commit() {
Map<DataSupplier, Collection<Datasource<Entity>>> commitData = collectCommitData();
boolean committed = false;
if (!commitData.isEmpty()) {
DataSupplier dataservice = getDataSupplier();
Set<DataSupplier> suppliers = commitData.keySet();
if (suppliers.size() == 1 && Objects.equals(suppliers.iterator().next(), dataservice)) {
CommitContext context = createCommitContext(dataservice, commitData);
fireBeforeCommit(context);
Set<Entity> committedEntities = dataservice.commit(context);
fireAfterCommit(context, committedEntities);
notifyAllDsCommited(dataservice, committedEntities);
committed = true;
} else {
throw new UnsupportedOperationException();
}
}
for (DsContext childDsContext : children) {
boolean c = commitToParent(childDsContext.getAll());
committed = committed || c;
}
boolean c = commitToParent(datasourceMap.values());
committed = committed || c;
return committed;
}
Aggregations