openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From is_maximum <mnr...@gmail.com>
Subject how to get dirty fields
Date Tue, 14 Oct 2008 13:57:01 GMT

Hi all,

We are planning to implement a tracking system in which we are using
LifecycleListeners of OpenJpa. The problem is that the state manager of
OpenJpa doesn't return only dirty fields but all the fields.

Here is the snippet code to retrieve the required fields:



    public static String getDirtyFields(Object object) {
        OpenJPAEntityManager entityManager =
OpenJPAPersistence.getEntityManager(object);//TODO: or EntityManager
        PersistenceCapable persistenceCapable =
ImplHelper.toPersistenceCapable(object, entityManager);
        OpenJPAStateManager stateManager =
(OpenJPAStateManager)persistenceCapable.pcGetStateManager();
        ClassMetaData metaData = stateManager.getMetaData();
        BitSet dirty = stateManager.getDirty();
        int i = dirty.nextSetBit(0);
        String output = "";
        while(i != -1) {

            String fieldName =
stateManager.getMetaData().getField(i).getName();
            String fieldValue =
stateManager.getMetaData().getField(i).getValue().toString();
            output = output + "FieldName: "+ fieldName+ ", FieldValue: "+
fieldValue+ "\n";
            i= dirty.nextSetBit(i+1);
        }
        return output;
    }



Is there anything wrong with this code? 

thanks

-- 
View this message in context: http://n2.nabble.com/how-to-get-dirty-fields-tp1332610p1332610.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message