use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.
the class TaskQueueTest method testBulkAddImplicitTransactionEnlistment_NoTaskOptions.
@Test
public void testBulkAddImplicitTransactionEnlistment_NoTaskOptions() {
MockQueueBulkAddApiHelper helper = newBasicAddRequest();
com.google.apphosting.datastore.proto2api.DatastoreV3Pb.Transaction pbTxn = com.google.apphosting.datastore.proto2api.DatastoreV3Pb.Transaction.newBuilder().setHandle(44).setApp(APP).build();
helper.expectedRequest.getAddRequestBuilder(0).setTransaction(pbTxn);
Transaction txn = mock(Transaction.class);
when(txn.getId()).thenReturn("44");
when(txn.getApp()).thenReturn(APP);
DatastoreService ds = mock(DatastoreService.class);
when(ds.getCurrentTransaction(null)).thenReturn(txn);
Queue q = helper.getQueue(ds);
q.add();
}
use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.
the class TransactionCleanupFilterTest method testAbandonedTransactions_allRolledBack.
@Test
public void testAbandonedTransactions_allRolledBack() throws ServletException, IOException {
DatastoreService datastoreMock = mock(DatastoreService.class);
Transaction txn1 = mock(Transaction.class);
when(txn1.getId()).thenReturn("txn1");
Transaction txn2 = mock(Transaction.class);
when(txn2.getId()).thenReturn("txn2");
when(datastoreMock.getActiveTransactions()).thenReturn(Lists.newArrayList(txn1, txn2));
MyTransactionCleanupFilter filter = new MyTransactionCleanupFilter(datastoreMock);
filter.init(null);
FilterChain chain = mock(FilterChain.class);
filter.doFilter(null, null, chain);
verify(chain, atLeastOnce()).doFilter(null, null);
verify(txn1, atLeastOnce()).rollback();
verify(txn2, atLeastOnce()).rollback();
}
use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.
the class TransactionCleanupFilterTest method testNoAbandonedTransactions.
@Test
public void testNoAbandonedTransactions() throws ServletException, IOException {
DatastoreService datastoreMock = mock(DatastoreService.class);
when(datastoreMock.getActiveTransactions()).thenReturn(ImmutableList.of());
MyTransactionCleanupFilter filter = new MyTransactionCleanupFilter(datastoreMock);
filter.init(null);
FilterChain chain = mock(FilterChain.class);
filter.doFilter(null, null, chain);
verify(chain, atLeastOnce()).doFilter(null, null);
}
use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.
the class DatastoreViewerServlet method deleteEntities.
private void deleteEntities(HttpServletRequest req, HttpServletResponse resp) throws IOException {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
int numDeleted = 0;
int numKeys = Integer.parseInt(req.getParameter(NUM_KEYS));
for (int i = 1; i <= numKeys; i++) {
String key = req.getParameter(KEY + i);
if (key != null) {
ds.delete(KeyFactory.stringToKey(key));
numDeleted++;
}
}
String message = String.format("%d entit%s deleted. If your app uses memcache to cache entities " + "(e.g. uses Objectify), you may see stale results unless you flush memcache.", numDeleted, numDeleted == 1 ? "y" : "ies");
resp.sendRedirect(String.format("%s&msg=%s", req.getParameter("next"), urlencode(message)));
}
use of com.google.appengine.api.datastore.DatastoreService in project appengine-java-standard by GoogleCloudPlatform.
the class DatastoreViewerServlet method doGetIndexes.
private void doGetIndexes(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// Empty namespace parameter equals to no namespace specified
String requestedNamespace = req.getParameter(NAMESPACE);
String namespace = requestedNamespace != null ? requestedNamespace : "";
String savedNamespace = NamespaceManager.get();
try {
NamespaceManager.set(namespace);
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Map<Index, IndexState> indexes = ds.getIndexes();
req.setAttribute(INDEXES, indexes);
req.setAttribute(APPLICATION_NAME, ApiProxy.getCurrentEnvironment().getAppId());
try {
getServletContext().getRequestDispatcher("/_ah/adminConsole?subsection=" + Subsection.indexDetails.name()).forward(req, resp);
} catch (ServletException e) {
throw new RuntimeException("Could not forward request", e);
}
} finally {
NamespaceManager.set(savedNamespace);
}
}
Aggregations