Search in sources :

Example 21 with InsertBatchQuery

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);
    }
}
Also used : EntitySorter(org.apache.cayenne.map.EntitySorter) DbEntity(org.apache.cayenne.map.DbEntity) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) Persistent(org.apache.cayenne.Persistent)

Aggregations

InsertBatchQuery (org.apache.cayenne.query.InsertBatchQuery)21 Test (org.junit.Test)11 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)9 DbAttribute (org.apache.cayenne.map.DbAttribute)8 DbEntity (org.apache.cayenne.map.DbEntity)7 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)4 ObjectId (org.apache.cayenne.ObjectId)4 DataNode (org.apache.cayenne.access.DataNode)4 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)4 EntityResolver (org.apache.cayenne.map.EntityResolver)4 SimpleLockingTestEntity (org.apache.cayenne.testdo.locking.SimpleLockingTestEntity)4 DataRow (org.apache.cayenne.DataRow)3 DbAdapter (org.apache.cayenne.dba.DbAdapter)3 BatchQuery (org.apache.cayenne.query.BatchQuery)3 UnitDbAdapter (org.apache.cayenne.unit.UnitDbAdapter)3 ArrayList (java.util.ArrayList)2 BatchQueryRow (org.apache.cayenne.query.BatchQueryRow)2 UpdateBatchQuery (org.apache.cayenne.query.UpdateBatchQuery)2 PreparedStatement (java.sql.PreparedStatement)1 HashMap (java.util.HashMap)1