1 19 20 package org.apache.cayenne.access; 21 22 import java.util.Collection ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 28 import org.apache.cayenne.map.DbEntity; 29 import org.apache.cayenne.query.DeleteBatchQuery; 30 import org.apache.cayenne.query.InsertBatchQuery; 31 32 38 class DataDomainFlattenedBucket { 39 40 final DataDomainFlushAction parent; 41 final Map flattenedInsertQueries; 42 final Map flattenedDeleteQueries; 43 44 DataDomainFlattenedBucket(DataDomainFlushAction parent) { 45 this.parent = parent; 46 this.flattenedInsertQueries = new HashMap (); 47 this.flattenedDeleteQueries = new HashMap (); 48 } 49 50 boolean isEmpty() { 51 return flattenedInsertQueries.isEmpty() && flattenedDeleteQueries.isEmpty(); 52 } 53 54 void addFlattenedInsert(DbEntity flattenedEntity, FlattenedArcKey flattenedInsertInfo) { 55 56 InsertBatchQuery relationInsertQuery = (InsertBatchQuery) flattenedInsertQueries 57 .get(flattenedEntity); 58 59 if (relationInsertQuery == null) { 60 relationInsertQuery = new InsertBatchQuery(flattenedEntity, 50); 61 flattenedInsertQueries.put(flattenedEntity, relationInsertQuery); 62 } 63 64 DataNode node = parent.getDomain().lookupDataNode(flattenedEntity.getDataMap()); 65 Map flattenedSnapshot = flattenedInsertInfo.buildJoinSnapshotForInsert(node); 66 relationInsertQuery.add(flattenedSnapshot); 67 } 68 69 void addFlattenedDelete(DbEntity flattenedEntity, FlattenedArcKey flattenedDeleteInfo) { 70 71 DeleteBatchQuery relationDeleteQuery = (DeleteBatchQuery) flattenedDeleteQueries 72 .get(flattenedEntity); 73 if (relationDeleteQuery == null) { 74 boolean optimisticLocking = false; 75 relationDeleteQuery = new DeleteBatchQuery(flattenedEntity, 50); 76 relationDeleteQuery.setUsingOptimisticLocking(optimisticLocking); 77 flattenedDeleteQueries.put(flattenedEntity, relationDeleteQuery); 78 } 79 80 DataNode node = parent.getDomain().lookupDataNode(flattenedEntity.getDataMap()); 81 List flattenedSnapshots = flattenedDeleteInfo.buildJoinSnapshotsForDelete(node); 82 if (!flattenedSnapshots.isEmpty()) { 83 Iterator snapsIt = flattenedSnapshots.iterator(); 84 while (snapsIt.hasNext()) { 85 relationDeleteQuery.add((Map ) snapsIt.next()); 86 } 87 } 88 } 89 90 void appendInserts(Collection queries) { 91 if (!flattenedInsertQueries.isEmpty()) { 92 queries.addAll(flattenedInsertQueries.values()); 93 } 94 } 95 96 void appendDeletes(Collection queries) { 97 if (!flattenedDeleteQueries.isEmpty()) { 98 queries.addAll(flattenedDeleteQueries.values()); 99 } 100 } 101 } 102 | Popular Tags |