use of com.google.appengine.api.datastore.EmbeddedEntity in project activityinfo by bedatadriven.
the class FormConverter method fromPropertyValue.
public static JsonValue fromPropertyValue(Object propertyValue) {
if (propertyValue == null) {
return Json.createNull();
} else if (propertyValue instanceof EmbeddedEntity) {
return fromEmbeddedEntity(((EmbeddedEntity) propertyValue));
} else if (propertyValue instanceof List) {
List<Object> propertyValueList = (List<Object>) propertyValue;
JsonValue convertedList = Json.createArray();
for (Object propertyValueListItem : propertyValueList) {
convertedList.add(fromPropertyValue(propertyValueListItem));
}
return convertedList;
} else if (propertyValue instanceof String) {
return Json.create((String) propertyValue);
} else if (propertyValue instanceof Number) {
return Json.create(((Number) propertyValue).doubleValue());
} else if (propertyValue instanceof Boolean) {
return Json.create((Boolean) propertyValue);
} else {
throw new UnsupportedOperationException("type: " + propertyValue.getClass().getName());
}
}
use of com.google.appengine.api.datastore.EmbeddedEntity in project java-docs-samples by GoogleCloudPlatform.
the class EntitiesTest method embeddedEntity_fromExisting_canRecover.
@Test
public void embeddedEntity_fromExisting_canRecover() throws Exception {
Entity initialContactInfo = new Entity("Contact");
initialContactInfo.setProperty("homeAddress", "123 Fake St, Made, UP 45678");
initialContactInfo.setProperty("phoneNumber", "555-555-5555");
initialContactInfo.setProperty("emailAddress", "test@example.com");
datastore.put(initialContactInfo);
Key employeeKey = putEmployeeWithContactInfo(initialContactInfo);
// [START embedded_entities_3]
Entity employee = datastore.get(employeeKey);
EmbeddedEntity embeddedContactInfo = (EmbeddedEntity) employee.getProperty("contactInfo");
Key infoKey = embeddedContactInfo.getKey();
Entity contactInfo = new Entity(infoKey);
contactInfo.setPropertiesFrom(embeddedContactInfo);
// [END embedded_entities_3]
datastore.put(contactInfo);
Entity got = datastore.get(infoKey);
assertThat(got.getKey()).isEqualTo(initialContactInfo.getKey());
assertThat((String) got.getProperty("homeAddress")).named("got.homeAddress").isEqualTo("123 Fake St, Made, UP 45678");
}
use of com.google.appengine.api.datastore.EmbeddedEntity in project java-docs-samples by GoogleCloudPlatform.
the class EntitiesTest method embeddedEntity_fromEmbedded_embedsProperties.
@Test
public void embeddedEntity_fromEmbedded_embedsProperties() throws Exception {
// CHECKSTYLE.OFF: VariableDeclarationUsageDistance - Increased clarity in sample
Entity employee = new Entity("Employee");
// CHECKSTYLE.ON: VariableDeclarationUsageDistance
// [START embedded_entities_1]
// Entity employee = ...;
EmbeddedEntity embeddedContactInfo = new EmbeddedEntity();
embeddedContactInfo.setProperty("homeAddress", "123 Fake St, Made, UP 45678");
embeddedContactInfo.setProperty("phoneNumber", "555-555-5555");
embeddedContactInfo.setProperty("emailAddress", "test@example.com");
employee.setProperty("contactInfo", embeddedContactInfo);
// [END embedded_entities_1]
datastore.put(employee);
Entity gotEmployee = datastore.get(employee.getKey());
EmbeddedEntity got = (EmbeddedEntity) gotEmployee.getProperty("contactInfo");
assertThat((String) got.getProperty("homeAddress")).named("got.homeAddress").isEqualTo("123 Fake St, Made, UP 45678");
}
use of com.google.appengine.api.datastore.EmbeddedEntity in project Cached-Datastore by Emperorlou.
the class EntityPool method addEmbeddedEntityDirectly.
public void addEmbeddedEntityDirectly(EmbeddedEntity... entity) {
for (EmbeddedEntity e : entity) {
// if (e.getKey()==null) throw new RuntimeException("Cannot add an embedded entity if it doesn't have a key.");
CachedEntity wrapper = new CachedEntity(e.getKey());
for (String fieldName : e.getProperties().keySet()) {
wrapper.setProperty(fieldName, e.getProperty(fieldName));
}
pool.put(e, wrapper);
}
}
use of com.google.appengine.api.datastore.EmbeddedEntity in project java-docs-samples by GoogleCloudPlatform.
the class EntitiesTest method putEmployeeWithContactInfo.
private Key putEmployeeWithContactInfo(Entity contactInfo) {
Entity employee = new Entity("Employee");
// [START embedded_entities_2]
// Entity employee = ...;
// Entity contactInfo = ...;
EmbeddedEntity embeddedContactInfo = new EmbeddedEntity();
// Optional, used so we can recover original.
embeddedContactInfo.setKey(contactInfo.getKey());
embeddedContactInfo.setPropertiesFrom(contactInfo);
employee.setProperty("contactInfo", embeddedContactInfo);
// [END embedded_entities_2]
datastore.put(employee);
return employee.getKey();
}
Aggregations