Re: Lifecycle Callback

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sun Oct 29 2006 - 18:45:38 EST

  • Next message: Andrus Adamchik: "Re: DataView status"

    Hi Adrian,

    Your code is right, but an extra setup is needed - DataContext needs
    to be decorated in two callback interceptors. I haven't documented it
    yet, as we still need to come up with a more transparent procedure.
    But here is how I am doing it in my apps:

    DataDomain dataDomain = configuration.getDomain("sobf");

    // build interceptor sitting between DD and DC - one interceptor can
    be shared by multiple DataContexts.
    DataChannel postInterceptor = new DataChannelCallbackInterceptor();
    postInterceptor.setChannel(domain);

    // do this for every ObjectContext used by the application:
    // build DC
    ObjectStore objectStore = new ObjectStore
    (dataDomain.getSharedSnapshotCache());
    DataContext dataContext = new DataContext(postInterceptor, objectStore);

    // build interceptor ObjectContext used by the application
    ObjectContextCallbackInterceptor preInterceptor = new
    ObjectContextCallbackInterceptor();
    preInterceptor.setContext(new DataContext(postInterceptor,
    objectStore));

    ObjectContext appContext = preInterceptor;

    Note that "appContext" is what your application should be using.

    Andrus

    On Oct 15, 2006, at 12:03 PM, Adrian Wiesmann wrote:
    > Hello list
    >
    > I am in the process to migrate my project to Cayenne 3 and doing so I
    > would like to use the Lifecycle Callbacks. My problem with them is,
    > that
    > I can't make them to work.
    >
    > I am using cayenne-generic-3.0-incubating-SNAPSHOT from 14. 10. 2006.
    >
    > In the sourcecode I am doing this:
    >
    > Configuration.initializeSharedConfiguration();
    > configuration = Configuration.getSharedConfiguration();
    >
    > dataDomain = configuration.getDomain("sobf");
    >
    > EntityResolver er = dataDomain.getEntityResolver();
    >
    > LifecycleEventCallbackMap cbPrePersist =
    > er.getCallbacks(LifecycleEventCallback.PRE_PERSIST );
    > cbPrePersist.addListener( CDBCommon.class, "prePersist" );
    > cbPrePersist.addListener( CThreatAgent.class, "prePersist" );
    >
    > I have the same sourcecode (last 3 lines) for all of the 7 callback
    > events.
    >
    > But neither the CThreatAgent nor the CDBCommon class get's called.
    > Neither
    > when I am creating a new DBObject, nor when I am commiting my
    > changes to
    > the DataContext.
    >
    > What am I missing or doing wrong?
    >
    > Thanks,
    > Adrian
    >



    This archive was generated by hypermail 2.0.0 : Sun Oct 29 2006 - 18:46:04 EST