cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken Anderson <ken.ander...@amphorainc.com>
Subject Re: Creating a fault for an ObjectId
Date Wed, 15 Feb 2017 15:20:46 GMT
I do this:

dataObject = (DataObject) Cayenne.objectForPK(getObjectContext(), MyEntity.class, oid);

But it will do the fetch if it’s not already in cache.

Ken

Ken Anderson
CTO Amphora, Inc.
Mobile:   +1 914 262 8540



www.amphorainc.com <http://www.amphorainc.com/>




On 2/15/17, 9:59 AM, "Hugi Thordarson" <hugi@karlmenn.is> wrote:

    Thanks Amadeo, but I ended up creating a method that looks like this. It would be nice
to get some feedback on it, if I’m violating any Cayenne Commandments.

    /**
     * @return An existing object or fault if registered with the OC, otherwise creates a
new hollow object based on the given ObjectId.
     */
    public static Persistent faultForObjectId( ObjectContext oc, ObjectId objectId ) {
    Persistent object = (Persistent) oc.getGraphManager().getNode( objectId );

    if( object == null ) {
    ClassDescriptor descriptor = oc.getEntityResolver().getClassDescriptor(objectId.getEntityName());

    object = (Persistent) descriptor.createObject();

    object.setPersistenceState(PersistenceState.HOLLOW);
    object.setObjectContext(oc);
    object.setObjectId(objectId);

    oc.getGraphManager().registerNode(objectId, object);
    }

    return object;
    }

    Cheers,
    - hugi


    > On 15. feb. 2017, at 14:41, Amedeo Mantica <amedeomantica@me.com> wrote:
    >
    > may be you want invalidateObject ?
    >
    >> On 15 Feb 2017, at 14:15, Hugi Thordarson <hugi@karlmenn.is> wrote:
    >>
    >> Hi all,
    >> I need to get a fault for an ObjectId from an ObjectContext. How would I do this?
    >>
    >> I don’t see any public API for this—the implementation of createFault in
CayenneContext seems to get me halfway there, but it will not return an existing fault, only
create new ones.
    >>
    >> Cheers,
    >> - hugi
    >



Confidentiality Notice: This e-mail and accompanying documents contain confidential information
intended for a specific individual and purpose. This e-mailed information is private and protected
by law. If you are not the intended recipient, you are hereby notified that any disclosure,
copying, or distribution, or the taking of any action based on the contents of this information,
is strictly prohibited.
Mime
View raw message