org.apache.cayenne.query

## Class InsertBatchQuery

- java.lang.Object
- - org.apache.cayenne.query.BatchQuery
  - - org.apache.cayenne.query.InsertBatchQuery

- All Implemented Interfaces:
    Serializable, ConfigurationNode, Query

      public class InsertBatchQuery
      extends BatchQuery

  Batched INSERT query. Allows inserting multiple object snapshots (DataRows) for a given DbEntity in a single query. InsertBatchQuery normally is not used directly. Rather DataContext creates one internally when committing DataObjects.
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected List<DbAttribute>` | `dbAttributes`
    `protected List<ObjectId>` | `objectIds`
    `protected List<Map>` | `objectSnapshots`

    - ### Fields inherited from class org.apache.cayenne.query.BatchQuery

      `batchIndex, dataMap, dbEntity, name`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `InsertBatchQuery(DbEntity entity, int batchCapacity)` Creates new InsertBatchQuery for a given DbEntity and estimated capacity.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(Map snapshot)` Adds a snapshot to batch.
    `void` | `add(Map snapshot, ObjectId id)` Adds a snapshot to batch.
    `List<DbAttribute>` | `getDbAttributes()` Returns a list of DbAttributes describing batch parameters.
    `ObjectId` | `getObjectId()` Returns an ObjectId associated with the current batch iteration.
    `Object` | `getValue(int dbAttributeIndex)` Returns a value at a given index for the current batch iteration.
    `int` | `size()` Returns the number of parameter rows in a batch.

    - ### Methods inherited from class org.apache.cayenne.query.BatchQuery

      `acceptVisitor, createSQLAction, getDataMap, getDbEntity, getMetaData, getName, getValue, isEmpty, isUsingOptimisticLocking, next, reset, route, setDataMap, setName`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### objectIds

          protected List<ObjectId> objectIds

      Since:
        1.2

    - #### objectSnapshots

          protected List<Map> objectSnapshots

    - #### dbAttributes

          protected List<DbAttribute> dbAttributes

  - ### Constructor Detail

    - #### InsertBatchQuery

          public InsertBatchQuery(DbEntity entity,
                                  int batchCapacity)

      Creates new InsertBatchQuery for a given DbEntity and estimated capacity.

  - ### Method Detail

    - #### getValue

          public Object getValue(int dbAttributeIndex)

      Description copied from class: `BatchQuery`
      Returns a value at a given index for the current batch iteration.
      Specified by:
        `getValue` in class `BatchQuery`

    - #### add

          public void add(Map snapshot)

      Adds a snapshot to batch. A shortcut for "add(snapshot, null)".

    - #### add

          public void add(Map snapshot,
                          ObjectId id)

      Adds a snapshot to batch. Optionally stores the object id for the snapshot. Note that snapshot can hold either the real values or the instances of org.apache.commons.collections.Factory that will be resolved to the actual value on the spot, thus allowing deferred propagated keys resolution.
      Since:
        1.2

    - #### size

          public int size()

      Description copied from class: `BatchQuery`
      Returns the number of parameter rows in a batch.
      Specified by:
        `size` in class `BatchQuery`

    - #### getDbAttributes

          public List<DbAttribute> getDbAttributes()

      Description copied from class: `BatchQuery`
      Returns a list of DbAttributes describing batch parameters.
      Specified by:
        `getDbAttributes` in class `BatchQuery`

    - #### getObjectId

          public ObjectId getObjectId()

      Returns an ObjectId associated with the current batch iteration. Used internally by Cayenne to match current iteration with a specific object and assign it generated keys.
      Overrides:
        `getObjectId` in class `BatchQuery`
      Since:
        1.2

Copyright © 2001–2018 Apache Cayenne. All rights reserved.