当前位置: 首页>>代码示例>>Java>>正文


Java FilterPredicate类代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.Query.FilterPredicate的典型用法代码示例。如果您正苦于以下问题:Java FilterPredicate类的具体用法?Java FilterPredicate怎么用?Java FilterPredicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FilterPredicate类属于com.google.appengine.api.datastore.Query包,在下文中一共展示了FilterPredicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNationalHighScores

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的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));
}
 
开发者ID:mastorak,项目名称:LeaderboardServer,代码行数:20,代码来源:ScoreDAO.java

示例2: getMonthlyHighScores

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的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));
}
 
开发者ID:mastorak,项目名称:LeaderboardServer,代码行数:29,代码来源:ScoreDAO.java

示例3: getWeeklyHighScores

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的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));
}
 
开发者ID:mastorak,项目名称:LeaderboardServer,代码行数:29,代码来源:ScoreDAO.java

示例4: getDailyHighScores

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的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));
}
 
开发者ID:mastorak,项目名称:LeaderboardServer,代码行数:30,代码来源:ScoreDAO.java

示例5: deleteSessionWithValue

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的package包/类
protected void deleteSessionWithValue(String varName, String varValue) {
  Transaction transaction = datastore.beginTransaction();
  try {
    Query query = new Query(SESSION_KIND)
        .setFilter(new FilterPredicate(varName, FilterOperator.EQUAL, varValue));
    Iterator<Entity> results = datastore.prepare(transaction, query).asIterator();
    while (results.hasNext()) {
      Entity stateEntity = results.next();
      datastore.delete(transaction, stateEntity.getKey());
    }
    transaction.commit();
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:18,代码来源:DatastoreSessionFilter.java

示例6: setFilter

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的package包/类
@Override
void setFilter(ArrayList<com.google.appengine.api.datastore.Query.Filter> filters) {
  if (attribute.getDataType() == DataType.DECIMAL) {
    Double d = null;
    if (value != null) {
      if ( value instanceof WrappedBigDecimal ) {
        WrappedBigDecimal wbd = (WrappedBigDecimal) value;
        if ( wbd.isSpecialValue() ) {
          d = wbd.d;
        } else {
          d = wbd.doubleValue();
        }
      } else if ( value instanceof BigDecimal ) {
        BigDecimal bd = (BigDecimal) value;
        d = bd.doubleValue();
      } else if ( value instanceof Double ) {
        d = (Double) value;
      } else {
        d = Double.valueOf(value.toString());
      }
    }
    filters.add(new FilterPredicate(attribute.getName(), QueryImpl.operationMap.get(op), d));
  } else {
    filters.add(new FilterPredicate(attribute.getName(), QueryImpl.operationMap.get(op), value));
  }
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:27,代码来源:SimpleFilterTracker.java

示例7: setFilter

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的package包/类
@Override
void setFilter(ArrayList<com.google.appengine.api.datastore.Query.Filter> filters) {
  if (attribute.getDataType() == DataType.DECIMAL) {
    Set<Double> dvSet = new HashSet<Double>();
    for (Object value : valueSet) {
      Double d = null;
      if (value != null) {
        BigDecimal bd = (BigDecimal) value;
        d = bd.doubleValue();
      }
      dvSet.add(d);
    }
    filters.add(new FilterPredicate( attribute.getName(), FilterOperator.IN, dvSet));
  } else {
    filters.add(new FilterPredicate( attribute.getName(), FilterOperator.IN, valueSet));
  }
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:18,代码来源:ValueSetFilterTracker.java

示例8: removeObject

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的package包/类
/**
 * Remove an object from the datastore
 * 
 * @param uri The URI
 */
public void removeObject(String uri) {
	if (!isObjectRegistered(uri)) {
		return;
	}
	// Remove all WebObjectInstance entries associated
	Filter uriFilter = new FilterPredicate("uri", FilterOperator.EQUAL, uri);
	Query instanceQuery = new Query(OBJECT_INSTANCE)
			.setFilter(uriFilter)
			.addSort("timestamp", SortDirection.DESCENDING);
	List<Entity> instances = datastoreService
			.prepare(instanceQuery)
			.asList(FetchOptions.Builder.withDefaults());
	List<Key> keys = new ArrayList<Key>();
	for (Entity e : instances) {
		keys.add(e.getKey());
	}
	datastoreService.delete(keys);
	
	// Remove actual WebObject entry
	Query objectQuery = new Query(OBJECT).setFilter(uriFilter);
	Entity object = datastoreService.prepare(objectQuery).asSingleEntity();
	datastoreService.delete(object.getKey());
}
 
开发者ID:lorenzosaino,项目名称:gae-webmonitor,代码行数:29,代码来源:DataStoreService.java

示例9: updateObjectInstanceTimestamp

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的package包/类
/**
 * Update the timestamp of an object instance
 * 
 * @param uri The URI of the Web object instance
 * @param oldTimestamp The old timestamp
 * @param newTimestamp The new timestamp
 */
public void updateObjectInstanceTimestamp(String uri, Date oldTimestamp,
		Date newTimestamp) {
	Filter uriFilter = new FilterPredicate("uri", FilterOperator.EQUAL, uri);
	Filter timestampFilter = new FilterPredicate("timestamp", FilterOperator.EQUAL, oldTimestamp);
	Query query = new Query(OBJECT_INSTANCE)
		.setFilter(uriFilter)
		.setFilter(timestampFilter);
	Entity instance = datastoreService.prepare(query).asSingleEntity();
	if (instance == null) {
		throw new IllegalArgumentException(
				"No record with matching URI and timestamp was found");
	}
	instance.setProperty("timestamp", newTimestamp);
	datastoreService.put(instance);
}
 
开发者ID:lorenzosaino,项目名称:gae-webmonitor,代码行数:23,代码来源:DataStoreService.java

示例10: getAllObjectInstances

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的package包/类
/**
 * Get all instances of an object present in the data store
 * 
 * @param uri The URI of the Web object
 * @return The list of Web instances
 */
public List<WebObjectInstance> getAllObjectInstances(String uri) {
	Filter uriFilter = new FilterPredicate("uri", FilterOperator.EQUAL, uri);
	Query query = new Query(OBJECT_INSTANCE)
			.setFilter(uriFilter)
			.addSort("timestamp", SortDirection.DESCENDING);

	List<Entity> instances = datastoreService.prepare(query)
			.asList(FetchOptions.Builder.withDefaults());
	List<WebObjectInstance> instanceList = new ArrayList<WebObjectInstance>();
	for (Entity e : instances) {
		String content = ((Text) e.getProperty("content")).getValue();
		String contentType = (String) e.getProperty("contentType");
		int statusCode = ((Integer) e.getProperty("statusCode")).intValue();
		Date timestamp = (Date) e.getProperty("timestamp");
		instanceList.add(new WebObjectInstance(uri, content, contentType,
				timestamp, statusCode));
	}
	return instanceList;
}
 
开发者ID:lorenzosaino,项目名称:gae-webmonitor,代码行数:26,代码来源:DataStoreService.java

示例11: getMostRecentObjectInstance

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的package包/类
/**
 * Get the most recent instance of a web object available
 * 
 * @param uri The URI of the Web object
 * @return The instance of the Web object
 */
public WebObjectInstance getMostRecentObjectInstance(String uri) {
	Filter uriFilter = new FilterPredicate("uri", FilterOperator.EQUAL, uri);
	Query query = new Query(OBJECT_INSTANCE)
			.setFilter(uriFilter)
			.addSort("timestamp", SortDirection.DESCENDING);
	List<Entity> instances = datastoreService.prepare(query).asList(
			FetchOptions.Builder.withDefaults());
	if (instances == null || instances.isEmpty()) {
		return null;
	}
	Entity mostRecentInstance = instances.get(0);
	String content = ((Text) mostRecentInstance.getProperty("content"))
			.getValue();
	String contentType = (String) mostRecentInstance
			.getProperty("contentType");
	Date timestamp = (Date) mostRecentInstance.getProperty("timestamp");
	int statusCode = ((Long) mostRecentInstance.getProperty("statusCode"))
			.intValue();
	return new WebObjectInstance(uri, content, contentType, timestamp,
			statusCode);
}
 
开发者ID:lorenzosaino,项目名称:gae-webmonitor,代码行数:28,代码来源:DataStoreService.java

示例12: getAccountKeyByUser

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的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;
}
 
开发者ID:icza,项目名称:sc2gears,代码行数:31,代码来源:CachingService.java

示例13: getAccountKeyByAuthKey

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的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;
}
 
开发者ID:icza,项目名称:sc2gears,代码行数:31,代码来源:CachingService.java

示例14: doGet

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException, ServletException {
  // [START exploding_index_example_1]
  Query q =
      new Query("Widget")
          .setFilter(
              CompositeFilterOperator.and(
                  new FilterPredicate("x", FilterOperator.EQUAL, 1),
                  new FilterPredicate("y", FilterOperator.EQUAL, 2)))
          .addSort("date", Query.SortDirection.ASCENDING);
  // [END exploding_index_example_1]
  List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());

  PrintWriter out = resp.getWriter();
  out.printf("Got %d widgets.\n", results.size());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:18,代码来源:IndexesServlet.java

示例15: printPropertyRange

import com.google.appengine.api.datastore.Query.FilterPredicate; //导入依赖的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());
    }
  }
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:24,代码来源:MetadataPropertiesTest.java


注:本文中的com.google.appengine.api.datastore.Query.FilterPredicate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。