use of org.apache.cayenne.query.InsertBatchQuery in project cayenne by apache.
the class DataDomainInsertBucket method appendQueriesInternal.
@Override
void appendQueriesInternal(Collection<Query> queries) {
DataDomainDBDiffBuilder diffBuilder = new DataDomainDBDiffBuilder();
EntitySorter sorter = parent.getDomain().getEntitySorter();
sorter.sortDbEntities(dbEntities, false);
for (DbEntity dbEntity : dbEntities) {
Collection<DbEntityClassDescriptor> descriptors = descriptorsByDbEntity.get(dbEntity);
InsertBatchQuery batch = new InsertBatchQuery(dbEntity, 27);
for (DbEntityClassDescriptor descriptor : descriptors) {
diffBuilder.reset(descriptor);
List<Persistent> objects = objectsByDescriptor.get(descriptor.getClassDescriptor());
if (objects.isEmpty()) {
continue;
}
checkReadOnly(descriptor.getEntity());
createPermIds(descriptor, objects);
sorter.sortObjectsForEntity(descriptor.getEntity(), objects, false);
for (Persistent o : objects) {
Map<String, Object> snapshot = diffBuilder.buildDBDiff(parent.objectDiff(o.getObjectId()));
// values so creating an empty changes map
if (snapshot == null) {
snapshot = new HashMap<>();
}
batch.add(snapshot, o.getObjectId());
if (!descriptor.isMaster()) {
trackFlattenedInsert(descriptor, o);
}
}
}
queries.add(batch);
}
}
Aggregations