@Override public void rollbackTransaction() { datastore.getCurrentTransaction().rollback(); }
@Override public void commitTransaction() { datastore.getCurrentTransaction().commit(); }
public Transaction getCurrentTransaction(Transaction transaction) { try { return inner.getCurrentTransaction(transaction); } catch (IllegalArgumentException e) { throw wrapIllegalArgumentException(e); } catch (DatastoreFailureException e) { throw wrapDatastoreFailureException(e); } }
public Transaction getCurrentTransaction() { try { return inner.getCurrentTransaction(); } catch (IllegalArgumentException e) { throw wrapIllegalArgumentException(e); } catch (DatastoreFailureException e) { throw wrapDatastoreFailureException(e); } }
@Override public void exit() { Transaction currentTransaction = datastore.getCurrentTransaction(null); if (currentTransaction != null && currentTransaction.isActive()) { currentTransaction.rollback(); } }
/** * Should work in all envs? * A bit complex / overkill ... * * @return true if in-container, false otherewise */ protected static boolean isInContainer() { try { DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); Transaction tx = ds.beginTransaction(); try { return (ds.getCurrentTransaction() != null); } finally { tx.rollback(); } } catch (Throwable ignored) { return false; } }
int[] indices = new int[keys.size()]; int index = 0; for (Entity e : service.prepare(service.getCurrentTransaction(null), q).asIterable()) { if (keySet.contains(e.getKey())) { Long indexVal = (Long) orderMapping.getObject(ec, e, new int[1]);
private Object wrapEntityQueryResult(Iterable<Entity> entities, Function<Entity, Object> resultTransformer, DatastoreService ds, Cursor endCursor) { if (isBulkDelete()) { List<Key> keysToDelete = Utils.newArrayList(); for (Entity e : entities) { keysToDelete.add(e.getKey()); } if (NucleusLogger.DATASTORE_NATIVE.isDebugEnabled()) { NucleusLogger.DATASTORE_NATIVE.debug("Deleting entities with keys " + StringUtils.collectionToString(keysToDelete)); } if (getExecutionContext().getStatistics() != null) { getExecutionContext().getStatistics().incrementNumWrites(); } ds.delete(ds.getCurrentTransaction(null), keysToDelete); return (long) keysToDelete.size(); } return newStreamingQueryResultForEntities(entities, resultTransformer, endCursor, query); }
Transaction tx = service.beginTransaction(); try { Assert.assertEquals(tx, service.getCurrentTransaction(null)); } finally { tx.rollback(); Assert.assertSame(dummy, service.getCurrentTransaction(dummy));
protected int[] internalShift(ObjectProvider op, boolean batched, int oldIndex, int amount) throws MappedDatastoreException { if (orderMapping == null) { return null; } DatastoreServiceConfig config = storeMgr.getDefaultDatastoreServiceConfigForReads(); DatastoreService service = DatastoreServiceFactoryInternal.getDatastoreService(config); AbstractClassMetaData acmd = elementCmd; String kind = storeMgr.getIdentifierFactory().newDatastoreContainerIdentifier(acmd).getIdentifierName(); Query q = new Query(kind); ExecutionContext ec = op.getExecutionContext(); Object id = ec.getApiAdapter().getTargetKeyForSingleFieldIdentity(op.getInternalObjectId()); Key key = id instanceof Key ? (Key) id : KeyFactory.stringToKey((String) id); q.setAncestor(key); // create an entity just to capture the name of the index property Entity entity = new Entity(kind); orderMapping.setObject(ec, entity, new int[] {1}, oldIndex); String indexProp = entity.getProperties().keySet().iterator().next(); q.addFilter(indexProp, Query.FilterOperator.GREATER_THAN_OR_EQUAL, oldIndex); for (Entity shiftMe : service.prepare(service.getCurrentTransaction(null), q).asIterable()) { Long pos = (Long) shiftMe.getProperty(indexProp); shiftMe.setProperty(indexProp, pos + amount); EntityUtils.putEntityIntoDatastore(ec, shiftMe); } return null; }
String indexProp = entity.getProperties().keySet().iterator().next(); q.addFilter(indexProp, Query.FilterOperator.GREATER_THAN, index); for (Entity shiftMe : service.prepare(service.getCurrentTransaction(null), q).asIterable()) { Long pos = (Long) shiftMe.getProperty(indexProp); shiftMe.setProperty(indexProp, pos - 1);
service.getCurrentTransaction().commit(); service.getCurrentTransaction().commit(); service.getCurrentTransaction().commit(); service.getCurrentTransaction().commit(); Transaction tx = service.getCurrentTransaction(); int numRows = service.prepare(tx, query).countEntities(FetchOptions.Builder.withDefaults()); tx.commit(); assertEquals(1, numRows); service.beginTransaction(); tx = service.getCurrentTransaction(); Entity result = service.prepare(tx, query).asSingleEntity(); assertEquals(childA.getKey(), result.getKey());
!(Boolean)extensions.get(DatastoreManager.QUERYEXT_EXCLUDE_FROM_TXN)) { txn = qd.primaryDatastoreQuery.getAncestor() != null ? ds.getCurrentTransaction(null) : null;