本文整理汇总了Java中com.google.cloud.datastore.Entity类的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Entity类属于com.google.cloud.datastore包,在下文中一共展示了Entity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: complete
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
@Override
protected StructuredQuery.Builder<Entity> complete(StructuredQuery.Filter filter,
Sort sort) {
if (sort == null) {
return Query.newEntityQueryBuilder()
.setFilter(setAncestorFilter(filter));
}
StructuredQuery.OrderBy[] orderBy = StreamSupport
.stream(sort.spliterator(), false)
.map(order -> order.isAscending()
? StructuredQuery.OrderBy.asc(order.getProperty())
: StructuredQuery.OrderBy.desc(order.getProperty()))
.toArray(len -> new StructuredQuery.OrderBy[len]);
if (orderBy.length == 0) {
return Query.newEntityQueryBuilder()
.setFilter(setAncestorFilter(filter));
}
else {
return Query.newEntityQueryBuilder()
.addOrderBy(orderBy[0], orderBy)
.setFilter(setAncestorFilter(filter));
}
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:25,代码来源:GcloudDatastoreQueryCreator.java
示例2: testAndCondition
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
@Test
public void testAndCondition() throws Exception {
// Setup
GcloudDatastoreQueryCreator creator = createCreator(PersonRepository.class,
PersonRepository.class.getMethod("findByEmailAddressAndLastName",
String.class, String.class),
"[email protected]", "Doe");
// Exercise
StructuredQuery.Builder<Entity> queryBuilder = creator.createQuery();
// Verify
assertEquals(
Query.newEntityQueryBuilder()
.setFilter(StructuredQuery.CompositeFilter.and(
StructuredQuery.PropertyFilter.eq("emailAddress",
"[email protected]"),
StructuredQuery.PropertyFilter.eq("lastName", "Doe")))
.build(),
queryBuilder.build());
}
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:22,代码来源:GcloudDatastoreQueryCreatorTests.java
示例3: testUnmarshalToObject_Blob
import com.google.cloud.datastore.Entity; //导入依赖的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
示例4: testUnmarshalToObject_Boolean
import com.google.cloud.datastore.Entity; //导入依赖的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
示例5: testUnmarshalToObject_Map1
import com.google.cloud.datastore.Entity; //导入依赖的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
示例6: testUnmarshalToObject_Map2
import com.google.cloud.datastore.Entity; //导入依赖的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
示例7: marshal
import com.google.cloud.datastore.Entity; //导入依赖的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
示例8: insert
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
/**
* Inserts the given list of entities into the Cloud Datastore.
*
* @param entities
* the entities to insert.
* @return the inserted entities. The inserted entities will not be same as the passed in
* entities. For example, the inserted entities may contain generated ID, key, parent key,
* etc.
* @throws EntityManagerException
* if any error occurs while inserting.
*/
@SuppressWarnings("unchecked")
public <E> List<E> insert(List<E> entities) {
if (entities == null || entities.isEmpty()) {
return new ArrayList<>();
}
try {
entityManager.executeEntityListeners(CallbackType.PRE_INSERT, entities);
FullEntity<?>[] nativeEntities = toNativeFullEntities(entities, entityManager, Intent.INSERT);
Class<?> entityClass = entities.get(0).getClass();
List<Entity> insertedNativeEntities = nativeWriter.add(nativeEntities);
List<E> insertedEntities = (List<E>) toEntities(entityClass, insertedNativeEntities);
entityManager.executeEntityListeners(CallbackType.POST_INSERT, insertedEntities);
return insertedEntities;
} catch (DatastoreException exp) {
throw DatastoreUtils.wrap(exp);
}
}
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:29,代码来源:DefaultDatastoreWriter.java
示例9: update
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
/**
* Updates the given entity in the Cloud Datastore. The passed in Entity must have its ID set for
* the update to work.
*
* @param entity
* the entity to update
* @return the updated entity.
* @throws EntityManagerException
* if any error occurs while updating.
*/
@SuppressWarnings("unchecked")
public <E> E update(E entity) {
try {
entityManager.executeEntityListeners(CallbackType.PRE_UPDATE, entity);
Intent intent = (nativeWriter instanceof Batch) ? Intent.BATCH_UPDATE : Intent.UPDATE;
Entity nativeEntity = (Entity) Marshaller.marshal(entityManager, entity, intent);
nativeWriter.update(nativeEntity);
E updatedEntity = (E) Unmarshaller.unmarshal(nativeEntity, entity.getClass());
entityManager.executeEntityListeners(CallbackType.POST_UPDATE, updatedEntity);
return updatedEntity;
} catch (DatastoreException exp) {
throw DatastoreUtils.wrap(exp);
}
}
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:26,代码来源:DefaultDatastoreWriter.java
示例10: upsert
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
/**
* Updates or inserts the given list of entities in the Cloud Datastore. If the entities do not
* have a valid ID, IDs may be generated.
*
* @param entities
* the entities to update/or insert.
* @return the updated or inserted entities
* @throws EntityManagerException
* if any error occurs while saving.
*/
@SuppressWarnings("unchecked")
public <E> List<E> upsert(List<E> entities) {
if (entities == null || entities.isEmpty()) {
return new ArrayList<>();
}
try {
entityManager.executeEntityListeners(CallbackType.PRE_UPSERT, entities);
FullEntity<?>[] nativeEntities = toNativeFullEntities(entities, entityManager, Intent.UPSERT);
Class<?> entityClass = entities.get(0).getClass();
List<Entity> upsertedNativeEntities = nativeWriter.put(nativeEntities);
List<E> upsertedEntities = (List<E>) toEntities(entityClass, upsertedNativeEntities);
entityManager.executeEntityListeners(CallbackType.POST_UPSERT, upsertedEntities);
return upsertedEntities;
} catch (DatastoreException exp) {
throw DatastoreUtils.wrap(exp);
}
}
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:28,代码来源:DefaultDatastoreWriter.java
示例11: store
import com.google.cloud.datastore.Entity; //导入依赖的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
示例12: updateNextNaturalTrigger
import com.google.cloud.datastore.Entity; //导入依赖的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
示例13: workflows
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
public Map<WorkflowId, Workflow> workflows() {
final Map<WorkflowId, Workflow> map = Maps.newHashMap();
final EntityQuery query = Query.newEntityQueryBuilder().setKind(KIND_WORKFLOW).build();
final QueryResults<Entity> result = datastore.run(query);
while (result.hasNext()) {
final Entity entity = result.next();
final Workflow workflow;
try {
workflow = OBJECT_MAPPER.readValue(entity.getString(PROPERTY_WORKFLOW_JSON), Workflow.class);
} catch (IOException e) {
LOG.warn("Failed to read workflow {}.", entity.getKey());
continue;
}
map.put(workflow.id(), workflow);
}
return map;
}
开发者ID:spotify,项目名称:styx,代码行数:20,代码来源:DatastoreStorage.java
示例14: patchState
import com.google.cloud.datastore.Entity; //导入依赖的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
示例15: entityToBackfill
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
private Backfill entityToBackfill(Entity entity) {
final WorkflowId workflowId = WorkflowId.create(entity.getString(PROPERTY_COMPONENT),
entity.getString(PROPERTY_WORKFLOW));
final BackfillBuilder builder = Backfill.newBuilder()
.id(entity.getKey().getName())
.start(timestampToInstant(entity.getTimestamp(PROPERTY_START)))
.end(timestampToInstant(entity.getTimestamp(PROPERTY_END)))
.workflowId(workflowId)
.concurrency((int) entity.getLong(PROPERTY_CONCURRENCY))
.nextTrigger(timestampToInstant(entity.getTimestamp(PROPERTY_NEXT_TRIGGER)))
.schedule(Schedule.parse(entity.getString(PROPERTY_SCHEDULE)))
.allTriggered(entity.getBoolean(PROPERTY_ALL_TRIGGERED))
.halted(entity.getBoolean(PROPERTY_HALTED));
if (entity.contains(PROPERTY_DESCRIPTION)) {
builder.description(entity.getString(PROPERTY_DESCRIPTION));
}
return builder.build();
}
开发者ID:spotify,项目名称:styx,代码行数:22,代码来源:DatastoreStorage.java
示例16: backfillToEntity
import com.google.cloud.datastore.Entity; //导入依赖的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
示例17: testLifeCycle
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
@Test
@RemoteOnly
public void testLifeCycle() throws IOException {
SessionData session = createSession(null);
Entity entity = datastore.get(keyFactory.newKey("_0.0.0.0_" + session.id));
assertNotNull(entity);
//invalidate it
String sessionCookie = session.cookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
URI target = getUri().resolve("/session/?a=delete");
HttpURLConnection http = HttpUrlUtil.openTo(target);
http.setRequestProperty("Cookie", sessionCookie);
assertThat(http.getResponseCode(), is(200));
String responseBody = HttpUrlUtil.getResponseBody(http);
assertNotNull(responseBody);
assertThat(responseBody, containsString("invalidated"));
entity = datastore.get(keyFactory.newKey("_0.0.0.0_" + session.id));
assertNull(entity);
}
开发者ID:GoogleCloudPlatform,项目名称:jetty-runtime,代码行数:25,代码来源:RemoteSessionIntegrationTest.java
示例18: updateRow
import com.google.cloud.datastore.Entity; //导入依赖的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
示例19: get
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
@Override
public String get(String key) {
try {
Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(encode(key));
Entity entity = datastore.get(entityKey);
Map<String, Object> map = new HashMap<>();
if (entity != null) {
for (String name : entity.getNames()) {
Value<?> value = entity.getValue(name);
if (value != null) {
put(map, name, value);
}
}
}
if (map.isEmpty()) return null;
return JacksonUtil.jsonFromObject(map);
} catch (Exception e) {
String error = ExceptionToString.format(e);
log.info(e.getMessage());
log.trace(error);
return null;
}
}
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:24,代码来源:GoogleDatastoreKeyStore.java
示例20: put
import com.google.cloud.datastore.Entity; //导入依赖的package包/类
/**
* TODO https://cloud.google.com/datastore/docs/best-practices
*
* For a key that uses a custom name, always use UTF-8 characters except a forward slash (/). Non-UTF-8 characters interfere with various processes such as
* importing a Cloud Datastore backup into Google BigQuery. A forward slash could interfere with future functionality.
*/
@Override
public void put(String key, String value) {
Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(encode(key));
Map<String, Object> map = JacksonUtil.getMapFromJson(value);
Builder builder = Entity.newBuilder(entityKey);
for (Entry<String, Object> entry : map.entrySet()) {
builder.set(encode(entry.getKey()), valerie(entry.getKey(), entry.getValue()));
}
Entity entity = builder.build();
try {
datastore.put(entity);
} catch (Exception e) {
String error = ExceptionToString.format(e);
log.error(error);
throw e;
}
}
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:26,代码来源:GoogleDatastoreKeyStore.java
注:本文中的com.google.cloud.datastore.Entity类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论