use of com.google.appengine.api.datastore.Entity in project siena by mandubian.
the class GaePersistenceManagerAsync method insert.
public SienaFuture<Integer> insert(final Iterable<?> objects) {
List<Entity> entities = new ArrayList<Entity>();
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Field idField = info.getIdField();
Entity entity = GaeMappingUtils.createEntityInstance(idField, info, obj);
GaeMappingUtils.fillEntity(obj, entity);
entities.add(entity);
}
Future<List<Key>> future = ds.put(entities);
Future<Integer> wrapped = new SienaFutureWrapper<List<Key>, Integer>(future) {
@Override
protected Integer wrap(List<Key> generatedKeys) throws Exception {
int i = 0;
for (Object obj : objects) {
Class<?> clazz = obj.getClass();
ClassInfo info = ClassInfo.getClassInfo(clazz);
Field idField = info.getIdField();
GaeMappingUtils.setIdFromKey(idField, obj, generatedKeys.get(i++));
}
return generatedKeys.size();
}
};
return new SienaFutureContainer<Integer>(wrapped);
}
use of com.google.appengine.api.datastore.Entity in project siena by mandubian.
the class GaePersistenceManagerAsync method get.
public SienaFuture<Void> get(final Object obj) {
final Key key = GaeMappingUtils.getKey(obj);
Future<Entity> future = ds.get(key);
Future<Void> wrapped = new SienaFutureWrapper<Entity, Void>(future) {
@Override
protected Void wrap(Entity entity) throws Exception {
GaeMappingUtils.fillModel(obj, entity);
return null;
}
};
return new SienaFutureContainer<Void>(wrapped);
}
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 GaePersistenceManagerAsync method update.
public SienaFuture<Void> update(Object obj) {
Entity entity = new Entity(GaeMappingUtils.getKey(obj));
GaeMappingUtils.fillEntity(obj, entity);
Future<Key> future = ds.put(entity);
Future<Void> wrapped = new SienaFutureWrapper<Key, Void>(future) {
@Override
protected Void wrap(Key key) throws Exception {
return null;
}
};
return new SienaFutureContainer<Void>(wrapped);
}
use of com.google.appengine.api.datastore.Entity in project iosched by google.
the class LogDataServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("application/json");
UpdateRunLogger logger = new UpdateRunLogger();
JsonObject response = new JsonObject();
int limitElements = 10;
if (req.getParameter("limit") != null) {
limitElements = Integer.parseInt(req.getParameter("limit"));
}
List<Entity> lastRunsEntities = logger.getMostRecentRuns(limitElements);
JsonArray lastRuns = new JsonArray();
for (Entity run : lastRunsEntities) {
JsonObject obj = new JsonObject();
JsonObject timings = new JsonObject();
TreeMap<String, Object> sortedMap = new TreeMap<String, Object>(run.getProperties());
for (Entry<String, Object> property : sortedMap.entrySet()) {
Object value = property.getValue();
String key = property.getKey();
if (key.startsWith("time_")) {
timings.add(key.substring("time_".length()), new JsonPrimitive((Number) value));
} else {
JsonPrimitive converted = null;
if (value instanceof ShortBlob) {
converted = new JsonPrimitive(bytesToHex(((ShortBlob) value).getBytes()));
} else if (value instanceof String) {
converted = new JsonPrimitive((String) value);
} else if (value instanceof Number) {
converted = new JsonPrimitive((Number) value);
} else if (value instanceof Boolean) {
converted = new JsonPrimitive((Boolean) value);
} else if (value instanceof Character) {
converted = new JsonPrimitive((Character) value);
} else if (value instanceof Date) {
converted = new JsonPrimitive(DateFormat.getDateTimeInstance().format((Date) value));
}
if (converted != null) {
obj.add(key, converted);
}
}
}
obj.add("timings", timings);
lastRuns.add(obj);
}
response.add("lastruns", lastRuns);
CloudFileManager cloudManager = new CloudFileManager();
response.add("bucket", new JsonPrimitive(cloudManager.getBucketName()));
response.add("productionManifest", new JsonPrimitive(cloudManager.getProductionManifestURL()));
response.add("stagingManifest", new JsonPrimitive(cloudManager.getStagingManifestURL()));
new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(response, resp.getWriter());
}
Aggregations