cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hugi Thordarson <h...@karlmenn.is>
Subject Re: Creating a fault for an ObjectId
Date Wed, 15 Feb 2017 14:59:48 GMT
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
> 


Mime
View raw message