[Mulgara-general] problem with Session.modelExists(URI uri)
Paul Gearon
gearon at ieee.org
Wed Oct 31 19:29:03 UTC 2007
Hi Eddie,
You're right, this is a bug.
It seems to have been introduced in the transaction manager. It's
pretty easy to see what's happened. The code localizes the URI into a
node number, and then looks up that number to see if it represents a
graph (or "model" in the old terminology). However, if the URI is not
known, then it can't be localized, which throws an exception.
I'm not really happy about throwing an exception for unknown URIs, as
it is a common operation, and there is always overhead associated with
this. However, checking for existence isn't an operation that happens
too many times per second (I think), so it's probably safe to wrap the
localize in a try block and return false in the catch. The lines to
wrap are in the execute() method of ModelExistsOperation:
src/jar/resolver/java/org/mulgara/resolver/ModelExistsOperation.java
line 69
was:
long model = systemResolver.lookupPersistent(new
URIReferenceImpl(modelURI));
result = systemResolver.modelExists(model);
change to:
try {
long model = systemResolver.lookupPersistent(new
URIReferenceImpl(modelURI));
result = systemResolver.modelExists(model);
} catch (LocalizeException le) {
result = false;
}
As I said, I'd rather see something better in lookupPersistent(), but
this will do for now.
To elaborate on what I mean when I say "something better", node
numbers (graph nodes, or gNodes) have a few invalid values, like 0 and
-1. We could just return those from localize, rather than throwing an
exception. Alternatively, we can use Long instead of long, and use
nulls for unknown URIs. Unfortunately, whoever fixes it will need to
go through a lot of code to make sure there aren't any unintended side
effects. Since this will take time that no one has at the moment,
then the try/catch solution is probably the way to go.
Regards,
Paul
On Oct 31, 2007, at 1:34 PM, Edwin Shin wrote:
> Session.modelExists(URI uri) in Mulgara 1.1.0 isn't working as I
> would expect.
>
> For example, inserting the following:
>
> session.modelExists(new URI(modelURI));
>
> after line 134 in
> org.mulgara.server.local.LocalSessionFactoryUnitTest (i.e., after
> the assignment of modelURI but before creating the model), yields:
>
> "Failed to determine model existence"
> which seems to root from
> "org.mulgara.resolver.spi.LocalizeException: Unable to localize
> rmi://localhost/testServer#testModel - Couldn't localize node"
>
> This didn't happen in Kowari (1.0.5).
>
> So I just started to omit the calls to modelExists() as creating a
> model that already exists doesn't seem to cause a problem--except I
> then with a remote client/server session (no longer using a
> LocalSessionFactory) I started seeing some other problems (but I
> haven't had a chance to track down exactly what's going on in that
> case). I figured I'd just inquire if this new (since Kowari)
> behavior of modelExists is intentional or if creating a model that
> already exists should never pose a problem (local or remote
> notwithstanding).
>
> -Eddie
> _______________________________________________
> Mulgara-general mailing list
> Mulgara-general at mulgara.org
> http://mulgara.org/mailman/listinfo/mulgara-general
More information about the Mulgara-general
mailing list