FAQ
In my app I'm creating a new datacontext based on a
existing datacontext, but the method I used to do this
is now deprecated and I don't know what to replace
it with:

getDataContext().getParentDataDomain().createDataContext();

?

--
Øyvind Harboe

Can Zylin Consulting help on your project?

US toll free 1-866-980-3434 / International +47 51 87 40 27

http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer

Search Discussions

  • Michael Gentry at Feb 10, 2011 at 1:28 pm
    Which version of Cayenne are you using? It isn't deprecated in Cayenne 3.0.

    mrg

    On Thu, Feb 10, 2011 at 3:12 AM, Øyvind Harboe wrote:
    In my app I'm creating a new datacontext based on a
    existing datacontext, but the method I used to do this
    is now deprecated and I don't know what to replace
    it with:

    getDataContext().getParentDataDomain().createDataContext();

    ?

    --
    Øyvind Harboe

    Can Zylin Consulting help on your project?

    US toll free 1-866-980-3434 / International +47 51 87 40 27

    http://www.zylin.com/zy1000.html
    ARM7 ARM9 ARM11 XScale Cortex
    JTAG debugger and flash programmer
  • Øyvind Harboe at Feb 10, 2011 at 1:30 pm

    On Thu, Feb 10, 2011 at 2:27 PM, Michael Gentry wrote:
    Which version of Cayenne are you using?  It isn't
    deprecated in Cayenne 3.0.
    I'm trying to upgrade to Cayenne 3.1, so I want to stop
    using it.




    --
    Øyvind Harboe

    Can Zylin Consulting help on your project?

    US toll free 1-866-980-3434 / International +47 51 87 40 27

    http://www.zylin.com/zy1000.html
    ARM7 ARM9 ARM11 XScale Cortex
    JTAG debugger and flash programmer
  • Andrus Adamchik at Feb 10, 2011 at 2:58 pm
    Content is created by a "runtime" object (normally a ServerRuntime) :

    ObjectContext context = cayenneRuntime.getContext();

    See an example in tutorial's "Main" class.

    Andrus

    On Feb 10, 2011, at 3:12 AM, Øyvind Harboe wrote:
    In my app I'm creating a new datacontext based on a
    existing datacontext, but the method I used to do this
    is now deprecated and I don't know what to replace
    it with:

    getDataContext().getParentDataDomain().createDataContext();

    ?

    --
    Øyvind Harboe

    Can Zylin Consulting help on your project?

    US toll free 1-866-980-3434 / International +47 51 87 40 27

    http://www.zylin.com/zy1000.html
    ARM7 ARM9 ARM11 XScale Cortex
    JTAG debugger and flash programmer
  • Øyvind Harboe at Feb 10, 2011 at 3:04 pm

    On Thu, Feb 10, 2011 at 3:57 PM, Andrus Adamchik wrote:
    Content is created by a "runtime" object (normally a ServerRuntime) :

    ObjectContext context = cayenneRuntime.getContext();

    See an example in tutorial's "Main" class.
    Can I get to the cayenneRuntime based on a datacontext
    class?

    Otherwise, I need to reorganize my program so as to push
    the cayenneRuntime to the far reaches of the code that needs
    it.

    --
    Øyvind Harboe

    Can Zylin Consulting help on your project?

    US toll free 1-866-980-3434 / International +47 51 87 40 27

    http://www.zylin.com/zy1000.html
    ARM7 ARM9 ARM11 XScale Cortex
    JTAG debugger and flash programmer
  • Andrus Adamchik at Feb 10, 2011 at 3:19 pm
    Yeah, one way is to reorg your code to make runtime accessible. An alternative would be to register a custom ObjectContextFactory with DI that will provide DataContext with access to runtime (or rather to org.apache.cayenne.di.Injector that is the configuration engine inside Runtime):

    class MyDataContextFactory extends DataContextFactory {

    @Override
    protected ObjectContext createdFromDataDomain(DataDomain parent) {

    ObjectContext context = super. createdFromDataDomain(parent);
    context.setUserProperty("injector", injector);
    return context;
    }
    }

    // create a peer ObjectContext:

    Injector i = (Injector) context.getUserProperty("injector");
    ObjectContext peerContext = i.getInstance(ObjectContextFactory.class).createContext();


    So that's an example of why DI is so cool (even in its current raw form) - you can have direct access to any piece of configuration and can change its behavior.

    Andrus

    On Feb 10, 2011, at 10:03 AM, Øyvind Harboe wrote:
    On Thu, Feb 10, 2011 at 3:57 PM, Andrus Adamchik wrote:
    Content is created by a "runtime" object (normally a ServerRuntime) :

    ObjectContext context = cayenneRuntime.getContext();

    See an example in tutorial's "Main" class.
    Can I get to the cayenneRuntime based on a datacontext
    class?

    Otherwise, I need to reorganize my program so as to push
    the cayenneRuntime to the far reaches of the code that needs
    it.

    --
    Øyvind Harboe

    Can Zylin Consulting help on your project?

    US toll free 1-866-980-3434 / International +47 51 87 40 27

    http://www.zylin.com/zy1000.html
    ARM7 ARM9 ARM11 XScale Cortex
    JTAG debugger and flash programmer
  • Øyvind Harboe at Feb 11, 2011 at 10:14 am
    Uhh.... injection again. Not in my repertoire as of writing :-)

    I'm using this code from within a subclass of
    CayenneDataObject, so I don't know who created the
    DataContext that this CayenneDataObject lives in.

    Can I get from a CayenneDataObject to a CayenneRuntime?


    I coded up the below which allows me to create a new
    DataContext with only the information in a DataContext:

    /** Duplicate code from deprecated method as we have no other way
    * to create a new DataContext based on an existing one.
    */
    public static DataContext createDataContext(DataContext dataContext)
    {
    DataDomain r = dataContext.getParentDataDomain();

    DataRowStore snapshotCache = r.isSharedCacheEnabled() ?
    r.getSharedSnapshotCache() :
    new DataRowStore(r.getName(), r.getProperties(), r.getEventManager());

    DataContext context = new DataContext(r, new ObjectStore(snapshotCache));

    context.setValidatingObjectsOnCommit(r.isValidatingObjectsOnCommit());
    return context;
    }


    --
    Øyvind Harboe

    Can Zylin Consulting help on your project?

    US toll free 1-866-980-3434 / International +47 51 87 40 27

    http://www.zylin.com/zy1000.html
    ARM7 ARM9 ARM11 XScale Cortex
    JTAG debugger and flash programmer

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedFeb 10, '11 at 8:12a
activeFeb 11, '11 at 10:14a
posts7
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2021 Grokbase