1 17 18 package org.objectweb.jac.aspects.transaction; 19 20 21 22 import java.util.Iterator ; 23 import java.util.Vector ; 24 import org.apache.log4j.Logger; 25 import org.objectweb.jac.core.Wrappee; 26 import org.objectweb.jac.core.rtti.ClassItem; 27 import org.objectweb.jac.core.rtti.ClassRepository; 28 import org.objectweb.jac.core.rtti.CollectionItem; 29 import org.objectweb.jac.core.rtti.FieldItem; 30 import org.objectweb.jac.util.Log; 31 32 public class Merging { 33 34 static Logger logger = Logger.getLogger("transaction"); 35 36 public static void merge(Wrappee receptor, 37 Wrappee original, 38 Wrappee modified) throws Exception { 39 40 logger.debug("merging "+modified+" with "+receptor); 41 42 Vector peerChangedFields = diffFields(receptor,original); 43 44 Vector changedFields = diffFields(original,modified); 45 46 Iterator it = changedFields.iterator(); 47 while(it.hasNext()) { 48 FieldItem field = (FieldItem)it.next(); 49 if( peerChangedFields.contains( field ) ) { 50 throw new RuntimeException ("concurrent modification during transaction on " 51 +field); 52 } 53 if( field instanceof CollectionItem ) { 54 } else { 56 field.setThroughWriter(receptor,field.get(modified)); 59 } 60 } 61 } 62 63 public static Vector diffFields(Wrappee o1, Wrappee o2) { 64 65 Vector result = new Vector (); 66 ClassItem cli = ClassRepository.get().getClass(o1.getClass()); 67 FieldItem[] fields = cli.getPrimitiveFields(); 68 69 for( int i=0; i<fields.length; i++ ) { 71 if(!fields[i].get(o1) 72 .equals(fields[i].get(o2))) { 73 logger.debug(fields[i]+" differs after transaction"); 74 result.add(fields[i]); 75 } 76 } 77 78 CollectionItem[] collections = cli.getCollections(); 79 80 87 88 return result; 89 90 } 91 92 } 93 94 95 | Popular Tags |