本文整理汇总了Java中com.google.appengine.api.datastore.Query.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setFilter方法的具体用法?Java Query.setFilter怎么用?Java Query.setFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.datastore.Query
的用法示例。
在下文中一共展示了Query.setFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNationalHighScores
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
/**
* Method to retrieve the national high scores
* @return
*/
public List<Entity> getNationalHighScores(String countryCode){
log.info("Retrieving national high scores");
//create the country code filter
Filter country = new FilterPredicate(Constants.COUNTRY_CODE,FilterOperator.EQUAL,countryCode);
//create the query to read the records sorted by score
Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
//set the filter to the query
q.setFilter(country);
PreparedQuery pq = datastore.prepare(q);
//retrieve and return the list of records
return pq.asList(FetchOptions.Builder.withLimit(100));
}
示例2: getMonthlyHighScores
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
/**
* Method to retrieve the monthly high scores
* @return
*/
public List<Entity> getMonthlyHighScores(){
log.info("Retrieving monthly high scores");
//calculate calendar info
Calendar calendar= Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int month=calendar.get(Calendar.MONTH);
//create filters
Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
Filter monthFilter = new FilterPredicate(Constants.MONTH,FilterOperator.EQUAL,month);
//create the query to read the records sorted by score
Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
//set filters to the query
q.setFilter(yearFilter);
q.setFilter(monthFilter);
//prepare query
PreparedQuery pq = datastore.prepare(q);
//retrieve and return the list of records
return pq.asList(FetchOptions.Builder.withLimit(100));
}
示例3: getWeeklyHighScores
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
/**
* Method to retrieve the weekly high scores
* @return
*/
public List<Entity> getWeeklyHighScores(){
log.info("Retrieving weekly high scores");
//calculate calendar info
Calendar calendar= Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int week=calendar.get(Calendar.WEEK_OF_YEAR);
//create filters
Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
Filter weekFilter = new FilterPredicate(Constants.WEEK_OF_THE_YEAR,FilterOperator.EQUAL,week);
//create the query to read the records sorted by score
Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
//set filters to the query
q.setFilter(yearFilter);
q.setFilter(weekFilter);
//prepare query
PreparedQuery pq = datastore.prepare(q);
//retrieve and return the list of records
return pq.asList(FetchOptions.Builder.withLimit(100));
}
示例4: getDailyHighScores
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
/**
* Method to retrieve the daily high scores
* @return
*/
public List<Entity> getDailyHighScores(){
log.info("Retrieving weekly high scores");
//calculate calendar info
Calendar calendar= Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int day=calendar.get(Calendar.DAY_OF_YEAR);
//create filters
Filter yearFilter = new FilterPredicate(Constants.YEAR,FilterOperator.EQUAL,year);
Filter dayFilter = new FilterPredicate(Constants.DAY_OF_THE_YEAR,FilterOperator.EQUAL,day);
//create the query to read the records sorted by score
Query q = new Query(Constants.RECORD).addSort(Constants.SCORE, SortDirection.DESCENDING);
//set filters to the query
q.setFilter(yearFilter);
q.setFilter(dayFilter);
//prepare query
PreparedQuery pq = datastore.prepare(q);
//retrieve and return the list of records
return pq.asList(FetchOptions.Builder.withLimit(100));
}
示例5: getSnapshotEntryAtOrBefore
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
@Nullable private SnapshotEntry getSnapshotEntryAtOrBefore(@Nullable Long atOrBeforeVersion)
throws RetryableFailure, PermanentFailure {
Query q = new Query(snapshotEntityKind)
.setAncestor(makeRootEntityKey(objectId))
.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.DESCENDING);
if (atOrBeforeVersion != null) {
q.setFilter(FilterOperator.LESS_THAN_OR_EQUAL.of(Entity.KEY_RESERVED_PROPERTY,
makeSnapshotKey(objectId, atOrBeforeVersion)));
}
Entity e = tx.prepare(q).getFirstResult();
log.info("query " + q + " returned first result " + e);
if (e == null) {
return null;
} else {
snapshotPropertyMover.postGet(e);
return parseSnapshot(e);
}
}
示例6: getAccountKeyByUser
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
/**
* Returns the Account key associated with the specified user.
* @param pm reference to the persistence manager
* @param user user to return the account key for
* @return the Account key associated with the specified user; or <code>null</code> if no account is associated with the specified user
*/
public static Key getAccountKeyByUser( final PersistenceManager pm, final User user ) {
final String memcacheKey = CACHE_KEY_USER_ACCOUNT_KEY_PREFIX + user.getEmail();
final String accountKeyString = (String) memcacheService.get( memcacheKey );
if ( accountKeyString != null )
return KeyFactory.stringToKey( accountKeyString );
final Query q = new Query( Account.class.getSimpleName() );
q.setFilter( new FilterPredicate( "user", FilterOperator.EQUAL, user ) );
q.setKeysOnly();
final List< Entity > entityList = DatastoreServiceFactory.getDatastoreService().prepare( q ).asList( FetchOptions.Builder.withDefaults() );
if ( entityList.isEmpty() )
return null;
final Key accountKey = entityList.get( 0 ).getKey();
try {
memcacheService.put( memcacheKey, KeyFactory.keyToString( accountKey ) );
}
catch ( final MemcacheServiceException mse ) {
LOGGER.log( Level.WARNING, "Failed to put key to memcache: " + memcacheKey, mse );
// Ignore memcache errors, do not prevent serving user request
}
return accountKey;
}
示例7: getAccountKeyByAuthKey
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
/**
* Returns the Account key associated with the specified authorization key.
* @param pm reference to the persistence manager
* @param authorizationKey authorization key to return the account key for
* @return the Account key associated with the specified authorization key; or <code>null</code> if the authorization key is invalid
*/
public static Key getAccountKeyByAuthKey( final PersistenceManager pm, final String authorizationKey ) {
final String memcacheKey = CACHE_KEY_AUTH_KEY_ACCOUNT_KEY_PREFIX + authorizationKey;
final String accountKeyString = (String) memcacheService.get( memcacheKey );
if ( accountKeyString != null )
return KeyFactory.stringToKey( accountKeyString );
final Query q = new Query( Account.class.getSimpleName() );
q.setFilter( new FilterPredicate( "authorizationKey", FilterOperator.EQUAL, authorizationKey ) );
q.setKeysOnly();
final List< Entity > entityList = DatastoreServiceFactory.getDatastoreService().prepare( q ).asList( FetchOptions.Builder.withDefaults() );
if ( entityList.isEmpty() )
return null;
final Key accountKey = entityList.get( 0 ).getKey();
try {
memcacheService.put( memcacheKey, KeyFactory.keyToString( accountKey ) );
}
catch ( final MemcacheServiceException mse ) {
LOGGER.log( Level.WARNING, "Failed to put key to memcache: " + memcacheKey, mse );
// Ignore memcache errors, do not prevent serving user request
}
return accountKey;
}
示例8: projectionQuery_grouping_filtersDuplicates
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
@Test
public void projectionQuery_grouping_filtersDuplicates() {
putTestData("some duplicate", 0L);
putTestData("some duplicate", 0L);
putTestData("too big", 1L);
// [START grouping]
Query q = new Query("TestKind");
q.addProjection(new PropertyProjection("A", String.class));
q.addProjection(new PropertyProjection("B", Long.class));
q.setDistinct(true);
q.setFilter(Query.FilterOperator.LESS_THAN.of("B", 1L));
q.addSort("B", Query.SortDirection.DESCENDING);
q.addSort("A");
// [END grouping]
List<Entity> entities =
datastore.prepare(q).asList(FetchOptions.Builder.withLimit(5));
assertThat(entities).hasSize(1);
Entity entity = entities.get(0);
assertThat((String) entity.getProperty("A")).named("entity.A").isEqualTo("some duplicate");
assertThat((long) entity.getProperty("B")).named("entity.B").isEqualTo(0L);
}
示例9: printPropertyRange
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
void printPropertyRange(DatastoreService ds, PrintWriter writer) {
// Start with unrestricted keys-only property query
Query q = new Query(Entities.PROPERTY_METADATA_KIND).setKeysOnly();
// Limit range
q.setFilter(
CompositeFilterOperator.and(
new FilterPredicate(
Entity.KEY_RESERVED_PROPERTY,
Query.FilterOperator.GREATER_THAN_OR_EQUAL,
Entities.createPropertyKey("Employee", "salary")),
new FilterPredicate(
Entity.KEY_RESERVED_PROPERTY,
Query.FilterOperator.LESS_THAN_OR_EQUAL,
Entities.createPropertyKey("Manager", "salary"))));
q.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
// Print query results
for (Entity e : ds.prepare(q).asIterable()) {
writer.println(e.getKey().getParent().getName() + ": " + e.getKey().getName());
}
}
示例10: representationsOfProperty
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
Collection<String> representationsOfProperty(DatastoreService ds, String kind, String property) {
// Start with unrestricted non-keys-only property query
Query q = new Query(Entities.PROPERTY_METADATA_KIND);
// Limit to specified kind and property
q.setFilter(
new FilterPredicate(
"__key__", Query.FilterOperator.EQUAL, Entities.createPropertyKey(kind, property)));
// Get query result
Entity propInfo = ds.prepare(q).asSingleEntity();
// Return collection of property representations
return (Collection<String>) propInfo.getProperty("property_representation");
}
示例11: projectionQuery_grouping_filtersDuplicates
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
@Test
public void projectionQuery_grouping_filtersDuplicates() {
putTestData("some duplicate", 0L);
putTestData("some duplicate", 0L);
putTestData("too big", 1L);
// [START grouping]
Query q = new Query("TestKind");
q.addProjection(new PropertyProjection("A", String.class));
q.addProjection(new PropertyProjection("B", Long.class));
q.setDistinct(true);
q.setFilter(Query.FilterOperator.LESS_THAN.of("B", 1L));
q.addSort("B", Query.SortDirection.DESCENDING);
q.addSort("A");
// [END grouping]
List<Entity> entities = datastore.prepare(q).asList(FetchOptions.Builder.withLimit(5));
assertThat(entities).hasSize(1);
Entity entity = entities.get(0);
assertThat((String) entity.getProperty("A")).named("entity.A").isEqualTo("some duplicate");
assertThat((long) entity.getProperty("B")).named("entity.B").isEqualTo(0L);
}
示例12: getSessionsByUserKey
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
public static ArrayList<Session> getSessionsByUserKey(DatastoreService datastore, Key userKey) {
Filter userFilter = new FilterPredicate(DatastoreProperties.USER_KEY.getName(), FilterOperator.EQUAL, userKey);
Query q = new Query(DatastoreProperties.KIND.getName());
q.setFilter(userFilter);
PreparedQuery pq = datastore.prepare(q);
ArrayList<Session> sessions = new ArrayList<Session>();
for(Entity result : pq.asIterable())
sessions.add(new Session(result));
return sessions;
}
示例13: printLowercaseKinds
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
void printLowercaseKinds(DatastoreService ds, PrintWriter writer) {
// Start with unrestricted kind query
Query q = new Query(Entities.KIND_METADATA_KIND);
List<Filter> subFils = new ArrayList();
// Limit to lowercase initial letters
subFils.add(
new FilterPredicate(
Entity.KEY_RESERVED_PROPERTY,
FilterOperator.GREATER_THAN_OR_EQUAL,
Entities.createKindKey("a")));
String endChar = Character.toString((char) ('z' + 1)); // Character after 'z'
subFils.add(
new FilterPredicate(
Entity.KEY_RESERVED_PROPERTY,
FilterOperator.LESS_THAN,
Entities.createKindKey(endChar)));
q.setFilter(CompositeFilterOperator.and(subFils));
// Print heading
writer.println("Lowercase kinds:");
// Print query results
for (Entity e : ds.prepare(q).asIterable()) {
writer.println(" " + e.getKey().getName());
}
}
示例14: getNamespaces
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
List<String> getNamespaces(DatastoreService ds, String start, String end) {
// Start with unrestricted namespace query
Query q = new Query(Entities.NAMESPACE_METADATA_KIND);
List<Filter> subFilters = new ArrayList();
// Limit to specified range, if any
if (start != null) {
subFilters.add(
new FilterPredicate(
Entity.KEY_RESERVED_PROPERTY,
FilterOperator.GREATER_THAN_OR_EQUAL,
Entities.createNamespaceKey(start)));
}
if (end != null) {
subFilters.add(
new FilterPredicate(
Entity.KEY_RESERVED_PROPERTY,
FilterOperator.LESS_THAN_OR_EQUAL,
Entities.createNamespaceKey(end)));
}
q.setFilter(CompositeFilterOperator.and(subFilters));
// Initialize result list
List<String> results = new ArrayList<String>();
// Build list of query results
for (Entity e : ds.prepare(q).asIterable()) {
results.add(Entities.getNamespaceFromNamespaceKey(e.getKey()));
}
// Return result list
return results;
}
示例15: convert
import com.google.appengine.api.datastore.Query; //导入方法依赖的package包/类
public Query convert(Criteria criteria) {
Query query = new Query(kind);
query.setFilter(FilterCriteriaConverter.INSTANCE.convert(criteria));
return query;
}