本文整理汇总了Java中com.google.cloud.datastore.Key类的典型用法代码示例。如果您正苦于以下问题:Java Key类的具体用法?Java Key怎么用?Java Key使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Key类属于com.google.cloud.datastore包,在下文中一共展示了Key类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setUp
import com.google.cloud.datastore.Key; //导入依赖的package包/类
/**
* Initializes Datastore and cleans out any residual values. Also initializes global variables
* used for testing.
*/
@Before
public void setUp() {
datastore = HELPER.getOptions().toBuilder().setNamespace("ghijklmnop").build().getService();
StructuredQuery<Key> query = Query.newKeyQueryBuilder().build();
QueryResults<Key> result = datastore.run(query);
datastore.delete(Iterators.toArray(result, Key.class));
keyFactory = datastore.newKeyFactory().setKind("Task");
taskKey = keyFactory.newKey("some-arbitrary-key");
testEntity = Entity.newBuilder(taskKey, TEST_FULL_ENTITY).build();
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(1990, JANUARY, 1);
startDate = Timestamp.of(calendar.getTime());
calendar.set(2000, JANUARY, 1);
endDate = Timestamp.of(calendar.getTime());
calendar.set(1999, DECEMBER, 31);
includedDate = Timestamp.of(calendar.getTime());
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:22,代码来源:ConceptsTest.java
示例2: delete
import com.google.cloud.datastore.Key; //导入依赖的package包/类
@Override
public void delete(Iterable<? extends T> entities) {
deleteKeys(new Iterable<Key>() {
@Override
public Iterator<Key> iterator() {
Iterator<? extends T> entityIter = entities.iterator();
return new Iterator<Key>() {
@Override
public boolean hasNext() {
return entityIter.hasNext();
}
@Override
public Key next() {
T entity = entityIter.next();
ID id = entityInformation.getId(entity);
return getKey(id);
}
};
}
});
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:23,代码来源:SimpleGcloudDatastoreRepository.java
示例3: save
import com.google.cloud.datastore.Key; //导入依赖的package包/类
@Override
public <S extends T> Iterable<S> save(Iterable<S> entities) {
Datastore datastore = this.datastoreOptions.getService();
List<FullEntity<? extends IncompleteKey>> buffer = new ArrayList<>();
for (S entity : entities) {
ID id = this.entityInformation.getId(entity);
Key key = getKey(id);
buffer.add(this.marshaller.toEntity(entity, key));
if (buffer.size() >= BUFFER_SIZE) {
datastore.put(buffer.toArray(new FullEntity[buffer.size()]));
buffer.clear();
}
}
if (buffer.size() > 0) {
datastore.put(buffer.toArray(new FullEntity[buffer.size()]));
}
return entities;
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:23,代码来源:SimpleGcloudDatastoreRepository.java
示例4: deleteKeys
import com.google.cloud.datastore.Key; //导入依赖的package包/类
private void deleteKeys(Iterable<Key> keys) {
Datastore datastore = this.datastoreOptions.getService();
List<Key> buffer = new ArrayList<>(BUFFER_SIZE);
for (Key key : keys) {
buffer.add(key);
if (buffer.size() >= BUFFER_SIZE) {
datastore.delete(buffer.toArray(new Key[buffer.size()]));
buffer.clear();
}
}
if (buffer.size() > 0) {
datastore.delete(buffer.toArray(new Key[buffer.size()]));
}
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:17,代码来源:SimpleGcloudDatastoreRepository.java
示例5: setAncestorFilter
import com.google.cloud.datastore.Key; //导入依赖的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));
}
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:17,代码来源:SimpleGcloudDatastoreRepository.java
示例6: getKey
import com.google.cloud.datastore.Key; //导入依赖的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;
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:17,代码来源:SimpleGcloudDatastoreRepository.java
示例7: setAncestorFilter
import com.google.cloud.datastore.Key; //导入依赖的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);
}
}
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:26,代码来源:GcloudDatastoreQueryCreator.java
示例8: testUnmarshalToObject_Blob
import com.google.cloud.datastore.Key; //导入依赖的package包/类
@Test
public void testUnmarshalToObject_Blob() {
// Setup
byte[] hello = "hello".getBytes(Charset.forName("UTF-8"));
Key key = Key.newBuilder("project", "kind", 1).build();
Entity entity = Entity.newBuilder(key).set("object", Blob.copyFrom(hello))
.set("bytes", Blob.copyFrom(hello)).set("string", Blob.copyFrom(hello))
.build();
Unmarshaller unmarshaller = new Unmarshaller();
TestBean bean = new TestBean();
// Exercise
unmarshaller.unmarshalToObject(entity, bean);
// Verify
Assert.assertArrayEquals(hello, (byte[]) bean.object);
Assert.assertArrayEquals(hello, bean.bytes);
Assert.assertEquals("hello", bean.string);
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:20,代码来源:UnmarshallerTests.java
示例9: testUnmarshalToObject_Boolean
import com.google.cloud.datastore.Key; //导入依赖的package包/类
@Test
public void testUnmarshalToObject_Boolean() {
// Setup
Key key = Key.newBuilder("project", "kind", 1).build();
Entity entity = Entity.newBuilder(key).set("object", true)
.set("boxedBoolean", true).set("primitiveBoolean", true).build();
Unmarshaller unmarshaller = new Unmarshaller();
TestBean bean = new TestBean();
// Exercise
unmarshaller.unmarshalToObject(entity, bean);
// Verify
Assert.assertEquals(Boolean.TRUE, bean.object);
Assert.assertEquals(Boolean.TRUE, bean.boxedBoolean);
Assert.assertTrue(bean.primitiveBoolean);
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:18,代码来源:UnmarshallerTests.java
示例10: testUnmarshalToObject_Map1
import com.google.cloud.datastore.Key; //导入依赖的package包/类
@Test
public void testUnmarshalToObject_Map1() {
// Setup
Key key = Key.newBuilder("project", "kind", 1).build();
Entity entity = Entity.newBuilder(key)
.set("object", Entity.newBuilder().set("k", "v").build())
.set("map", Entity.newBuilder().set("k", "v").build()).build();
Unmarshaller unmarshaller = new Unmarshaller();
TestBean bean = new TestBean();
// Exercise
unmarshaller.unmarshalToObject(entity, bean);
// Verify
Map<String, Object> expected = new HashMap<>();
expected.put("k", "v");
Assert.assertEquals(expected, bean.object);
Assert.assertEquals(expected, bean.map);
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:20,代码来源:UnmarshallerTests.java
示例11: testUnmarshalToObject_Map2
import com.google.cloud.datastore.Key; //导入依赖的package包/类
@Test
public void testUnmarshalToObject_Map2() {
// Setup
Key key = Key.newBuilder("project", "kind", 1).build();
Entity entity = Entity.newBuilder(key)
.set("object", Entity.newBuilder()
.set("k1", Entity.newBuilder().set("k2", "v2").build()).build())
.set("map", Entity.newBuilder()
.set("k1", Entity.newBuilder().set("k2", "v2").build()).build())
.build();
Unmarshaller unmarshaller = new Unmarshaller();
TestBean bean = new TestBean();
// Exercise
unmarshaller.unmarshalToObject(entity, bean);
// Verify
Map<String, Object> innerMap = new HashMap<>();
innerMap.put("k2", "v2");
Map<String, Object> expected = new HashMap<>();
expected.put("k1", innerMap);
Assert.assertEquals(expected, bean.object);
Assert.assertEquals(expected, bean.map);
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:25,代码来源:UnmarshallerTests.java
示例12: 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);
}
}
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:23,代码来源:DefaultDatastoreMetadata.java
示例13: getProperties
import com.google.cloud.datastore.Key; //导入依赖的package包/类
@Override
public List<DatastoreProperty> getProperties(String kind) {
try {
Key nativeKey = entityManager.newNativeKeyFactory().setKind(ENTITY_KINDS).newKey(kind);
DefaultDatastoreKey key = new DefaultDatastoreKey(nativeKey);
String query = "SELECT * FROM " + ENTITY_PROPERTIES
+ " WHERE __key__ HAS ANCESTOR @1 ORDER BY __key__";
EntityQueryRequest request = entityManager.createEntityQueryRequest(query);
request.addPositionalBinding(key);
QueryResponse<DatastoreProperty> response = entityManager
.executeEntityQueryRequest(DatastoreProperty.class, request);
return response.getResults();
} catch (DatastoreException exp) {
throw new EntityManagerException(exp);
}
}
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:17,代码来源:DefaultDatastoreMetadata.java
示例14: marshal
import com.google.cloud.datastore.Key; //导入依赖的package包/类
/**
* Marshals the given entity and and returns the equivalent Entity needed for the underlying Cloud
* Datastore API.
*
* @return A native entity that is equivalent to the POJO being marshalled. The returned value
* could either be a FullEntity or Entity.
*/
private BaseEntity<?> marshal() {
marshalKey();
if (key instanceof Key) {
entityBuilder = Entity.newBuilder((Key) key);
} else {
entityBuilder = FullEntity.newBuilder(key);
}
marshalFields();
marshalAutoTimestampFields();
if (intent == Intent.UPDATE) {
marshalVersionField();
}
marshalEmbeddedFields();
return entityBuilder.build();
}
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:23,代码来源:Marshaller.java
示例15: executeKeyQueryRequest
import com.google.cloud.datastore.Key; //导入依赖的package包/类
/**
* Executes the given {@link KeyQueryRequest} and returns the response.
*
* @param request
* the key query request
* @return the query response
*/
public QueryResponse<DatastoreKey> executeKeyQueryRequest(KeyQueryRequest request) {
try {
GqlQuery.Builder<Key> queryBuilder = Query.newGqlQueryBuilder(ResultType.KEY,
request.getQuery());
queryBuilder.setNamespace(entityManager.getEffectiveNamespace());
queryBuilder.setAllowLiteral(request.isAllowLiterals());
QueryUtils.applyNamedBindings(queryBuilder, request.getNamedBindings());
QueryUtils.applyPositionalBindings(queryBuilder, request.getPositionalBindings());
GqlQuery<Key> gqlQuery = queryBuilder.build();
QueryResults<Key> results = nativeReader.run(gqlQuery);
List<DatastoreKey> entities = new ArrayList<>();
DefaultQueryResponse<DatastoreKey> response = new DefaultQueryResponse<>();
response.setStartCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
while (results.hasNext()) {
Key result = results.next();
DatastoreKey datastoreKey = new DefaultDatastoreKey(result);
entities.add(datastoreKey);
}
response.setResults(entities);
response.setEndCursor(new DefaultDatastoreCursor(results.getCursorAfter().toUrlSafe()));
return response;
} catch (DatastoreException exp) {
throw new EntityManagerException(exp);
}
}
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:33,代码来源:DefaultDatastoreReader.java
示例16: store
import com.google.cloud.datastore.Key; //导入依赖的package包/类
void store(Workflow workflow) throws IOException {
storeWithRetries(() -> datastore.runInTransaction(transaction -> {
final Key componentKey = componentKeyFactory.newKey(workflow.componentId());
if (transaction.get(componentKey) == null) {
transaction.put(Entity.newBuilder(componentKey).build());
}
final String json = OBJECT_MAPPER.writeValueAsString(workflow);
final Key workflowKey = workflowKey(workflow.id());
final Optional<Entity> workflowOpt = getOpt(transaction, workflowKey);
final Entity workflowEntity = asBuilderOrNew(workflowOpt, workflowKey)
.set(PROPERTY_WORKFLOW_JSON, StringValue.newBuilder(json).setExcludeFromIndexes(true).build())
.build();
return transaction.put(workflowEntity);
}));
}
开发者ID:spotify,项目名称:styx,代码行数:18,代码来源:DatastoreStorage.java
示例17: updateNextNaturalTrigger
import com.google.cloud.datastore.Key; //导入依赖的package包/类
public void updateNextNaturalTrigger(WorkflowId workflowId, TriggerInstantSpec triggerSpec) throws IOException {
storeWithRetries(() -> datastore.runInTransaction(transaction -> {
final Key workflowKey = workflowKey(workflowId);
final Optional<Entity> workflowOpt = getOpt(transaction, workflowKey);
if (!workflowOpt.isPresent()) {
throw new ResourceNotFoundException(
String.format("%s:%s doesn't exist.", workflowId.componentId(), workflowId.id()));
}
final Entity.Builder builder = Entity
.newBuilder(workflowOpt.get())
.set(PROPERTY_NEXT_NATURAL_TRIGGER, instantToTimestamp(triggerSpec.instant()))
.set(PROPERTY_NEXT_NATURAL_OFFSET_TRIGGER, instantToTimestamp(triggerSpec.offsetInstant()));
return transaction.put(builder.build());
}));
}
开发者ID:spotify,项目名称:styx,代码行数:17,代码来源:DatastoreStorage.java
示例18: patchState
import com.google.cloud.datastore.Key; //导入依赖的package包/类
void patchState(WorkflowId workflowId, WorkflowState state) throws IOException {
storeWithRetries(() -> datastore.runInTransaction(transaction -> {
final Key workflowKey = workflowKey(workflowId);
final Optional<Entity> workflowOpt = getOpt(transaction, workflowKey);
if (!workflowOpt.isPresent()) {
throw new ResourceNotFoundException(
String.format("%s:%s doesn't exist.", workflowId.componentId(), workflowId.id()));
}
final Entity.Builder builder = Entity.newBuilder(workflowOpt.get());
state.enabled().ifPresent(x -> builder.set(PROPERTY_WORKFLOW_ENABLED, x));
state.nextNaturalTrigger()
.ifPresent(x -> builder.set(PROPERTY_NEXT_NATURAL_TRIGGER, instantToTimestamp(x)));
state.nextNaturalOffsetTrigger()
.ifPresent(x -> builder.set(PROPERTY_NEXT_NATURAL_OFFSET_TRIGGER, instantToTimestamp(x)));
return transaction.put(builder.build());
}));
}
开发者ID:spotify,项目名称:styx,代码行数:19,代码来源:DatastoreStorage.java
示例19: backfillToEntity
import com.google.cloud.datastore.Key; //导入依赖的package包/类
private Entity backfillToEntity(Backfill backfill) {
final Key key = datastore.newKeyFactory().setKind(KIND_BACKFILL).newKey(backfill.id());
Entity.Builder builder = Entity.newBuilder(key)
.set(PROPERTY_CONCURRENCY, backfill.concurrency())
.set(PROPERTY_START, instantToTimestamp(backfill.start()))
.set(PROPERTY_END, instantToTimestamp(backfill.end()))
.set(PROPERTY_COMPONENT, backfill.workflowId().componentId())
.set(PROPERTY_WORKFLOW, backfill.workflowId().id())
.set(PROPERTY_SCHEDULE, backfill.schedule().toString())
.set(PROPERTY_NEXT_TRIGGER, instantToTimestamp(backfill.nextTrigger()))
.set(PROPERTY_ALL_TRIGGERED, backfill.allTriggered())
.set(PROPERTY_HALTED, backfill.halted());
backfill.description().ifPresent(x -> builder.set(PROPERTY_DESCRIPTION, StringValue
.newBuilder(x).setExcludeFromIndexes(true).build()));
return builder.build();
}
开发者ID:spotify,项目名称:styx,代码行数:20,代码来源:DatastoreStorage.java
示例20: updateRow
import com.google.cloud.datastore.Key; //导入依赖的package包/类
@Override
public void updateRow(String key, Map<String, Object> recordValues) {
Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(key);
Builder builder = Entity.newBuilder(entityKey);
for (Entry<String, Object> entry : recordValues.entrySet()) {
builder.set(entry.getKey(), GoogleDatastoreKeyStore.valerie(entry.getKey(), entry.getValue()));
}
Entity entity = builder.build();
try {
datastore.put(entity);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:17,代码来源:GoogleIndexHandler.java
注:本文中的com.google.cloud.datastore.Key类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论