The following problems relate to CocoBase version 4.0. I do not know if they are present in other versions.
I have found what seem to be bugs, or at least inconsistant behaviour, when using global Transaction instances. The problems relate specifically to the static Stack of 'global' transactions and therefore are not present with 'local' transactions. The reason I am interested in global transactions is that I need to use the TransactionFactory to bind new factory instances to the current transaction.
problem1:
Transaction txn = Transaction.getTransaction();
// Okay. txn == null (no transaction in progress)
Transaction txn2 = new Transaction(myBase, true);
txn = Transaction.getTransaction();
// Okay. txn == txn2 (the latest global transaction)
txn2.begin();
.... create / delete / update objects etc.
txn2.commit();
txn2.close();
txn = Transaction.getTransaction();
// Not okay. I would have expected 'txn' to be equal
// to null since there is no transaction (the only
// transaction has now been closed). 'txn' in fact
// still refers to the transaction that was created
// above. A call to txn.isOpen() returns true!
problem2:
Transaction txnOne = new Transaction(myBase, true);
txnOne.begin();
Transaction txnTwo = new Transaction(myBase, true);
txnTwo.begin();
txnTwo.commit();
txnTwo.close();
txnOne.commit();
txnOne.close();
int numberOfActiveTransactions = Transaction.transactionStack.size();
int numberOfActiveTransactions = Transaction.transactionStack.size();
// I would expect numberOfActiveTransactions to be zero,
// but the value is in fact 1
problem3: (similar to problem 2 above but a different result)
Transaction txnOne = new Transaction(myBase, true);
Transaction txnTwo = new Transaction(myBase, true);
txnOne.begin(); // <-- moved after the creation of the second transaction
txnTwo.begin();
txnTwo.commit();
txnTwo.close();
txnOne.commit();
txnOne.close();
int numberOfActiveTransactions = Transaction.transactionStack.size();
int numberOfActiveTransactions = Transaction.transactionStack.size();
// I would expect numberOfActiveTransactions to be zero,
// but the value is now 2
The javadoc documentation for the method Transaction.close() states "This will close the transaction object, and remove this Transaction from the global 'active' transaction list."
|