本文整理汇总了Java中com.google.appengine.api.datastore.PropertyProjection类的典型用法代码示例。如果您正苦于以下问题:Java PropertyProjection类的具体用法?Java PropertyProjection怎么用?Java PropertyProjection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyProjection类属于com.google.appengine.api.datastore包,在下文中一共展示了PropertyProjection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: projectionQuery_grouping_filtersDuplicates
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的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);
}
示例2: projectionQuery_grouping_filtersDuplicates
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的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);
}
示例3: getRootPipelinesDisplayName
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Override
public Set<String> getRootPipelinesDisplayName() {
Query query = new Query(JobRecord.DATA_STORE_KIND);
query.addProjection(
new PropertyProjection(JobRecord.ROOT_JOB_DISPLAY_NAME, String.class));
query.setDistinct(true);
final PreparedQuery preparedQuery = dataStore.prepare(query);
return tryFiveTimes(new Operation<Set<String>>("getRootPipelinesDisplayName") {
@Override
public Set<String> call() {
Set<String> pipelines = new LinkedHashSet<>();
for (Entity entity : preparedQuery.asIterable()) {
pipelines.add((String) entity.getProperty(JobRecord.ROOT_JOB_DISPLAY_NAME));
}
return pipelines;
}
});
}
示例4: getAsAppEngineQuery
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
public static Query getAsAppEngineQuery(SQuery2 squery) {
Query query =
hasAncestor(squery) ? new Query(squery.getKind(), KeyFactory.createKey(squery
.getAncestorKind(), squery.getAncestorId())) : new Query(squery.getKind());
// Set keys only
if (squery.isKeysOnly())
query.setKeysOnly();
// Add projections
for (Projection2 projection : squery.getProjections())
query.addProjection(new PropertyProjection(projection.getPropertyName(), projection
.getClazz()));
// Add sort order
for (Sort2 sorter : squery.getSorters())
query.addSort(sorter.getPropertyName(), sorter.isAscending() ? Query.SortDirection.ASCENDING
: Query.SortDirection.DESCENDING);
// Add clause
if (squery.getClause() != null)
query.setFilter(buildClause(squery, squery.getClause()));
return query;
}
示例5: testProjectionQueryOnlyReturnsEntitiesContainingProjectedProperty
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testProjectionQueryOnlyReturnsEntitiesContainingProjectedProperty() throws Exception {
String methodName = "testProjectionQueryOnlyReturnsEntitiesContainingProjectedProperty";
Entity parent = createTestEntityWithUniqueMethodNameKey("Kind", methodName);
Key key = parent.getKey();
Entity e1 = createEntity("Kind", key)
.withProperty("foo", "foo")
.store();
Entity e2 = createEntity("Kind", key)
.withProperty("bar", "bar")
.store();
Query query = new Query("Kind")
.setAncestor(key)
.addProjection(new PropertyProjection("foo", String.class));
List<Entity> results = service.prepare(query).asList(withDefaults());
assertEquals(Collections.singletonList(e1), results);
}
示例6: testProjectionQueryReturnsEntitiesContainingProjectedPropertyEvenIfPropertyValueIsNull
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testProjectionQueryReturnsEntitiesContainingProjectedPropertyEvenIfPropertyValueIsNull() throws Exception {
String methodName = "testProjectionQueryOnlyReturnsEntitiesContainingProjectedPropertyEvenIfPropertyValueIsNull";
Entity parent = createTestEntityWithUniqueMethodNameKey("Kind", methodName);
Key key = parent.getKey();
Entity e1 = createEntity("Kind", key)
.withProperty("foo", null)
.store();
Query query = new Query("Kind")
.setAncestor(key)
.addProjection(new PropertyProjection("foo", String.class));
List<Entity> results = service.prepare(query).asList(withDefaults());
assertEquals(Collections.singletonList(e1), results);
}
示例7: testProjectionsWithoutType
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testProjectionsWithoutType() throws Exception {
String methodName = "testProjectionsWithoutType";
Entity parent = createTestEntityWithUniqueMethodNameKey("Product", methodName);
Key key = parent.getKey();
Entity e = createEntity("Product", key)
.withProperty("long", 123L)
.store();
Query query = new Query("Product")
.setAncestor(key)
.addProjection(new PropertyProjection("long", null));
PreparedQuery preparedQuery = service.prepare(query);
Entity result = preparedQuery.asSingleEntity();
assertEquals(e.getKey(), result.getKey());
RawValue rawValue = (RawValue) result.getProperty("long");
assertEquals(Long.valueOf(123L), rawValue.asType(Long.class));
assertEquals(Long.valueOf(123L), rawValue.asStrictType(Long.class));
}
示例8: testOrderOfReturnedResultsIsSameAsOrderOfElementsInInStatementWhenUsingProjections
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testOrderOfReturnedResultsIsSameAsOrderOfElementsInInStatementWhenUsingProjections() throws Exception {
String methodName = "testOrderOfReturnedResultsIsSameAsOrderOfElementsInInStatementWhenUsingProjections";
Entity parent = createTestEntityWithUniqueMethodNameKey("Product", methodName);
Key key = parent.getKey();
Entity b = createEntity("Product", key)
.withProperty("name", "b")
.withProperty("price", 1L)
.store();
Entity a = createEntity("Product", key)
.withProperty("name", "a")
.withProperty("price", 2L)
.store();
Query query = new Query("Product")
.setAncestor(key)
.addProjection(new PropertyProjection("price", Long.class))
.setFilter(new Query.FilterPredicate("name", IN, Arrays.asList("a", "b")));
assertResultsInOrder(query, a, b);
query = query.setFilter(new Query.FilterPredicate("name", IN, Arrays.asList("b", "a")));
assertResultsInOrder(query, b, a);
}
示例9: testWithPropertyProjection
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testWithPropertyProjection() {
Query query = new Query(kindName, rootKey);
query.addProjection(new PropertyProjection("geoptData", GeoPt.class));
Filter filter1 = Query.CompositeFilterOperator.or(
Query.FilterOperator.LESS_THAN.of("intList", 5),
Query.FilterOperator.GREATER_THAN.of("intList", 90));
Filter filter2 = Query.FilterOperator.EQUAL.of("intList", 52);
query.setFilter(Query.CompositeFilterOperator.and(filter1, filter2));
// sql statement
String sql = "SELECT geoptData FROM " + kindName;
sql += " WHERE ((intList < 5 or intList > 90) AND intList = 52)";
sql += " AND __ancestor__ is " + rootKey;
assertEquals(sql.toLowerCase(), query.toString().toLowerCase());
// check query result
List<Entity> results = service.prepare(query).asList(fo);
Assert.assertTrue(results.size() > 0);
assertEquals(new GeoPt((float) (2.12), (float) (2.98)), results.get(0).getProperty("geoptData"));
for (Entity e : results) {
assertEquals(1, e.getProperties().size());
assertTrue(e.getProperties().containsKey("geoptData"));
}
}
示例10: testProjectionQueryOperatingOnlyOnASinglePropertyDoesNotRequireConfiguredIndex
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testProjectionQueryOperatingOnlyOnASinglePropertyDoesNotRequireConfiguredIndex() throws Exception {
executeQuery(new Query("Unindexed")
.addProjection(new PropertyProjection("someProperty", null)));
executeQuery(new Query("Unindexed")
.addProjection(new PropertyProjection("someProperty", null))
.setFilter(new Query.FilterPredicate("someProperty", GREATER_THAN, "a")));
executeQuery(new Query("Unindexed")
.addProjection(new PropertyProjection("someProperty", null))
.setFilter(new Query.FilterPredicate("someProperty", GREATER_THAN, "a"))
.addSort("someProperty"));
executeQuery(new Query("Unindexed")
.addProjection(new PropertyProjection("someProperty", null))
.setFilter(new Query.FilterPredicate("someProperty", GREATER_THAN, "a"))
.addSort("someProperty", Query.SortDirection.DESCENDING));
}
示例11: testDistinctMix
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testDistinctMix() {
Query query = new Query(kindName, rootKey);
query.addProjection(new PropertyProjection("stringData", String.class));
query.addProjection(new PropertyProjection("floatData", Float.class));
query.setDistinct(true);
assertEquals(7, service.prepare(query).countEntities(fo));
assertTrue(query.getDistinct());
// distinct false
query = new Query(kindName, rootKey);
query.addProjection(new PropertyProjection("stringData", String.class));
query.addProjection(new PropertyProjection("floatData", Float.class));
query.setDistinct(false);
assertEquals(count, service.prepare(query).countEntities(fo));
assertFalse(query.getDistinct());
}
示例12: timeZonesArray
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
public static ArrayList<TimeZone> timeZonesArray() {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Query q = new Query(TimeZone.DatastoreProperties.KIND.getName());
q.addProjection(new PropertyProjection(TimeZone.DatastoreProperties.TIME_ZONE_ID.getName(), String.class));
PreparedQuery pq = datastore.prepare(q);
ArrayList<TimeZone> timeZones = new ArrayList<TimeZone>();
for(Entity result : pq.asIterable())
timeZones.add(new TimeZone(result));
return timeZones;
}
示例13: testBasicQuery
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testBasicQuery() {
Query query = new Query(kindName, rootKey);
query.addProjection(new PropertyProjection("stringData", String.class));
query.addProjection(new PropertyProjection("intData", Integer.class));
String sql = "SELECT stringData, intData FROM " + kindName + " WHERE __ancestor__ is " + rootKey;
assertEquals(sql.toLowerCase(), query.toString().toLowerCase());
List<Entity> results = service.prepare(query).asList(fetchOption);
assertEquals(count, results.size());
for (Entity e : results) {
assertEquals(2, e.getProperties().size());
assertTrue(e.getProperties().containsKey("stringData"));
assertTrue(e.getProperties().containsKey("intData"));
}
}
示例14: testListQuery
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testListQuery() {
Query query = new Query(kindName, rootKey);
query.addProjection(new PropertyProjection("stringList", String.class));
query.addProjection(new PropertyProjection("intList", Integer.class));
List<Entity> results = service.prepare(query).asList(fetchOption);
// Distinct stringList data 2 * Distinct intList data 3 * entity's count 10
assertEquals(60, results.size());
Entity e = results.get(0);
assertEquals(2, e.getProperties().size());
assertTrue(e.getProperties().containsKey("stringList"));
assertTrue(e.getProperties().containsKey("intList"));
}
示例15: testQueryOrder
import com.google.appengine.api.datastore.PropertyProjection; //导入依赖的package包/类
@Test
public void testQueryOrder() {
Query query = new Query(kindName, rootKey);
query.addProjection(new PropertyProjection("intData", Integer.class));
query.addSort("stringData", Query.SortDirection.DESCENDING);
List<Entity> results = service.prepare(query).asList(fetchOption);
assertEquals(count, results.size());
int first = new Integer(results.get(0).getProperty("intData").toString());
int last = new Integer(results.get(count - 1).getProperty("intData").toString());
assertTrue(first > last);
}