本文整理了Java中com.google.cloud.datastore.Entity.getValue()
方法的一些代码示例,展示了Entity.getValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.getValue()
方法的具体详情如下:
包路径:com.google.cloud.datastore.Entity
类名称:Entity
方法名:getValue
暂无
代码示例来源:origin: google/data-transfer-project
private static Map<String, Object> getProperties(Entity entity)
throws IOException, ClassNotFoundException {
if (entity == null) {
return null;
}
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
for (String property : entity.getNames()) {
// builder.put(property, entity.getValue(property));
if (entity.getValue(property) instanceof StringValue) {
builder.put(property, (String) entity.getString(property));
} else if (entity.getValue(property) instanceof LongValue) {
// This conversion is safe because of integer to long conversion above
builder.put(property, new Long(entity.getLong(property)).intValue());
} else if (entity.getValue(property) instanceof DoubleValue) {
builder.put(property, (Double) entity.getDouble(property));
} else if (entity.getValue(property) instanceof BooleanValue) {
builder.put(property, (Boolean) entity.getBoolean(property));
} else if (entity.getValue(property) instanceof TimestampValue) {
builder.put(property, (Timestamp) entity.getTimestamp(property));
} else {
Blob blob = entity.getBlob(property);
Object obj = null;
try (ObjectInputStream in = new ObjectInputStream(blob.asInputStream())) {
obj = in.readObject();
}
builder.put(property, obj); // BlobValue
}
}
return builder.build();
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGet() {
Entity entity = DATASTORE.get(KEY3);
assertNull(entity);
entity = DATASTORE.get(KEY1);
assertEquals(ENTITY1, entity);
StringValue value1 = entity.getValue("str");
assertEquals(STR_VALUE, value1);
BooleanValue value2 = entity.getValue("bool");
assertEquals(BOOL_VALUE, value2);
ListValue value3 = entity.getValue("list");
assertEquals(LIST_VALUE2, value3);
TimestampValue value4 = entity.getValue("date");
assertEquals(TIMESTAMP_VALUE, value4);
LatLngValue value5 = entity.getValue("latLng");
assertEquals(LAT_LNG_VALUE, value5);
FullEntity<IncompleteKey> value6 = entity.getEntity("partial1");
assertEquals(PARTIAL_ENTITY1, value6);
ListValue value7 = entity.getValue("emptyList");
assertEquals(EMPTY_LIST_VALUE, value7);
assertEquals(7, entity.getNames().size());
assertFalse(entity.contains("bla"));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGet() {
Entity entity = datastore.get(KEY3);
assertNull(entity);
entity = datastore.get(KEY1);
assertEquals(ENTITY1, entity);
StringValue value1 = entity.getValue("str");
assertEquals(STR_VALUE, value1);
BooleanValue value2 = entity.getValue("bool");
assertEquals(BOOL_VALUE, value2);
ListValue value3 = entity.getValue("list");
assertEquals(LIST_VALUE2, value3);
TimestampValue value4 = entity.getValue("date");
assertEquals(TIMESTAMP_VALUE, value4);
LatLngValue value5 = entity.getValue("latLng");
assertEquals(LAT_LNG_VALUE, value5);
FullEntity<IncompleteKey> value6 = entity.getEntity("partial1");
assertEquals(PARTIAL_ENTITY1, value6);
ListValue value7 = entity.getValue("emptyList");
assertEquals(EMPTY_LIST_VALUE, value7);
assertEquals(7, entity.getNames().size());
assertFalse(entity.contains("bla"));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGetArrayNoDeferredResults() {
datastore.put(ENTITY3);
Iterator<Entity> result =
datastore.fetch(KEY1, Key.newBuilder(KEY1).setName("bla").build(), KEY2, KEY3).iterator();
assertEquals(ENTITY1, result.next());
assertNull(result.next());
assertEquals(ENTITY2, result.next());
Entity entity3 = result.next();
assertEquals(ENTITY3, entity3);
assertTrue(entity3.isNull("null"));
assertFalse(entity3.getBoolean("bool"));
assertEquals(LIST_VALUE2.get(), entity3.getList("list"));
FullEntity<IncompleteKey> partial1 = entity3.getEntity("partial1");
FullEntity<IncompleteKey> partial2 = entity3.getEntity("partial2");
assertEquals(PARTIAL_ENTITY2, partial1);
assertEquals(ENTITY2, partial2);
assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").getType());
assertEquals(LAT_LNG_VALUE, entity3.getValue("latLng"));
assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList"));
assertEquals(8, entity3.getNames().size());
assertFalse(entity3.contains("bla"));
try {
entity3.getString("str");
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected - no such property
}
assertFalse(result.hasNext());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGetArrayNoDeferredResults() {
DATASTORE.put(ENTITY3);
Iterator<Entity> result =
DATASTORE.fetch(KEY1, Key.newBuilder(KEY1).setName("bla").build(), KEY2, KEY3).iterator();
assertEquals(ENTITY1, result.next());
assertNull(result.next());
assertEquals(ENTITY2, result.next());
Entity entity3 = result.next();
assertEquals(ENTITY3, entity3);
assertTrue(entity3.isNull("null"));
assertFalse(entity3.getBoolean("bool"));
assertEquals(LIST_VALUE2.get(), entity3.getList("list"));
FullEntity<IncompleteKey> partial1 = entity3.getEntity("partial1");
FullEntity<IncompleteKey> partial2 = entity3.getEntity("partial2");
assertEquals(PARTIAL_ENTITY2, partial1);
assertEquals(ENTITY2, partial2);
assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").getType());
assertEquals(LAT_LNG_VALUE, entity3.getValue("latLng"));
assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList"));
assertEquals(8, entity3.getNames().size());
assertFalse(entity3.contains("bla"));
try {
entity3.getString("str");
fail("Expecting a failure");
} catch (DatastoreException expected) {
// expected - no such property
}
assertFalse(result.hasNext());
}
代码示例来源:origin: spotify/styx
static <T> Optional<T> readOpt(Entity entity, String property) {
return entity.contains(property)
? Optional.of(entity.<Value<T>>getValue(property).get())
: Optional.empty();
}
内容来源于网络,如有侵权,请联系作者删除!