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 Details

  • Constructor Details

  • 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)