1 28 29 package com.caucho.ejb.entity; 30 31 import com.caucho.amber.AmberQuery; 32 import com.caucho.amber.manager.AmberConnection; 33 34 import java.util.AbstractSet ; 35 import java.util.ArrayList ; 36 import java.util.Iterator ; 37 38 41 abstract public class CmpSetImpl extends AbstractSet { 42 private ArrayList _base = new ArrayList (); 43 private AmberQuery _query; 44 45 public void __caucho_init(AmberConnection aConn) 46 { 47 _query.init(aConn); 48 } 49 50 protected void fill(AmberQuery query) 51 { 52 try { 53 _query = query; 54 55 _base.clear(); 56 query.list(_base); 57 } catch (RuntimeException e) { 58 throw e; 59 } catch (Exception e) { 60 throw new RuntimeException (e); 61 } 62 } 63 64 public int size() 65 { 66 return _base.size(); 67 } 68 69 public Object get(int index) 70 { 71 return _base.get(index); 72 } 73 74 public Object remove(int index) 75 { 76 Object oldValue = _base.remove(index); 77 78 if (removeImpl(oldValue)) 79 return oldValue; 80 else 81 return null; 82 } 83 84 protected boolean removeImpl(Object oldValue) 85 { 86 throw new UnsupportedOperationException (); 87 } 88 89 public Iterator iterator() 90 { 91 return new Itr(); 92 } 93 94 97 public class Itr implements Iterator { 98 int _index; 99 int _size; 100 101 Itr() 102 { 103 _size = size(); 104 } 105 106 109 public boolean hasNext() 110 { 111 return _index < _size; 112 } 113 114 117 public Object next() 118 { 119 if (_index < _size) 120 return get(_index++); 121 else 122 return null; 123 } 124 125 128 public void remove() 129 { 130 _index--; 131 _size--; 132 133 CmpSetImpl.this.remove(_index); 134 } 135 } 136 } 137 | Popular Tags |