You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by is_maximum <mn...@gmail.com> on 2008/10/16 14:51:28 UTC

how to determine dirty fields

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-determine-dirty-fields-tp1340915p1340915.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.