@Override public EntitySet merge(Collection<? extends Entity> entities) { return EntitySet.of(entities); }
/** * Creates the {@code EntitySet} wrapping an existing set. */ public static EntitySet of(Set<? extends Entity> entities) { return new EntitySet(entities); }
/** * Returns the entity if it exists in the set. * * @param entityClass class of entity * @param entityId entity id * @throws IllegalArgumentException if the entity not found */ public <T extends Entity<K>, K> T get(Class<T> entityClass, K entityId) { return optional(entityClass, entityId).orElseThrow(() -> new IllegalArgumentException("Entity not found")); }
/** * Returns the entity if it exists in the set. * * @param prototype a prototype instance whose class and id are used to look up an entity in the set. * @throws IllegalArgumentException if the entity not found */ @SuppressWarnings("unchecked") public <T extends Entity> T get(T prototype) { Preconditions.checkNotNullArgument(prototype, "prototype entity is null"); return (T) get(prototype.getClass(), prototype.getId()); }
@Override public <E extends Entity> E commit(E entity, @Nullable View view) { return commit(new CommitContext().addInstanceToCommit(entity, view)).get(entity); }
@Override public EntitySet commit(CommitContext context) { return EntitySet.of(dataService.commit(context)); }
@Override public <E extends Entity> E save(E entity) { CommitContext cc = new CommitContext(entity); cc.setJoinTransaction(true); return dataManager.commit(cc).get(entity); }
/** * Returns the entity wrapped in {@code Optional} if it exists in the set. * * @param prototype a prototype instance whose class and id are used to look up an entity in the set. */ @SuppressWarnings("unchecked") public <T extends Entity> Optional<T> optional(T prototype) { Preconditions.checkNotNullArgument(prototype, "prototype entity is null"); return (Optional<T>) optional(prototype.getClass(), prototype.getId()); }
/** * Creates the {@code EntitySet} by copying the given collection to the internal set. */ public static EntitySet of(Collection<? extends Entity> entities) { return new EntitySet(entities); }
@Override public EntitySet merge(Collection<? extends Entity> entities) { checkNotNullArgument(entities, "entity collection is null"); List<Entity> managedList = new ArrayList<>(entities.size()); disableListeners = true; try { Set<Entity> merged = Sets.newIdentityHashSet(); for (Entity entity : entities) { Entity managed = internalMerge(entity, merged); managedList.add(managed); } } finally { disableListeners = false; } return EntitySet.of(managedList); }
@Override public <E extends Entity> E save(E entity, @Nullable String viewName) { CommitContext cc = new CommitContext(); cc.addInstanceToCommit(entity, viewName); cc.setJoinTransaction(true); return dataManager.commit(cc).get(entity); }
@Override public EntitySet commit(CommitContext context) { Set<Entity> result = new HashSet<>(); ReportService reportService = AppBeans.get(ReportService.NAME, ReportService.class); Report reportToStore = null; for (Entity entity : context.getCommitInstances()) { if (entity instanceof Report) { reportToStore = (Report) entity; } else if (entity instanceof ReportTemplate) { reportToStore = ((ReportTemplate) entity).getReport(); } } if (reportToStore != null) { result.add(reportService.storeReportEntity(reportToStore)); } return EntitySet.of(result); } }
@Override public <E extends Entity> E save(E entity, @Nullable View view) { CommitContext cc = new CommitContext(); cc.addInstanceToCommit(entity, view); cc.setJoinTransaction(true); return dataManager.commit(cc).get(entity); }
return EntitySet.of(result);