return entity.accept(new ElementVisitor<Single, Void>() { @Override public Single visitTenant(Tenant tenant, Void ignored) {
@Override public int hashCode() { return getPath().hashCode(); }
private SegmentType getIntendedFinalType(Class<?> type) { if (type == null) { return null; } try { return AbstractElement.segmentTypeFromType(type); } catch (IllegalArgumentException | IllegalStateException e) { return null; } } }
@SuppressWarnings("unchecked") private static Class<? extends Entity<?, ?>> convertAsEntityType(SegmentType type) { Class<? extends AbstractElement<?, ?>> cls = AbstractElement.toElementClass(type); if (Relationship.class.isAssignableFrom(cls)) { throw new IllegalArgumentException("Type filter not applicable to relationships."); } return (Class<? extends Entity<?, ?>>) cls; }
@Override public void update(U u) throws EntityNotFoundException, RelationNotFoundException { inTx(tx -> { Util.update(context.entityClass, tx, context.select().get(), u, this::preUpdate, this::postUpdate); return null; }); if (useCachedEntity && context.getCreatedEntity() != null) { context.setCreatedEntity((E) context.getCreatedEntity().update().with(u)); } }
.map((s) -> AbstractElement.toElementClass(s.getSegment().getElementType())).collect(toSet()); Set<String> expectedIds = Arrays.asList(sources).stream().map((s) -> s.getSegment().getElementId()) .collect(toSet());
@Override public int hashCode() { return getPath().hashCode(); }
protected BE getParent(Transaction<BE> tx) { return ElementTypeVisitor.accept(AbstractElement.segmentTypeFromType(context.entityClass), new ElementTypeVisitor.Simple<BE, Void>() { @SuppressWarnings("unchecked") @Override protected BE defaultAction(SegmentType elementType, Void parameter) { BE res = tx.querySingle(context.sourcePath); if (res == null) { throw new EntityNotFoundException(context.previous.entityClass, Query.filters(context.sourcePath)); } return res; } @Override public BE visitTenant(Void parameter) { return null; } }, null); }
AbstractElement<?, ?> el = (AbstractElement<?, ?>) e; String entityName = name; return el.accept(new ElementVisitor<T, Void>() { @Override public T visitTenant(Tenant tenant, Void ignored) {
@SuppressWarnings({"unchecked", "rawtypes"}) private Notification<?, ?> cloneWithNewEntity(Notification<?, ?> notif, AbstractElement<?, ?> element) { if (!(notif.getValue() instanceof AbstractElement)) { return notif; } Object context = notif.getActionContext(); Object value = notif.getValue(); if (context instanceof AbstractElement && element.getPath().equals(((AbstractElement) context).getPath())) { context = element; } if (element.getPath().equals(((AbstractElement) value).getPath())) { value = element; } return new Notification(context, value, notif.getAction()); }
TraversalContext<BE, E> proceedTo(Path path) { if (!AbstractElement.segmentTypeFromType(entityClass).equals(path.getSegment().getElementType())) { throw new IllegalArgumentException("Path doesn't point to the type of element currently being accessed."); } return replacePath(Util.extendTo(this, path)); }
void add(EntityAndPendingNotifications<BE, ?> entity) { if (this.path != null) { throw new IllegalStateException("Cannot add element to partial results from a non-root segment."); } ProcessingTree<BE> found = extendTreeTo(entity.getEntity().getPath()); found.representation = entity.getEntityRepresentation(); found.element = entity.getEntity(); found.notifications.addAll(entity.getNotifications()); }
entityPath = parentCanonicalPath.extend(AbstractElement.segmentTypeFromType(context.entityClass), id) .get();
TraversalContext<BE, E> toCreatedEntity(E entity, boolean cache) { return new TraversalContext<>(inventory, Query.to(entity.getPath()), Query.empty(), backend, entityClass, configuration, observableContext, transactionRetries, this, cache ? entity : null, null); }
private boolean processDeletion(ProcessingTree<BE> changesTree, List<Notification<?, ?>> ns) { DBG.debugf("Checking for deletion of entity %s", changesTree.cp); Optional<Notification<?, ?>> deleteNotification = ns.stream() .filter(n -> n.getAction() == Action.deleted() && n.getValue() instanceof AbstractElement) .filter(n -> ((AbstractElement<?, ?>) n.getValue()).getPath().equals(changesTree.cp)) .findAny(); if (deleteNotification.isPresent()) { DBG.debugf("Processing deletion of the entity %s", changesTree.cp); //just emit what the caller wanted and don't bother any longer Notification<?, ?> n = deleteNotification.get(); correctedChanges.add(new EntityAndPendingNotifications<BE, AbstractElement<?, ?>>( null, (AbstractElement<?, ?>) n.getValue(), ns)); changesTree.dfsTraversal(pt -> { correctChanges(pt, false); return true; }); DBG.debugf("Done processing deletion of entity %s", changesTree.cp); return true; } DBG.debugf("No delete notifications found for entity %s", changesTree.cp); return false; }
private void addHashChangeNotifications(AbstractElement<?, ?> entity, Hashes newHashes, List<Notification<?, ?>> notifications) { DBG.debugf("Adding hash change notifications to entity %s", entity.getPath()); if (entity instanceof Syncable) { Syncable el = (Syncable) entity; if (!Objects.equals(el.getSyncHash(), newHashes.getSyncHash())) { notifications.add(new Notification<>(el, el, syncHashChanged())); } } if (entity instanceof ContentHashable) { ContentHashable el = (ContentHashable) entity; if (!Objects.equals(el.getContentHash(), newHashes.getContentHash())) { notifications.add(new Notification<>(el, el, contentHashChanged())); } } if (entity instanceof IdentityHashable) { IdentityHashable el = (IdentityHashable) entity; if (!Objects.equals(el.getIdentityHash(), newHashes.getIdentityHash())) { notifications.add(new Notification<>(el, el, identityHashChanged())); } } }
"Entity on path " + p.element.getPath() + " requires identity hash re-computation" + " but was not found contributing to a tree hash of a parent. This is" + " inconsistency in the inventory model and a bug.");
if (!ns.getEntity().getPath().equals(entity.getPath())) { continue;