You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Stephan Zednik <ze...@rpi.edu> on 2012/05/21 22:25:40 UTC
closing a TDB-backed Model
Hi,
I am looking into refactoring some code to use TDB-backed Jena Models rather than in-memory Jena Models.
I wrote some tests to try and understand what resource management I will need to perform, specifically the opening and closing of TBD-backed models.
In the following test the Model m does not report itself as closed after I have called m's close( ) method. It also does not report itself as closed if I close the Dataset, then m, then test if m is closed.
Am I missing something?
Thanks,
--Stephan
public class TDBFactoryTest {
@Test
public void test() {
String tdb_directory = "/opt/var/tdb/mdsa";
File location = new File(tdb_directory);
Dataset ds = TDBFactory.createDataset(tdb_directory);
Model m = ds.getDefaultModel();
OntModel o = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
o.addSubModel(m);
assertFalse("expected OntModel to not be closed", o.isClosed()); // PASSES
assertFalse("expected OntModel to not be empty", o.isEmpty()); // PASSES
// ... print out some statements ...
o.removeSubModel(m);
o.close();
assertTrue("expected OntModel to be closed",o.isClosed()); // PASSES
assertFalse("expected Model to not be closed", m.isClosed()); // PASSES
TDB.sync(m);
m.close();
assertTrue("expected Model to be closed",m.isClosed()); // FAILS!
ds.close();
//assertTrue("expected Dataset to be closed", null); // test for closure?
}
}
Re: closing a TDB-backed Model
Posted by Andy Seaborne <an...@apache.org>.
Hi Stephan,
The concept of open/close for models goes back to before were around.
In TDB a model is conceptually a view of the dataset. By changing the
dataset, it is possible to change the model. The concept of open and
close is rooted in models as independent units and that does not sit so
well with models as parts of an RDF datasets. Nowadays TDB ignores
closing graphs when the graphs are part of datasets; only strangely
created graphs which don't reside in proper datasets, does close do
anything and that capability is not exported to the TDB API. And is
likely to go away -- it's just legacy these days.
In fact, all this is likely to go further - a TDB graph will be
implemented as a view of the database. The existing hard-wired
understanding of the TDB internals would go away. When TDB started, it
was at first a single graph and so the TDB graph code does go straight
to the internal data structures. Now TDB has datasets properly, this
can be undone and a general graph-as-view mechanism provided that is not
TDB specific.
The other thing to note is that transactions are per-dataset. The model
operations for transactions do not apply (we may be able to activate
them later but we need to solve the interactions of two models on the
same dataset in a way that does not create weird affects for the
application writer).
Andy
On 21/05/12 21:25, Stephan Zednik wrote:
> Hi,
>
> I am looking into refactoring some code to use TDB-backed Jena
> Modelsrather than in-memory Jena Models.
>
> I wrote some tests to try and understand what resource management I
will need to perform, specifically the opening and closing of TBD-backed
models.
>
> In the following test the Model m does not report itself as closed
after I have called m's close( ) method. It also does not report itself
as closed if I close the Dataset, then m, then test if m is closed.
>
> Am I missing something?
> Thanks,
> --Stephan
>
> public class TDBFactoryTest {
>
> @Test
> public void test() {
> String tdb_directory = "/opt/var/tdb/mdsa";
> File location = new File(tdb_directory);
> Dataset ds = TDBFactory.createDataset(tdb_directory);
> Model m = ds.getDefaultModel();
> OntModel o = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
> o.addSubModel(m);
>
> assertFalse("expected OntModel to not be closed", o.isClosed()); // PASSES
> assertFalse("expected OntModel to not be empty", o.isEmpty()); // PASSES
>
> // ... print out some statements ...
>
> o.removeSubModel(m);
> o.close();
>
> assertTrue("expected OntModel to be closed",o.isClosed()); // PASSES
> assertFalse("expected Model to not be closed", m.isClosed()); // PASSES
>
> TDB.sync(m);
> m.close();
> assertTrue("expected Model to be closed",m.isClosed()); // FAILS!
>
> ds.close();
> //assertTrue("expected Dataset to be closed", null); // test for closure?
> }
> }