You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Andy Seaborne <an...@apache.org> on 2013/05/02 14:42:47 UTC

Re: Dataset.close()

On 30/04/13 22:49, Stephen Allen wrote:
> On Tue, Apr 30, 2013 at 2:40 PM, David Jordan <Da...@sas.com> wrote:
>> I posted a message about transactions and caching earlier today. I have an additional question.
>>
>> If you have a series of calls
>> dataset.begin …
>> dataset.commit …
>> dataset.begin …
>> dataset.commit …
>>
>> Is it the case that the database state used within the first transaction is available to the subsequent transactions.
>> Is a call to dataset.close cause all of this database state to be freed up and no longer associated with the dataset.
>
> The dataset.close() call will actually close the database and free all
> resources.  Any further calls to the dataset will throw an exception.
>   Instead, what you want to do is call dataset.end() in a finally
> block.  This will ensure that the transaction is ended (it will abort
> the transaction if commit() has not been called, and do nothing if
> commit() has been called).
>
> dataset.begin(ReadWrite.WRITE);
> try {
>    // Query or add/delete data from the dataset
>    ...
>    // Maybe some exception happens here!  That's OK,
>    // the finally block will effectively be an abort() and our
>    // transaction will be closed
>    ...
>
>    if (someMeasureOfBadness > 0) {
>      dataset.abort();
>    }
>    else {
>      dataset.commit();
>    }
> }
> finally {
>    dataset.end();
> }
>
>> When you make the call the second time to dataset.begin(), suppose another transaction had already committed a transaction involving updates.
>> When the second transaction begins, will it then replace state the dataset is maintaining, with the newly committed updates?
>
> Yes, as long as the first transaction "happens-before" the second,
> then the second one will see the results of the first.
>
>> My goal here is how to properly maintain cached state, avoid the overhead of re-reading the database, redoing inferencing inside each transaction.
>>


database.close() on a TDB transactional database only closes it all down 
if it has not been used transactionally.  A Dataset is analogous to JDBC 
connection and carries per-thread information.  Dataset.close only 
clears the per-thread information.  Another thread may have a reference 
to the database (whether in a transaction or not currently active).

The more global shutdown operation is StoreConnection.release.  The app 
must then not use the database again until a new StoreConnection is 
created (or a new Dataset object created).

Normally, you don't call .close().

	Andy