本文整理汇总了Java中com.google.cloud.datastore.KeyFactory.newKey方法的典型用法代码示例。如果您正苦于以下问题:Java KeyFactory.newKey方法的具体用法?Java KeyFactory.newKey怎么用?Java KeyFactory.newKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.datastore.KeyFactory
的用法示例。
在下文中一共展示了KeyFactory.newKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAncestorFilter
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
private <U> void setAncestorFilter(StructuredQuery.Builder<U> queryBuilder) {
Datastore datastore = datastoreOptions.getService();
Deque<PathElement> ancestors = Context.getAncestors();
Deque<PathElement> init = new LinkedList<>();
init.addAll(ancestors);
PathElement last = init.pollLast();
if (last != null) {
KeyFactory keyFactory = datastore.newKeyFactory();
keyFactory.addAncestors(init).setKind(last.getKind());
Key key = last.hasId() ? keyFactory.newKey(last.getId())
: keyFactory.newKey(last.getName());
queryBuilder.setFilter(StructuredQuery.PropertyFilter.hasAncestor(key));
}
}
示例2: getKey
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
private Key getKey(ID id) {
Datastore datastore = this.datastoreOptions.getService();
KeyFactory keyFactory = datastore.newKeyFactory().setKind(this.kind);
Iterable<PathElement> ancestors = Context.getAncestors();
keyFactory.addAncestors(ancestors);
Key key;
if (id instanceof Number) {
key = keyFactory.newKey(((Number) id).longValue());
}
else {
key = keyFactory.newKey(id.toString());
}
return key;
}
示例3: setAncestorFilter
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
protected StructuredQuery.Filter setAncestorFilter(StructuredQuery.Filter filter) {
Datastore datastore = datastoreOptions.getService();
Deque<PathElement> ancestors = Context.getAncestors();
Deque<PathElement> init = new LinkedList<>();
init.addAll(ancestors);
PathElement last = init.pollLast();
if (last == null) {
return filter;
}
else {
KeyFactory keyFactory = datastore.newKeyFactory();
keyFactory.addAncestors(init).setKind(last.getKind());
Key key = last.hasId()
? keyFactory.newKey(last.getId()) : keyFactory.newKey(last.getName());
StructuredQuery.Filter ancestorFilter = StructuredQuery.PropertyFilter.hasAncestor(key);
if (filter == null) {
return ancestorFilter;
}
else {
return StructuredQuery.CompositeFilter.and(filter, ancestorFilter);
}
}
}
示例4: testNamespaceRunQuery
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
@Test
public void testNamespaceRunQuery() {
setUpQueryTests();
// [START namespace_run_query]
KeyFactory keyFactory = datastore.newKeyFactory().setKind("__namespace__");
Key startNamespace = keyFactory.newKey("g");
Key endNamespace = keyFactory.newKey("h");
Query<Key> query = Query.newKeyQueryBuilder()
.setKind("__namespace__")
.setFilter(CompositeFilter.and(
PropertyFilter.gt("__key__", startNamespace),
PropertyFilter.lt("__key__", endNamespace)))
.build();
List<String> namespaces = new ArrayList<>();
QueryResults<Key> results = datastore.run(query);
while (results.hasNext()) {
namespaces.add(results.next().getName());
}
// [END namespace_run_query]
assertEquals(ImmutableList.of("ghijklmnop"), namespaces);
}
示例5: setUp
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
store = new DatastoreStore();
KeyFactory keyFactory = new KeyFactory("project").setKind("kind");
key = keyFactory.newKey(keyId);
attributeKey = keyFactory.newKey("attribute");
QueryResults<Key> keyQueryResults = new IteratorQueryResults<>(ImmutableList.of(key).iterator());
when(datastore.newKeyFactory()).thenAnswer((invocation) -> new KeyFactory("project"));
when(datastore.run(any(KeyQuery.class))).thenReturn(keyQueryResults);
when(manager.getContext()).thenReturn(new StandardContext());
when(manager.willAttributeDistribute(anyString(), any())).thenReturn(true);
when(manager.createEmptySession()).thenReturn(new DatastoreSession(manager));
store.setDatastore(datastore);
store.setClock(clock);
store.setSessionKind("kind");
store.setManager(manager);
}
示例6: longListToNativeKeys
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
/**
* Converts the given list of identifiers into an array of native Key objects.
*
* @param entityClass
* the entity class to which these identifiers belong to.
* @param identifiers
* the list of identifiers to convert.
* @return an array of Key objects
*/
private Key[] longListToNativeKeys(Class<?> entityClass, List<Long> identifiers) {
if (identifiers == null || identifiers.isEmpty()) {
return new Key[0];
}
EntityMetadata entityMetadata = EntityIntrospector.introspect(entityClass);
Key[] nativeKeys = new Key[identifiers.size()];
KeyFactory keyFactory = entityManager.newNativeKeyFactory();
keyFactory.setKind(entityMetadata.getKind());
for (int i = 0; i < identifiers.size(); i++) {
long id = identifiers.get(i);
nativeKeys[i] = keyFactory.newKey(id);
}
return nativeKeys;
}
示例7: stringListToNativeKeys
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
/**
* Converts the given list of identifiers into an array of native Key objects.
*
* @param entityClass
* the entity class to which these identifiers belong to.
* @param identifiers
* the list of identifiers to convert.
* @return an array of Key objects
*/
private Key[] stringListToNativeKeys(Class<?> entityClass, List<String> identifiers) {
if (identifiers == null || identifiers.isEmpty()) {
return new Key[0];
}
EntityMetadata entityMetadata = EntityIntrospector.introspect(entityClass);
Key[] nativeKeys = new Key[identifiers.size()];
KeyFactory keyFactory = entityManager.newNativeKeyFactory();
keyFactory.setKind(entityMetadata.getKind());
for (int i = 0; i < identifiers.size(); i++) {
String id = identifiers.get(i);
nativeKeys[i] = keyFactory.newKey(id);
}
return nativeKeys;
}
示例8: testKeyWithMultilevelParent
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
@Test
public void testKeyWithMultilevelParent() {
// [START key_with_multilevel_parent]
KeyFactory keyFactory = datastore.newKeyFactory()
.addAncestors(PathElement.of("User", "Alice"), PathElement.of("TaskList", "default"))
.setKind("Task");
Key taskKey = keyFactory.newKey("sampleTask");
// [END key_with_multilevel_parent]
assertValidKey(taskKey);
}
示例9: setUpTransferTests
import com.google.cloud.datastore.KeyFactory; //导入方法依赖的package包/类
private List<Key> setUpTransferTests() {
KeyFactory keyFactory = datastore.newKeyFactory().setKind("People");
Key from = keyFactory.newKey("from");
Key to = keyFactory.newKey("to");
datastore.put(Entity.newBuilder(from).set("balance", 100).build());
datastore.put(Entity.newBuilder(to).set("balance", 0).build());
return ImmutableList.of(from, to);
}