@Override public String getId() { return this.raw.getId(); }
/** Rolls back every operation in the current transaction. */ @Override public void rollback() { for (ResourceManager<Transaction> manager : managers.values()) { Transaction transaction = manager.transaction(); if (transaction.isActive()) { try { transaction.rollback(); } catch (Exception e) { logger.warning("Transaction [" + transaction.getId() + "]: Rollback failed due to [" + e + "]; Consistency will be ensured in read"); } } } }
@Override public void commit(Xid xid, boolean onePhase) throws XAException { super.commit(xid, onePhase); if (currentTxn != null) { currentTxn.commit(); if (NucleusLogger.TRANSACTION.isDebugEnabled()) { NucleusLogger.TRANSACTION.debug( LOCALISER.msg("AppEngine.Transaction.Committed", currentTxn.getInnerTxn().getId())); } currentTxn = null; } else { throw new XAException(LOCALISER.msg("AppEngine.Transaction.CommitInvalid")); } }
@Override public void rollback(Xid xid) throws XAException { super.rollback(xid); if (currentTxn != null) { currentTxn.rollback(); if (NucleusLogger.TRANSACTION.isDebugEnabled()) { NucleusLogger.TRANSACTION.debug( LOCALISER.msg("AppEngine.Transaction.RolledBack", currentTxn.getInnerTxn().getId())); } currentTxn = null; } else { throw new XAException(LOCALISER.msg("AppEngine.Transaction.RollbackInvalid")); } } }
@Override public void start(Xid xid, int flags) throws XAException { super.start(xid, flags); if (currentTxn == null) { // No currentTxn, and DatastoreService will have been created by DatastoreConnectionFactoryImpl, so call beginTxn Transaction datastoreTxn = datastoreService.beginTransaction(txnOpts); currentTxn = new DatastoreTransaction(datastoreTxn); if (NucleusLogger.TRANSACTION.isDebugEnabled()) { NucleusLogger.TRANSACTION.debug( LOCALISER.msg("AppEngine.Transaction.Started", currentTxn.getInnerTxn().getId())); } } else { throw new XAException(LOCALISER.msg("AppEngine.Transaction.AlreadyStarted")); } }
@Test public void testMiscOps() throws Exception { AsyncDatastoreService service = DatastoreServiceFactory.getAsyncDatastoreService(); DatastoreAttributes attributes = waitOnFuture(service.getDatastoreAttributes()); Assert.assertNotNull(attributes); Assert.assertNotNull(attributes.getDatastoreType()); Map<Index, Index.IndexState> indexes = waitOnFuture(service.getIndexes()); Assert.assertNotNull(indexes); Transaction tx = waitOnFuture(service.beginTransaction()); try { String txId = tx.getId(); Assert.assertNotNull(txId); Assert.assertEquals(txId, tx.getId()); String appId = tx.getApp(); Assert.assertNotNull(appId); Assert.assertEquals(appId, tx.getApp()); } finally { tx.rollback(); } }