Java Code Examples for com.google.appengine.api.datastore.Query#FilterPredicate
The following examples show how to use
com.google.appengine.api.datastore.Query#FilterPredicate .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestReport.java From appengine-tck with Apache License 2.0 | 6 votes |
/** * Finds the {@code TestReport} with the given build type id ordered by build id in the descendant order. * * @param buildTypeId the build type id. * @param limit the optional fetch limit, by default {@link com.google.appengine.tck.site.endpoints.TestReport#DEFAULT_FETCH_LIMIT}. * @param reports the reports entry point * @return the matching test reports list or an empty one if none. */ @SuppressWarnings("unchecked") public static List<TestReport> findByBuildTypeIdOrderByBuildIdDesc(String buildTypeId, Optional<Integer> limit, Reports reports) { final MemcacheService memcacheService = reports.getMemcacheService(); List<TestReport> results = (List<TestReport>) memcacheService.get(buildTypeId); if (results == null) { final Filter buildTypeFilter = new Query.FilterPredicate("buildTypeId", FilterOperator.EQUAL, buildTypeId); final Query query = new Query(TEST_REPORT).setFilter(buildTypeFilter).addSort("buildId", DESCENDING); final DatastoreService datastoreService = reports.getDatastoreService(); final PreparedQuery preparedQuery = datastoreService.prepare(query); final List<Entity> entities = preparedQuery.asList(FetchOptions.Builder.withLimit(limit.or(DEFAULT_FETCH_LIMIT))); results = new ArrayList<>(); for (Entity oneEntity : entities) { final TestReport report = from(oneEntity); results.add(report); } memcacheService.put(buildTypeId, results); } return results; }
Example 2
Source File: DeviceSubscription.java From io2014-codelabs with Apache License 2.0 | 5 votes |
/** * Deletes all device subscription entities continuously using task push queue. * * @param time Threshold time before which entities created will be deleted. If time is null, * current time is used and set as Threshold time. * @param cursor Query cursor indicates last query result set position */ protected void deleteAllContinuously(Date time, String cursor) { if (time == null) { time = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime(); } Query.FilterPredicate timeFilter = new Query.FilterPredicate(PROPERTY_TIMESTAMP, FilterOperator.LESS_THAN_OR_EQUAL, time); QueryResultIterable<Entity> entities; List<Key> keys = new ArrayList<Key> (); List<String> subIds = new ArrayList<String> (); Query queryAll; queryAll = new Query(DeviceSubscription.SUBSCRIPTION_KIND).setFilter(timeFilter); FetchOptions options = FetchOptions.Builder.withLimit(BATCH_DELETE_SIZE); if (!StringUtility.isNullOrEmpty(cursor)) { options.startCursor(Cursor.fromWebSafeString(cursor)); } entities = this.datastoreService.prepare(queryAll).asQueryResultIterable(options); if (entities != null && entities.iterator() != null) { for (Entity entity : entities) { keys.add(entity.getKey()); String[] ids = new Gson().fromJson((String) entity.getProperty(PROPERTY_SUBSCRIPTION_IDS), String[].class); subIds.addAll(Arrays.asList(ids)); } } if (keys.size() > 0) { deleteInBatch(keys); enqueueDeleteDeviceSubscription(time, entities.iterator().getCursor().toWebSafeString()); } if (subIds.size() > 0) { deletePsiSubscriptions(subIds); } }
Example 3
Source File: FilterDto.java From io2014-codelabs with Apache License 2.0 | 5 votes |
/** * Converts the tree of {@link FilterDto}s to a tree of {@link FilterDto}s. */ public Filter getDatastoreFilter() { switch (this.operator) { case EQ: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.EQUAL, getOperand()); case LT: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.LESS_THAN, getOperand()); case LE: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.LESS_THAN_OR_EQUAL, getOperand()); case GT: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.GREATER_THAN, getOperand()); case GE: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.GREATER_THAN_OR_EQUAL, getOperand()); case NE: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.NOT_EQUAL, getOperand()); case IN: LinkedList<Object> l = new LinkedList<Object>(values); l.removeFirst(); return new Query.FilterPredicate(getPropName(), Query.FilterOperator.IN, l); case AND: return new Query.CompositeFilter(CompositeFilterOperator.AND, getSubfilters(subfilters)); case OR: return new Query.CompositeFilter(CompositeFilterOperator.OR, getSubfilters(subfilters)); } return null; }
Example 4
Source File: DeviceSubscription.java From solutions-mobile-backend-starter-java with Apache License 2.0 | 5 votes |
/** * Deletes all device subscription entities continuously using task push queue. * * @param time Threshold time before which entities created will be deleted. If time is null, * current time is used and set as Threshold time. * @param cursor Query cursor indicates last query result set position */ protected void deleteAllContinuously(Date time, String cursor) { if (time == null) { time = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime(); } Query.FilterPredicate timeFilter = new Query.FilterPredicate(PROPERTY_TIMESTAMP, FilterOperator.LESS_THAN_OR_EQUAL, time); QueryResultIterable<Entity> entities; List<Key> keys = new ArrayList<Key> (); List<String> subIds = new ArrayList<String> (); Query queryAll; queryAll = new Query(DeviceSubscription.SUBSCRIPTION_KIND).setFilter(timeFilter); FetchOptions options = FetchOptions.Builder.withLimit(BATCH_DELETE_SIZE); if (!StringUtility.isNullOrEmpty(cursor)) { options.startCursor(Cursor.fromWebSafeString(cursor)); } entities = this.datastoreService.prepare(queryAll).asQueryResultIterable(options); if (entities != null && entities.iterator() != null) { for (Entity entity : entities) { keys.add(entity.getKey()); String[] ids = new Gson().fromJson((String) entity.getProperty(PROPERTY_SUBSCRIPTION_IDS), String[].class); subIds.addAll(Arrays.asList(ids)); } } if (keys.size() > 0) { deleteInBatch(keys); enqueueDeleteDeviceSubscription(time, entities.iterator().getCursor().toWebSafeString()); } if (subIds.size() > 0) { deletePsiSubscriptions(subIds); } }
Example 5
Source File: FilterDto.java From solutions-mobile-backend-starter-java with Apache License 2.0 | 5 votes |
/** * Converts the tree of {@link FilterDto}s to a tree of {@link FilterDto}s. */ public Filter getDatastoreFilter() { switch (this.operator) { case EQ: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.EQUAL, getOperand()); case LT: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.LESS_THAN, getOperand()); case LE: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.LESS_THAN_OR_EQUAL, getOperand()); case GT: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.GREATER_THAN, getOperand()); case GE: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.GREATER_THAN_OR_EQUAL, getOperand()); case NE: return new Query.FilterPredicate(getPropName(), Query.FilterOperator.NOT_EQUAL, getOperand()); case IN: LinkedList<Object> l = new LinkedList<Object>(values); l.removeFirst(); return new Query.FilterPredicate(getPropName(), Query.FilterOperator.IN, l); case AND: return new Query.CompositeFilter(CompositeFilterOperator.AND, getSubfilters(subfilters)); case OR: return new Query.CompositeFilter(CompositeFilterOperator.OR, getSubfilters(subfilters)); } return null; }
Example 6
Source File: QueryTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testFilterPredicate() { Query query = new Query(kindName, rootKey); query.setFilter(new FilterPredicate("intData", Query.FilterOperator.EQUAL, 20)); Entity e = service.prepare(query).asSingleEntity(); assertEquals("check query kind", kindName, query.getKind()); assertEquals("check query ancesor", rootKey, query.getAncestor()); Query.FilterPredicate fp = (Query.FilterPredicate) query.getFilter(); assertEquals("check FilterPredicate name", "intData", fp.getPropertyName()); assertEquals("check FilterPredicate operator", Query.FilterOperator.EQUAL, fp.getOperator()); assertEquals("check FilterPredicate value", e.getProperty("intData").toString(), fp.getValue().toString()); }
Example 7
Source File: CommentManagerNoSql.java From solutions-photo-sharing-demo-java with Apache License 2.0 | 5 votes |
@Override public Iterable<Comment> getComments(Photo photo) { Query query = new Query(getKind()); Query.Filter photoIdFilter = new Query.FilterPredicate(CommentNoSql.FIELD_NAME_PHOTO_ID, FilterOperator.EQUAL, photo.getId()); List<Filter> filters = Arrays.asList(photoIdFilter, new Query.FilterPredicate( CommentNoSql.FIELD_NAME_PHOTO_OWNER_ID, FilterOperator.EQUAL, photo.getOwnerId())); Filter filter = new Query.CompositeFilter(CompositeFilterOperator.AND, filters); query.setFilter(filter); query.addSort(CommentNoSql.FIELD_NAME_TIMESTAMP, SortDirection.DESCENDING); FetchOptions options = FetchOptions.Builder.withDefaults(); return queryEntities(query, options); }
Example 8
Source File: PhotoManagerNoSql.java From solutions-photo-sharing-demo-java with Apache License 2.0 | 5 votes |
@Override public Iterable<Photo> getActivePhotos() { Query query = new Query(getKind()); Query.Filter filter = new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE, FilterOperator.EQUAL, true); query.addSort(PhotoNoSql.FIELD_NAME_UPLOAD_TIME, SortDirection.DESCENDING); query.setFilter(filter); FetchOptions options = FetchOptions.Builder.withDefaults(); return queryEntities(query, options); }
Example 9
Source File: PhotoManagerNoSql.java From solutions-photo-sharing-demo-java with Apache License 2.0 | 5 votes |
@Override public Iterable<Photo> getOwnedPhotos(String userId) { Query query = new Query(getKind()); query.setAncestor(userManager.createDemoUserKey(userId)); Query.Filter filter = new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE, FilterOperator.EQUAL, true); query.setFilter(filter); FetchOptions options = FetchOptions.Builder.withDefaults(); return queryEntities(query, options); }
Example 10
Source File: PhotoManagerNoSql.java From solutions-photo-sharing-demo-java with Apache License 2.0 | 5 votes |
@Override public Iterable<Photo> getSharedPhotos(String userId) { Query query = new Query(getKind()); Query.Filter ownerFilter = new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_OWNER_ID, FilterOperator.NOT_EQUAL, userId); List<Query.Filter> filterList = Arrays.asList(ownerFilter, new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_SHARED, FilterOperator.EQUAL, true), new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE, FilterOperator.EQUAL, true) ); Filter filter = new Query.CompositeFilter(CompositeFilterOperator.AND, filterList); query.setFilter(filter); FetchOptions options = FetchOptions.Builder.withDefaults(); return queryEntities(query, options); }
Example 11
Source File: PhotoManagerNoSql.java From solutions-photo-sharing-demo-java with Apache License 2.0 | 5 votes |
@Override public Iterable<Photo> getDeactivedPhotos() { Query query = new Query(getKind()); Query.Filter filter = new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE, FilterOperator.EQUAL, false); query.setFilter(filter); FetchOptions options = FetchOptions.Builder.withDefaults(); return queryEntities(query, options); }
Example 12
Source File: QueryTestBase.java From appengine-tck with Apache License 2.0 | 4 votes |
private Query.FilterPredicate createFilter(Query.FilterOperator operator, Object value) { return new Query.FilterPredicate(SINGLE_PROPERTY_NAME, operator, value); }