@SuppressWarnings("unchecked") static <B extends Blueprint, E extends AbstractElement> Class<? extends E> getEntityTypeOf(B blueprint) { return (Class<? extends E>) Inventory.types().byBlueprint(blueprint.getClass()).getElementType(); }
static <B extends Blueprint> SegmentType getSegmentTypeOf(B blueprint) { return Inventory.types().byBlueprint(blueprint.getClass()).getSegmentType(); }
@SuppressWarnings("unchecked") static <B extends Blueprint, E extends AbstractElement<B, ?>> Class<? extends E> getEntityTypeOf(B blueprint) { return (Class<? extends E>) Inventory.types().byBlueprint(blueprint.getClass()).getElementType(); }
private static boolean canBeIdentityRoot(SegmentType segmentType) { return IdentityHashable.class.isAssignableFrom(Inventory.types().bySegment(segmentType).getElementType()); }
static <B extends Blueprint> SegmentType getSegmentTypeOf(B blueprint) { return Inventory.types().byBlueprint(blueprint.getClass()).getSegmentType(); }
@SuppressWarnings({"unchecked", "rawtypes"}) private Mutator<BE, E, B, U, String> createMutator(Transaction<BE> tx) { return (Mutator<BE, E, B, U, String>) ElementTypeVisitor.accept( Inventory.types().byElement(context.entityClass).getSegmentType(), new ElementTypeVisitor<Mutator<BE, ?, ?, ?, String>, Void>() { @Override public Mutator<BE, ?, ?, ?, String> visitTenant(Void parameter) {
@SuppressWarnings({"unchecked", "rawtypes"}) default <E extends Entity, B extends Entity.Blueprint> Stream<FullNode> getChildNodes(RelativePath parent, Class<E> childType) { SegmentType childSegmentType = Inventory.types().byElement((Class)childType).getSegmentType(); return getChildren(parent, childType).map(b -> { RelativePath childPath = parent.modified().extend(childSegmentType, b.getId()).get(); return getNode(childPath); }).filter(Objects::nonNull); }
@SuppressWarnings({"unchecked", "rawtypes"}) default <E extends Entity<? extends B, ?>, B extends Entity.Blueprint> Stream<FullNode> getChildNodes(RelativePath parent, Class<E> childType) { SegmentType childSegmentType = Inventory.types().byElement((Class)childType).getSegmentType(); return getChildren(parent, childType).map(b -> { RelativePath childPath = parent.modified().extend(childSegmentType, b.getId()).get(); return getNode(childPath); }).filter(n -> n != null); }
private boolean __correctChangesPrologue(ProcessingTree<BE> changedEntity) { if (changedEntity.cp == null) { return false; } if (!changedEntity.isSignificant()) { //fast track - this is an entity that has not been CRUD'd but is present in the tree to complete the //hierarchy DBG.debug("Entity not hash-significant. Proceeding quickly."); return false; } if (!(Entity.Blueprint.class.isAssignableFrom( Inventory.types().bySegment(changedEntity.cp.getSegment().getElementType()).getBlueprintType()))) { //this is currently the case for metadata packs, which do not have their IDs assigned by the user. //we therefore mark them as processed. DBG.debug("Metadatapacks not processable. Bailing out quickly."); return true; } try { DBG.debug("Refreshing the entity in the current transaction."); changedEntity.loadFrom(tx); } catch (ElementNotFoundException e) { //ok, we're inside a delete and the root entity no longer exists... bail out quickly... if (processDeletion(changedEntity, changedEntity.notifications)) { return true; } else { throw new EntityNotFoundException(Query.filters(Query.to(changedEntity.cp))); } } return processDeletion(changedEntity, changedEntity.notifications); }
Function<RelativePath, Hashes> hashLoader) { Class<?> entityType = Inventory.types().byBlueprint(entity.getClass()).getElementType();
@SuppressWarnings("unchecked") private InventoryStructure.Builder<B> mergeShallowTree(InventoryStructure<?> currentTree, RelativePath treePath, InventoryStructure.AbstractBuilder<?> newTree, Set<SegmentType> mergedTypes) { DBG.debugf("Starting to merge shallow tree. Loading children under [%s]", treePath); try (Stream<InventoryStructure.FullNode> currentChildren = currentTree.getAllChildNodes(treePath)) { DBG.debugf("Done loading the children under [%s]", treePath); Set<Path.Segment> newChildPaths = newTree.getChildrenPaths(); currentChildren.forEach(currentChild -> { SegmentType childType = Inventory.types().byBlueprint(currentChild.getEntity().getClass()).getSegmentType(); Path.Segment childPathSegment = new Path.Segment(childType, currentChild.getEntity().getId()); if (newChildPaths.contains(childPathSegment)) { mergeShallowTree(currentTree, treePath.modified().extend(childPathSegment).get(), newTree.getChild(childPathSegment), mergedTypes); } else if (!mergedTypes.contains(childType)) { newTree.addChild(currentChild.getEntity(), currentChild.getAttachment()); } }); DBG.debugf("Done merging shallow tree of [%s]", treePath); if (newTree instanceof InventoryStructure.Builder) { return (InventoryStructure.Builder<B>) newTree; } else { return null; } } }
@SuppressWarnings("unchecked") private InventoryStructure.Builder<B> mergeDeepTree(InventoryStructure<?> currentTree, RelativePath treePath, InventoryStructure.AbstractBuilder<?> newTree, Set<SegmentType> mergedTypes) { DBG.debugf("Starting to merge shallow tree. Loading children under [%s]", treePath); try (Stream<InventoryStructure.FullNode> currentChildren = currentTree.getAllChildNodes(treePath)) { DBG.debugf("Done loading the children under [%s]", treePath); Set<Path.Segment> newChildPaths = newTree.getChildrenPaths(); currentChildren.forEach(currentChild -> { SegmentType childType = Inventory.types().byBlueprint(currentChild.getEntity().getClass()).getSegmentType(); Path.Segment childPathSegment = new Path.Segment(childType, currentChild.getEntity().getId()); if (newChildPaths.contains(childPathSegment)) { mergeDeepTree(currentTree, treePath.modified().extend(childPathSegment).get(), newTree.getChild(childPathSegment), mergedTypes); } else if (!mergedTypes.contains(childType)) { newTree.addChild(currentChild.getEntity(), currentChild.getAttachment()); mergeDeepTree(currentTree, treePath.modified().extend(childPathSegment).get(), newTree.getChild(childPathSegment), mergedTypes); } }); DBG.debugf("Done merging shallow tree of [%s]", treePath); if (newTree instanceof InventoryStructure.Builder) { return (InventoryStructure.Builder<B>) newTree; } else { return null; } } }