You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Colin Bankier <co...@hotmail.com> on 2008/04/01 03:13:46 UTC

Re: How to propoerly close context db connection

Thanks Andrus - but shouldn't something like getQueryCache().clear() at least
clear any cache so that cayenne will retrieve the data fresh from the DB
once the file has been overwritten? (Even if the connection isn't closed
properly while this is happening.) This doesn't seem to be having any
effect.

I've also tried to look at the CAY-632 RefreshQuery, or
context.invalidateObjects(), but really wanted to refresh the whole cache -
not just a particular collection of objects. Perhaps I just need to know how
to use these correctly.

Any suggestions on how to do this would be greatly appreciated.
Cheers,
Colin.

  

Andrus Adamchik wrote:
> 
> Cayenne itself works with a DataSource. All connection management and  
> starting and stopping the embedded DB is deferred to the DataSource  
> and is beyond Cayenne scope. The default DataSource implementation  
> pools connections. If you need a different policy, you need to provide  
> a DataSource that does whatever is appropriate in your environment.  
> Custom DataSource is installed by providing a special  
> DataSourceFactory for a give DataNode in the Modeler.
> 
> Andrus
> 

-- 
View this message in context: http://www.nabble.com/How-to-propoerly-close-context-db-connection-tp16392733p16403625.html
Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: How to propoerly close context db connection

Posted by Marcin Skladaniec <ma...@ish.com.au>.
I'm not sure, but try this:

query.setCachePolicy(QueryMetadata.LOCAL_CACHE_REFRESH); // or  
SHARED_CACHE_REFRESH
or
query.setRefreshingObjects(true)

this will force the refresh of the results of the query you execute,  
regardless of what they are

Cheers
Marcin



On 01/04/2008, at 11:13 AM, Colin Bankier wrote:
>
> Thanks Andrus - but shouldn't something like getQueryCache().clear()  
> at least
> clear any cache so that cayenne will retrieve the data fresh from  
> the DB
> once the file has been overwritten? (Even if the connection isn't  
> closed
> properly while this is happening.) This doesn't seem to be having any
> effect.
>
> I've also tried to look at the CAY-632 RefreshQuery, or
> context.invalidateObjects(), but really wanted to refresh the whole  
> cache -
> not just a particular collection of objects. Perhaps I just need to  
> know how
> to use these correctly.
>
> Any suggestions on how to do this would be greatly appreciated.
> Cheers,
> Colin.
>
>
>
> Andrus Adamchik wrote:
>>
>> Cayenne itself works with a DataSource. All connection management and
>> starting and stopping the embedded DB is deferred to the DataSource
>> and is beyond Cayenne scope. The default DataSource implementation
>> pools connections. If you need a different policy, you need to  
>> provide
>> a DataSource that does whatever is appropriate in your environment.
>> Custom DataSource is installed by providing a special
>> DataSourceFactory for a give DataNode in the Modeler.
>>
>> Andrus
>>
>
> -- 
> View this message in context: http://www.nabble.com/How-to-propoerly-close-context-db-connection-tp16392733p16403625.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>


Re: How to propoerly close context db connection

Posted by Colin Bankier <co...@hotmail.com>.

Thanks to everyone who posted to help me out. Sorry I was pulled away from
working on this for a while and only now got the time to finally solve it.
It turned out that, as Andrus mentioned, the problem was with the DB itself
- which is Derby in this case - and reading the docs on how to properly
shutdown the Derby database solved the problem.
A simple DriverManager.getConnection("jdbc:derby:;shutdown=true") did the
trick.
Cheers,
Colin.




Andrus Adamchik wrote:
> 
> Embedded DB's add a whole other dimension to that by keeping committed  
> data in memory at the driver level - something Cayenne is not aware  
> of. So anything you do with "clearCache" or RefreshQuery, etc.,  
> affects Cayenne cache, and not the embedded DB JDBC layer. So here  
> you'd need to read the embedded DB docs (is that Derby, HSQL, H2?) and  
> see what they recommend to do in such situation. There maybe a SQL  
> query that would shutdown/reopen the file, or something else (like  
> restarting the DataSource).
> 
> Andrus
> 

-- 
View this message in context: http://www.nabble.com/How-to-propoerly-close-context-db-connection-tp16392733p16767462.html
Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: How to propoerly close context db connection

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Colin,

Cayenne internal cache state is in no way related to the connection  
state - it can survive closing connections, etc. If you are connecting  
to a separate DB process, Cayenne cache management techniques (as  
mentioned by Marcin, and what you found in the docs), is the only  
thing you need to know.

Embedded DB's add a whole other dimension to that by keeping committed  
data in memory at the driver level - something Cayenne is not aware  
of. So anything you do with "clearCache" or RefreshQuery, etc.,  
affects Cayenne cache, and not the embedded DB JDBC layer. So here  
you'd need to read the embedded DB docs (is that Derby, HSQL, H2?) and  
see what they recommend to do in such situation. There maybe a SQL  
query that would shutdown/reopen the file, or something else (like  
restarting the DataSource).

Andrus


On Apr 1, 2008, at 4:13 AM, Colin Bankier wrote:
> Thanks Andrus - but shouldn't something like getQueryCache().clear()  
> at least
> clear any cache so that cayenne will retrieve the data fresh from  
> the DB
> once the file has been overwritten? (Even if the connection isn't  
> closed
> properly while this is happening.) This doesn't seem to be having any
> effect.
>
> I've also tried to look at the CAY-632 RefreshQuery, or
> context.invalidateObjects(), but really wanted to refresh the whole  
> cache -
> not just a particular collection of objects. Perhaps I just need to  
> know how
> to use these correctly.
>
> Any suggestions on how to do this would be greatly appreciated.
> Cheers,
> Colin.
>
>
>
> Andrus Adamchik wrote:
>>
>> Cayenne itself works with a DataSource. All connection management and
>> starting and stopping the embedded DB is deferred to the DataSource
>> and is beyond Cayenne scope. The default DataSource implementation
>> pools connections. If you need a different policy, you need to  
>> provide
>> a DataSource that does whatever is appropriate in your environment.
>> Custom DataSource is installed by providing a special
>> DataSourceFactory for a give DataNode in the Modeler.
>>
>> Andrus
>>
>
> -- 
> View this message in context: http://www.nabble.com/How-to-propoerly-close-context-db-connection-tp16392733p16403625.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>
>