1 56 package org.objectstyle.cayenne.query; 57 58 import java.util.ArrayList ; 59 import java.util.Collection ; 60 import java.util.Collections ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 import java.util.Map ; 64 65 import org.apache.commons.collections.IteratorUtils; 66 import org.objectstyle.cayenne.map.DbAttribute; 67 import org.objectstyle.cayenne.map.DbEntity; 68 69 74 public class DeleteBatchQuery extends BatchQuery { 75 private List qualifierSnapshots; 76 private List dbAttributes; 77 private Iterator qualifierIterator = IteratorUtils.EMPTY_ITERATOR; 78 private Map currentQualifier = Collections.EMPTY_MAP; 79 80 private boolean usingOptimisticLocking; 81 private List qualifierAttributes; 82 private Collection nullQualifierNames; 83 84 92 public DeleteBatchQuery(DbEntity objectEntity, 93 List qualifierAttributes, 94 Collection nullQualifierNames, 95 int batchCapacity) { 96 97 super(objectEntity); 98 99 this.qualifierAttributes = qualifierAttributes; 100 this.nullQualifierNames = 101 nullQualifierNames != null ? nullQualifierNames : Collections.EMPTY_SET; 102 103 qualifierSnapshots = new ArrayList (batchCapacity); 104 dbAttributes = new ArrayList (qualifierAttributes.size()); 105 dbAttributes.addAll(qualifierAttributes); 106 } 108 109 116 public DeleteBatchQuery(DbEntity dbEntity, int batchCapacity) { 117 this(dbEntity, dbEntity.getPrimaryKey(), Collections.EMPTY_SET, batchCapacity); 118 } 119 120 121 127 public boolean isNull(DbAttribute attribute) { 128 return nullQualifierNames.contains(attribute.getName()); 129 } 130 131 136 public boolean isUsingOptimisticLocking() { 137 return usingOptimisticLocking; 138 } 139 140 143 public void setUsingOptimisticLocking(boolean usingOptimisticLocking) { 144 this.usingOptimisticLocking = usingOptimisticLocking; 145 } 146 147 150 public List getQualifierAttributes() { 151 return Collections.unmodifiableList(qualifierAttributes); 152 } 153 154 public void reset() { 155 qualifierIterator = qualifierSnapshots.iterator(); 156 currentQualifier = Collections.EMPTY_MAP; 157 } 158 159 public boolean next() { 160 if (!qualifierIterator.hasNext()) 161 return false; 162 currentQualifier = (Map ) qualifierIterator.next(); 163 currentQualifier = (currentQualifier != null ? currentQualifier : Collections.EMPTY_MAP); 164 return true; 165 } 166 167 public Object getValue(int dbAttributeIndex) { 168 DbAttribute attribute = 169 (DbAttribute) dbAttributes.get(dbAttributeIndex); 170 return currentQualifier.get(attribute.getName()); 171 } 172 173 public void add(Map dataObjectId) { 174 qualifierSnapshots.add(dataObjectId); 175 } 176 177 public int size() { 178 return qualifierSnapshots.size(); 179 } 180 181 public List getDbAttributes() { 182 return dbAttributes; 183 } 184 185 190 public Map getCurrentQualifier() { 191 return currentQualifier; 192 } 193 } 194 | Popular Tags |