本文整理汇总了Java中com.googlecode.cqengine.query.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于com.googlecode.cqengine.query包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: next
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
private void next() {
Query<Value> bucket;
if (statements.size() >= 2) {
bucket = QueryFactory.and(statements.remove(0), statements.remove(0), statements);
} else if (statements.size() == 1) {
bucket = statements.get(0);
} else {
return; // empty statement, ignore.
}
if (builder == null) {
builder = bucket;
} else {
builder = QueryFactory.or(builder, bucket);
}
statements.clear();
}
示例2: getCollectionStream
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
@Override public Stream<Restaurant> getCollectionStream(Repository repository) {
Query<EntityHandle<AddressChanged>> geoRestrictions = and(
lessThanOrEqualTo(AddressChanged.BOUNDING_BOX_10K_LAT_START, address.latitude()),
lessThanOrEqualTo(AddressChanged.BOUNDING_BOX_10K_LONG_START, address.longitude()),
greaterThanOrEqualTo(AddressChanged.BOUNDING_BOX_10K_LAT_END, address.latitude()),
greaterThanOrEqualTo(AddressChanged.BOUNDING_BOX_10K_LONG_END, address.longitude()));
Query<EntityHandle<AddressChanged>> isRestaurant = existsIn(
repository.getIndexEngine().getIndexedCollection(RestaurantRegistered.class),
AddressChanged.REFERENCE_ID, RestaurantRegistered.ID);
Query<EntityHandle<AddressChanged>> latestEntity =
isLatestEntity(repository.getIndexEngine().getIndexedCollection(AddressChanged.class),
(v) -> equal(AddressChanged.REFERENCE_ID, v.get().reference()),
AddressChanged.TIMESTAMP);
Query<EntityHandle<AddressChanged>> query = and(latestEntity, geoRestrictions, isRestaurant);
ResultSet<EntityHandle<AddressChanged>> resultSet = repository.query(AddressChanged.class, query);
return streamOf(resultSet)
.map(h -> new Restaurant(repository, h.get().reference()))
.onClose(resultSet::close);
}
示例3: openingHours
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
public Map<Integer, List<OpeningHours>> openingHours() {
return
Arrays.stream(DayOfWeek.values())
.map(dow -> {
Query<EntityHandle<WorkingHoursChanged>> scope = QueryFactory.and(equal(WorkingHoursChanged
.REFERENCE_ID, getId()),
equal(WorkingHoursChanged.DAY_OF_WEEK, dow));
Query<EntityHandle<WorkingHoursChanged>> query =
scoped(scope, max(WorkingHoursChanged.TIMESTAMP));
try (ResultSet<EntityHandle<WorkingHoursChanged>> resultSet =
getRepository().query(WorkingHoursChanged.class, query)) {
return resultSet.uniqueResult().get();
}
})
.collect(Collectors.toMap(e -> e.dayOfWeek().getValue(), WorkingHoursChanged::openDuring));
}
示例4: withQuantizerOnAttribute
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
public static <A extends Comparable<A>, O extends Entity> NavigableIndex<A, O>
withQuantizerOnAttribute(DataSource dataSource, Quantizer<A> quantizer, Attribute<O, A> attribute) {
return new NavigableIndex<A, O>(dataSource, (Attribute<O, A>) serializableComparable(attribute)) {
@Override public boolean isQuantized() {
return true;
}
@Override protected A getQuantizedValue(A attributeValue) {
return quantizer.getQuantizedValue(attributeValue);
}
@Override
public ResultSet<EntityHandle<O>> retrieve(Query<EntityHandle<O>> query, QueryOptions queryOptions) {
ResultSet<EntityHandle<O>> rs = super.retrieve(query, queryOptions);
return new QuantizedResultSet<>(rs, query, queryOptions);
}
};
}
示例5: apply
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
@SneakyThrows
@Override public Stream<Event> apply(Class<? extends Entity> entity) {
Layout<? extends Entity> layout = Layout.forClass(entity);
byte[] fingerprint = layout.getHash();
Query<EntityHandle<EntityLayoutIntroduced>> query = equal(EntityLayoutIntroduced.FINGERPRINT, fingerprint);
try (ResultSet<EntityHandle<EntityLayoutIntroduced>> resultSet = repository
.query(EntityLayoutIntroduced.class,
query)) {
if (resultSet.isEmpty()) {
return Stream.of(new EntityLayoutIntroduced(fingerprint, Optional.of(layout)));
} else {
return Stream.empty();
}
}
}
示例6: testJoin
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
@Test(timeOut = 2000)
@SneakyThrows
public void testJoin() {
Query<EntityHandle<TestEvent>> testQuery = and(equal(TestEvent.TEST, "test"),
existsIn(repository.getIndexEngine().getIndexedCollection
(AnotherEvent.class),
TestEvent.TEST, AnotherEvent.TEST));
QuerySubscriber querySubscriber = new QuerySubscriber(repository);
querySubscriber.bindIndexLoader(new JavaStaticFieldIndexLoader());
CompletableFuture<Void> future = new CompletableFuture<>();
querySubscriber.addQuery(TestEvent.class, testQuery, (q) -> future.complete(null));
repository.addEntitySubscriber(querySubscriber);
repository.publish(new AnotherCommand()).get();
repository.publish(new TestCommand()).get();
future.get();
}
示例7: matchesSimpleAttribute
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, HybridTimestamp> attribute, O object, QueryOptions
queryOptions) {
Query<O> actualQuery = query == null ? queryFunction.apply(object) : query;
Optional<Boolean> terminatedQuery = terminatedQuery(object, actualQuery, queryOptions);
if (terminatedQuery.isPresent()) {
return terminatedQuery.get();
}
HybridTimestamp value = attribute.getValue(object, queryOptions);
IndexedCollection<O> collection = (IndexedCollection<O>) getCollection(queryOptions);
try (ResultSet<O> resultSet = collection.retrieve(and(
actualQuery,
greaterThan(timestampAttribute, value)))) {
return matches(resultSet, actualQuery, object, queryOptions);
}
}
示例8: matchesNonSimpleAttribute
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
@Override
protected boolean matchesNonSimpleAttribute(Attribute<O, HybridTimestamp> attribute, O object, QueryOptions
queryOptions) {
Query<O> actualQuery = query == null ? queryFunction.apply(object) : query;
Optional<Boolean> terminatedQuery = terminatedQuery(object, actualQuery, queryOptions);
if (terminatedQuery.isPresent()) {
return terminatedQuery.get();
}
Iterable<HybridTimestamp> values = attribute.getValues(object, queryOptions);
List<Query<O>> conditions = StreamSupport.stream(values.spliterator(), false)
.map(v -> greaterThan(timestampAttribute, v))
.collect(Collectors.toList());
Query<O> timestampQuery = conditions.size() == 1 ? conditions.get(0) : new Or<>(conditions);
IndexedCollection<O> collection = (IndexedCollection<O>) getCollection(queryOptions);
try (ResultSet<O> resultSet = collection.retrieve(and(
actualQuery,
timestampQuery))) {
return matches(resultSet, actualQuery, object, queryOptions);
}
}
示例9: getMappers
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
private static Map<Class<? extends Query>, Mapper> getMappers(){
HashMap<Class<? extends Query>,Mapper> map = new HashMap<>();
//Simple
map.put(Equal.class,new EqualMapper());
map.put(GreaterThan.class,new GreaterThanMapper());
map.put(LessThan.class,new LessThanMapper());
map.put(Between.class,new BetweenMapper());
map.put(Has.class,new HasMapper());
//Logical
map.put(And.class,new AndMapper());
map.put(Or.class,new OrMapper());
map.put(Not.class,new NotMapper());
return Collections.unmodifiableMap(map);
}
示例10: in
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
/**
* <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
*/
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);
}
}
示例11: where
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
/**
* Same as {@link #where(java.lang.Object) }, but it
* also passes the given {@link QueryOptions} to the internal collection
* when querying it
* @param <Q>
* @param obj
* @param options
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <Q> Stream<T> where(Q obj, QueryOptions options) {
if(obj instanceof Query){
Query<T> query = (Query<T>)obj;
ResultSet rs = coll.retrieve(query);
try(Stream<T> stream = StreamSupport.stream(rs.spliterator(),false)){
List<T> buf = stream.collect(Collectors.toList());
return buf.stream();
}
finally{
rs.close();
}
}
throw new IllegalArgumentException(getClass().getName() +" does not support " + obj.getClass().getName() + " for querying");
}
示例12: in
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
/**
* <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);
}
}
示例13: test
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
@Test @SneakyThrows
public void test() {
UUID uuid = UUID.randomUUID();
repository.publish(new TestCommand("test1", uuid)).get();
Query<EntityHandle<TestEvent>> query = isLatestEntity(equal(TestEvent.REFERENCE_ID, uuid),
TestEvent.TIMESTAMP);
try (ResultSet<EntityHandle<TestEvent>> resultSet = repository.query(TestEvent.class, query)) {
assertEquals(resultSet.size(), 1);
assertEquals(resultSet.uniqueResult().get().test(), "test1");
}
repository.publish(new TestCommand("test2", uuid)).get();
try (ResultSet<EntityHandle<TestEvent>> resultSet = repository.query(TestEvent.class, query)) {
assertEquals(resultSet.size(), 1);
assertEquals(resultSet.uniqueResult().get().test(), "test2");
}
}
示例14: testMassive
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
@Test @SneakyThrows
public void testMassive() {
UUID uuid = UUID.randomUUID();
for (int i = 0; i < 10000; i++ ) {
repository.publish(new TestCommand("test" + (i + 1), uuid)).get();
}
Query<EntityHandle<TestEvent>> query = isLatestEntity(equal(TestEvent.REFERENCE_ID, uuid),
TestEvent.TIMESTAMP);
long t1 = System.nanoTime();
try (ResultSet<EntityHandle<TestEvent>> resultSet = repository.query(TestEvent.class, query)) {
assertEquals(resultSet.size(), 1);
assertEquals(resultSet.uniqueResult().get().test(), "test10000");
long t2 = System.nanoTime();
long time = TimeUnit.SECONDS.convert(t2 - t1, TimeUnit.NANOSECONDS);
if (time > 1) {
System.err.println("Warning: [IsLatestEntityTest.testMassive] isLatestEntity is slow, took " + time +
" seconds");
}
}
}
示例15: testFunction
import com.googlecode.cqengine.query.Query; //导入依赖的package包/类
@Test @SneakyThrows
public void testFunction() {
UUID uuid = UUID.randomUUID();
repository.publish(new TestCommand("test1", uuid)).get();
repository.publish(new TestCommand("test2", uuid)).get();
UUID uuidN = UUID.randomUUID();
repository.publish(new TestCommand("testN1", uuidN)).get();
repository.publish(new TestCommand("testN2", uuidN)).get();
Query<EntityHandle<TestEvent>> query = isLatestEntity((h) -> equal(TestEvent.REFERENCE_ID, h.get().reference()),
TestEvent.TIMESTAMP);
try (ResultSet<EntityHandle<TestEvent>> resultSet = repository.query(TestEvent.class, query)) {
assertEquals(resultSet.size(), 2);
List<EntityHandle<TestEvent>> result = Iterables.toList(resultSet);
assertTrue(Iterators.any(result.iterator(), e -> e.get().test().contentEquals("test2")));
assertTrue(Iterators.any(result.iterator(), e -> e.get().test().contentEquals("testN2")));
}
}