On 23/12/13 10:56, Arto My Friend wrote:
My code was working fine, creating a resource and later read from it..
Dataset dataset = TDBFactory.createDataset(TDB_PATH);
dataset.begin(ReadWrite.WRITE);
model = dataset.getDefaultModel();
String uid = generateUUID();
Resource user = model.createResource(BASE_URI + RES_PREFIX_USER + uid)
.addProperty(PROP_HAS_CHECKIN, model.createSeq(BASE_URI + RES_PREFIX_REC +
uid))
.addProperty(FOAF.mbox, email)
.addProperty(PROP_UUID, uid);
dataset.commit();
model.close();
dataset.end();
String uid = user.getProperty(MobiSosCore.PROP_UUID).getString();
However, after I changed the way I retrieve dataset to be
Dataset baseDataset = TDBFactory.createDataset(TDB_PATH);
EntityDefinition entDef = new EntityDefinition("entityField", "geoField");
dataset = SpatialDatasetFactory.createLucene(baseDataset, INDEX_DIR,
entDef);
The program throw out ClosedException at the call of getProperty().
It seems to me that after base dataset is joined with spatial index, the
retrieved resource cannot be read outside a transaction block.
Please help. I want to know what underlying mechanisms that I should
understand to get my code right?
I'm surprised it works the first way at all - when I tried to write a
test for it, I get ClosedException when accessing the resource after the
model is closed.
The text daatset example looks correct. model is closed so
user.getProperty should throw an exception. If you've done
"model.close" all access to the model should cause the exception and
"user" contains a reference to the model internally.
If you have a complete, minimal example, could you send it and I can
debug it.
When used with TDB, models are just views on the dataset at a particular
transaction time. The model.close isn't necessary although you may wish
to do it, but do it inside the transaction because you, correctly, got
the model inside the transaction. (History: when we have BDB support,
closing things properly was essential as it release BDB resources.)
Things can't pass the transaction boundary although given the internal
details of TDB (it's effectively a MVCC system) it is possible some can
work much fop the time (later updates may break them).
Good use is to nest inside a transaction and what is inside a
transaction is scoped to the transaction.
Andy
Art