@Override public Query<EntityHandle<Deleted>> apply(EntityHandle<Deleted> v) { return equal(Deleted.REFERENCE_ID, v.uuid()); } }
/** * Creates a {@link StandingQueryAttribute} which returns true if the given attribute does not have values for * an object. * <p> * An index can then be built on this attribute, and it will be able to to answer a <code>not(has(attribute))</code> * query, returning objects which do not have values for that attribute, in constant time complexity O(1). * * @param entityIndex The index which will be used in a <code>not(has(attribute))</code> query * @return a {@link StandingQueryAttribute} which returns true if the given attribute does not have values for * an object */ @Deprecated static <O extends Entity, A> StandingQueryAttribute<EntityHandle<O>> forObjectsMissing(EntityIndex<O, A> entityIndex) { return forStandingQuery(not(has(entityIndex))); }
/** * Overloaded variant of {@link #queryOptions(Object...)} - see that method for details. * <p> * Note: This method is unnecessary as of Java 7, and is provided only for backward compatibility with Java 6 and * earlier, to eliminate generic array creation warnings output by the compiler in those versions. */ @Deprecated @SuppressWarnings({"JavaDoc"}) static QueryOptions queryOptions(Object queryOption) { return queryOptions(Collections.singleton(queryOption)); }
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); queryOptions(orderBy(descending(timestampAttribute)), applyThresholds(threshold(EngineThresholds.INDEX_ORDERING_SELECTIVITY, 0.5))))) { Iterator<EntityHandle<T>> iterator = resultSet.iterator(); if (!iterator.hasNext()) {
.build(); acc = Stream.concat(acc, Stream.of(replacement)); ResultSet<EntityHandle<A>> resultSet = repository.query(oldClass, all(oldClass)); Iterator<EntityHandle<A>> iterator = resultSet.iterator(); Stream<Event> stream = StreamSupport 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(),
/** * <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); } }
@Override public Stream<T> getCollectionStream(Repository repository) { IndexedCollection<EntityHandle<Deleted>> deletedCollection = repository.getIndexEngine() .getIndexedCollection(Deleted.class); IndexedCollection<EntityHandle<Undeleted>> undeletedCollection = repository.getIndexEngine() .getIndexedCollection( Undeleted.class); Query<EntityHandle<Deleted>> query = and(not(existsIn(undeletedCollection, Deleted.ID, Undeleted.DELETED_ID)), isLatestEntity(deletedCollection, new DeletedQueryFunction(), Deleted.TIMESTAMP)); ResultSet<EntityHandle<Deleted>> resultSet = repository.query(Deleted.class, query); return streamOf(resultSet) .map(h -> loader.load(repository, h.get().reference()).get()) .onClose(resultSet::close); }
default Optional<Deleted> deleted() { Not<EntityHandle<Deleted>> additionalQuery = not(existsIn(getRepository().getIndexEngine() .getIndexedCollection(Undeleted.class), Deleted.ID, Undeleted.DELETED_ID)); return latestAssociatedEntity(Deleted.class, Deleted.REFERENCE_ID, Deleted.TIMESTAMP, additionalQuery); }
@Test @SneakyThrows public void all() { ResultSet<EntityHandle<TestCommand>> resultSet = repository .query(TestCommand.class, EntityQueryFactory.all(TestCommand.class)); assertTrue(resultSet.isEmpty()); repository.publish(TestCommand.builder().build()).get(); resultSet = repository.query(TestCommand.class, EntityQueryFactory.all(TestCommand.class)); assertTrue(resultSet.isNotEmpty()); assertEquals(resultSet.size(), 1); }
@Override public Stream<T> getCollectionStream(Repository repository) { IndexedCollection<EntityHandle<Deleted>> deletedCollection = repository.getIndexEngine().getIndexedCollection(Deleted.class); IndexedCollection<EntityHandle<Undeleted>> undeletedCollection = repository.getIndexEngine().getIndexedCollection(Undeleted.class); ResultSet<EntityHandle<E>> resultSet = repository .query(klass, not(existsIn(deletedCollection, idAttribute, Deleted.REFERENCE_ID, not(existsIn(undeletedCollection, Deleted.ID, Undeleted.DELETED_ID))))); return streamOf(resultSet) .map(h -> loader.load(repository, h.get().uuid()).get()) .onClose(resultSet::close); }
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()); } } }
/** * A convenience method to encapsulate several objects together as {@link com.googlecode.cqengine.query.option.QueryOptions}, * where the class of the object will become its key in the QueryOptions map. * * @param queryOptions The objects to encapsulate as QueryOptions * @return A {@link QueryOptions} object */ @Deprecated static QueryOptions queryOptions(Object... queryOptions) { return queryOptions(Arrays.asList(queryOptions)); }
/** * 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()); } } }
/** * Overloaded variant of {@link #queryOptions(Object...)} - see that method for details. * <p> * Note: This method is unnecessary as of Java 7, and is provided only for backward compatibility with Java 6 and * earlier, to eliminate generic array creation warnings output by the compiler in those versions. */ @Deprecated @SuppressWarnings({"JavaDoc"}) static QueryOptions queryOptions(Object queryOption1, Object queryOption2) { @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) List<Object> queryOptions = Arrays.asList(queryOption1, queryOption2); return queryOptions(queryOptions); }
@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); } }