openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Boblitz John <john.bobl...@bertschi.com>
Subject RE: Any way to access original field values by name from Auditor context
Date Mon, 10 Feb 2014 15:36:56 GMT
I was working on something similar and this might get you closer

        StateManagerImpl sm = (StateManagerImpl)currentState.pcGetStateManager();
        SaveFieldManager sfm = sm.getSaveFieldManager();
        PersistenceCapable oldState = sfm.getState();

I believe you must also specifiy openjpa.RestoreState so that this can work ...

Hope this helps ...

John

> -----Original Message-----
> From: James Talbut [mailto:jtalbut@spudsoft.co.uk]
> Sent: Monday, February 10, 2014 3:10 PM
> To: users@openjpa.apache.org
> Subject: Any way to access original field values by name from Auditor context
> 
> Hi,
> 
> I'm trying to record old and new field values in an Auditor.
> Using something like this I can get the new value (using the
> audited.getUpdatedFields() to provide the values for 'field'):
> 
>     private Object getFieldValue(Broker broker, Object object, String field) {
>         if (object == null) {
>             return null;
>         }
>         PersistenceCapable persistenceCapable =
> ImplHelper.toPersistenceCapable(object,
> JPAFacadeHelper.toEntityManager(broker));
>         OpenJPAStateManager stateManager =
> (OpenJPAStateManager)persistenceCapable.pcGetStateManager();
>         if (stateManager == null) {
>             return null;
>         }
>         int fieldIdx = stateManager.getMetaData().getField(field).getIndex();
>         Object value = stateManager.fetch(fieldIdx);
>         if ((value instanceof RowSetHolder) &&
>                 (((RowSetHolder)value).getSize() == 0)) {
>             return null;
>         }
>         return value;
>     }
> 
> But the old value has no state manager, so pcGetStateManager always returns
> null.
> 
> The old object does have the correct values set on it, but I don't have to have to
> use reflection (and somehow work out the mapping from field name to method
> name).
> 
> Is there any equivalent to the above that will work for the old values (as
> returned by audited.getOriginalObject()) ?
> 
> Thanks.
> 
> Jim

Mime
View raw message