protected Map<DataSupplier, Collection<Datasource<Entity>>> collectCommitData() { Collection<Datasource> datasources = new ArrayList<>(); for (DsContext childDsContext : children) { datasources.addAll(childDsContext.getAll()); } datasources.addAll(datasourceMap.values()); Map<DataSupplier, Collection<Datasource<Entity>>> commitDatasources = new HashMap<>(); for (Datasource datasource : datasources) { if (Datasource.CommitMode.DATASTORE == datasource.getCommitMode() && datasource.isAllowCommit() && (datasource.isModified() || !((DatasourceImplementation) datasource).getItemsToCreate().isEmpty())) { DataSupplier dataservice = datasource.getDataSupplier(); Collection<Datasource<Entity>> collection = commitDatasources.get(dataservice); if (collection == null) { collection = new ArrayList<>(); commitDatasources.put(dataservice, collection); } collection.add(datasource); } } return commitDatasources; }
protected boolean commitToParent(Collection<Datasource> datasources) { List<Datasource> list = new ArrayList<>(); for (Datasource datasource : datasources) { if (Datasource.CommitMode.PARENT.equals(datasource.getCommitMode()) && (datasource.isModified() || !((DatasourceImplementation) datasource).getItemsToCreate().isEmpty())) { list.add(datasource); } } List<Datasource> sortedList = new DsTree(list).toDsList(); for (Datasource datasource : sortedList) { datasource.commit(); } return !list.isEmpty(); }
/** * Called by the framework to set an edited entity after creation of all components and datasources, and after * {@link #init(java.util.Map)}. * <p>Don't override this method in subclasses, use hooks {@link #initNewItem(com.haulmont.cuba.core.entity.Entity)} * and {@link #postInit()} instead.</p> * @param item entity instance */ @SuppressWarnings("unchecked") @Override public void setItem(Entity item) { if (PersistenceHelper.isNew(item)) { DatasourceImplementation parentDs = (DatasourceImplementation) getParentDs(); if (parentDs == null || !parentDs.getItemsToCreate().contains(item)) { initNewItem((T) item); } } setItemInternal(item); postInit(); }
Collection<Entity> parentItemsToCreate = ((DatasourceImplementation) parentCollectionDs).getItemsToCreate(); for (Entity createdItem : new ArrayList<>(parentItemsToCreate)) { if (!this.itemsToCreate.contains(createdItem)) {
dataSupplier.commit(ctx); List<UserRole> modifiedRoles = new ArrayList<>(rolesDsImpl.getItemsToCreate()); modifiedRoles.addAll(rolesDsImpl.getItemsToUpdate()); rolesDsImpl.committed(Collections.emptySet());
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.getCommitInstances(), context.getViews()); } for (Entity entity : implementation.getItemsToUpdate()) { addToContext(entity, datasource, context.getCommitInstances(), context.getViews()); } for (Entity entity : implementation.getItemsToDelete()) { addToContext(entity, datasource, context.getRemoveInstances(), context.getViews()); } } finally { implementation.enableListeners(listenersEnabled); } } } repairReferences(context); return context; }
&& !parentDs.getItemsToCreate().contains(item) && !parentDs.getItemsToUpdate().contains(item) && parentDs instanceof CollectionDatasource && ((CollectionDatasource) parentDs).containsItem(item.getId())