1 19 20 package org.apache.cayenne.query; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import java.util.List ; 26 import java.util.Map ; 27 28 import org.apache.cayenne.map.DbAttribute; 29 import org.apache.cayenne.map.DbEntity; 30 31 36 public class DeleteBatchQuery extends BatchQuery { 37 38 protected List qualifierSnapshots; 39 protected List dbAttributes; 40 protected boolean usingOptimisticLocking; 41 42 private List qualifierAttributes; 43 private Collection nullQualifierNames; 44 45 53 public DeleteBatchQuery(DbEntity dbEntity, int batchCapacity) { 54 this(dbEntity, dbEntity.getPrimaryKey(), Collections.EMPTY_SET, batchCapacity); 55 } 56 57 66 public DeleteBatchQuery(DbEntity dbEntity, List qualifierAttributes, 67 Collection nullQualifierNames, int batchCapacity) { 68 69 super(dbEntity); 70 71 this.qualifierAttributes = qualifierAttributes; 72 this.nullQualifierNames = nullQualifierNames != null 73 ? nullQualifierNames 74 : Collections.EMPTY_SET; 75 76 qualifierSnapshots = new ArrayList (batchCapacity); 77 dbAttributes = new ArrayList (qualifierAttributes.size()); 78 dbAttributes.addAll(qualifierAttributes); 79 batchIndex = -1; 80 } 81 82 87 public boolean isNull(DbAttribute attribute) { 88 return nullQualifierNames.contains(attribute.getName()); 89 } 90 91 96 public boolean isUsingOptimisticLocking() { 97 return usingOptimisticLocking; 98 } 99 100 103 public void setUsingOptimisticLocking(boolean usingOptimisticLocking) { 104 this.usingOptimisticLocking = usingOptimisticLocking; 105 } 106 107 110 public List getQualifierAttributes() { 111 return Collections.unmodifiableList(qualifierAttributes); 112 } 113 114 public Object getValue(int dbAttributeIndex) { 115 DbAttribute attribute = (DbAttribute) dbAttributes.get(dbAttributeIndex); 116 return getCurrentQualifier().get(attribute.getName()); 117 } 118 119 public void add(Map dataObjectId) { 120 qualifierSnapshots.add(dataObjectId); 121 } 122 123 public int size() { 124 return qualifierSnapshots.size(); 125 } 126 127 public List getDbAttributes() { 128 return dbAttributes; 129 } 130 131 136 public Map getCurrentQualifier() { 137 return (Map ) qualifierSnapshots.get(batchIndex); 138 } 139 } 140 | Popular Tags |