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


Java CompositeFilterOperator类代码示例

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


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

示例1: doGet

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的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

示例2: printPropertyRange

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的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

示例3: queryRestrictions_compositeFilter_isInvalid

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Test
public void queryRestrictions_compositeFilter_isInvalid() throws Exception {
  long minBirthYear = 1940;
  long maxHeight = 200;
  // [START inequality_filters_one_property_invalid_example]
  Filter birthYearMinFilter =
      new FilterPredicate("birthYear", FilterOperator.GREATER_THAN_OR_EQUAL, minBirthYear);

  Filter heightMaxFilter =
      new FilterPredicate("height", FilterOperator.LESS_THAN_OR_EQUAL, maxHeight);

  Filter invalidFilter = CompositeFilterOperator.and(birthYearMinFilter, heightMaxFilter);

  Query q = new Query("Person").setFilter(invalidFilter);
  // [END inequality_filters_one_property_invalid_example]

  // Note: The local devserver behavior is different than the production
  // version of Cloud Datastore, so there aren't any assertions we can make
  // in this test.  The query appears to work with the local test runner,
  // but will fail in production.
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:22,代码来源:QueriesTest.java

示例4: queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEntities

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Test
public void queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEntities()
    throws Exception {
  Entity a = new Entity("Widget", "a");
  List<Long> xs = Arrays.asList(1L, 2L);
  a.setProperty("x", xs);
  datastore.put(a);

  // [START surprising_behavior_example_1]
  Query q =
      new Query("Widget")
          .setFilter(
              CompositeFilterOperator.and(
                  new FilterPredicate("x", FilterOperator.GREATER_THAN, 1),
                  new FilterPredicate("x", FilterOperator.LESS_THAN, 2)));
  // [END surprising_behavior_example_1]

  // Entity "a" will not match because no individual value matches all filters.
  // See the documentation for more details:
  // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
  List<Entity> results =
      datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults());
  assertThat(results).named("query results").isEmpty();
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:QueriesTest.java

示例5: queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEntities

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Test
public void queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEntities()
    throws Exception {
  Entity a = new Entity("Widget", "a");
  List<Long> xs = Arrays.asList(1L, 2L);
  a.setProperty("x", xs);
  datastore.put(a);

  // [START surprising_behavior_example_1]
  Query q =
      new Query("Widget")
          .setFilter(
              CompositeFilterOperator.and(
                  new FilterPredicate("x", FilterOperator.GREATER_THAN, 1),
                  new FilterPredicate("x", FilterOperator.LESS_THAN, 2)));
  // [END surprising_behavior_example_1]

  // Entity "a" will not match because no individual value matches all filters.
  // See the documentation for more details:
  // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions
  // #properties_with_multiple_values_can_behave_in_surprising_ways
  List<Entity> results =
      datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults());
  assertThat(results).named("query results").isEmpty();
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:26,代码来源:QueriesTest.java

示例6: testPropertyMetadata

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Test
public void testPropertyMetadata() {
    NamespaceManager.set(namespaceDat[2]);
    // sort by kind/property, kindDat[1] < kindDat[0] < kindDat[2]
    Query q = new Query("__property__").addSort(Entity.KEY_RESERVED_PROPERTY).setKeysOnly();
    // filter out properties for kind "testing"
    Key key1 = Entities.createPropertyKey(kindDat[0], "urlData");
    Key key2 = Entities.createPropertyKey(kindDat[2], "urlData");
    q.setFilter(CompositeFilterOperator.and(
        new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, key1),
        new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.LESS_THAN_OR_EQUAL, key2)));
    List<Entity> el = service.prepare(q).asList(fo);
    // un-indexed property, textData, will not be returned in __property__ queries.
    assertEquals(13, el.size());
    for (int i = 0; i < el.size(); i++) {
        assertEquals(namespaceDat[2], el.get(i).getKey().getNamespace());
        assertEquals(kindDat[2], el.get(i).getKey().getParent().getName());
        if (i == 0) {
            assertEquals("adressData", el.get(0).getKey().getName());
        } else if (i == el.size() - 1) {
            assertEquals("urlData", el.get(el.size() - 1).getKey().getName());
        }
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:25,代码来源:SchemaTest.java

示例7: updateRegistrations

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
private static void updateRegistrations(Level level, Map<String, School> schools) {
	DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

	for (School school : schools.values()) {
		Filter schoolNameFilter = new FilterPredicate("schoolName", FilterOperator.EQUAL, school.getName());
		Filter schoolLevelFilter = new FilterPredicate("schoolLevel", FilterOperator.EQUAL, level.toString());
		Filter regTypeFilter = new FilterPredicate("registrationType", FilterOperator.EQUAL, "coach");

		Query query = new Query("registration").setFilter(CompositeFilterOperator.and(schoolNameFilter, schoolLevelFilter, regTypeFilter));
		List<Entity> registrations = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());

		if (registrations.size() > 0) {
			Entity registration = registrations.get(0);
			for (Entry<Test, Integer> numTest : school.getNumTests().entrySet()) {
				registration.setProperty(numTest.getKey().toString(), numTest.getValue());
			}
			datastore.put(registration);
		}
	}
}
 
开发者ID:sushain97,项目名称:contestManagement,代码行数:21,代码来源:Main.java

示例8: getConnection

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Override
public Connection<?> getConnection(ConnectionKey connectionKey) {
	final CompositeFilter filter = CompositeFilterOperator.and(
		FilterOperator.EQUAL.of("providerId", connectionKey.getProviderId()),
		FilterOperator.EQUAL.of("providerUserId", connectionKey.getProviderUserId())
	);
	final Query query = new Query(getKind())
		.setAncestor(userKey)
		.setFilter(filter);
	Entity singleEntity;
	try {
		singleEntity = datastore.prepare(query).asSingleEntity();			
	} catch (TooManyResultsException ex) {
		log.warning("Too many results were found for query " + query.toString());
		throw new NoSuchConnectionException(connectionKey);
	}
	if (singleEntity == null) throw new NoSuchConnectionException(connectionKey);
	return connectionMapper.mapEntity(singleEntity);
}
 
开发者ID:amobiz,项目名称:spring-social-showcase-sec-appengine,代码行数:20,代码来源:AppEngineConnectionRepository.java

示例9: findUserIdsWithConnection

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Override
public List<String> findUserIdsWithConnection(Connection<?> connection) {
	ConnectionKey key = connection.getKey();
	final CompositeFilter filter = CompositeFilterOperator.and(
		FilterOperator.EQUAL.of("providerId", key.getProviderId()),
		FilterOperator.EQUAL.of("providerUserId", key.getProviderUserId())
	);
       // fetch and return only keys, not full entities.
	Query query = new Query(getKind()).setFilter(filter).setKeysOnly();
	List<String> localUserIds = DatastoreUtils.queryForList(datastore.prepare(query), userIdMapper);
	if (localUserIds.size() == 0 && connectionSignUp != null) {			
			String newUserId = connectionSignUp.execute(connection);
			if (newUserId != null) {
				createConnectionRepository(newUserId).addConnection(connection);
				return Arrays.asList(newUserId);
			}
	}
	return localUserIds;
}
 
开发者ID:amobiz,项目名称:spring-social-showcase-sec-appengine,代码行数:20,代码来源:AppEngineUsersConnectionRepository.java

示例10: doExecute

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
protected Object doExecute(Object[] parameters) {
    Class<?> domainClass = queryMethod.getEntityInformation().getJavaType();
    int paramIndex = 0;
    
    PartTree tree = new PartTree(getQueryMethod().getName(), getQueryMethod().getEntityInformation().getJavaType());
    System.out.println(tree);
    
    List<Filter> orFilters = new ArrayList<Filter>();
    for (Iterator<OrPart> orPartIter = tree.iterator(); orPartIter.hasNext();) {
        OrPart orPart = orPartIter.next();
        
        List<Filter> andFilters = new ArrayList<Filter>();
        for (Iterator<Part> partIter = orPart.iterator(); partIter.hasNext();) {
            Part part = partIter.next();
            PropertyPath propertyPath  = part.getProperty();
            String propName = propertyPath.getSegment();
            Object propValue = parameters[paramIndex++];
            
            FilterOperator operator = getFilterOperation(part);
            Filter filter = new Query.FilterPredicate(propName, operator, propValue);
            andFilters.add(filter);
        }
        if (andFilters.size() == 1) {
            orFilters.add(andFilters.get(0));
        } else if (andFilters.size() >= 2){
            orFilters.add(CompositeFilterOperator.and(andFilters));
        }
    }
    
    com.googlecode.objectify.cmd.Query q = ofy().load().type(domainClass);
    if (orFilters.size() == 1) {
        q = q.filter(orFilters.get(0));
    } else if (orFilters.size() >= 2){
        q = q.filter(CompositeFilterOperator.or(orFilters));
    }
    return q.list();
}
 
开发者ID:nhuttrung,项目名称:spring-data-objectify,代码行数:38,代码来源:ObjectifyRepositoryQuery.java

示例11: doGet

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException, ServletException {
  Query q =
      new Query("Widget")
          .setFilter(
              CompositeFilterOperator.and(
                  new FilterPredicate("x", FilterOperator.EQUAL, 1),
                  new FilterPredicate("y", FilterOperator.EQUAL, "red")))
          .addSort("date", Query.SortDirection.ASCENDING);
  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,代码行数:16,代码来源:IndexesServlet.java

示例12: printLowercaseKinds

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

示例13: getNamespaces

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

示例14: queryInterface_orFilter_printsMatchedEntities

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Test
public void queryInterface_orFilter_printsMatchedEntities() throws Exception {
  // Arrange
  Entity a = new Entity("Person", "a");
  a.setProperty("height", 100);
  Entity b = new Entity("Person", "b");
  b.setProperty("height", 150);
  Entity c = new Entity("Person", "c");
  c.setProperty("height", 200);
  datastore.put(ImmutableList.<Entity>of(a, b, c));

  StringWriter buf = new StringWriter();
  PrintWriter out = new PrintWriter(buf);
  long minHeight = 125;
  long maxHeight = 175;

  // Act
  // [START interface_3]
  Filter tooShortFilter = new FilterPredicate("height", FilterOperator.LESS_THAN, minHeight);

  Filter tooTallFilter = new FilterPredicate("height", FilterOperator.GREATER_THAN, maxHeight);

  Filter heightOutOfRangeFilter = CompositeFilterOperator.or(tooShortFilter, tooTallFilter);

  Query q = new Query("Person").setFilter(heightOutOfRangeFilter);
  // [END interface_3]

  // Assert
  List<Entity> results =
      datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults());
  assertThat(results).named("query results").containsExactly(a, c);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:33,代码来源:QueriesTest.java

示例15: queryRestrictions_compositeFilter_returnsMatchedEntities

import com.google.appengine.api.datastore.Query.CompositeFilterOperator; //导入依赖的package包/类
@Test
public void queryRestrictions_compositeFilter_returnsMatchedEntities() throws Exception {
  // Arrange
  Entity a = new Entity("Person", "a");
  a.setProperty("birthYear", 1930);
  Entity b = new Entity("Person", "b");
  b.setProperty("birthYear", 1960);
  Entity c = new Entity("Person", "c");
  c.setProperty("birthYear", 1990);
  datastore.put(ImmutableList.<Entity>of(a, b, c));

  // Act
  long minBirthYear = 1940;
  long maxBirthYear = 1980;
  // [START inequality_filters_one_property_valid_example_1]
  Filter birthYearMinFilter =
      new FilterPredicate("birthYear", FilterOperator.GREATER_THAN_OR_EQUAL, minBirthYear);

  Filter birthYearMaxFilter =
      new FilterPredicate("birthYear", FilterOperator.LESS_THAN_OR_EQUAL, maxBirthYear);

  Filter birthYearRangeFilter =
      CompositeFilterOperator.and(birthYearMinFilter, birthYearMaxFilter);

  Query q = new Query("Person").setFilter(birthYearRangeFilter);
  // [END inequality_filters_one_property_valid_example_1]

  // Assert
  List<Entity> results =
      datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults());
  assertThat(results).named("query results").containsExactly(b);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:33,代码来源:QueriesTest.java


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