Query existenceCheck = context.hop().filter().with(id(id)).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(); }); }
/** * @return a symmetric builder that will start appending filter fragments to the query */ public static SymmetricExtender filter() { return empty().extend().filter(); }
/** * Appends the provided set of filters to the current select candidates. * * @param filters the set of filters to append * @return this builder */ public Builder<BE, E> where(Filter... filters) { selectExtender.filter().with(filters); return this; }
/** * Create query branches in the select candidates with each of the provided sets of filters. * * @param filters the sets of filters, each representing a new branch in the query * @return this builder */ public Builder<BE, E> where(Filter[][] filters) { selectExtender.filter().with(filters); return this; }
@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)); }
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()); }); }
/** * @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); }
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(); }); }