1 package org.apache.ojb.broker.util.collections; 2 3 17 18 import java.util.Iterator ; 19 import java.util.Vector ; 20 import org.apache.ojb.broker.PersistenceBroker; 21 import org.apache.ojb.broker.PersistenceBrokerException; 22 23 34 public class RemovalAwareSet extends ManageableHashSet implements IRemovalAwareCollection 35 { 36 private Vector allObjectsToBeRemoved = new Vector (); 37 38 41 public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException 42 { 43 allObjectsToBeRemoved.removeAll(this); 46 47 Iterator iter = allObjectsToBeRemoved.iterator(); 48 while (iter.hasNext()) 49 { 50 broker.delete(iter.next()); 51 } 52 allObjectsToBeRemoved.clear(); 53 } 54 55 protected void registerForDeletion(Object toBeRemoved) 56 { 57 if (!allObjectsToBeRemoved.contains(toBeRemoved)) 59 { 60 this.allObjectsToBeRemoved.add(toBeRemoved); 61 } 62 } 63 64 67 public boolean remove(Object o) 68 { 69 boolean result = super.remove(o); 70 registerForDeletion(o); 71 return result; 72 } 73 74 77 public synchronized void removeAllElements() 78 { 79 for (Iterator it = iterator(); it.hasNext();) 80 { 81 registerForDeletion(it.next()); 82 } 83 super.clear(); 84 } 85 86 public synchronized void clear() 87 { 88 removeAllElements(); 89 } 90 91 public void resetDeleted() 92 { 93 this.allObjectsToBeRemoved.clear(); 94 } 95 96 } 97 | Popular Tags |