1 56 57 package org.objectstyle.cayenne.access.util; 58 59 import java.util.ArrayList ; 60 import java.util.HashMap ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 import java.util.Map ; 64 65 import org.objectstyle.cayenne.access.DataNode; 66 import org.objectstyle.cayenne.map.ObjEntity; 67 import org.objectstyle.cayenne.query.Query; 68 69 73 public class DataNodeCommitHelper { 74 public static final int INSERT = 1; 75 public static final int UPDATE = 2; 76 public static final int DELETE = 3; 77 78 protected DataNode node; 79 protected List objEntitiesForInsert = new ArrayList (); 80 protected List objEntitiesForDelete = new ArrayList (); 81 protected List objEntitiesForUpdate = new ArrayList (); 82 protected Map flattenedInsertQueries = new HashMap (); 83 protected Map flattenedDeleteQueries = new HashMap (); 84 protected List queries = new ArrayList (); 85 86 90 public static DataNodeCommitHelper getHelperForNode( 91 List helpers, 92 DataNode node) { 93 94 DataNodeCommitHelper helper = null; 95 Iterator it = helpers.iterator(); 96 while (it.hasNext()) { 97 DataNodeCommitHelper itHelper = (DataNodeCommitHelper) it.next(); 98 if (itHelper.getNode() == node) { 99 helper = itHelper; 100 break; 101 } 102 } 103 104 if (helper == null) { 105 helper = new DataNodeCommitHelper(node); 106 helpers.add(helper); 107 } 108 109 return helper; 110 } 111 112 public DataNodeCommitHelper(DataNode node) { 113 this.node = node; 114 } 115 116 117 public void addToEntityList(ObjEntity ent, int listType) { 118 switch (listType) { 119 case 1 : 120 objEntitiesForInsert.add(ent); 121 break; 122 case 2 : 123 objEntitiesForUpdate.add(ent); 124 break; 125 case 3 : 126 objEntitiesForDelete.add(ent); 127 break; 128 } 129 } 130 131 public void addToQueries(Query q) { 132 queries.add(q); 133 } 134 135 138 public DataNode getNode() { 139 return node; 140 } 141 142 145 public List getQueries() { 146 return queries; 147 } 148 152 public List getObjEntitiesForDelete() { 153 return objEntitiesForDelete; 154 } 155 156 160 public List getObjEntitiesForInsert() { 161 return objEntitiesForInsert; 162 } 163 164 168 public List getObjEntitiesForUpdate() { 169 return objEntitiesForUpdate; 170 } 171 172 public Map getFlattenedDeleteQueries() { 173 return flattenedDeleteQueries; 174 } 175 176 public Map getFlattenedInsertQueries() { 177 return flattenedInsertQueries; 178 } 179 } 180 | Popular Tags |