Java Code Examples for java.sql.CallableStatement#setArray()

The following examples show how to use java.sql.CallableStatement#setArray() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: binnavi   File: PostgreSQLTypeFunctions.java    License: Apache License 2.0 7 votes vote down vote up
/**
 * Increments the offsets of all members which have an offset > startOffset.
 *
 * @param connection The connection to the database.
 * @param members The ids of the members whose updates should be updated.
 * @param delta The value that is added to all member offsets.
 * @param implicitDelta The delta that is added to the implicitly update member offsets.
 * @param implicitlyUpdatedMembers
 * @param module The module that contains the members.
 * @throws CouldntSaveDataException Thrown if the member offsets could not be updated.
 */
public static void updateMemberOffsets(final Connection connection,
    final List<Integer> members,
    final int delta,
    final List<Integer> implicitlyUpdatedMembers,
    final int implicitDelta,
    final INaviModule module) throws CouldntSaveDataException {
  try {
    final CallableStatement statement =
        connection.prepareCall("{ call update_member_offsets(?, ?, ?, ?, ?) }");
    try {
      statement.setInt(1, module.getConfiguration().getId());
      statement.setArray(2, connection.createArrayOf("int4", members.toArray()));
      statement.setInt(3, delta);
      statement.setArray(4, connection.createArrayOf("int4", implicitlyUpdatedMembers.toArray()));
      statement.setInt(5, implicitDelta);
      statement.execute();
    } finally {
      statement.close();
    }
  } catch (final SQLException exception) {
    throw new CouldntSaveDataException(exception);
  }
}