Mike,
Here is a few strategies:
1. Use Cayenne built-in remote notifications.
Configure your app in the Modeler to use remote notifications ("Remote
Change Notifications" checkbox for domain). If your batch job is in
Java you can send remote events from the batch job, otherwise you can
run a script that starts a separate Java tool that sends an event. For
an example of how to send a remote event see
DataRowStore.sendUpdateNotification(...). Good thing about snapshot
events is that you can tell the listener exactly which objects were
modified.
2. Continue using LAST_EXTERNAL_UPDATE and manually invalidate cache.
Here is one (but not the only) way to do that for just the shared
entities. For each "shared" entity create a named query in the Modeler
with Result Caching policy of "Shared Cache". Whenever you detect from
LAST_EXTERNAL_UPDATE that refresh is needed, you can do a refresh like
that:
2a. Call "DateRowStore.cacheSnapshots("query_name", null) for each
"shared" query. This assumes that all your DataContexts access shared
object via such queries, and in no other way, and also that you don't
mind stale data in existing DataContexts.
or
2b. Call DataContext.performQuery("query_name", true) for each shared
query. This will give you fresh objects immediately and as a side
effect refresh shared cache.
Andrus
On Nov 19, 2004, at 4:32 PM, Mike Kienenberger wrote:
> Once a day, an external batch job runs and updates some fields in
> tables my
> application has marked as "read-only"
>
> Before I ported my app to cayenne, it ran under WebObjects EOF, and I
> handled the situation like this:
>
> The batch job updated a LAST_EXTERNAL_UPDATE date field in its own
> table
> after it finished.
>
> My web app on every login attempt would run a checkLastExternalUpdate()
> method which, if the LAST_EXTERNAL_UPDATE field changed, would then
> perform
> EditingContext.invalidateAllObjects() and force all objects used by the
> application to be refetched on next reference.
>
>
> I'd like to do this "better" under cayenne, only forcing a refetch of
> objects in specific (read-only) tables rather than every object in the
> app.
> I'm not thrilled with the LAST_EXTERNAL_UPDATE approach either, but
> it's
> better than listening on a socket.
>
> However, I'm unclear how to go about this with Cayenne.
>
> The best I can come up with is one (or both) of the following:
>
>
> getDataContext().invalidateObjects(getDataContext().getObjectStore().ge
> tObjects());
>
> getDataContext().getObjectStore().getDataRowCache().clear();
>
>
> Thanks,
>
> -Mike
This archive was generated by hypermail 2.0.0 : Sat Nov 20 2004 - 18:14:49 EST