openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Talbut <jtal...@spudsoft.co.uk>
Subject Any way to access original field values by name from Auditor context
Date Mon, 10 Feb 2014 14:09:47 GMT
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