@Override public void deleteStructuredData(Element dataRepresentation) { if (!StructuredData.class.equals(extractType(dataRepresentation))) { throw new IllegalArgumentException("The supplied element is not a data entity's data."); } Iterator<Element> dataElements = getTransitiveClosureOver(dataRepresentation, outgoing, contains.name()); closeAfter(dataElements, () -> { // we know the closure is constructed eagerly in this impl, so this loop is OK. while (dataElements.hasNext()) { delete(dataElements.next()); } delete(dataRepresentation); return null; }); }
private static Relationships.WellKnown getWellKnown(String relationship) { for (Relationships.WellKnown r : Relationships.WellKnown.values()) { if (r.name().equals(relationship)) { return r; } } return null; } }
private static <E> void disallowDeleteWhenTheresContainsToo(Transaction<E> backend, E origin, Relationships.Direction direction, String relationship, E target, String errorDetails) { if (backend.hasRelationship(origin, target, contains.name())) { throw new IllegalArgumentException("'" + relationship + "' relationship cannot be deleted if there is" + " also a '" + contains + "' relationship between the same two entities. " + errorDetails); } }
private Contained(CanonicalPath entity) { super(entity, Relationships.WellKnown.contains.name(), EntityRole.TARGET); }
@Override protected EntityAndPendingNotifications<BE, DataEntity> wireUpNewEntity(BE entity, DataEntity.Blueprint<R> blueprint, CanonicalPath parentPath, BE parent, Transaction<BE> tx) { Validator.validate(tx, blueprint.getValue(), entity); BE value = tx.persist(blueprint.getValue()); //don't report this relationship, it is implicit //also, don't run the RelationshipRules checks - we're in the "privileged code" that is allowed to do //this tx.relate(entity, value, hasData.name(), null); DataEntity data = new DataEntity(parentPath, blueprint.getRole(), blueprint.getValue(), null, null, null, blueprint.getProperties()); return new EntityAndPendingNotifications<>(entity, data, emptyList()); }
private StructuredData loadStructuredData(Vertex owner, Relationships.WellKnown owningEdge) { Iterator<Vertex> it = owner.vertices(Direction.OUT, owningEdge.name()); if (!it.hasNext()) { closeIfNeeded(it); return null; } return loadStructuredData(closeAfter(it, it::next), true); }
private static <BE> void preDelete(DataModificationChecks<BE> checks, BE entityRepresentation, Transaction<BE> tx) { checks.preDelete(entityRepresentation, tx); Set<BE> rels = tx.getRelationships(entityRepresentation, Relationships.Direction.outgoing, hasData.name()); if (rels.isEmpty()) { Log.LOGGER.wNoDataAssociatedWithEntity(tx.extractCanonicalPath(entityRepresentation)); return; } BE dataRel = rels.iterator().next(); BE structuredData = tx.getRelationshipTarget(dataRel); tx.deleteStructuredData(structuredData); }
public static <E> void checkDelete(Transaction<E> backend, E origin, Relationships.Direction direction, Relationships.WellKnown relationship, E target) { check(backend, origin, direction, relationship.name(), target, CheckType.DELETE); }
/** * @see #linkWith(String, Path, Map) */ default Single linkWith(Relationships.WellKnown name, Path targetOrSource, Map<String, Object> properties) throws IllegalArgumentException { return linkWith(name.name(), targetOrSource, properties); }
static <BE> Relationship associationWith(TraversalContext<BE, ?> context, SegmentType sourceEntityType, Relationships.WellKnown relationship, Path path) throws RelationNotFoundException { return inTx(context, tx -> { Query sourceQuery = context.sourcePath.extend().filter().with(type(sourceEntityType)).get(); Query targetQuery = Util.queryTo(context.sourcePath, path); SegmentType targetType = path.getSegment().getElementType(); return Util.getAssociation(tx, sourceQuery, sourceEntityType, targetQuery, targetType, relationship.name()); }); }
private static boolean isOutgoingContains(Filter f) { if (!(f instanceof Related)) { return false; } Related rel = (Related) f; return rel.getEntityRole() == Related.EntityRole.SOURCE && contains.name().equals(rel.getRelationshipName()); }
@Override public Relationships.Multiple named(Relationships.WellKnown name) { return named(name.name()); }
@Override public Relationships.Multiple named(Relationships.WellKnown name) { return named(name.name()); }
private void convertToPipeline(RelativePath path, GraphTraversal<?, ?> pipeline) { for (Path.Segment s : path.getPath()) { if (SegmentType.up.equals(s.getElementType())) { pipeline.in(Relationships.WellKnown.contains.name()); } else { pipeline.out(Relationships.WellKnown.contains.name()) .hasLabel(Constants.Type.of(s.getElementType()).name()); apply(s, pipeline); } } }
/** * Overloaded version of {@link #asTargetBy(String)} that uses the * {@link org.hawkular.inventory.api.Relationships.WellKnown} as the name of the relationship. * * @param relationship the type of the relationship * @return a new "related" filter instance */ public static Related asTargetBy(Relationships.WellKnown relationship) { return new Related(null, relationship.name(), EntityRole.TARGET); }
/** * An overloaded version of {@link #asTargetWith(org.hawkular.inventory.paths.CanonicalPath, String)} that uses * one of the {@link org.hawkular.inventory.api.Relationships.WellKnown} as the name of the relationship. * * @param entityPath the entity that is the source of the relationship * @param relationship the type of the relationship * @return a new "related" filter instance */ public static Related asTargetWith(CanonicalPath entityPath, Relationships.WellKnown relationship) { return new Related(entityPath, relationship.name(), EntityRole.TARGET); }
/** * Overloaded version of {@link #by(String)} that uses the * {@link org.hawkular.inventory.api.Relationships.WellKnown} as the name of the relationship. * * @param relationship the type of the relationship * @return a new "related" filter instance */ public static Related by(Relationships.WellKnown relationship) { return new Related(null, relationship.name(), EntityRole.SOURCE); }
/** * An overloaded version of {@link #with(org.hawkular.inventory.paths.CanonicalPath, String)} that uses one of * the {@link org.hawkular.inventory.api.Relationships.WellKnown} as the name of the relationship. * * @param entityPath the entity that is the target of the relationship * @param relationship the type of the relationship * @return a new "related" filter instance */ public static Related with(CanonicalPath entityPath, Relationships.WellKnown relationship) { return new Related(entityPath, relationship.name(), EntityRole.SOURCE); }
static <BE> Relationship associate(TraversalContext<BE, ?> context, SegmentType sourceEntityType, Relationships.WellKnown relationship, Path id) { return inTx(context, tx -> { BE target = Util.find(tx, context.sourcePath, id); Query sourceQuery = context.sourcePath.extend().filter().with(type(sourceEntityType)).get(); BE source = tx.querySingle(sourceQuery); EntityAndPendingNotifications<BE, Relationship> rel = Util.createAssociation(tx, source, relationship.name(), target, null); tx.getPreCommit().addNotifications(rel); return rel.getEntity(); }); }
static <BE> Relationship disassociate(TraversalContext<BE, ?> context, SegmentType sourceEntityType, Relationships.WellKnown relationship, Path id) { return inTx(context, tx -> { BE target = Util.find(tx, context.sourcePath, id); Query sourceQuery = context.sourcePath.extend().filter().with(type(sourceEntityType)).get(); EntityAndPendingNotifications<BE, Relationship> rel = Util.deleteAssociation(tx, sourceQuery, sourceEntityType, relationship.name(), target); tx.getPreCommit().addNotifications(rel); return rel.getEntity(); }); }