[Mulgara-svn] r296 - in branches/mgr-58/src/jar: query/java/org/mulgara/query resolver/java/org/mulgara/resolver resolver-spi/java/org/mulgara/resolver/spi
andrae at mulgara.org
andrae at mulgara.org
Mon Jul 9 12:00:16 UTC 2007
Author: andrae
Date: 2007-07-09 07:00:15 -0500 (Mon, 09 Jul 2007)
New Revision: 296
Modified:
branches/mgr-58/src/jar/query/java/org/mulgara/query/ConstraintFalse.java
branches/mgr-58/src/jar/query/java/org/mulgara/query/ConstraintTrue.java
branches/mgr-58/src/jar/resolver-spi/java/org/mulgara/resolver/spi/DatabaseMetadata.java
branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/CreateModelOperation.java
branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseMetadataImpl.java
branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/ModifyModelOperation.java
Log:
WARNING: Don't even attempt to compile this - work in progress.
Current progress towards getting the model-name fix done - mostly fixes and
cleanup to DatabaseOperationContext.
Modified: branches/mgr-58/src/jar/query/java/org/mulgara/query/ConstraintFalse.java
===================================================================
--- branches/mgr-58/src/jar/query/java/org/mulgara/query/ConstraintFalse.java 2007-07-06 20:30:37 UTC (rev 295)
+++ branches/mgr-58/src/jar/query/java/org/mulgara/query/ConstraintFalse.java 2007-07-09 12:00:15 UTC (rev 296)
@@ -78,15 +78,6 @@
}
/**
- * Gets the CanonicalForm attribute of the ConstraintFalse object
- *
- * @return The CanonicalForm value
- */
- public ConstraintExpression getCanonicalForm() {
- return this;
- }
-
- /**
* Gets the Rows attribute of the ConstraintFalse object
*
* @return The Rows value
Modified: branches/mgr-58/src/jar/query/java/org/mulgara/query/ConstraintTrue.java
===================================================================
--- branches/mgr-58/src/jar/query/java/org/mulgara/query/ConstraintTrue.java 2007-07-06 20:30:37 UTC (rev 295)
+++ branches/mgr-58/src/jar/query/java/org/mulgara/query/ConstraintTrue.java 2007-07-09 12:00:15 UTC (rev 296)
@@ -76,15 +76,6 @@
}
/**
- * Gets the CanonicalForm attribute of the ConstraintTrue object
- *
- * @return The CanonicalForm value
- */
- public ConstraintExpression getCanonicalForm() {
- return this;
- }
-
- /**
* Gets the Rows attribute of the ConstraintTrue object
*
* @return The Rows value
Modified: branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/CreateModelOperation.java
===================================================================
--- branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/CreateModelOperation.java 2007-07-06 20:30:37 UTC (rev 295)
+++ branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/CreateModelOperation.java 2007-07-09 12:00:15 UTC (rev 296)
@@ -91,7 +91,7 @@
/**
* The URI of the model to be created.
*/
- private final URI modelURI;
+ private final URI modelURL;
/**
* The URI of the type of the model to be created.
@@ -112,7 +112,7 @@
* @throws IllegalArgumentException if <var>modelURI</var> is
* <code>null</code>
*/
- CreateModelOperation(URI modelURI, URI modelTypeURI) throws QueryException
+ CreateModelOperation(URI modelURL, URI modelTypeURI) throws QueryException
{
// Validate "modelURI" parameter
if (modelURI == null) {
@@ -125,7 +125,7 @@
}
// Initialize fields
- this.modelURI = modelURI;
+ this.modelURL = modelURL;
this.modelTypeURI = modelTypeURI;
}
@@ -137,84 +137,36 @@
SystemResolver systemResolver,
DatabaseMetadata metadata) throws Exception
{
+ // if modelTypeURI is null - consider external !?!?!?
// Default to the system model type
if (modelTypeURI == null) {
modelTypeURI = metadata.getSystemModelTypeURI();
}
- // Verify that the model URI is relative to the database URI. The model
- // URI can use one of the hostname aliases instead of the canonical
- // hostname of the database URI. No checking of the scheme specific part
- // of the model URI is performed if the database URI is opaque.
- boolean badModelURI = true;
- URI databaseURI = metadata.getURI();
- String scheme = modelURI.getScheme();
- String fragment = modelURI.getFragment();
- if (scheme != null && scheme.equals(databaseURI.getScheme()) &&
- fragment != null) {
- if (databaseURI.isOpaque()) {
- // databaseURI is opaque.
- if (modelURI.isOpaque()) {
- // Strip out the query string.
- String ssp = modelURI.getSchemeSpecificPart();
- int qIndex = ssp.indexOf('?');
- if (qIndex >= 0) {
- ssp = ssp.substring(0, qIndex);
- }
-
- if (ssp.equals(databaseURI.getSchemeSpecificPart())) {
- // modelURI is relative to databaseURI.
- badModelURI = false;
- }
- }
- } else {
- // databaseURI is hierarchial.
- String path;
- String host;
-
- if (
- !modelURI.isOpaque() && (
- modelURI.getSchemeSpecificPart().equals(
- databaseURI.getSchemeSpecificPart()
- ) || (
- (host = modelURI.getHost()) != null &&
- modelURI.getPort() == databaseURI.getPort() &&
- (path = modelURI.getPath()) != null &&
- path.equals(databaseURI.getPath()) &&
- metadata.getHostnameAliases().contains(host.toLowerCase())
- )
- )
- ) {
- // modelURI is relative to databaseURI.
- badModelURI = false;
- }
- }
+ long model;
+ URI modelURI = convertModelURLtoURI(modelURL);
+ if (modelURI != null) {
+ // internal, so use model-name.
+ model = systemResolver.localize(modelURI);
+ } else {
+ // could be external, so attempt to use model-url directly.
+ model = systemResolver.localize(modelURL);
}
- if (badModelURI) {
- throw new QueryException(
- "Model URI is not relative to the database URI (modelURI:\"" +
- modelURI + "\", databaseURI:\"" + databaseURI + "\")"
- );
- }
// Look up the resolver factory for the model type
ResolverFactory resolverFactory =
operationContext.findModelTypeResolverFactory(modelTypeURI);
if (resolverFactory == null) {
throw new QueryException(
- "Couldn't find resolver factory in internal resolver map " +
- modelTypeURI);
+ "Couldn't find resolver factory in internal resolver map " + modelTypeURI);
}
- // PREVIOUSLY WITHIN TRANSACTION
-
// Obtain an appropriate resolver bound to this session
Resolver resolver = operationContext.obtainResolver(resolverFactory);
assert resolver != null;
// Find the local node identifying the model
- long model = systemResolver.localizePersistent(new URIReferenceImpl(
- modelURI));
+ long model = systemResolver.localizePersistent(new URIReferenceImpl(modelURI));
assert model != NodePool.NONE;
// Check model does not already exist with a different model type.
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-07-06 20:30:37 UTC (rev 295)
+++ branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseMetadataImpl.java 2007-07-09 12:00:15 UTC (rev 296)
@@ -303,4 +303,8 @@
this.serverURI = serverURI;
this.systemModelURI = new URI(serverURI.getScheme(), serverURI.getAuthority(), "");
}
+
+ public URI getServerURI() {
+ return serverURI;
+ }
}
Modified: branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
===================================================================
--- branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java 2007-07-06 20:30:37 UTC (rev 295)
+++ branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java 2007-07-09 12:00:15 UTC (rev 296)
@@ -218,56 +218,6 @@
return internalResolverFactory;
} else {
- // This might be an external model or an aliased internal model.
- // get the model URI
- Node modelNode = systemResolver.globalize(model);
- if (!(modelNode instanceof URIReference)) {
- throw new QueryException(modelNode.toString() + " is not a valid Model");
- }
- URI modelURI = ((URIReference)modelNode).getURI();
-
- // check if this is really a reference to a local model, using a different server name
- Node aliasedNode = getCanonicalAlias(modelURI);
- if (aliasedNode != null) {
- long aliasedModel = systemResolver.localize(aliasedNode);
- return findModelResolverFactory(aliasedModel);
- }
-
- // test the model URI against the current server
- try {
- if (logger.isDebugEnabled()) {
- logger.debug("Comparing " + metadata.getURI().toString() + " to " + (new URI(modelURI.getScheme(),
- modelURI.getSchemeSpecificPart(), null)).toString());
- }
-
- // Check all the hostname aliases to see if we're attempting to
- // contact the local server.
- URI tmpModelName = new URI(modelURI.getScheme(),
- modelURI.getSchemeSpecificPart(), null);
- String host = tmpModelName.getHost();
-
- // Ensure that the host name can be extracted - in case there's an
- // opaque hostname.
- if (tmpModelName.isOpaque()) {
- throw new QueryException("Unable to extract hostname from: " +
- tmpModelName);
- }
-
- // Do not test for locality if jar or file protocol
- if (!(modelURI.getScheme().startsWith("file")) &&
- !(modelURI.getScheme().startsWith("jar"))) {
-
- // Check that it's the same host name and server name.
- if ((metadata.getHostnameAliases().contains(host)) &&
- (metadata.getServerName().equals(metadata.getServerName(modelURI)))) {
- // should be on the current server, but was not found here
- throw new QueryException(modelNode.toString() + " is not a Model");
- }
- }
- } catch (URISyntaxException use) {
- throw new QueryException("Internal error. Model URI cannot be manipulated.");
- }
-
// This is not a local model, get the protocol
String modelProtocol = findProtocol(model);
if (logger.isDebugEnabled()) {
@@ -298,8 +248,6 @@
}
} catch (GlobalizeException eg) {
throw new QueryException("Unable to globalize modeltype", eg);
- } catch (LocalizeException el) {
- throw new QueryException("Unable to localize model", el);
}
}
@@ -309,60 +257,36 @@
* @return a completely unwrapped resolver factory
*/
// TODO: Common code with findModelResolverFactory should be consolidated.
- private ResolverFactory findResolverFactory(long model) throws QueryException
+ private ResolverFactory findUncachedExternalResolverFactory(long model) throws QueryException
{
if (logger.isDebugEnabled()) {
logger.debug("Finding raw resolver factory for model " + model);
}
try {
- // get the model URI
- Node modelNode = systemResolver.globalize(model);
- if (!(modelNode instanceof URIReference)) {
- throw new QueryException(modelNode.toString() + " is not a valid Model");
- }
- URI modelURI = ((URIReference)modelNode).getURI();
-
- // test the model URI against the current server
- try {
- if (logger.isDebugEnabled()) {
- logger.debug("Comparing " + metadata.getURI().toString() + " to "
- + (new URI(modelURI.getScheme(), modelURI.getSchemeSpecificPart(), null)).toString());
- }
- if (metadata.getURI().equals(
- new URI(modelURI.getScheme(), modelURI.getSchemeSpecificPart(), null))) {
- // should be on the current server, but was not found here
- throw new QueryException(modelNode.toString() + " is not a Model");
- }
- } catch (URISyntaxException use) {
- throw new QueryException("Internal error. Model URI cannot be manipulated.");
- }
-
- // This is not a local model, get the protocol
String modelProtocol = findProtocol(model);
if (logger.isDebugEnabled()) {
logger.debug("Model " + model + " protocol is " + modelProtocol);
}
-
- // find the factory for this protocol
- ResolverFactory resolverFactory =
- (ResolverFactory) externalResolverFactoryMap.get(modelProtocol);
+ ResolverFactory resolverFactory = (ResolverFactory)externalResolverFactoryMap.get(modelProtocol);
if (resolverFactory == null) {
- throw new QueryException(
- "Unsupported protocol for destination model (" +
- modelProtocol + ", " + model + " : '" + modelProtocol + "')");
+ throw new QueryException("Unable to obtain resolver factory for model" + systemResolver.globalize(model));
}
return resolverFactory;
} catch (GlobalizeException eg) {
- throw new QueryException("Unable to globalize modeltype", eg);
+ throw new QueryException("Unable to globalize model", eg);
}
}
public ResolverFactory findModelTypeResolverFactory(URI modelTypeURI)
throws QueryException
{
- return (InternalResolverFactory) internalResolverFactoryMap.get(modelTypeURI);
+ try {
+ return (InternalResolverFactory) internalResolverFactoryMap.get(modelTypeURI);
+ } catch (LocalizeException el) {
+ throw new
+ }
}
public List getSecurityAdapterList()
@@ -569,63 +493,15 @@
* @throws QueryException When the model URI cannot be manipulated.
*/
private Node getCanonicalAlias(URI modelURI) throws QueryException {
- if (logger.isDebugEnabled()) {
- logger.debug("Checking for an alias on: " + modelURI);
- }
-
- // extract the host name
- String host = modelURI.getHost();
- if (host == null) {
+ URI uri = convertModelURLtoURI(modelURI);
+ if (uri == null) {
return null;
+ } else {
+ return new URIReferenceImpl(uri);
}
- // Check if this host has been heard of before
- if (metadata.getHostnameAliases().contains(host)) {
- // this name is acceptable, so leave it alone
- return null;
- }
- // Check with a DNS server to see if this host is recognised
- InetAddress addr = null;
- try {
- addr = InetAddress.getByName(host);
- } catch (UnknownHostException uhe) {
- // The host was unknown, so allow resolution to continue as before
- return null;
- }
- // check the various names against known aliases
- if (metadata.getHostnameAliases().contains(addr.getHostName()) ||
- metadata.getHostnameAliases().contains(addr.getCanonicalHostName()) ||
- metadata.getHostnameAliases().contains(addr.getHostAddress())) {
- // change the host name to one that is recognised
- return getLocalURI(modelURI);
- }
-
- // not found, so return nothing
- return null;
}
-
/**
- * Convert a URI to a URIReference which refers to the canonical local machine name.
- *
- * @param uri The URI to update.
- * @return The URIReference representing the same URI as the parameter, with the host name updated.
- * @throws QueryException When the uri cannot be manipulated.
- */
- private Node getLocalURI(URI uri) throws QueryException {
- // use the system model to find the local host name
- String newHost = metadata.getSystemModelURI().getHost();
- // update the URI
- try {
- URI newModelURI = new URI(uri.getScheme(), newHost, uri.getPath(), uri.getFragment());
- logger.debug("Changing model URI from " + uri + " to " + newModelURI);
-
- return new URIReferenceImpl(newModelURI);
- } catch (URISyntaxException e) {
- throw new QueryException("Internal error. Model URI cannot be manipulated.");
- }
- }
-
- /**
* Resolve a localized constraint into the tuples which satisfy it.
*
* This method must be called within a transactional context.
@@ -896,8 +772,7 @@
if (changedCachedModelSet.contains(modelLocalNode)) {
// Write back the modifications to the original model
try {
- Resolver resolver =
- findResolverFactory(model).newResolver(true, systemResolver, systemResolver);
+ Resolver resolver = findUncachedExternalResolverFactory(model).newResolver(true, systemResolver, systemResolver);
Variable s = new Variable("s");
Variable p = new Variable("p");
Variable o = new Variable("o");
@@ -937,4 +812,50 @@
systemResolver + " into transaction", e);
}
}
+
+
+ private URI convertModelURLtoURI(URI modelURL) throws QueryException {
+ if (!isLocalModel(modelURL)) {
+ return null;
+ } else {
+ URI serverURI = metadata.getServerURI();
+ return new URI(serverURI.getScheme(),
+ serverURI.getAuthority(),
+ serverURI.getPath(),
+ modelURL.getQuery(),
+ modelURL.getFragment());
+ }
+ }
+
+ private boolean isLocalModelURL(URI modelURL) throws QueryException {
+ if (modelURL.getScheme().equals("local")) {
+ return modelURL.getAuthority().equals(metadata.getServerName());
+ }
+ if (!modelURL.getPath().equals(metadata.getServerName())) {
+ return false;
+ }
+ if (modelURL.getScheme().equals("rdfdb")) {
+ return modelURL.getAuthority().equals(metadata.getServerURI.getAuthority());
+ }
+
+ String host = modelURI.getHost();
+ if (host == null) {
+ return false;
+ }
+ if (metadata.getHostnameAliases().contains(host.toLowerCase())) {
+ return true;
+ }
+
+ // Check with a DNS server to see if this host is recognised
+ try {
+ InetAddress addr = InetAddress.getByName(host);
+ if (metadata.getHostnameAliases().contains(addr.getHostName()) ||
+ metadata.getHostnameAliases().contains(addr.getCanonicalHostName()) ||
+ metadata.getHostnameAliases().contains(addr.getHostAddress())) {
+ return true;
+ }
+ } catch (UnknownHostException uhe) {
+ return false;
+ }
+ }
}
Modified: branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/ModifyModelOperation.java
===================================================================
--- branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/ModifyModelOperation.java 2007-07-06 20:30:37 UTC (rev 295)
+++ branches/mgr-58/src/jar/resolver/java/org/mulgara/resolver/ModifyModelOperation.java 2007-07-09 12:00:15 UTC (rev 296)
@@ -225,6 +225,7 @@
boolean insert) throws Exception
{
long model = systemResolver.localize(new URIReferenceImpl(modelURI));
+
model = operationContext.getCanonicalModel(model);
// Make sure security adapters are satisfied
Modified: branches/mgr-58/src/jar/resolver-spi/java/org/mulgara/resolver/spi/DatabaseMetadata.java
===================================================================
--- branches/mgr-58/src/jar/resolver-spi/java/org/mulgara/resolver/spi/DatabaseMetadata.java 2007-07-06 20:30:37 UTC (rev 295)
+++ branches/mgr-58/src/jar/resolver-spi/java/org/mulgara/resolver/spi/DatabaseMetadata.java 2007-07-09 12:00:15 UTC (rev 296)
@@ -67,6 +67,8 @@
*/
public String getServerName(URI serverURI);
+ public URI getServerURI();
+
public URI getURI();
public URI getSecurityDomainURI();
public URI getSystemModelURI();
More information about the Mulgara-svn
mailing list