class Transaction {

    @SuppressWarnings("deprecation")
    public static <T, E extends Throwable> T execute(TransactionCallbackWithException<T, E> callback) throws E {
        String name = "tx-" + counter.incrementAndGet();
        short databaseId = TransactionLegacy.CLOUD_DB;
        TransactionLegacy currentTxn = TransactionLegacy.currentTxn(false);
        if (currentTxn != null) {
            databaseId = currentTxn.getDatabaseId();
        }
        try (final TransactionLegacy txn = TransactionLegacy.open(name, databaseId, false)) {
            txn.start();
            T result = callback.doInTransaction(STATUS);
            txn.commit();
            return result;
        }
    }

}