/** * @return a new query selecting the select candidates from the source path. The resulting extender * is set up to append filter fragments. */ Query.SymmetricExtender select() { return sourcePath.extend().filter().withExact(selectCandidates); }
/** * @return a symmetric builder that will start appending path fragments to the query */ public static SymmetricExtender path() { return empty().extend().path(); }
/** * @return a symmetric builder that will start appending filter fragments to the query */ public static SymmetricExtender filter() { return empty().extend().filter(); }
/** * @return appends the select candidates to the source path. The only difference between this and {@link #select()} * is that this method returns the extender set up to append path fragments. */ Query.SymmetricExtender hop() { return sourcePath.extend().path().withExact(selectCandidates).path(); }
@SuppressWarnings("unchecked") public static Query queryTo(Query sourcePath, Path path) { if (path instanceof CanonicalPath) { return Query.to((CanonicalPath) path); } else { Query.SymmetricExtender extender = sourcePath.extend().path(); extender.with(With.relativePath(null, (RelativePath) path)); return extender.get(); } }
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(); }); }
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()); }); }
@SuppressWarnings("unchecked") public static Query extendTo(TraversalContext<?, ?> context, Path path) { if (path instanceof CanonicalPath) { return context.select().with(With.path((CanonicalPath) path)).get(); } else { Marker marker = Marker.next(); return context.sourcePath.extend().path().with(marker).with(context.selectCandidates) .with(With.relativePath(marker.getLabel(), (RelativePath) path)).get(); } }
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(); }); }
@Override protected String getProposedId(Transaction<BE> tx, Feed.Blueprint blueprint) { BE tenant = tx.querySingle(context.sourcePath.extend().filter() .with(type(Tenant.class)).get()); if (tenant == null) { throw new EntityNotFoundException(Tenant.class, Query.filters(context.sourcePath)); } CanonicalPath feedPath = tx.extractCanonicalPath(tenant) .extend(Feed.SEGMENT_TYPE, blueprint.getId()).get(); return context.configuration.getFeedIdStrategy().generate(context.inventory.keepTransaction(tx), new Feed(feedPath, null, null, null)); }