@Override public Query<EntityHandle<Deleted>> apply(EntityHandle<Deleted> v) { return equal(Deleted.REFERENCE_ID, v.uuid()); } }
private Optional<EntityLayoutIntroduced> layoutIntroduction(Repository repository, Layout<?> layout) { try (ResultSet<EntityHandle<EntityLayoutIntroduced>> resultSet = repository .query(EntityLayoutIntroduced.class, equal(EntityLayoutIntroduced.FINGERPRINT, layout.getHash()))) { if (resultSet.isEmpty()) { return Optional.empty(); } else { return Optional.of(resultSet.uniqueResult().get()); } } }
/** * <p> Creates a {@link In} query which asserts that an attribute has at least one value matching any value in a set of values. * <p> Note that <b><u>this can result in more efficient queries</u></b> than several {@link Equal} queries "OR"ed together using other means. * * @param entityIndex The index to which the query refers * @param disjoint Set it to {@code true} if deduplication is not necessary because the results are disjoint. Set it to {@code false} deduplication is needed * @param attributeValues The set of values to match * @param <A> The type of the attribute * @param <O> The type of the object containing the attribute * @return An {@link In} query */ @Deprecated static <O extends Entity, A> Query<EntityHandle<O>> in(EntityIndex<O, A> entityIndex, boolean disjoint, Collection<A> attributeValues) { int n = attributeValues.size(); switch (n) { case 0: return none(entityIndex.getAttribute().getEffectiveObjectType()); case 1: A singleValue = attributeValues.iterator().next(); return equal(entityIndex, singleValue); default: // Copy the values into a Set if necessary... Set<A> values = (attributeValues instanceof Set ? (Set<A>)attributeValues : new HashSet<A>(attributeValues)); return new In<>(entityIndex.getAttribute(), disjoint, values); } }
/** * Lookup an entity by a unique ID. * * @param repository repository * @param klass entity klass * @param keyAttribute entity ID attribute * @param id ID * @param <T> entity type * @return Non-empty {@link Optional} if the entity is found, empty otherwise */ static <T extends Entity> Optional<T> lookup(Repository repository, Class<T> klass, EntityIndex<T, UUID> keyAttribute, UUID id) { try (ResultSet<EntityHandle<T>> resultSet = repository.query(klass, equal(keyAttribute, id))) { if (resultSet.isEmpty()) { return Optional.empty(); } else { return Optional.of(resultSet.uniqueResult().get()); } } }
@Override public Stream<T> getCollectionStream(Repository repository) { ResultSet<EntityHandle<NameChanged>> resultSet = repository .query(NameChanged.class, equal(NameChanged.NAME, name)); return streamOf(resultSet) .map(h -> loader.load(repository, h.get().reference()).get()) .onClose(resultSet::close); } }
@Override public Stream<T> getCollectionStream(Repository repository) { ResultSet<EntityHandle<DescriptionChanged>> resultSet = repository .query(DescriptionChanged.class, equal(DescriptionChanged.DESCRIPTION, description)); return streamOf(resultSet) .map(h -> loader.load(repository, h.get().reference()).get()) .onClose(resultSet::close); } }
EntityIndex<T, UUID> keyAttribute, EntityIndex<T, HybridTimestamp> timestampAttribute, Query<EntityHandle<T>> ...additionalQueries) { Query<EntityHandle<T>> query = equal(keyAttribute, getId()); for (Query<EntityHandle<T>> q : additionalQueries) { query = and(query, q);
B transformed = transformation.apply(h.get()); try (ResultSet<EntityHandle<EventCausalityEstablished>> causality = repository .query(EventCausalityEstablished.class, equal(EventCausalityEstablished.EVENT, h.uuid()))) { Stream<EntityHandle<EventCausalityEstablished>> causalityStream = StreamSupport .stream(Spliterators.spliterator(causality.iterator(), causality.size(),