- private static TransactionContext createLocalTransactionContext(final LocalTransactionFactory factory, final TransactionProxy parent) {
- return new LocalTransactionContext(parent.getIdentifier(), factory.newReadWriteTransaction(parent.getIdentifier()));
+ private static TransactionContext createLocalTransactionContext(final LocalTransactionFactory factory,
+ final TransactionProxy parent) {
+
+ switch(parent.getType()) {
+ case READ_ONLY:
+ final DOMStoreReadTransaction readOnly = factory.newReadOnlyTransaction(parent.getIdentifier());
+ return new LocalTransactionContext(readOnly, parent.getIdentifier(), factory) {
+ @Override
+ protected DOMStoreWriteTransaction getWriteDelegate() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected DOMStoreReadTransaction getReadDelegate() {
+ return readOnly;
+ }
+ };
+ case READ_WRITE:
+ final DOMStoreReadWriteTransaction readWrite = factory.newReadWriteTransaction(parent.getIdentifier());
+ return new LocalTransactionContext(readWrite, parent.getIdentifier(), factory) {
+ @Override
+ protected DOMStoreWriteTransaction getWriteDelegate() {
+ return readWrite;
+ }
+
+ @Override
+ protected DOMStoreReadTransaction getReadDelegate() {
+ return readWrite;
+ }
+ };
+ case WRITE_ONLY:
+ final DOMStoreWriteTransaction writeOnly = factory.newWriteOnlyTransaction(parent.getIdentifier());
+ return new LocalTransactionContext(writeOnly, parent.getIdentifier(), factory) {
+ @Override
+ protected DOMStoreWriteTransaction getWriteDelegate() {
+ return writeOnly;
+ }
+
+ @Override
+ protected DOMStoreReadTransaction getReadDelegate() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ default:
+ throw new IllegalArgumentException("Invalid transaction type: " + parent.getType());
+ }