[Mulgara-svn] r290 - in branches/mgr-58/src/jar: query/java/org/mulgara/query/rdf resolver/java/org/mulgara/resolver

andrae at mulgara.org andrae at mulgara.org
Wed Jul 4 08:18:53 UTC 2007


Author: andrae
Date: 2007-07-04 03:18:52 -0500 (Wed, 04 Jul 2007)
New Revision: 290

Modified:
   branches/mgr-58/src/jar/query/java/org/mulgara/query/rdf/Mulgara.java
   branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/BootstrapOperation.java
   branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/Database.java
   branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseMetadataImpl.java
Log:
Code to bootstrap the system model URI, and the server URI.
It isn't compiled, or tested, but I'm pretty sure I got everything.

Can't really test at all until I insert at least the create/resolve changes.



Modified: branches/mgr-58/src/jar/query/java/org/mulgara/query/rdf/Mulgara.java
===================================================================
--- branches/mgr-58/src/jar/query/java/org/mulgara/query/rdf/Mulgara.java	2007-06-23 01:42:28 UTC (rev 289)
+++ branches/mgr-58/src/jar/query/java/org/mulgara/query/rdf/Mulgara.java	2007-07-04 08:18:52 UTC (rev 290)
@@ -16,7 +16,8 @@
  * created by Plugged In Software Pty Ltd are Copyright (C) 2001,2002
  * Plugged In Software Pty Ltd. All Rights Reserved.
  *
- * Contributor(s): N/A.
+ * Contributor(s): 
+ *  Andrae Muys / Netymon Pty Ltd (andrae at netymon.com)
  *
  * [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
@@ -46,4 +47,5 @@
    * Mulgara RDF namespace.
    */
   public final static String NAMESPACE = "http://mulgara.org/mulgara#";
+  public final static String LOCAL_MODEL_NAMESPACE = "rdfdb://local/mulgara#";
 }

Modified: branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/BootstrapOperation.java
===================================================================
--- branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/BootstrapOperation.java	2007-06-23 01:42:28 UTC (rev 289)
+++ branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/BootstrapOperation.java	2007-07-04 08:18:52 UTC (rev 290)
@@ -1,3 +1,37 @@
+/*
+ * The contents of this file are originally derived from
+ * src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java from
+ * which it inherits this copyright notice.
+ *
+ * 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): 
+ *  Extraction modifications copyright Netymon Pty Ltd
+ *    Andrae Muys / Netymon Pty Ltd (andrae at netymon.com)
+ *  System Model Bootstrap code copyright Netymon Pty Ltd
+ *    Andrae Muys andrae at netymon.com
+ *
+ * [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
@@ -39,18 +73,26 @@
   public void execute(OperationContext       operationContext,
                       SystemResolver         systemResolver,
                       DatabaseMetadata       metadata) throws Exception {
-    // Find the local node identifying the model
-    long model = systemResolver.localizePersistent(
-        new URIReferenceImpl(databaseMetadata.getSystemModelURI()));
+
+    long bootstrapModel = systemResolver.localizePersistent(
+        new URIReferenceImpl(databaseMetadata.getBootstrapModelURI()));
     long rdfType = systemResolver.localizePersistent(
         new URIReferenceImpl(databaseMetadata.getRdfTypeURI()));
-    long modelType = systemResolver.localizePersistent(
+    long serverURIType = systemResolver.localizePersistent(
+        new URIReferenceImpl(databaseMetadata.getServerURIType()));
+
+    URI serverURI = retrieveOrCreateServerURI(systemResolver, bootstrapModel, rdfType, serverURIType, metadata);
+    databaseMetadata.setServerURI(serverURI); // Also sets the system-model-uri (appends a #)
+
+    long systemModel = systemResolver.localizePersistent(
+        new URIReferenceImpl(databaseMetadata.getSystemModelURI()));
+    long systemModelType = systemResolver.localizePersistent(
         new URIReferenceImpl(databaseMetadata.getSystemModelTypeURI()));
 
-    // Use the session to create the model
-    systemResolver.modifyModel(model, new SingletonStatements(model, rdfType,
-        modelType), true);
-    databaseMetadata.initializeSystemNodes(model, rdfType, modelType);
+    // Ensure the system model exists.
+    systemResolver.modifyModel(systemModel,
+        new SingletonStatements(systemModel, rdfType, systemModelType), true);
+    databaseMetadata.initializeSystemNodes(systemModel, rdfType, systemModelType);
 
     long preSubject = systemResolver.localizePersistent(
         new URIReferenceImpl(databaseMetadata.getPreallocationSubjectURI()));
@@ -59,17 +101,24 @@
     long preModel = systemResolver.localizePersistent(
         new URIReferenceImpl(databaseMetadata.getPreallocationModelURI()));
 
-    // Every node cached by DatabaseMetadata must be preallocated
+    // Every local node created in this function must be preallocated.
+    // For ease of checking, they are prealloc'd in the order they are created.
     systemResolver.modifyModel(preModel,
-        new SingletonStatements(preSubject, prePredicate, model),
+        new SingletonStatements(preSubject, prePredicate, bootstrapModel),
         true);
     systemResolver.modifyModel(preModel,
         new SingletonStatements(preSubject, prePredicate, rdfType),
         true);
     systemResolver.modifyModel(preModel,
-        new SingletonStatements(preSubject, prePredicate, modelType),
+        new SingletonStatements(preSubject, prePredicate, serverURIType),
         true);
     systemResolver.modifyModel(preModel,
+        new SingletonStatements(preSubject, prePredicate, systemModel),
+        true);
+    systemResolver.modifyModel(preModel,
+        new SingletonStatements(preSubject, prePredicate, systemModelType),
+        true);
+    systemResolver.modifyModel(preModel,
         new SingletonStatements(preSubject, prePredicate, preSubject),
         true);
     systemResolver.modifyModel(preModel,
@@ -81,7 +130,7 @@
 
     databaseMetadata.initializePreallocationNodes(preSubject, prePredicate, preModel);
 
-    result = model;
+    result = systemModel;
   }
 
   public boolean isWriteOperation()
@@ -92,4 +141,47 @@
   public long getResult() {
     return result;
   }
+
+  private URI retrieveOrCreateServerURI(SystemResolver systemResolver, long bootstrapModel,
+      long rdfType, long serverURIType, DatabaseMetadata metadata) throws TuplesException {
+    Tuples serverURIs = systemResolver.resolve(new ConstraintImpl(new Variable("ServerURI"),
+                                                                  new LocalNode(rdfType),
+                                                                  new LocalNode(serverURIType),
+                                                                  new LocalNode(bootstrapModel)));
+    serverURIs.beforeFirst();
+    while (serverURIs.next()) {
+      Node node = systemResolver.globalize(serverURIs.getColumnValue(0));
+      if (!(node instanceof URIReference)) {
+        logger.error("ServerURI found in Bootstrap Model not a URI: " + node);
+      } else {
+        URI serverURI = ((URIReference)node).getURI();
+        if (serverURIs.next()) {
+          logger.error("Multiple ServerURIs found in Bootstrap Model
+          do {
+            logger.error("Extra ServerURI found: " + serverURIs.getColumnValue(0));
+            logger.error("Extra ServerURI globalized: " + systemResolver.globalize(serverURIs.getColumnValue(0)));
+          } while (serverURIs.next());
+        }
+
+        return serverURI;
+      }
+    }
+
+    logger.warn("No valid ServerURI found in Bootstrap Model - creating new ServerURI");
+
+    UUID uuid = UUID.randomUUID();
+    // Note the '_' in the path is to remind us that the server-name is
+    // indicative only.  It is *not* a function of the database's current name,
+    // but captured from the server-name the *first* time an instance is used.
+    // It's use is to provide a convenient way for people to easily distinguish
+    // between serverURI's from different servers.
+    // This may be a mistake - if so it can be removed without harm as this is
+    // purely informative.
+    URI serverURI = new URI("rdfdb", uuid.toString(), "/_" + metadata.getServerName(), null);
+    long serverNode = resolver.localizePersistent(new URIReferenceImpl(serverURI));
+    systemResolver.modifyModel(bootstrapModel,
+        new SingletonStatements(serverNode, rdfType, serverURIType), true);
+
+    return serverURI;
+  }
 }

Modified: branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/Database.java
===================================================================
--- branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/Database.java	2007-06-23 01:42:28 UTC (rev 289)
+++ branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/Database.java	2007-07-04 08:18:52 UTC (rev 290)
@@ -676,8 +676,6 @@
       new DatabaseMetadataImpl(uri,
                                hostnameAliases,
                                securityDomainURI,
-                               systemModelURI,
-                               RDF.TYPE,
                                systemResolverFactory.getSystemModelTypeURI());
 
     DatabaseSession session = new DatabaseSession(

Modified: branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseMetadataImpl.java
===================================================================
--- branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseMetadataImpl.java	2007-06-23 01:42:28 UTC (rev 289)
+++ branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseMetadataImpl.java	2007-07-04 08:18:52 UTC (rev 290)
@@ -16,7 +16,9 @@
  * created by Plugged In Software Pty Ltd are Copyright (C) 2001,2002
  * Plugged In Software Pty Ltd. All Rights Reserved.
  *
- * Contributor(s): N/A.
+ * Contributor(s):
+ *  System Model Bootstrap code copyright Netymon Pty Ltd
+ *    Andrae Muys andrae at netymon.com
  *
  * [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
@@ -55,11 +57,16 @@
   private static final URI PREALLOCATED_SUBJECT_URI;
   private static final URI PREALLOCATED_PREDICATE_URI;
   private static final URI PREALLOCATED_MODEL_URI;
+  private static final URI BOOTSTRAP_MODEL_URI;
+  private static final URI SERVER_URI_TYPE;
+
   static {
     try {
      PREALLOCATED_SUBJECT_URI = new URI(Mulgara.NAMESPACE + "preallocatedNodes");
      PREALLOCATED_PREDICATE_URI = new URI(Mulgara.NAMESPACE + "preallocatedNode");
-     PREALLOCATED_MODEL_URI = new URI(Mulgara.NAMESPACE + "preallocatedNodeModel");
+     PREALLOCATED_MODEL_URI = new URI(Mulgara.LOCAL_MODEL_NAMESPACE + "preallocatedNodeModel");
+     BOOTSTRAP_MODEL_URI = new URI(Mulgara.LOCAL_MODEL_NAMESPACE + "bootstrapModel");
+     SERVER_URI_TYPE = new URI(Mulgara.NAMESPACE + "ServerURI");
     } catch (URISyntaxException eu) {
       throw new Error("Invalid URI Syntax", eu);
     }
@@ -71,7 +78,6 @@
   private URI uri;
   private URI securityDomainURI;
   private URI systemModelURI;
-  private URI rdfTypeURI;
   private URI systemModelTypeURI;
 
   /** The set of alternative hostnames for the current host. */
@@ -83,30 +89,20 @@
   private String serverName;
 
 
-  DatabaseMetadataImpl(URI uri, Set hostnameAliases, URI securityDomainURI, URI systemModelURI, URI rdfTypeURI, URI systemModelTypeURI)
+  DatabaseMetadataImpl(URI uri, Set hostnameAliases, URI securityDomainURI, URI systemModelTypeURI)
   {
     // Validate parameters.
     if (uri == null) {
       throw new IllegalArgumentException("uri null");
-    }
-    if (hostnameAliases == null) {
+    } else if (hostnameAliases == null) {
       throw new IllegalArgumentException("hostnameAliases null");
-    }
-    if (systemModelURI == null) {
-      throw new IllegalArgumentException("systemModelURI null");
-    }
-    if (rdfTypeURI == null) {
-      throw new IllegalArgumentException("rdfTypeURI null");
-    }
-    if (systemModelTypeURI == null) {
+    } else if (systemModelTypeURI == null) {
       throw new IllegalArgumentException("systemModelTypeURI null");
     }
 
     this.uri = uri;
     this.hostnameAliases = hostnameAliases;
     this.securityDomainURI = securityDomainURI;
-    this.systemModelURI = systemModelURI;
-    this.rdfTypeURI = rdfTypeURI;
     this.systemModelTypeURI = systemModelTypeURI;
 
     // Set server name from the path part of the server URI.
@@ -126,6 +122,16 @@
   }
 
 
+  public URI getBootstrapModelURI() {
+    return BOOTSTRAP_MODEL_URI;
+  }
+
+
+  public URI getServerURIType() {
+    return SERVER_URI_TYPE;
+  }
+
+
   public URI getSystemModelURI()
   {
     return systemModelURI;
@@ -140,7 +146,7 @@
 
   public URI getRdfTypeURI()
   {
-    return rdfTypeURI;
+    return RDF.TYPE;
   }
 
 
@@ -269,20 +275,15 @@
   {
     if (preallocatedSubjectNode < 0) {
       throw new IllegalArgumentException("Attempting to set invalid preallocatedSubjectNode");
-    }
-    if (preallocatedPredicateNode < 0) {
+    } else if (preallocatedPredicateNode < 0) {
       throw new IllegalArgumentException("Attempting to set invalid preallocatedPredicateNode");
-    }
-    if (preallocatedModelNode < 0) {
+    } else if (preallocatedModelNode < 0) {
       throw new IllegalArgumentException("Attempting to set invalid preallocatedModelNode");
-    }
-    if (this.preallocatedSubjectNode >= 0) {
+    } else if (this.preallocatedSubjectNode >= 0) {
       throw new IllegalArgumentException("Attempting to set preallocatedSubjectNode twice");
-    }
-    if (this.preallocatedPredicateNode >= 0) {
+    } else if (this.preallocatedPredicateNode >= 0) {
       throw new IllegalArgumentException("Attempting to set preallocatedPredicateNode twice");
-    }
-    if (this.preallocatedModelNode >= 0) {
+    } else if (this.preallocatedModelNode >= 0) {
       throw new IllegalArgumentException("Attempting to set preallocatedModelNode twice");
     }
 
@@ -290,4 +291,16 @@
     this.preallocatedPredicateNode = preallocatedPredicateNode;
     this.preallocatedModelNode = preallocatedModelNode;
   }
+
+
+  protected void setServerURI(URI serverURI) {
+    if (serverURI == null) {
+      throw new IllegalArgumentException("Setting null serverURI in Database Metadata");
+    } else if (this.serverURI != null) {
+      throw new IllegalArgumentException("Attempt to set serverURI twice");
+    }
+
+    this.serverURI = serverURI;
+    this.systemModelURI = new URI(serverURI.getScheme(), serverURI.getAuthority(), "");
+  }
 }




More information about the Mulgara-svn mailing list