/** * Modifies this extender to append path fragments with future calls to {@code with()} methods. * @return this instance */ public SymmetricExtender path() { queryFragmentSupplier = PathFragment::from; converter = PathFragment::new; if (isFilter != null && isFilter && !filters.fragments.isEmpty()) { with(NoopFilter.INSTANCE); } isFilter = false; return this; }
@Override protected void preCreate(OperationType.Blueprint blueprint, Transaction<BE> tx) { //disallow this if the parent resource type is a part of a metadata pack if (tx.traverseToSingle(getParent(tx), Query.path().with(asTargetBy(incorporates), With.type(MetadataPack.class)).get()) != null) { throw new IllegalArgumentException("Cannot create an operation type of resource type included in " + "a meta data pack. This would invalidate the metadata pack's identity."); } }
public final void update(Id id, U update) throws EntityNotFoundException { inTx(tx -> { Query q = id == null ? context.select().get() : context.select().with(id(id.toString())).get(); Util.update(context.entityClass, tx, q, update, (e, u, t) -> preUpdate(id, e, u, t), this::postUpdate); return null; }); }
@SuppressWarnings({"ConstantConditions", "unchecked"}) public static Query to(CanonicalPath entity) { return Query.path().with(With.path(entity)).get(); }
@Override public void preCreate(DataEntity.Blueprint blueprint, Transaction<BE> transaction) { BE mp = transaction.querySingle(context.select().path().with(asTargetBy(contains), asTargetBy(incorporates), With.type(MetadataPack.class)).get()); if (mp != null) { BE ot = transaction.querySingle(context.select().get()); throw new IllegalArgumentException( "Data '" + blueprint.getId() + "' cannot be created" + " under operation type " + transaction.extractCanonicalPath(ot) + ", because the owning resource type is part of a meta data pack." + " Doing this would invalidate meta data pack's identity."); } }
private static <BE> boolean isInMetadataPack(BE metricType, Transaction<BE> tx) { return tx.traverseToSingle(metricType, Query.path().with(Related.asTargetBy(incorporates), With.type(MetadataPack.class)).get()) != null; }
private static <BE> boolean isResourceTypeInMetadataPack(BE operationType, Transaction<BE> tx) { return tx.traverseToSingle(operationType, Query.path().with(asTargetBy(contains), asTargetBy(incorporates), With.type(MetadataPack.class)).get()) != null; } }
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(); }); }
@Override public final void initialize(Configuration configuration) { this.backend = doInitialize(configuration); tenantContext = new TraversalContext<>(this, Query.empty(), Query.path().with(With.type(Tenant.class)).get(), backend, Tenant.class, configuration, observableContext, transactionConstructor); relationshipContext = new TraversalContext<>(this, Query.empty(), Query.path().get(), backend, Relationship.class, configuration, observableContext, transactionConstructor); this.configuration = configuration; }
public final void delete(Id id) throws EntityNotFoundException { inTx(tx -> { Query q = id == null ? context.select().get() : context.select().with(id(id.toString())).get(); Util.delete(context.entityClass, tx, q, (e, t) -> preDelete(id, e, t), this::postDelete); return null; }); }
/** * Appends the provided set of filters to the current select candidates. * The filters are applied as path fragments. * * @param filters the set of filters to append as path fragments * @return this builder */ public Builder<BE, E> hop(Filter... filters) { selectExtender.path().with(filters); return this; }
/** * Create query branches in the select candidates with each of the provided sets of filters. * The filters are applied as path fragments. * * @param filters the sets of the filters to append as path fragments * @return this builder */ public Builder<BE, E> hop(Filter[][] filters) { selectExtender.path().with(filters); return this; }
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(); }); }
@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(); } }
private static <BE> boolean isResourceTypeInMetadataPack(BE resourceType, Transaction<BE> tx) { return tx.traverseToSingle(resourceType, Query.path() .with(asTargetBy(incorporates), type(MetadataPack.class)).get()) != null; } }
/** * 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()); }); }
@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(); } }