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.ObjectId; 29 import org.apache.cayenne.map.DbAttribute; 30 import org.apache.cayenne.map.DbEntity; 31 32 37 public class UpdateBatchQuery extends BatchQuery { 38 39 42 protected List objectIds; 43 44 protected List qualifierSnapshots; 45 protected List updateSnapshots; 46 47 protected boolean usingOptimisticLocking; 48 49 private List updatedAttributes; 50 private List qualifierAttributes; 51 private Collection nullQualifierNames; 52 private List dbAttributes; 53 54 64 public UpdateBatchQuery(DbEntity dbEntity, List qualifierAttributes, 65 List updatedAttribute, Collection nullQualifierNames, int batchCapacity) { 66 67 super(dbEntity); 68 69 this.updatedAttributes = updatedAttribute; 70 this.qualifierAttributes = qualifierAttributes; 71 this.nullQualifierNames = nullQualifierNames != null 72 ? nullQualifierNames 73 : Collections.EMPTY_SET; 74 75 qualifierSnapshots = new ArrayList (batchCapacity); 76 updateSnapshots = new ArrayList (batchCapacity); 77 objectIds = new ArrayList (batchCapacity); 78 79 dbAttributes = new ArrayList (updatedAttributes.size() 80 + qualifierAttributes.size()); 81 dbAttributes.addAll(updatedAttributes); 82 dbAttributes.addAll(qualifierAttributes); 83 } 84 85 90 public boolean isNull(DbAttribute attribute) { 91 return nullQualifierNames.contains(attribute.getName()); 92 } 93 94 99 public boolean isUsingOptimisticLocking() { 100 return usingOptimisticLocking; 101 } 102 103 106 public void setUsingOptimisticLocking(boolean usingOptimisticLocking) { 107 this.usingOptimisticLocking = usingOptimisticLocking; 108 } 109 110 public Object getValue(int dbAttributeIndex) { 111 DbAttribute attribute = (DbAttribute) dbAttributes.get(dbAttributeIndex); 112 113 Object snapshot = (dbAttributeIndex < updatedAttributes.size()) ? updateSnapshots 116 .get(batchIndex) : qualifierSnapshots.get(batchIndex); 117 return getValue((Map ) snapshot, attribute); 118 } 119 120 123 public void add(Map qualifierSnapshot, Map updateSnapshot) { 124 add(qualifierSnapshot, updateSnapshot, null); 125 } 126 127 132 public void add(Map qualifierSnapshot, Map updateSnapshot, ObjectId id) { 133 qualifierSnapshots.add(qualifierSnapshot); 134 updateSnapshots.add(updateSnapshot); 135 objectIds.add(id); 136 } 137 138 public int size() { 139 return qualifierSnapshots.size(); 140 } 141 142 public List getDbAttributes() { 143 return dbAttributes; 144 } 145 146 149 public List getUpdatedAttributes() { 150 return Collections.unmodifiableList(updatedAttributes); 151 } 152 153 156 public List getQualifierAttributes() { 157 return Collections.unmodifiableList(qualifierAttributes); 158 } 159 160 165 public Map getCurrentQualifier() { 166 return (Map ) qualifierSnapshots.get(batchIndex); 167 } 168 169 176 public ObjectId getObjectId() { 177 return (ObjectId) objectIds.get(batchIndex); 178 } 179 } 180 | Popular Tags |