[Mulgara-svn] r133 - in branches/xafix-impl: conf src/jar/resolver/java/org/mulgara/resolver
andrae at mulgara.org
andrae at mulgara.org
Thu Nov 16 13:47:20 UTC 2006
Author: andrae
Date: 2006-11-16 07:47:19 -0600 (Thu, 16 Nov 2006)
New Revision: 133
Added:
branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/TransactionOperation.java
Modified:
branches/xafix-impl/conf/log4j-mulgara.xml
branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java
branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java
Log:
Tests now passing:
resolver-test
jxunit standard_queries
subqueries
transactions
These three exercise the core transaction functionality.
Next-up: decoupling the DatabaseOperationContext from DatabaseSession.
Modified: branches/xafix-impl/conf/log4j-mulgara.xml
===================================================================
--- branches/xafix-impl/conf/log4j-mulgara.xml 2006-11-16 05:39:41 UTC (rev 132)
+++ branches/xafix-impl/conf/log4j-mulgara.xml 2006-11-16 13:47:19 UTC (rev 133)
@@ -63,11 +63,9 @@
<priority value="INFO"/>
</category>
-->
- <!--
<category name="org.mulgara.resolver.DatabaseSession">
- <priority value="debug"/>
+ <priority value="info"/>
</category>
- -->
<!-- WARN and above goes to console, all else to logfile appender -->
<root>
Modified: branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
===================================================================
--- branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java 2006-11-16 05:39:41 UTC (rev 132)
+++ branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java 2006-11-16 13:47:19 UTC (rev 133)
@@ -647,6 +647,7 @@
transactionManager.getTransaction(this, operation.isWriteOperation());
transaction.execute(operation, resolverSessionFactory, metadata);
} catch (MulgaraTransactionException em) {
+ logger.info("Error executing operation: " + errorString, em);
throw new QueryException(errorString, em);
}
}
Modified: branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java
===================================================================
--- branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java 2006-11-16 05:39:41 UTC (rev 132)
+++ branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java 2006-11-16 13:47:19 UTC (rev 133)
@@ -82,8 +82,8 @@
public MulgaraTransaction(MulgaraTransactionManager manager, DatabaseOperationContext context)
throws Exception {
-// report("Creating Transaction");
- errorReport("Creating Transaction");
+ report("Creating Transaction");
+// errorReport("Creating Transaction");
try {
if (manager == null) {
throw new IllegalArgumentException("Manager null in MulgaraTransaction");
@@ -184,7 +184,6 @@
void dereference() throws MulgaraTransactionException {
report("Dereferencing Transaction");
try {
- checkActivated();
if (using < 1) {
throw implicitRollback(new MulgaraTransactionException(
"Reference Failure. Dereferencing while using < 1: " + using));
@@ -239,6 +238,23 @@
}
+ void execute(TransactionOperation to) throws MulgaraTransactionException {
+ report("Executing TransactionOperation");
+ try {
+ activate();
+ try {
+ to.execute();
+ } catch (Throwable th) {
+ throw implicitRollback(th);
+ } finally {
+ deactivate();
+ }
+ } finally {
+ report("Executed TransactionOperation");
+ }
+ }
+
+
MulgaraTransactionException implicitRollback(Throwable cause) throws MulgaraTransactionException {
report("Implicit Rollback triggered");
@@ -314,8 +330,8 @@
}
private void terminateTransaction() throws MulgaraTransactionException {
-// report("Terminating Transaction: " + rollback);
- errorReport("Terminating Transaction: " + rollback);
+ report("Terminating Transaction: " + rollback);
+// errorReport("Terminating Transaction: " + rollback);
try {
switch (rollback) {
case NO_ROLLBACK:
@@ -339,16 +355,21 @@
break;
}
} finally {
- manager.transactionComplete(this);
- manager = null;
- inuse = 0;
- using = 0;
try {
- context.clear();
- } catch (QueryException eq) {
- throw new MulgaraTransactionException("Error clearing context", eq);
+ try {
+ context.clear();
+ } catch (QueryException eq) {
+ throw new MulgaraTransactionException("Error clearing context", eq);
+ }
} finally {
- report("Terminated transaction");
+ try {
+ manager.transactionComplete(this);
+ } finally {
+ manager = null;
+ inuse = 0;
+ using = 0;
+ report("Terminated transaction");
+ }
}
}
}
@@ -423,7 +444,9 @@
//
private void checkActivated() throws MulgaraTransactionException {
- if (!currentThread.equals(Thread.currentThread())) {
+ if (currentThread == null) {
+ throw new MulgaraTransactionException("Transaction failed activation check");
+ } else if (!currentThread.equals(Thread.currentThread())) {
throw new MulgaraTransactionException("Concurrent access attempted to transaction: Transaction has NOT been rolledback.");
} else if (inuse < 1) {
throw implicitRollback(
Modified: branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java
===================================================================
--- branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java 2006-11-16 05:39:41 UTC (rev 132)
+++ branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java 2006-11-16 13:47:19 UTC (rev 133)
@@ -172,7 +172,9 @@
}
private synchronized void releaseWriteLock() {
- // FIXME:should check here that it's the correct thread calling release.
+ // Calling this method multiple times is safe as the lock cannot be obtained
+ // between calls as this method is private, and all calling methods are
+ // synchronized.
currentWritingSession = null;
userTransaction = null;
this.notify();
@@ -200,12 +202,17 @@
public synchronized void rollback(DatabaseSession session) throws MulgaraTransactionException {
if (session == currentWritingSession) {
try {
- userTransaction.explicitRollback();
- userTransaction.completeTransaction();
+ userTransaction.execute(new TransactionOperation() {
+ public void execute() throws MulgaraTransactionException {
+ userTransaction.explicitRollback();
+ }
+ });
+ if (userTransaction != null) {
+ // transaction referenced by something - need to explicitly end it.
+ userTransaction.completeTransaction();
+ }
} finally {
failedSessions.add(currentWritingSession);
- userTransaction = null;
- currentWritingSession = null;
releaseWriteLock();
setAutoCommit(session, false);
}
@@ -266,20 +273,13 @@
try {
if (session == currentWritingSession) {
logger.error("Terminating session while holding writelock:" + session +
- ":" + currentWritingSession + ": " + userTransaction);
- userTransaction.execute(new AnswerOperation() {
- public void execute() {
- try {
- logger.warn("Checkpoint 1");
- userTransaction.implicitRollback(
- new MulgaraTransactionException("Terminating session while holding writelock"));
- logger.warn("Checkpoint 2");
- } catch (Exception e) {
- throw new IllegalStateException("Error in rollback", e);
- }
+ ":" + currentWritingSession + ": " + userTransaction);
+ userTransaction.execute(new TransactionOperation() {
+ public void execute() throws MulgaraTransactionException {
+ userTransaction.implicitRollback(
+ new MulgaraTransactionException("Terminating session while holding writelock"));
}
});
- logger.warn("Checkpoint 3");
}
} catch (Throwable th) {
error = th;
Added: branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/TransactionOperation.java
===================================================================
--- branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/TransactionOperation.java 2006-11-16 05:39:41 UTC (rev 132)
+++ branches/xafix-impl/src/jar/resolver/java/org/mulgara/resolver/TransactionOperation.java 2006-11-16 13:47:19 UTC (rev 133)
@@ -0,0 +1,24 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.rosenlaw.com/OSL3.0.htm
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * This file is an original work developed by Netymon Pty Ltd
+ * (http://www.netymon.com, mailto:mail at netymon.com). Portions created
+ * by Netymon Pty Ltd are Copyright (c) 2006 Netymon Pty Ltd.
+ * All Rights Reserved.
+ */
+
+package org.mulgara.resolver;
+
+import org.mulgara.query.TuplesException;
+
+interface TransactionOperation {
+ public void execute() throws MulgaraTransactionException;
+}
More information about the Mulgara-svn
mailing list