Hi Andy
Thanks for answering my question.Is this code only for version 3.0 and higher?
Do we need to close the model or commit and end the dataset are enough?
ThanksAbdul
From: Andy Seaborne <[email protected]>
To: [email protected]
Sent: Wednesday, 10 August 2016, 13:13
Subject: Re: Model Inconsisten
On 10/08/16 12:57, Abduladem Eljamel wrote:
> Hi,,I hope everyone is fine.I would like to know the difference between code
> 1 andcode 2 below. When can each one be used for?
> What is "NoSuchElementException" Exception andmodel inconsistent?If there is
> a reference to cite the explanation,please tell me.
> ThanksAbdul---------------------
> code 1:
> Dataset dataset = TDBFactory.createDataset(location);Model model =
> dataset.getDefaultModel();
> try { dataset.begin(ReadWrite.WRITE) ;
> // write triples to model
> dataset.commit() ;
> } finally {
> dataset.end() ;
> }----------code 2:Dataset dataset = TDBFactory.createDataset(location);Model
>model = dataset.getDefaultModel();try {
>model.enterCriticalSection(Lock.WRITE);
> // write triples to model
> model.commit();
> TDB.sync(model);
> } finally {
> model.leaveCriticalSection();
> }
>
The correct form (all 3.x versions):
Dataset dataset = TDBFactory.createDataset(location);
dataset.begin(ReadWrite.WRITE) ;
try {
// Inside begin-commit.
Model model = dataset.getDefaultModel();
// write triples to model
dataset.commit() ;
} finally {
dataset.end() ;
}
Andy