com.google.appengine.api.datastore.Query.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中com.google.appengine.api.datastore.Query.<init>方法的一些代码示例,展示了Query.<init>的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.<init>方法的具体详情如下:
包路径:com.google.appengine.api.datastore.Query
类名称:Query
方法名:<init>

Query.<init>介绍

暂无

代码示例

代码示例来源:origin: com.googlecode.cedar-common/objectify

/** */
public QueryImpl(ObjectifyFactory fact, Objectify objectify) 
{
  this.factory = fact;
  this.ofy = objectify;
  this.actual = new com.google.appengine.api.datastore.Query();
}

代码示例来源:origin: GoogleCloudPlatform/appengine-gcs-client

private Query makeQuery(String bucket) {
 String origNamespace = NamespaceManager.get();
 try {
  NamespaceManager.set("");
  return new Query(ENTITY_KIND_PREFIX + bucket);
 } finally {
  NamespaceManager.set(origNamespace);
 }
}

代码示例来源:origin: feroult/yawp

@Override
public List<String> listNamespaces() {
  DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
  Query query = new Query("__namespace__").setKeysOnly();
  PreparedQuery pq = ds.prepare(query);
  List<String> namespaces = new ArrayList<>();
  for (Entity entity : pq.asIterable()) {
    namespaces.add(entity.getKey().getName());
  }
  return namespaces;
}

代码示例来源:origin: PeterKnego/LeanEngine-Server

public static LeanAccount findAccountByProvider(String providerID, String provider) {
  if (providerID == null) {
    log.severe("Empty providerID. Can not find account without providerID.");
    return null;
  }
  Query query = new Query(accountsKind);
  query.addFilter("_provider_id", Query.FilterOperator.EQUAL, providerID);
  query.addFilter("_provider", Query.FilterOperator.EQUAL, provider);
  PreparedQuery pq = datastore.prepare(query);
  Entity accountEntity = pq.asSingleEntity();
  return (accountEntity == null) ? null : toLeanAccount(accountEntity);
}

代码示例来源:origin: com.google.appengine.tools/appengine-pipeline

public List<Entity> queryAll(final String kind, final Key rootJobKey) {
 Query query = new Query(kind);
 query.setFilter(new FilterPredicate(ROOT_JOB_KEY_PROPERTY, EQUAL, rootJobKey));
 final PreparedQuery preparedQuery = dataStore.prepare(query);
 final FetchOptions options = FetchOptions.Builder.withChunkSize(500);
 return tryFiveTimes(new Operation<List<Entity>>("queryFullPipeline") {
  @Override
  public List<Entity> call() {
   return preparedQuery.asList(options);
  }
 });
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test(expected = DatastoreNeedIndexException.class)
public void testQueryWithDescendingSortOrderOnKeysRequiresConfiguredIndex() throws Exception {
  executeQuery(
    new Query("Unindexed")
      .addSort(Entity.KEY_RESERVED_PROPERTY, Query.SortDirection.DESCENDING));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

public static void deleteTempData(Class<? extends TempData> type) {
  // check if in-container
  if (isInContainer() == false) {
    return;
  }
  String kind = getKind(type);
  DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
  final List<Entity> list = ds.prepare(new Query(kind)).asList(FetchOptions.Builder.withDefaults());
  for (Entity e : list) {
    deleteTempDataInTx(ds, e, type);
  }
}

代码示例来源:origin: feroult/yawp

private PreparedQuery prepareQuery(QueryBuilder<?> builder, boolean keysOnly) throws FalsePredicateException {
  Query q = new Query(builder.getModel().getKind());
  if (keysOnly) {
    q.setKeysOnly();
  }
  prepareQueryAncestor(builder, q);
  prepareQueryWhere(builder, q);
  prepareQueryOrder(builder, q);
  return datastore().prepare(q);
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testEndFetch() {
  int onePage = total - 30;
  Query query = new Query(kindName, rootKey);
  // fetch first page
  Cursor cursor = checkPage(query, null, null, onePage, onePage, null, null);
  Cursor decodedCursor = Cursor.fromWebSafeString(cursor.toWebSafeString());
  // fetch next page,   get remaining after 1st page.
  checkPage(query, decodedCursor, null, onePage, total - onePage, null, null);
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testSortPredicates() {
  Query query = new Query(kindName, rootKey);
  query.addSort("intData", Query.SortDirection.DESCENDING);
  List<Entity> es = service.prepare(query).asList(fo);
  assertEquals((long) 40, es.get(0).getProperty("intData"));
  List<Query.SortPredicate> qsp = query.getSortPredicates();
  assertEquals("check SortPredicate name", "intData", qsp.get(0).getPropertyName());
  assertEquals("check SortPredicate direction", Query.SortDirection.DESCENDING, qsp.get(0).getDirection());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test(expected = DatastoreNeedIndexException.class)
public void testQueryWithInequalityFilterAndSortOnAnotherPropertyRequiresConfiguredIndex() throws Exception {
  executeQuery(
    new Query("Unindexed")
      .setFilter(new Query.FilterPredicate("someProperty", GREATER_THAN, "foo"))
      .addSort("someProperty")
      .addSort("otherProperty"));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
  public void testQueryOnSomePropertyWithKeyInDifferentNamespace() {
    NamespaceManager.set("one");
    Key keyInNamespaceOne = KeyFactory.createKey("kind", 1);

    NamespaceManager.set("two");
    Query query = new Query("kind").setFilter(new Query.FilterPredicate("someProperty", EQUAL, keyInNamespaceOne));
    PreparedQuery preparedQuery = service.prepare(query);
    preparedQuery.asSingleEntity();    // should not throw IllegalArgumentException as in previous test
    preparedQuery.asIterator().hasNext();    // should not throw IllegalArgumentException as in previous test
    preparedQuery.asList(withDefaults()).size();    // should not throw IllegalArgumentException as in previous test
  }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void queriesDontReturnDeletedEntities() throws Exception {
  String methodName = "queriesDontReturnDeletedEntities";
  Entity entity = createTestEntityWithUniqueMethodNameKey(SMOKE_TEST_ENTITY, methodName);
  Key key = entity.getKey();
  service.put(entity);
  service.delete(key);
  List<Entity> entities = service.prepare(new Query(SMOKE_TEST_ENTITY).setAncestor(key))
    .asList(FetchOptions.Builder.withDefaults());
  assertEquals(0, entities.size());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testQueryWithAncestorAndInequalityFilterOnKeyPropertyDoesNotRequireConfiguredIndex() throws Exception {
  executeQuery(
    new Query("Unindexed")
      .setAncestor(KeyFactory.createKey("Ancestor", 1))
      .setFilter(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN, KeyFactory.createKey("Unindexed", 1))));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testFilterOnMultiValuedProperty() throws Exception {
  Key parentKey = createQueryBasicsTestParent("testFilterOnMultiValuedProperty");
  createEntity("Entry", parentKey)
    .withProperty("letters", Arrays.asList("a", "b", "c"))
    .store();
  Query query = new Query("Entry")
    .setAncestor(parentKey)
    .setFilter(new Query.FilterPredicate("letters", EQUAL, "a"));
  assertNotNull(service.prepare(query).asSingleEntity());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testQueryWithEqalityAndInequalityFilterOnKeyPropertyDoesNotRequireConfiguredIndex() throws Exception {
  executeQuery(
    new Query("Unindexed")
      .setFilter(
        and(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN, KeyFactory.createKey("Unindexed", 1)),
          new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, EQUAL, KeyFactory.createKey("Unindexed", 2)))));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

private void checkCount(String statsKind) {
    FetchOptions fo = FetchOptions.Builder.withDefaults();
    Query query = new Query(statsKind);
    assertTrue(service.prepare(query).countEntities(fo) > 0);
    for (Entity readRec : service.prepare(query).asIterable()) {
      assertTrue((Long) readRec.getProperty("count") > 0);
    }
  }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

public void purgeTestRunRecords() {
  DatastoreService datastoreService = DatastoreServiceFactory. getDatastoreService();
  FilterPredicate testRunFilter = new FilterPredicate(TEST_RUN_ID, FilterOperator.EQUAL, testRunId);
  Query query = new Query(entityName).setFilter(testRunFilter).setKeysOnly();
  for (Entity readRec : datastoreService.prepare(query).asIterable()) {
    datastoreService.delete(readRec.getKey());
  }
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testNullPropertyValue() throws Exception {
  Key parentKey = createQueryBasicsTestParent("testNullPropertyValue");
  createEntity("Entry", parentKey)
    .withProperty("user", null)
    .store();
  Entity entity = service.prepare(new Query("Entry")
    .setAncestor(parentKey)).asSingleEntity();
  assertNull(entity.getProperty("user"));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testDistinctSort() {
  Query query = new Query(kindName, rootKey);
  query.addProjection(new PropertyProjection("stringData", String.class));
  query.addProjection(new PropertyProjection("floatData", Float.class));
  query.addSort("stringData", Query.SortDirection.DESCENDING);
  query.setDistinct(true);
  assertEquals(7, service.prepare(query).countEntities(fo));
  assertTrue(query.getDistinct());
  query.addSort("floatData", Query.SortDirection.DESCENDING);
  assertEquals(7, service.prepare(query).countEntities(fo));
}

相关文章