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 -
Constructor Summary
ConstructorsConstructorDescriptionBatchingIDChanger(StatementBatcher batcher, IDBField idField) BatchingIDChanger(StatementBatcher batcher, IDBField idField, IDBTable table) -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidvoidhandleArbitraryChanges(List<Integer> affectedIDs, int shift) voidhandleConsecutiveChanges(int firstID, int lastID, int shift) voidhandleSingleChange(int oldID, int newID) protected final StringshiftStr(int shift) protected String
-
Field Details
-
batcher
-
idField
-
table
-
-
Constructor Details
-
BatchingIDChanger
-
BatchingIDChanger
-
-
Method Details
-
handleSingleChange
public void handleSingleChange(int oldID, int newID) - Specified by:
handleSingleChangein interfaceorg.eclipse.net4j.util.IDChanger.ChangeHandler
-
handleConsecutiveChanges
public void handleConsecutiveChanges(int firstID, int lastID, int shift) - Specified by:
handleConsecutiveChangesin interfaceorg.eclipse.net4j.util.IDChanger.ChangeHandler
-
handleArbitraryChanges
- Specified by:
handleArbitraryChangesin interfaceorg.eclipse.net4j.util.IDChanger.ChangeHandler
-
sql
-
batch
-
shiftStr
-