All,
I have been playing around with the
AuditInterceptor and I noticed that it didn't work if you had 'dynamic-update'
set.
It didn't recognise the modifications you do in the
Interceptor because it has already determined the optimized update
statement.
To fix this I did something like this:
public Boolean isUnsaved(Object o)
{
return null; } public int[] findDirty(Object o,
Serializable serializable, Object[] objects, Object[] objects1, String[]
strings, Type[] types) {
ArrayList ints = new ArrayList(); if(objects == null || objects1 == null){ return null; } for(int i = 0; i < objects.length; i++) { Type type = types[i]; if(type.getReturnedClass().equals(AuditInfo.class)) continue; try{ Object current = objects[i]; Object previous = objects1[i]; System.out.println("strings[i] = " + strings[i]); System.out.println("previous = " + previous); System.out.println("current = " + current); if(current == previous) continue; if(current != null && previous != null){ if(previous.toString().equals(current.toString())){ continue; } } }catch(Exception e){ e.printStackTrace(); } System.out.println("adding i = " + i); ints.add(new Integer(i)); } if(ints.size() > 0){ int[] intArray = new int[ints.size()+1]; int ind = 0; for(Iterator iterator = ints.iterator(); iterator.hasNext();) { Integer integer = (Integer) iterator.next(); intArray[ind++] = integer.intValue(); System.out.println("integer = " + integer); } intArray[ind++] = strings.length-1; // intArray[ind++] = strings.length - 2; return intArray; } return new int[0]; } public Object instantiate(Class
aClass, Serializable serializable) throws CallbackException
{
return null; } Which allowed me to only execute updates on the
specific fields that needed it. It does however update ALL of the
AuditInfo fields; I am sure there is a way around this.. but I
haven't worked on it yet.
You can also modify the findDirty logic to use the
Type array to do better value checking, but the to string implementation worked
for my simple needs.
Note: if you have composite types etc you will have
to modify this to use a compareTo or something.
Cheers
Troy
|