本文整理汇总了Java中com.google.cloud.datastore.Key.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Key.getName方法的具体用法?Java Key.getName怎么用?Java Key.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.datastore.Key
的用法示例。
在下文中一共展示了Key.getName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKinds
import com.google.cloud.datastore.Key; //导入方法依赖的package包/类
@Override
public List<String> getKinds(boolean excludeSystemKinds) {
try {
String query = "SELECT __key__ FROM " + ENTITY_KINDS + " ORDER BY __key__";
GqlQuery.Builder<Key> gqlQueryBuilder = Query.newGqlQueryBuilder(ResultType.KEY, query);
gqlQueryBuilder.setNamespace(entityManager.getEffectiveNamespace());
GqlQuery<Key> gqlQuery = gqlQueryBuilder.build();
QueryResults<Key> results = entityManager.getDatastore().run(gqlQuery);
List<String> kinds = new ArrayList<>(50);
while (results.hasNext()) {
Key key = results.next();
String kind = key.getName();
if (excludeSystemKinds && kind.startsWith("__")) {
continue;
}
kinds.add(key.getName());
}
return kinds;
} catch (DatastoreException exp) {
throw new EntityManagerException(exp);
}
}
示例2: testPropertyRunQuery
import com.google.cloud.datastore.Key; //导入方法依赖的package包/类
@Test
public void testPropertyRunQuery() {
setUpQueryTests();
// [START property_run_query]
Query<Key> query = Query.newKeyQueryBuilder().setKind("__property__").build();
QueryResults<Key> keys = datastore.run(query);
Map<String, Collection<String>> propertiesByKind = new HashMap<>();
while (keys.hasNext()) {
Key key = keys.next();
String kind = key.getParent().getName();
String propertyName = key.getName();
Collection<String> properties = propertiesByKind.get(kind);
if (properties == null) {
properties = new HashSet<>();
propertiesByKind.put(kind, properties);
}
properties.add(propertyName);
}
// [END property_run_query]
Map<String, ImmutableSet<String>> expected = ImmutableMap.of("Task", ImmutableSet.of(
"done", "category", "done", "completed", "priority", "created", "percent_complete", "tag"));
assertEquals(expected, propertiesByKind);
}
示例3: getNamespaces
import com.google.cloud.datastore.Key; //导入方法依赖的package包/类
@Override
public QueryResponse<String> getNamespaces(DatastoreCursor fromCursor, int limit) {
try {
String query = "SELECT __key__ FROM " + ENTITY_NAMESPACES + " ORDER BY __key__";
if (limit > 0) {
query += " LIMIT @Limit";
}
query += " OFFSET @Offset";
GqlQuery.Builder<Key> gqlQueryBuilder = Query.newGqlQueryBuilder(ResultType.KEY, query);
if (limit > 0) {
gqlQueryBuilder.setBinding("Limit", limit);
}
gqlQueryBuilder.setBinding("Offset", Cursor.fromUrlSafe(fromCursor.getEncoded()));
GqlQuery<Key> gqlQuery = gqlQueryBuilder.build();
Datastore datastore = entityManager.getDatastore();
QueryResults<Key> results = datastore.run(gqlQuery);
DefaultQueryResponse<String> response = new DefaultQueryResponse<>();
List<String> namespaces = new ArrayList<>(Math.max(limit, 50));
response.setStartCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
while (results.hasNext()) {
Key key = results.next();
String name = key.getName();
namespaces.add(name == null ? "" : name);
}
response.setResults(namespaces);
response.setEndCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
return response;
} catch (DatastoreException exp) {
throw new EntityManagerException(exp);
}
}
示例4: testPropertyFilteringRunQuery
import com.google.cloud.datastore.Key; //导入方法依赖的package包/类
@Test
public void testPropertyFilteringRunQuery() {
setUpQueryTests();
// [START property_filtering_run_query]
Key startKey = datastore.newKeyFactory()
.setKind("__property__")
.addAncestors(PathElement.of("__kind__", "Task"))
.newKey("priority");
Query<Key> query = Query.newKeyQueryBuilder()
.setKind("__property__")
.setFilter(PropertyFilter.ge("__key__", startKey))
.build();
Map<String, Collection<String>> propertiesByKind = new HashMap<>();
QueryResults<Key> keys = datastore.run(query);
while (keys.hasNext()) {
Key key = keys.next();
String kind = key.getParent().getName();
String propertyName = key.getName();
Collection<String> properties = propertiesByKind.get(kind);
if (properties == null) {
properties = new HashSet<String>();
propertiesByKind.put(kind, properties);
}
properties.add(propertyName);
}
// [END property_filtering_run_query]
Map<String, ImmutableSet<String>> expected =
ImmutableMap.of("Task", ImmutableSet.of("priority", "tag"));
assertEquals(expected, propertiesByKind);
}