use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.
the class DatastoreViewerServlet method getKinds.
/**
* Return all kinds in the current namespace.
*/
List<String> getKinds() {
List<String> kinds = new ArrayList<String>();
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Query q = new Query(Query.KIND_METADATA_KIND).addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
for (Entity e : ds.prepare(q).asIterable()) {
kinds.add(e.getKey().getName());
}
return kinds;
}
use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.
the class DatastoreViewerServlet method doGetEntityDetails.
private void doGetEntityDetails(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String key = req.getParameter(KEY);
String keyName = null;
Long keyId = null;
String kind = null;
String parentKey = null;
String parentKind = null;
if (key != null) {
Key k = KeyFactory.stringToKey(key);
if (k.getName() != null) {
keyName = k.getName();
} else {
keyId = k.getId();
}
kind = k.getKind();
if (k.getParent() != null) {
parentKey = KeyFactory.keyToString(k.getParent());
parentKind = k.getParent().getKind();
}
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Entity e;
try {
e = ds.get(KeyFactory.stringToKey(key));
} catch (EntityNotFoundException e1) {
throw new RuntimeException("Could not locate entity " + key);
}
req.setAttribute("entity", new EntityDetailsView(e));
} else {
// TODO Handle creation case
}
String url = String.format("/_ah/adminConsole?subsection=entityDetails&" + "key=%s&keyName=%s&keyId=%d&kind=%s&parentKey=%s&parentKind=%s", key, keyName, keyId, kind, parentKey, parentKind);
try {
getServletContext().getRequestDispatcher(url).forward(req, resp);
} catch (ServletException e) {
throw new RuntimeException("Could not forward request", e);
}
}
use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.
the class DatastoreViewerServlet method getEntityViews.
/**
* Retrieve all EntityViews of the given kind for display, sorted by the
* (possibly null) given order.
*/
List<EntityView> getEntityViews(String kind, String order, int start, int numPerPage) {
List<EntityView> entityViews = new ArrayList<EntityView>();
Query q = new Query(kind);
SortDirection dir = SortDirection.ASCENDING;
if (order != null) {
// If the order string begins with a dash, sort in descending order.
if (order.charAt(0) == '-') {
dir = SortDirection.DESCENDING;
order = order.substring(1);
}
q.addSort(order, dir);
}
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
FetchOptions opts = FetchOptions.Builder.withOffset(start).limit(numPerPage);
for (Entity e : ds.prepare(q).asIterable(opts)) {
entityViews.add(new EntityView(e));
}
return entityViews;
}
use of com.google.appengine.api.datastore.DatastoreService in project xuml-tools by davidmoten.
the class DatastoreTextGae method put.
@Override
public void put(String kind, String name, String property, String value) {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Key k = KeyFactory.createKey(kind, name);
System.out.println("putting " + k + "=" + value);
Entity ent = new Entity(k);
ent.setProperty(property, new Text(value));
ds.put(ent);
}
use of com.google.appengine.api.datastore.DatastoreService in project nigori by ucam-cl-dtg.
the class AppEngineDatabase method getRevisions.
@Override
public Collection<byte[]> getRevisions(User user, byte[] index) throws IOException {
PersistenceManager pm = pmfInstance.getPersistenceManager();
try {
// TODO(drt24): cleanup this method
// TODO(drt24): we can do this faster with a key only lookup
Key lookupKey = getLookupKey(user, index);
// If this doesn't exist there is no key so null gets returned by JDOObjectNotFoundException
Lookup lookup = pm.getObjectById(Lookup.class, lookupKey);
List<byte[]> answer = new ArrayList<byte[]>();
Query getRevisionValues = new Query(AppEngineRecord.class.getSimpleName());
getRevisionValues.setAncestor(lookupKey);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
List<Entity> results = datastore.prepare(getRevisionValues).asList(FetchOptions.Builder.withDefaults());
for (Entity result : results) {
ByteArrayInputStream bais = new ByteArrayInputStream(((Blob) result.getProperty("revision")).getBytes());
ObjectInputStream ndis = new ObjectInputStream(bais);
answer.add(((Revision) ndis.readObject()).getBytes());
}
if (lookup != null) {
return answer;
} else {
return null;
}
} catch (JDOObjectNotFoundException e) {
return null;
} catch (ClassNotFoundException e) {
throw new IOException(e);
} finally {
pm.close();
}
}
Aggregations