Package org.eclipse.net4j.db

# Class BatchingIDChanger

java.lang.Object
org.eclipse.net4j.db.BatchingIDChanger

All Implemented Interfaces:
  `org.eclipse.net4j.util.IDChanger.ChangeHandler`

public class BatchingIDChanger extends Object implements org.eclipse.net4j.util.IDChanger.ChangeHandler
A `IDChanger.ChangeHandler` that batches SQL update statements to change IDs in a database table.

The class uses a `StatementBatcher` to accumulate SQL statements for execution.

This class is expected to be used with `IDChanger.changeIDs(Map, ChangeHandler)` to perform ID changes in bulk. Here is an example of how to use it:

     Mapinvalid input: '<'Integer, Integer> idChanges = ...; // Map of old IDs to new IDs.

     // Create a StatementBatcher with a try-with-resources statement.
     // The final execution of the batch will occur when the batcher is closed.
     try (StatementBatcher batcher = new StatementBatcher(connection))
     {
       IDBField idField = ...; // Obtain the ID field from your database schema.
       BatchingIDChanger handler = new BatchingIDChanger(batcher, idField);

       // Perform the ID changes using the handler.
       IDChanger.changeIDs(idChanges, handler);
     }

Since:
  4.13
Author:
  Eike Stepper

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final StatementBatcher`
`batcher`
`protected final IDBField`
`idField`
`protected final IDBTable`
`table`

## Constructor Summary

Constructors
Constructor
Description
`BatchingIDChanger(StatementBatcher batcher, IDBField idField)`
`BatchingIDChanger(StatementBatcher batcher, IDBField idField, IDBTable table)`

## Method Summary

Modifier and Type
Method
Description
`protected final void`
`batch(Object newValueExpression, String whereCondition)`
`void`
`handleArbitraryChanges(List<Integer> affectedIDs, int shift)`
`void`
`handleConsecutiveChanges(int firstID, int lastID, int shift)`
`void`
`handleSingleChange(int oldID, int newID)`
`protected final String`
`shiftStr(int shift)`
`protected String`
`sql(Object newValue, String condition)`

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

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

## Field Details

### batcher

protected final StatementBatcher batcher

### idField

protected final IDBField idField

### table

protected final IDBTable table

## Constructor Details

### BatchingIDChanger

public BatchingIDChanger(StatementBatcher batcher, IDBField idField)

### BatchingIDChanger

public BatchingIDChanger(StatementBatcher batcher, IDBField idField, IDBTable table)

## Method Details

### handleSingleChange

public void handleSingleChange(int oldID, int newID)

Specified by:
  `handleSingleChange` in interface `org.eclipse.net4j.util.IDChanger.ChangeHandler`

### handleConsecutiveChanges

public void handleConsecutiveChanges(int firstID, int lastID, int shift)

Specified by:
  `handleConsecutiveChanges` in interface `org.eclipse.net4j.util.IDChanger.ChangeHandler`

### handleArbitraryChanges

public void handleArbitraryChanges(List<Integer> affectedIDs, int shift)

Specified by:
  `handleArbitraryChanges` in interface `org.eclipse.net4j.util.IDChanger.ChangeHandler`

### sql

protected String sql(Object newValue, String condition)

### batch

protected final void batch(Object newValueExpression, String whereCondition)

### shiftStr

protected final String shiftStr(int shift)