public <B extends Blueprint> ElementTypes<? extends AbstractElement<B, ?>, B, ?> byBlueprint(Class<B> blueprintType) { for(SegmentType st : SegmentType.values()) { ElementTypes ret = elementTypes.get(st); if (ret.getBlueprintType().equals(blueprintType)) { return ret; } } throw new IllegalArgumentException("Unknown blueprint type: " + blueprintType); }
public <E extends AbstractElement<B, U>, B extends Blueprint, U extends AbstractElement.Update> ElementTypes<E, B, U> byElement(Class<E> elementType) { for(SegmentType st : SegmentType.values()) { ElementTypes ret = elementTypes.get(st); if (ret.getElementType().equals(elementType)) { return ret; } } throw new IllegalArgumentException("Unknown element type: " + elementType); }
public <E extends AbstractElement<B, U>, B extends Blueprint, U extends AbstractElement.Update> ElementTypes<E, B, U> byMultiple(Class<? extends ResolvableToMany<E>> multipleAccessorType) { for(SegmentType st : SegmentType.values()) { ElementTypes ret = elementTypes.get(st); if (ret.getMultipleAccessorType().equals(multipleAccessorType)) { return ret; } } throw new IllegalArgumentException("Unknown multiple accessor type: " + multipleAccessorType); } }
Function<RelativePath, Hashes> hashLoader) { Class<?> entityType = Inventory.types().byBlueprint(entity.getClass()).getElementType();
@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") 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; } } }
@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; } } }
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); }
static <B extends Blueprint> SegmentType getSegmentTypeOf(B blueprint) { return Inventory.types().byBlueprint(blueprint.getClass()).getSegmentType(); }
private static boolean canBeIdentityRoot(SegmentType segmentType) { return IdentityHashable.class.isAssignableFrom(Inventory.types().bySegment(segmentType).getElementType()); }
@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(); }
static <B extends Blueprint> SegmentType getSegmentTypeOf(B blueprint) { return Inventory.types().byBlueprint(blueprint.getClass()).getSegmentType(); }
@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); }
@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); }
public <E extends AbstractElement<B, U>, B extends Blueprint, U extends AbstractElement.Update> ElementTypes<E, B, U> bySingle(Class<? extends ResolvableToSingle<E, U>> singleAccessorType) { for(SegmentType st : SegmentType.values()) { ElementTypes ret = elementTypes.get(st); if (ret.getSingleAccessorType().equals(singleAccessorType)) { return ret; } } throw new IllegalArgumentException("Unknown single accessor type: " + singleAccessorType); }
public <U extends AbstractElement.Update> ElementTypes<?, ?, U> byUpdate(Class<U> updateType) { for(SegmentType st : SegmentType.values()) { ElementTypes ret = elementTypes.get(st); if (ret.getUpdateType().equals(updateType)) { return ret; } } throw new IllegalArgumentException("Unknown update type: " + updateType); }
@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(); }
public <B extends Blueprint> ElementTypes<? extends AbstractElement, B> byBlueprint(Class<B> blueprintType) { for(SegmentType st : SegmentType.values()) { ElementTypes ret = elementTypes.get(st); if (ret.getBlueprintType().equals(blueprintType)) { return ret; } } throw new IllegalArgumentException("Unknown blueprint type: " + blueprintType); }
public <E extends AbstractElement, B extends Blueprint> ElementTypes<E, B> byElement(Class<E> elementType) { for(SegmentType st : SegmentType.values()) { ElementTypes ret = elementTypes.get(st); if (ret.getElementType().equals(elementType)) { return ret; } } throw new IllegalArgumentException("Unknown element type: " + elementType); } }