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 void notifyAllDsCommited(DataSupplier dataservice, Set<Entity> committedEntities) { // Notify all datasources in context List<Datasource> datasources = new ArrayList<>(); for (DsContext childDsContext : children) { for (Datasource ds : childDsContext.getAll()) { if (Objects.equals(ds.getDataSupplier(), dataservice) && ds.getCommitMode() == Datasource.CommitMode.DATASTORE) { datasources.add(ds); } } } for (Datasource ds : datasourceMap.values()) { if (Objects.equals(ds.getDataSupplier(), dataservice) && ds.getCommitMode() == Datasource.CommitMode.DATASTORE) { datasources.add(ds); } } List<Datasource> sortedList = new DsTree(datasources).toDsList(); for (Datasource datasource : sortedList) { ((DatasourceImplementation) datasource).committed(committedEntities); } }
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(); }