Hi Roman,
You should get a "TDBTransactionException: Not in a transaction". It is
not possible to pass
On 13/02/17 15:55, [email protected] wrote:
Hi,
I tried update Jena from 3.1.0 to 3.2.0. And at a later point I tried to update
to Jena 3.1.1. In both cases I had the problem, that the following code didn't
work anymore.
public Model pullNamedModelFromTDB(String pathToTDB, String modelURI) {
// create a TDB-dataset
Dataset dataset = TDBFactory.createDataset(pathToTDB);
dataset.begin( ReadWrite.WRITE );
try {
// get the named model from the dataset
Model tdb = dataset.getNamedModel(modelURI);
This does not copy it out of the dataset, it creates a view of the data
inside the dataset, in fact, a view
// finish the "WRITE" transaction
dataset.commit();
return tdb;
} finally {
// close the dataset
dataset.end();
dataset.close();
No needed. close(), if it has any meaning, may close the dataset for
ever. It's all cached internally.
// write a message if the data was successfully find in the jena tdb
System.out.println("The model " + modelURI + " was successfully loaded from
directory: " + pathToTDB);
}
}
Model defaultCompositionModel;
defaultCompositionModel =
connectionToTDB.pullNamedModelFromTDB(currDirectoryPath,
defaultCompositionNGURI);
System.out.println("close test = " + defaultCompositionModel.isClosed());
System.out.println("empty test = " + defaultCompositionModel.isEmpty());
The program stops immediatly when I try to access the data of the named model.
With an exception, I hope.
So is there a new/correct way to pull a Named Model from a Dataset to
use it afterward? The Code above works fine with the old
versions(3.1.0 & 3.0.0). I saw there was a change in
"DatasetImpl.java"-code. A variable called "dftModel" was removed
from the code. I also saw that there was a change on Feb 8, 2017,
where an if-statement was added for the transformation from a graph
in a model.
The correct ways depends on what you want to do:
A:: If you want to copy out the model, then create a memory model and
copy with model.add(tdb) to create an in-memory detached copy.
See also the new RDF Connection:
http://jena.apache.org/documentation/rdfconnection/
This provides whole graph operations - better than DataseAccessor.
It can operate in copy-out, copy-in mode, makign it liek a remote
connection and also for making it transaction safe.
B:: If you want to change the model and change the dataset, then get the
model inside a transaction each time. It isn't a copy - it should not
be expensive.
Passing anything that is associated with the transaction out of the
begin-commit is not safe. It used to lead to missing updates. It sort
of worked for read-only operations although that could go wrong as well.
"dftModel" - this is related - the code no longer holds on to default
model across transactions.
Feb 8 - after the release. It is actually making an error situation
happen earlier and with a relevant error message. In TDB all graphs
"exist" so the return is never null and so this is not relevant here.
Andy
Thanks in advance!
Roman