[Mulgara-svn] r111 - trunk/src/jar/resolver/java/org/mulgara/resolver

andrae at mulgara.org andrae at mulgara.org
Wed Oct 25 08:19:21 UTC 2006


Author: andrae
Date: 2006-10-25 03:19:20 -0500 (Wed, 25 Oct 2006)
New Revision: 111

Added:
   trunk/src/jar/resolver/java/org/mulgara/resolver/AnswerOperation.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/AnswerOperationResult.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/ModelExistsOperation.java
Modified:
   trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
Log:
Migrates the implementation of modelExists into an Operation object.  Also
introduces two new classes required for the eventual migration to
TransactionalAnswer.



Copied: trunk/src/jar/resolver/java/org/mulgara/resolver/AnswerOperation.java (from rev 99, branches/xafix/src/jar/resolver/java/org/mulgara/resolver/AnswerOperation.java)
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/AnswerOperation.java	2006-10-11 12:35:42 UTC (rev 99)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/AnswerOperation.java	2006-10-25 08:19:20 UTC (rev 111)
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+public abstract class AnswerOperation {
+  // Should use enum here.
+  public static final int OBJECT = 1;
+  public static final int INT = 2;
+  public static final int LONG = 3;
+  public static final int BOOLEAN = 3;
+
+  protected int returnType;
+
+  protected Object object;
+  protected int integer;
+  protected long longint;
+  protected boolean bool;
+
+  public abstract void execute();
+
+  protected void returnObject(Object object) {
+    returnType = OBJECT;
+    this.object = object;
+  }
+
+  protected void returnInt(int integer) {
+    returnType = INT;
+    this.integer = integer;
+  }
+
+  protected void returnLong(long longint) {
+    returnType = LONG;
+    this.longint = longint;
+  }
+
+  protected void returnBoolean(boolean bool) {
+    returnType = BOOLEAN;
+    this.bool = bool;
+  }
+
+  public AnswerOperationResult getResult() {
+    return new AnswerOperationResult() {
+        public Object getObject() {
+          if (returnType != OBJECT) {
+            throw new IllegalStateException("Invalid return type accessed: " + returnType);
+          }
+          return object;
+        }
+
+        public int getInt() {
+          if (returnType != INT) {
+            throw new IllegalStateException("Invalid return type accessed: " + returnType);
+          }
+          return integer;
+        }
+
+        public long getLong() {
+          if (returnType != LONG) {
+            throw new IllegalStateException("Invalid return type accessed: " + returnType);
+          }
+          return longint;
+        }
+
+        public boolean getBoolean() {
+          if (returnType != BOOLEAN) {
+            throw new IllegalStateException("Invalid return type accessed: " + returnType);
+          }
+          return bool;
+        }
+    };
+  }
+}

Copied: trunk/src/jar/resolver/java/org/mulgara/resolver/AnswerOperationResult.java (from rev 99, branches/xafix/src/jar/resolver/java/org/mulgara/resolver/AnswerOperationResult.java)

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-24 07:47:11 UTC (rev 110)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-25 08:19:20 UTC (rev 111)
@@ -944,50 +944,11 @@
   }
 
   public boolean modelExists(URI modelURI) throws QueryException {
+    ModelExistsOperation operation = new ModelExistsOperation(modelURI);
 
-    // Attempt to create a read only transaction
-    try {
-      startTransactionalOperation(false);
-    }
-    catch (IllegalArgumentException iae) {
+    execute(operation, "Failed to determine model existence");
 
-      // If we're in a transaction then try to do it anyway.
-      try {
-        long model = systemResolver.lookupPersistent(new URIReferenceImpl(
-            modelURI));
-
-        return systemResolver.modelExists(model);
-      }
-      catch (ResolverException re) {
-        throw new QueryException("Failed to resolve URI: " + modelURI, re);
-      }
-      catch (LocalizeException le) {
-        // Return false - we failed to find the node.
-        return false;
-      }
-    }
-
-    // If we created a new transaction perform the same operation with
-    // try/catches for correct handling of exceptions.
-    try {
-      long model;
-
-      try {
-        model = systemResolver.lookupPersistent(new URIReferenceImpl(
-            modelURI));
-      }
-      catch (LocalizeException le) {
-        // Return false - we failed to find the node.
-        return false;
-      }
-      return systemResolver.modelExists(model);
-
-    } catch (Throwable e) {
-      rollbackTransactionalBlock(e);
-    } finally {
-      finishTransactionalOperation("Could not find model " + modelURI);
-    }
-    throw new QueryException("Illegal transactional state in session");
+    return operation.getResult();
   }
 
   /**

Copied: trunk/src/jar/resolver/java/org/mulgara/resolver/ModelExistsOperation.java (from rev 105, branches/xafix/src/jar/resolver/java/org/mulgara/resolver/ModelExistsOperation.java)
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/ModelExistsOperation.java	2006-10-17 12:10:50 UTC (rev 105)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/ModelExistsOperation.java	2006-10-25 08:19:20 UTC (rev 111)
@@ -0,0 +1,83 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * 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.
+ *
+ * The Original Code is the Kowari Metadata Store.
+ *
+ * The Initial Developer of the Original Code is Plugged In Software Pty
+ * Ltd (http://www.pisoftware.com, mailto:info at pisoftware.com). Portions
+ * created by Plugged In Software Pty Ltd are Copyright (C) 2001,2002
+ * Plugged In Software Pty Ltd. All Rights Reserved.
+ *
+ * Contributor(s): This file, excluding the two lines of the execute method 
+ *   is an original work developed by Netymon Pty Ltd.  Excluding these to
+ *   lines this file is:
+ *   Copyright (c) 2006 Netymon Pty Ltd.
+ *   All Rights Reserved.
+ *
+ * [NOTE: The text of this Exhibit A may differ slightly from the text
+ * of the notices in the Source Code files of the Original Code. You
+ * should use the text of this Exhibit A rather than the text found in the
+ * Original Code Source Code for Your Modifications.]
+ *
+ */
+
+package org.mulgara.resolver;
+
+// Java 2 standard packages
+import java.net.URI;
+
+// Third party packages
+import org.apache.log4j.Logger;
+
+// Local packages
+import org.mulgara.query.*;
+import org.mulgara.query.rdf.URIReferenceImpl;
+import org.mulgara.resolver.spi.*;
+import org.mulgara.server.Session;
+
+class ModelExistsOperation implements Operation
+{
+  /** Logger.  */
+  private static final Logger logger = Logger.getLogger(ModelExistsOperation.class.getName());
+
+  private URI modelURI = null;
+
+  private boolean result;
+
+
+  ModelExistsOperation(URI modelURI) {
+    this.modelURI = modelURI;
+  }
+
+  //
+  // Methods implementing Operation
+  //
+
+  public void execute(OperationContext       operationContext,
+                      SystemResolver         systemResolver,
+                      ResolverSessionFactory resolverSessionFactory,
+                      DatabaseMetadata       metadata) throws Exception
+  {
+    long model = systemResolver.lookupPersistent(new URIReferenceImpl(
+        modelURI));
+
+    result = systemResolver.modelExists(model);
+  }
+
+  public boolean isWriteOperation() {
+    return false;
+  }
+
+  
+  boolean getResult() {
+    return result;
+  }
+}




More information about the Mulgara-svn mailing list