[Mulgara-svn] r1091 - in trunk/src/jar: resolver/java/org/mulgara/resolver resolver-relational/java/org/mulgara/resolver/relational resolver-store/java/org/mulgara/store/statement/xa server-rmi/java/org/mulgara/server/rmi tuples/java/org/mulgara/store/tuples tuples-hybrid/java/org/mulgara/store/xa util/java/org/mulgara/util util-xa/java/org/mulgara/store/xa

pag at mulgara.org pag at mulgara.org
Thu Jul 17 21:56:55 UTC 2008


Author: pag
Date: 2008-07-17 14:56:54 -0700 (Thu, 17 Jul 2008)
New Revision: 1091

Added:
   trunk/src/jar/util/java/org/mulgara/util/StackTrace.java
Modified:
   trunk/src/jar/resolver-relational/java/org/mulgara/resolver/relational/LiteralDesc.java
   trunk/src/jar/resolver-store/java/org/mulgara/store/statement/xa/TripleAVLFile.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/ContentHandlerManagerImpl.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/LocalQueryResolver.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransactionFactory.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransaction.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransactionFactory.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraXAResourceContext.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/StringPoolSession.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteAnswerWrapperAnswer.java
   trunk/src/jar/tuples-hybrid/java/org/mulgara/store/xa/CacheLine.java
   trunk/src/jar/tuples-hybrid/java/org/mulgara/store/xa/HybridTuples.java
   trunk/src/jar/tuples/java/org/mulgara/store/tuples/LiteralTuples.java
   trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java
   trunk/src/jar/tuples/java/org/mulgara/store/tuples/UnorderedProjection.java
   trunk/src/jar/util-xa/java/org/mulgara/store/xa/AVLNode.java
   trunk/src/jar/util-xa/java/org/mulgara/store/xa/FreeList.java
   trunk/src/jar/util-xa/java/org/mulgara/store/xa/ManagedBlockFile.java
   trunk/src/jar/util/java/org/mulgara/util/Bootstrap.java
Log:
Removed all references to 'new Throwable', replacing with StackTrace where appropriate, or an appropriate exception type otherwise.

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -42,6 +42,7 @@
 import org.mulgara.store.tuples.AbstractTuples;
 import org.mulgara.store.tuples.Tuples;
 import org.mulgara.store.tuples.TuplesOperations;
+import org.mulgara.util.StackTrace;
 
 /**
  * Wrapper around a partially-evaluated {@link Tuples} instance, evaluating
@@ -229,7 +230,7 @@
 
   public void close() throws TuplesException {
     if (logger.isDebugEnabled()) {
-      logger.debug("closing AppendAggregateTuples " + hashCode(), new Throwable());
+      logger.debug("closing AppendAggregateTuples " + hashCode() + "\n" + new StackTrace());
     }
     for (Query query : queryList) {
       if (logger.isDebugEnabled()) {

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/ContentHandlerManagerImpl.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/ContentHandlerManagerImpl.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/ContentHandlerManagerImpl.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -28,11 +28,8 @@
 package org.mulgara.resolver;
 
 // Java 2 standard packages
-import java.beans.Beans;
-import java.io.IOException;
 import java.lang.reflect.*;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 // Third party packages
@@ -45,11 +42,11 @@
 import org.mulgara.content.ContentHandlerException;
 import org.mulgara.content.ContentHandlerManager;
 import org.mulgara.content.ContentLoader;
-import org.mulgara.content.CorruptContentException;
 import org.mulgara.content.NotModifiedException;
 import org.mulgara.query.QueryException;
 import org.mulgara.resolver.spi.ResolverSession;
 import org.mulgara.resolver.spi.Statements;
+import org.mulgara.util.StackTrace;
 
 /**
  *  Mediates access to ContentHandlers
@@ -71,8 +68,8 @@
     Logger.getLogger(ContentHandlerManagerImpl.class.getName());
 
 
-  protected List contentHandlerList;
-  protected List contentLoaderList;
+  protected List<ContentHandler> contentHandlerList;
+  protected List<ContentLoader> contentLoaderList;
   protected ContentHandler defaultHandler;
 
   /**
@@ -83,8 +80,8 @@
   ContentHandlerManagerImpl(ContentHandler defaultContentHandler)
     throws ContentHandlerException
   {
-    contentHandlerList  = new ArrayList();
-    contentLoaderList   = new ArrayList();
+    contentHandlerList  = new ArrayList<ContentHandler>();
+    contentLoaderList   = new ArrayList<ContentLoader>();
     this.defaultHandler = defaultContentHandler;
 
     contentHandlerList.add(defaultContentHandler);
@@ -106,12 +103,10 @@
       throw new IllegalArgumentException("Content is null");
     }
 
-    Iterator i = contentHandlerList.iterator();
-    while (i.hasNext()) {
-      ContentHandler contentHandler = (ContentHandler)i.next();
+    for (ContentHandler contentHandler: contentHandlerList) {
       if (contentHandler.canParse(content)) {
         if ( logger.isInfoEnabled()) {
-          logger.info("Determined " + contentHandler.getClass() + " can parse content", new Throwable());
+          logger.info("Determined " + contentHandler.getClass() + " can parse content\n" + new StackTrace());
         }
         return contentHandler;
       }
@@ -166,7 +161,7 @@
       throw new IllegalArgumentException("Null \"className\" parameter");
     }
 
-    Class contentHandlerClass;
+    Class<?> contentHandlerClass;
     try {
       contentHandlerClass = Class.forName(className);
     } catch (ClassNotFoundException e) {
@@ -192,7 +187,7 @@
       contentHandlerList.add(handler);
 
       if (handler instanceof ContentLoader) {
-        contentLoaderList.add(handler);
+        contentLoaderList.add((ContentLoader)handler);
       }
     } catch (IllegalAccessException e) {
       logger.warn("Error generating content handler", e);
@@ -224,15 +219,9 @@
   /**
    * @return head(filter(\x:x.canLoad(uri), contentLoaders)) or null if filter is empty.
    */
-  public ContentLoader getContentLoader(Content content)
-    throws ContentHandlerException, NotModifiedException
-  {
-    Iterator i = contentLoaderList.iterator();
-    while (i.hasNext()) {
-      ContentLoader loader = (ContentLoader)i.next();
-      if (loader.canParse(content)) {
-        return loader;
-      }
+  public ContentLoader getContentLoader(Content content) throws ContentHandlerException, NotModifiedException {
+    for (ContentLoader loader: contentLoaderList) {
+      if (loader.canParse(content)) return loader;
     }
 
     return null;

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/LocalQueryResolver.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/LocalQueryResolver.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/LocalQueryResolver.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -64,6 +64,7 @@
 import org.mulgara.store.tuples.RestrictPredicateFactory;
 import org.mulgara.store.tuples.Tuples;
 import org.mulgara.store.tuples.TuplesOperations;
+import org.mulgara.util.StackTrace;
 
 /**
  * Localized version of a global {@link Query}.
@@ -262,7 +263,7 @@
       }
 
       if (logger.isDebugEnabled()) {
-        logger.debug("Stacktrace: ", new Throwable());
+        logger.debug(new StackTrace().toString());
       }
 
       Tuples result = ConstraintOperations.resolveConstraintExpression(this,

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -93,6 +93,17 @@
   public void reference() throws MulgaraTransactionException {}  
   public void dereference() throws MulgaraTransactionException {}
 
+  /**
+   * Calls through to {@link #abortTransaction(String,Throwable)} passing the message in
+   * the cause as the message for the transaction abort.
+   * @param cause The state triggering the abort.
+   * @return The exception for aborting.
+   * @throws MulgaraTransactionException Indicated failure to cleanly abort.
+   */
+  public MulgaraTransactionException abortTransaction(Throwable cause) throws MulgaraTransactionException {
+    return abortTransaction(cause.getMessage(), cause);
+  }
+
   public MulgaraTransactionException abortTransaction(String errorMessage, Throwable cause)
       throws MulgaraTransactionException {
     report("abortTransaction");

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransactionFactory.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransactionFactory.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransactionFactory.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -21,19 +21,14 @@
 // Java2 packages
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-// Third party packages
-import org.apache.log4j.Logger;
-
 // Local packages
 import org.mulgara.query.MulgaraTransactionException;
 import org.mulgara.query.QueryException;
-import org.mulgara.transaction.TransactionManagerFactory;
 import org.mulgara.util.Assoc1toNMap;
 
 /**
@@ -233,7 +228,7 @@
     acquireMutex();
     try {
       if (writeTransaction != null) {
-        writeTransaction.abortTransaction("Explicit abort requested by write-lock manager", new Throwable());
+        writeTransaction.abortTransaction(new MulgaraTransactionException("Explicit abort requested by write-lock manager"));
         writeTransaction = null;
       }
     } finally {

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransaction.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransaction.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransaction.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -23,10 +23,7 @@
 import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.locks.ReentrantLock;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
 import javax.transaction.Transaction;
-import javax.transaction.xa.XAResource;
 
 // Third party packages
 import org.apache.log4j.Logger;
@@ -34,11 +31,10 @@
 // Local packages
 import org.mulgara.resolver.spi.DatabaseMetadata;
 import org.mulgara.resolver.spi.EnlistableResource;
-import org.mulgara.resolver.spi.ResolverSessionFactory;
+import org.mulgara.util.StackTrace;
 
 import org.mulgara.query.MulgaraTransactionException;
 import org.mulgara.query.TuplesException;
-import org.mulgara.query.QueryException;
 
 /**
  * Responsible for the javax.transaction.Transaction object.
@@ -455,6 +451,7 @@
    * from abortTransaction().
    * Post-condition: The transaction is terminated and cleaned up.
    */
+  @SuppressWarnings("finally")
   MulgaraTransactionException implicitRollback(Throwable cause) throws MulgaraTransactionException {
     try {
       report("Implicit Rollback triggered");
@@ -511,6 +508,17 @@
   }
 
   /**
+   * Calls through to {@link #abortTransaction(String,Throwable)} passing the message in
+   * the cause as the message for the transaction abort.
+   * @param cause The state triggering the abort.
+   * @return The exception for aborting.
+   * @throws MulgaraTransactionException Indicated failure to cleanly abort.
+   */
+  public MulgaraTransactionException abortTransaction(Throwable cause) throws MulgaraTransactionException {
+    return abortTransaction(cause.getMessage(), cause);
+  }
+
+  /**
    * Forces the transaction to be abandoned, including bypassing JTA to directly
    * rollback/abort the underlying store-phases if required.
    * Heavilly nested try{}finally{} should guarentee that even JVM errors should
@@ -705,7 +713,7 @@
     if (state != State.FINISHED && state != State.FAILED) {
       errorReport("Finalizing incomplete transaction - aborting...", null);
       try {
-        abortTransaction("Transaction finalized while still valid", new Throwable());
+        abortTransaction(new MulgaraTransactionException("Transaction finalized while still valid"));
       } catch (Throwable th) {
         errorReport("Attempt to abort transaction from finalize failed", th);
       }
@@ -735,7 +743,12 @@
   }
 
   private void errorReport(String desc, Throwable cause) {
-    logger.error(desc + ": " + System.identityHashCode(this) + ", state=" + state +
-        ", inuse=" + inuse + ", using=" + using, cause != null ? cause : new Throwable());
+    if (cause != null) {
+      logger.error(desc + ": " + System.identityHashCode(this) + ", state=" + state +
+          ", inuse=" + inuse + ", using=" + using, cause);
+    } else {
+      logger.error(desc + ": " + System.identityHashCode(this) + ", state=" + state +
+          ", inuse=" + inuse + ", using=" + using + "\n" + new StackTrace());
+    }
   }
 }

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransactionFactory.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransactionFactory.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraInternalTransactionFactory.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -24,15 +24,11 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAResource;
 
 // Third party packages
 import org.apache.log4j.Logger;
@@ -41,6 +37,7 @@
 import org.mulgara.query.MulgaraTransactionException;
 import org.mulgara.transaction.TransactionManagerFactory;
 import org.mulgara.util.Assoc1toNMap;
+import org.mulgara.util.StackTrace;
 
 /**
  * Implements the internal transaction controls offered by Session.
@@ -255,7 +252,7 @@
           } else {
             // AutoCommit off -> off === no-op. Log info.
             if (logger.isInfoEnabled()) {
-              logger.info("Attempt to set autocommit false twice", new Throwable());
+              logger.info("Attempt to set autocommit false twice\n" + new StackTrace());
             }
           }
         }
@@ -413,7 +410,7 @@
     acquireMutex();
     try {
       if (writeTransaction != null) {
-        writeTransaction.abortTransaction("Explicit abort requested by write-lock manager", new Throwable());
+        writeTransaction.abortTransaction(new MulgaraTransactionException("Explicit abort requested by write-lock manager"));
         writeTransaction = null;
       }
     } finally {

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -54,6 +54,12 @@
   void dereference() throws MulgaraTransactionException;
 
   /**
+   * Calls through to {@link #abortTransaction(String, Throwable)} to force the transaction
+   * to be abandoned, using the same message as is present in the cause.
+   */
+  MulgaraTransactionException abortTransaction(Throwable cause) throws MulgaraTransactionException;
+
+  /**
    * Forces the transaction to be abandoned, including bypassing JTA to directly
    * rollback/abort the underlying store-phases if required.
    * This this transaction is externally managed this amounts to a heuristic

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -31,6 +31,7 @@
 // Local packages
 import org.mulgara.query.MulgaraTransactionException;
 import org.mulgara.transaction.TransactionManagerFactory;
+import org.mulgara.util.StackTrace;
 
 /**
  * Manages the Write-Lock.
@@ -116,7 +117,7 @@
       }
 
       if (logger.isDebugEnabled()) {
-        logger.debug("Obtaining write lock", new Throwable());
+        logger.debug("Obtaining write lock\n" + new StackTrace());
       }
       sessionHoldingWriteLock = session;
     } finally {
@@ -144,7 +145,7 @@
         throw new MulgaraTransactionException("Attempted to release write lock being held by another session");
       }
       if (logger.isDebugEnabled()) {
-        logger.debug("Releasing writelock", new Throwable());
+        logger.debug("Releasing writelock\n" + new StackTrace());
       }
       sessionHoldingWriteLock = null;
       writeLockCondition.signal();

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraXAResourceContext.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraXAResourceContext.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraXAResourceContext.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -230,7 +230,7 @@
         try {
           if (!xa.isHeuristicallyRollbacked()) {
             try {
-              xa.abortTransaction("External XA Manager specified 'forget'", new Throwable());
+              xa.abortTransaction(new MulgaraTransactionException("External XA Manager specified 'forget'"));
             } catch (MulgaraTransactionException em) {
               logger.error("Failed to abort transaction in forget", em);
               throw new XAException(XAException.XAER_RMERR);

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/StringPoolSession.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/StringPoolSession.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/StringPoolSession.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -54,6 +54,7 @@
 import org.mulgara.store.xa.XANodePool;
 import org.mulgara.store.xa.XAResolverSession;
 import org.mulgara.store.xa.XAStringPool;
+import org.mulgara.util.StackTrace;
 
 /**
  * A database session.
@@ -132,7 +133,7 @@
   ) {
 
     if (logger.isDebugEnabled()) {
-      logger.debug("Constructing StringPoolSession " + System.identityHashCode(this), new Throwable());
+      logger.debug("Constructing StringPoolSession " + System.identityHashCode(this) + "\n" + new StackTrace());
     }
 
     assert databaseURI.getFragment() == null;

Modified: trunk/src/jar/resolver-relational/java/org/mulgara/resolver/relational/LiteralDesc.java
===================================================================
--- trunk/src/jar/resolver-relational/java/org/mulgara/resolver/relational/LiteralDesc.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver-relational/java/org/mulgara/resolver/relational/LiteralDesc.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -51,24 +51,22 @@
 import org.apache.log4j.Logger;
 
 import org.jrdf.graph.Node;
-import org.jrdf.graph.URIReference;
-import org.jrdf.graph.Literal;
 
 import org.mulgara.query.Variable;
 import org.mulgara.query.rdf.URIReferenceImpl;
 import org.mulgara.query.rdf.LiteralImpl;
 import org.mulgara.query.TuplesException;
 import org.mulgara.resolver.relational.d2rq.D2RQDefn;
+import org.mulgara.util.StackTrace;
 
 public class LiteralDesc extends VariableDesc {
   private static Logger logger = Logger.getLogger(LiteralDesc.class);
 
-  private final String column = "_";
   private int index = -1;
   // p used for debugging purposes.
   private Variable p;
 
-  private Throwable t;
+  private StackTrace t;
 
   public LiteralDesc(D2RQDefn defn, Variable p) {
     super(defn);
@@ -115,8 +113,8 @@
     }
     
     if (this.index != -1 && this.index != index) {
-      logger.warn("Reassigning index will fail, was assigned: ", this.t);
-      logger.warn("Reassigning index will fail, now assigned: ", new Throwable());
+      logger.warn("Reassigning index will fail, was assigned:\n" + this.t);
+      logger.warn("Reassigning index will fail, now assigned:\n" + new StackTrace());
       throw new IllegalArgumentException("Index assigned multiple values in union.  Non-union compatible selects formed. Old index = " + this.index + ", New index = " + index + ", p=" + p);
     }
 
@@ -124,7 +122,7 @@
       logger.debug("Assigning index to LiteralDesc: " + System.identityHashCode(this) + "=" + index);
     }
     this.index = index;
-    this.t = new Throwable();
+    this.t = new StackTrace();
   }
 
   public String toString() {

Modified: trunk/src/jar/resolver-store/java/org/mulgara/store/statement/xa/TripleAVLFile.java
===================================================================
--- trunk/src/jar/resolver-store/java/org/mulgara/store/statement/xa/TripleAVLFile.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/resolver-store/java/org/mulgara/store/statement/xa/TripleAVLFile.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -28,7 +28,6 @@
 
 // Java 2 standard packages
 import java.io.*;
-import java.nio.*;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.*;
@@ -41,12 +40,11 @@
 import org.mulgara.query.Cursor;
 import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
-import org.mulgara.store.*;
 import org.mulgara.store.statement.*;
-import org.mulgara.store.statement.xa.*;
 import org.mulgara.store.tuples.*;
 import org.mulgara.store.xa.*;
 import org.mulgara.util.Constants;
+import org.mulgara.util.StackTrace;
 
 /**
  * @created 2001-10-13
@@ -1666,8 +1664,9 @@
     private final class TuplesImpl implements StoreTuples {
 
       // keep a stack trace of the instantiation of this object
-      private Throwable stack = logger.isDebugEnabled() ? new Throwable() : null;
-      private List objectIds = new ArrayList();
+      @SuppressWarnings("unused")
+      private StackTrace stack = logger.isDebugEnabled() ? new StackTrace() : null;
+      private List<Integer> objectIds = new ArrayList<Integer>();
 
       private long[] startTriple;
 
@@ -1683,6 +1682,7 @@
 
       private boolean nrTriplesValid = false;
 
+      @SuppressWarnings("unused")
       private int prefixLength;
 
       private int[] columnMap;
@@ -2070,8 +2070,8 @@
 
           copy.variables = getVariables();
 
-          copy.stack = logger.isDebugEnabled() ? new Throwable() : null;
-          copy.objectIds = new ArrayList(objectIds);
+          copy.stack = logger.isDebugEnabled() ? new StackTrace() : null;
+          copy.objectIds = new ArrayList<Integer>(objectIds);
           copy.objectIds.add(new Integer(System.identityHashCode(this)));
 
           return copy;
@@ -2108,7 +2108,7 @@
       public void finalize() {
         if (logger.isDebugEnabled()) {
           if (stack != null) {
-            logger.debug("TuplesImpl not closed (" + System.identityHashCode(this) + ")", stack);
+            logger.debug("TuplesImpl not closed (" + System.identityHashCode(this) + ")\n" + stack);
             logger.debug("----Provenance : " + objectIds);
           }
         }

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteAnswerWrapperAnswer.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteAnswerWrapperAnswer.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteAnswerWrapperAnswer.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -28,10 +28,7 @@
 package org.mulgara.server.rmi;
 
 // Java 2 standard packages
-import java.io.Serializable;
 import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.Hashtable;
 
 // Third party packages
 import org.apache.log4j.*;
@@ -41,6 +38,7 @@
 import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
 import org.mulgara.server.rmi.AnswerPage;
+import org.mulgara.util.StackTrace;
 
 /**
  * Wrap a {@link RemoteAnswer} to make it into an {@link Answer}.
@@ -103,7 +101,7 @@
   /**
    * Keeps the stack trace of where the answer was originally closed.
    */
-  private Throwable closed;
+  private StackTrace closed;
 
   //
   // Constructor
@@ -220,7 +218,7 @@
         // make onFirstPage false if the page is invalid
         onFirstPage = (currentPage != null);
         // Abandon the last prefetched page, and start a new prefetch thread
-        prefetchThread = new PrefetchThread(new Throwable());
+        prefetchThread = new PrefetchThread(new StackTrace());
       }
     } catch (RemoteException er) {
       logger.warn("RemoteException thrown in beforeFirst", er);
@@ -252,9 +250,9 @@
 
     if (closed != null) {
       logger.warn("Was already closed at: " + closed);
-      throw new TuplesException("Attempting to close answer twice.", new Throwable());
+      throw new TuplesException("Attempting to close answer twice.\n" + new StackTrace());
     }
-    closed = new Throwable();
+    closed = new StackTrace();
 
     // no more references left, close the remote object
     try {
@@ -459,7 +457,7 @@
       page = remoteAnswer.nextPage();
     }
     // launch new prefetch thread
-    prefetchThread = new PrefetchThread(new Throwable());
+    prefetchThread = new PrefetchThread(new StackTrace());
 
     return page;
   }
@@ -512,12 +510,12 @@
     private boolean finished;
 
     /** Stack Trace for client-side invokation */
-    private Throwable caller;
+    private StackTrace caller;
 
     /**
      * Main constructor.  Starts the current thread.
      */
-    public PrefetchThread(Throwable caller) {
+    public PrefetchThread(StackTrace caller) {
 
       this.caller = caller;
       page = null;
@@ -536,8 +534,8 @@
         // finished will never be set
 
         // log exception and include the stack trace that created this Thread.
-        caller.initCause(e);
-        logger.warn("Exception thrown in prefetchThread.", caller);
+        logger.warn("Exception thrown in prefetchThread.\n" + caller);
+        logger.warn("Caused by", e);
       }
     }
 

Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/LiteralTuples.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/LiteralTuples.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/LiteralTuples.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -34,8 +34,6 @@
 import org.apache.log4j.*;
 
 // Locally written packages
-import org.mulgara.query.Constraint;
-import org.mulgara.query.Cursor;
 import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
 
@@ -63,21 +61,18 @@
   /**
    * Logger.
    */
-  private static Logger logger =
-      Logger.getLogger(LiteralTuples.class.getName());
+  @SuppressWarnings("unused")
+  private static Logger logger = Logger.getLogger(LiteralTuples.class.getName());
 
-  private int numberOfVariables;
+  private List<long[]> tuples;
 
-  private List tuples;
-  private Iterator tupleIterator;
-
   private int currentTuple;
   private boolean[] columnContainsUnbound;
   private long[] prefix;
   private boolean sorted;
 
   public LiteralTuples(String[] variableNames, boolean sorted) {
-    List vars = new ArrayList();
+    List<Variable> vars = new ArrayList<Variable>();
     for (int i = 0; i < variableNames.length; i++) {
       Variable v = new Variable(variableNames[i]);
       assert!vars.contains(v);
@@ -102,9 +97,8 @@
   }
 
   private void init(Variable[] variables, boolean sorted) {
-    tuples = new ArrayList();
+    tuples = new ArrayList<long[]>();
     currentTuple = 0;
-    tupleIterator = null;
     setVariables(Arrays.asList(variables));
     columnContainsUnbound = new boolean[variables.length];
     Arrays.fill(columnContainsUnbound, false);
@@ -130,9 +124,6 @@
 
 
   public void appendTuple(long[] tuple) throws TuplesException {
-    if (tupleIterator != null) {
-      throw new TuplesException("Can't append row after beforeFirst is called");
-    }
     if (tuple.length != getNumberOfVariables()) {
       throw new TuplesException("Arity of rows dosn't match arity of tuples");
     }
@@ -152,7 +143,7 @@
       throw new TuplesException("getColumnValue called before beforeFirst()");
     }
 
-    return ((long[]) tuples.get(currentTuple))[column];
+    return tuples.get(currentTuple)[column];
   }
 
   public long getRowCount() throws TuplesException {
@@ -191,11 +182,10 @@
     beforeFirst(Tuples.NO_PREFIX, 0);
   }
 
-  public void beforeFirst(long[] prefix,
-      int suffixTruncation) throws TuplesException {
-//    Throwable th = new Throwable();
+  public void beforeFirst(long[] prefix, int suffixTruncation) throws TuplesException {
+//    StackTrace th = new StackTrace();
 //    th.fillInStackTrace();
-//    logger.debug("LiteralTuples[" + Arrays.asList(getVariables()) + "].beforeFirst called with prefix " + toString(prefix), th);
+//    logger.debug("LiteralTuples[" + Arrays.asList(getVariables()) + "].beforeFirst called with prefix " + toString(prefix) + "\n" + th);
 //    logger.debug("LiteralTuples[" + Arrays.asList(getVariables()) + "].beforeFirst called with prefix " + toString(prefix));
 
     assert suffixTruncation == 0;
@@ -204,7 +194,7 @@
 
     search:for (currentTuple = 0; currentTuple < tuples.size(); currentTuple++) {
       for (int j = 0; j < prefix.length; j++) {
-        if (((long[]) tuples.get(currentTuple))[j] != prefix[j]) {
+        if (tuples.get(currentTuple)[j] != prefix[j]) {
           continue search;
         }
       }
@@ -217,7 +207,7 @@
   public boolean next() throws TuplesException {
     if (++currentTuple < tuples.size()) {
       for (int j = 0; j < prefix.length; j++) {
-        if (((long[]) tuples.get(currentTuple))[j] != prefix[j]) {
+        if (tuples.get(currentTuple)[j] != prefix[j]) {
           return false;
         }
       }

Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/TuplesOperations.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -41,6 +41,7 @@
 import org.mulgara.query.filter.Filter;
 import org.mulgara.query.filter.value.Bool;
 import org.mulgara.resolver.spi.*;
+import org.mulgara.util.StackTrace;
 
 /**
  * TQL answer. An answer is a set of solutions, where a solution is a mapping of
@@ -506,8 +507,8 @@
             // and then next should return true too.
             logger.error(
                 "No rows but getRowCardinality returned Cursor.ONE: (class=" +
-                tuples.getClass().getName() + ") " + tuples.toString(),
-                new Throwable()
+                tuples.getClass().getName() + ") " + tuples.toString() + "\n" +
+                new StackTrace()
             );
             throw new AssertionError(
                 "No rows but getRowCardinality returned Cursor.ONE"

Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/UnorderedProjection.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/UnorderedProjection.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/UnorderedProjection.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -37,6 +37,7 @@
 import org.mulgara.query.Cursor;
 import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
+import org.mulgara.util.StackTrace;
 
 /**
  * Rearrange columns, discarding any existing sort order. If columns need to be
@@ -157,7 +158,7 @@
 
     if (columnMapping[column] == ABSENT_COLUMN) {
       if (logger.isInfoEnabled()) {
-        logger.info(getVariables()[column] + " is never bound", new Throwable());
+        logger.info(getVariables()[column] + " is never bound\n " + new StackTrace());
       }
       return Tuples.UNBOUND;
     }
@@ -201,7 +202,7 @@
     if (columnMapping[column] == ABSENT_COLUMN) {
 
       if (logger.isInfoEnabled()) {
-        logger.info(getVariables()[column] + " is never bound", new Throwable());
+        logger.info(getVariables()[column] + " is never bound\n" + new StackTrace());
       }
 
       return true;

Modified: trunk/src/jar/tuples-hybrid/java/org/mulgara/store/xa/CacheLine.java
===================================================================
--- trunk/src/jar/tuples-hybrid/java/org/mulgara/store/xa/CacheLine.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/tuples-hybrid/java/org/mulgara/store/xa/CacheLine.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -3,6 +3,7 @@
 import org.apache.log4j.Logger;
 
 import org.mulgara.query.TuplesException;
+import org.mulgara.util.StackTrace;
 
 /**
  *
@@ -29,7 +30,7 @@
 
   protected final int segmentSize;
 
-  protected Throwable closed;
+  protected StackTrace closed;
   protected int firstCloser;
 
 
@@ -69,12 +70,12 @@
 
   public void close(int closer) throws TuplesException {
     if (closed != null) {
-      logger.error("Attempt to close CacheLine twice by " + closer, new Throwable());
-      logger.error("    First closed at ", closed);
+      logger.error("Attempt to close CacheLine twice by " + closer + new StackTrace());
+      logger.error("    First closed at " + closed);
       logger.error("    First closed by " + firstCloser);
       throw new TuplesException("Attempt to close CacheLine twice");
     }
-    closed = new Throwable();
+    closed = new StackTrace();
     firstCloser = closer;
   }
 

Modified: trunk/src/jar/tuples-hybrid/java/org/mulgara/store/xa/HybridTuples.java
===================================================================
--- trunk/src/jar/tuples-hybrid/java/org/mulgara/store/xa/HybridTuples.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/tuples-hybrid/java/org/mulgara/store/xa/HybridTuples.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -51,6 +51,7 @@
 import org.mulgara.store.tuples.TuplesOperations;
 import org.mulgara.store.xa.AbstractBlockFile;
 import org.mulgara.store.xa.BlockFile;
+import org.mulgara.util.StackTrace;
 import org.mulgara.util.TempDir;
 
 /**
@@ -113,8 +114,8 @@
 
   // Debugging.
   private final static Logger logger = Logger.getLogger(HybridTuples.class);
-  private Throwable allocated;
-  private Throwable closed;
+  private StackTrace allocated;
+  private StackTrace closed;
 
 
 
@@ -169,7 +170,7 @@
     } else {
       this.tuples = TuplesOperations.empty();
     }
-    this.allocated = new Throwable();
+    this.allocated = new StackTrace();
   }
 
 
@@ -278,7 +279,7 @@
       if (blockFile != null) {
         blockFileRefCount.refCount++;
       }
-      copy.allocated = new Throwable();
+      copy.allocated = new StackTrace();
       copy.tuples = (Tuples)tuples.clone();
 
       return copy;
@@ -306,13 +307,12 @@
    */
   public void close() throws TuplesException {
     if (closed != null) {
-      logger.error("Attempt to close HybridTuples twice; first closed", closed);
-      logger.error("Attempt to close HybridTuples twice; second closed",
-          new Throwable());
-      logger.error("    allocated", allocated);
+      logger.error("Attempt to close HybridTuples twice; first closed: " + closed);
+      logger.error("Attempt to close HybridTuples twice; second closed: " + new StackTrace());
+      logger.error("    allocated: " + allocated);
       throw new TuplesException("Attempted to close HybribTuples more than once");
     }
-    closed = new Throwable();
+    closed = new StackTrace();
 
     for (int i = 0; i < heapCache.length; i++) {
       heapCache[i].close(System.identityHashCode(this));

Modified: trunk/src/jar/util/java/org/mulgara/util/Bootstrap.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Bootstrap.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/util/java/org/mulgara/util/Bootstrap.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -139,8 +139,7 @@
       addToSystemClasspath(jarURLs);
     }
     catch (Exception e) {
-      new Throwable("Failed to add Embedded Jars to the System Classpath",
-          e).printStackTrace();
+      new Exception("Failed to add Embedded Jars to the System Classpath", e).printStackTrace();
     }
 
     // set the list of URLs

Added: trunk/src/jar/util/java/org/mulgara/util/StackTrace.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/StackTrace.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/StackTrace.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -0,0 +1,94 @@
+/*
+ * 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.opensource.org/licenses/osl-3.0.txt
+ *
+ * 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.
+ */
+
+package org.mulgara.util;
+
+/**
+ * Creates a stack trace for the current position at creation, or from a provided
+ * Throwable object.
+ *
+ * @created Jul 17, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class StackTrace {
+
+  /** The string output for this stack. */
+  private String fullTrace;
+
+  /** The Throwable containing all the information for this stack. */
+  private final Throwable throwable;
+
+  /**
+   * The offset for accessing the stack array. Either 0 or 1.
+   * 1 is used to skip the frame for the constructor of this object.
+   */
+  private final int offset;
+
+  /**
+   * Build a new stack around a provided Throwable.
+   * @param throwable The throwable object with the stack to encode.
+   */
+  public StackTrace(Throwable throwable) {
+    this.throwable = throwable;
+    offset = 0;
+    fullTrace = getStringTrace();
+  }
+
+  /**
+   * Build a new stack based on the current position.
+   */
+  public StackTrace() {
+    this.throwable = new Throwable();
+    offset = 1;
+    fullTrace = getStringTrace();
+  }
+
+  /**
+   * Output this stack as a string.
+   */
+  public String toString() {
+    return fullTrace;
+  }
+
+  /**
+   * Get a stack frame for a given level from this stack. 
+   * @param level The level of the frame to retrieve. 0 <= level < {@link #getStackDepth()}
+   * @return A StackTraceElement encoding the frame for the given level.
+   */
+  public StackTraceElement getFrame(int level) {
+    return throwable.getStackTrace()[level + offset];
+  }
+
+  /**
+   * The maximum depth of this stack.
+   * @return The number of the deepest frame + 1.
+   */
+  public int getStackDepth() {
+    return throwable.getStackTrace().length - offset;
+  }
+
+  /**
+   * Gets the string for this stack trace.
+   * @return A string encoding of the stack trace.
+   */
+  private String getStringTrace() {
+    StringBuilder b = new StringBuilder("STACK TRACE:\n");
+    StackTraceElement[] stack = throwable.getStackTrace();
+    for (int level = offset; level < stack.length; level ++) {
+      b.append("  ").append(stack[level].toString()).append("\n");
+    }
+    return b.toString();
+  }
+
+}

Modified: trunk/src/jar/util-xa/java/org/mulgara/store/xa/AVLNode.java
===================================================================
--- trunk/src/jar/util-xa/java/org/mulgara/store/xa/AVLNode.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/util-xa/java/org/mulgara/store/xa/AVLNode.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -119,7 +119,7 @@
   /** Whether or not this node has been modified. */
   private boolean dirty;
 
-  //  private Throwable trace;
+  //  private StackTrace trace;
 
   /** The number of references to this node. */
   private int refCount;
@@ -1135,7 +1135,7 @@
     this.leftChildNode = null;
     this.rightChildNode = null;
 
-    //X    trace = new Throwable();
+    //X    trace = new StackTrace();
     refCount = 1;
     writable = false;
     dirty = false;
@@ -1161,7 +1161,7 @@
     this.leftChildNode = null;
     this.rightChildNode = null;
 
-    //X    trace = new Throwable();
+    //X    trace = new StackTrace();
     refCount = 1;
     writable = true;
     dirty = true;
@@ -1519,7 +1519,7 @@
 
   //X  protected void finalize() {
   //X    if (trace != null) logger.warn(
-  //X      "Unpooled AVLNode.  refCount=" + refCount + ", dirty=" + dirty, trace
+  //X      "Unpooled AVLNode.  refCount=" + refCount + ", dirty=" + dirty + "\n " + trace
   //X    );
   //X  }
 

Modified: trunk/src/jar/util-xa/java/org/mulgara/store/xa/FreeList.java
===================================================================
--- trunk/src/jar/util-xa/java/org/mulgara/store/xa/FreeList.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/util-xa/java/org/mulgara/store/xa/FreeList.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -36,6 +36,7 @@
 // Third party packages
 import org.apache.log4j.Logger;
 import org.mulgara.util.IntFile;
+import org.mulgara.util.StackTrace;
 
 /**
  * A fifo of integer items. A list of "phases" is maintained where each phase
@@ -946,7 +947,7 @@
 
 
     /** Holds a stack trace of construction so we can tell where problems occurred. */
-    private Throwable stack = null;
+    private StackTrace stack = null;
 
 
     /**
@@ -973,7 +974,7 @@
       }
       // record the stack if info is enabled
       if (logger.isInfoEnabled()) {
-        stack = new Throwable();
+        stack = new StackTrace();
       }
     }
 
@@ -1019,7 +1020,7 @@
 
         // record the stack if info is enabled
         if (logger.isInfoEnabled()) {
-          stack = new Throwable();
+          stack = new StackTrace();
         }       
       }
     }
@@ -1225,7 +1226,7 @@
 
       if ( (token == null) && (refCount > 0)) {
         if (logger.isInfoEnabled()) {
-          logger.info("Lost phase token.", stack);
+          logger.info("Lost phase token.\n" + stack);
         }
         refCount = 0;
       }

Modified: trunk/src/jar/util-xa/java/org/mulgara/store/xa/ManagedBlockFile.java
===================================================================
--- trunk/src/jar/util-xa/java/org/mulgara/store/xa/ManagedBlockFile.java	2008-07-17 17:13:08 UTC (rev 1090)
+++ trunk/src/jar/util-xa/java/org/mulgara/store/xa/ManagedBlockFile.java	2008-07-17 21:56:54 UTC (rev 1091)
@@ -32,6 +32,7 @@
 
 // Third party packages
 import org.apache.log4j.Logger;
+import org.mulgara.util.StackTrace;
 
 /**
  * A class that implements efficient copy-on-write semantics for a BlockFile.
@@ -301,7 +302,7 @@
         if (logger.isInfoEnabled()) {
           logger.info("File " + file +
               " may not have been closed properly on shutdown.\n  nrBlocks=" + nrBlocks +
-              "  nrValidBlocks=" + nrValidBlocks, new Throwable());
+              "  nrValidBlocks=" + nrValidBlocks + "\n" + new StackTrace());
         }
         blockFile.setNrBlocks(nrValidBlocks);
       }




More information about the Mulgara-svn mailing list