use of com.google.appengine.api.datastore.Entity in project qi4j-sdk by Qi4j.
the class GaeEntityStoreMixin method get.
@Override
public Reader get(EntityReference ref) throws EntityStoreException {
try {
Key key = KeyFactory.createKey(entityKind, ref.toURI());
Entity entity = datastore.get(key);
Text serializedState = (Text) entity.getProperty("value");
if (serializedState == null) {
throw new EntityNotFoundException(ref);
}
return new StringReader(serializedState.getValue());
} catch (com.google.appengine.api.datastore.EntityNotFoundException e) {
e.printStackTrace();
throw new EntityNotFoundException(ref);
}
}
use of com.google.appengine.api.datastore.Entity in project siena by mandubian.
the class GaeMappingUtils method createEntityInstanceFromParent.
public static Entity createEntityInstanceFromParent(Field idField, ClassInfo info, Object obj, Key parentKey, ClassInfo parentInfo, Field parentField) {
Entity entity = null;
Id id = idField.getAnnotation(Id.class);
Class<?> type = idField.getType();
if (id != null) {
switch(id.value()) {
case NONE:
Object idVal = null;
idVal = Util.readField(obj, idField);
if (idVal == null)
throw new SienaException("Id Field " + idField.getName() + " value null");
String keyVal = Util.toString(idField, idVal);
entity = new Entity(getKindWithAncestorField(info, parentInfo, parentField), keyVal, parentKey);
break;
case AUTO_INCREMENT:
// manages String ID as not long!!!
if (Long.TYPE == type || Long.class.isAssignableFrom(type)) {
entity = new Entity(getKindWithAncestorField(info, parentInfo, parentField), parentKey);
} else {
Object idStringVal = null;
idStringVal = Util.readField(obj, idField);
if (idStringVal == null)
throw new SienaException("Id Field " + idField.getName() + " value null");
String keyStringVal = Util.toString(idField, idStringVal);
entity = new Entity(getKindWithAncestorField(info, parentInfo, parentField), keyStringVal, parentKey);
}
break;
case UUID:
entity = new Entity(getKindWithAncestorField(info, parentInfo, parentField), UUID.randomUUID().toString(), parentKey);
break;
default:
throw new SienaRestrictedApiException("DB", "createEntityInstance", "Id Generator " + id.value() + " not supported");
}
} else
throw new SienaException("Field " + idField.getName() + " is not an @Id field");
return entity;
}
use of com.google.appengine.api.datastore.Entity in project siena by mandubian.
the class GaeMappingUtils method mapEntitiesKeysOnly.
public static <T> List<T> mapEntitiesKeysOnly(Iterable<Entity> entities, Class<T> clazz) {
Field id = ClassInfo.getIdField(clazz);
List<T> list = new ArrayList<T>();
for (Entity entity : entities) {
T obj;
try {
obj = Util.createObjectInstance(clazz);
list.add(obj);
setIdFromKey(id, obj, entity.getKey());
} catch (SienaException e) {
throw e;
} catch (Exception e) {
throw new SienaException(e);
}
}
return list;
}
use of com.google.appengine.api.datastore.Entity in project siena by mandubian.
the class GaeMappingUtils method createEntityInstanceForUpdate.
public static Entity createEntityInstanceForUpdate(ClassInfo info, Object obj) {
Key key = makeKey(info, obj);
Entity entity = new Entity(key);
return entity;
}
use of com.google.appengine.api.datastore.Entity in project siena by mandubian.
the class GaeMappingUtils method mapEntities.
public static <T> List<T> mapEntities(List<Entity> entities, Class<T> clazz) {
Field id = ClassInfo.getIdField(clazz);
List<T> list = new ArrayList<T>(entities.size());
for (Entity entity : entities) {
T obj;
try {
obj = Util.createObjectInstance(clazz);
fillModel(obj, entity);
list.add(obj);
setIdFromKey(id, obj, entity.getKey());
} catch (SienaException e) {
throw e;
} catch (Exception e) {
throw new SienaException(e);
}
}
return list;
}
Aggregations