Changeset 6714


Ignore:
Timestamp:
Feb 3, 2015, 1:02:57 PM (9 years ago)
Author:
Nicklas Nordborg
Message:

References #1914: Exception from DbCleaner?

Divide the delete query into chunks of 10000 at a time. This is well below the limit in PostgreSQL and hopefully works in MySQL as well, though I have not been able to find any information about any limit for MySQL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.4-stable/src/core/net/sf/basedb/core/ChangeHistory.java

    r6355 r6714  
    2222package net.sf.basedb.core;
    2323
     24import java.util.ArrayList;
    2425import java.util.Date;
    2526import java.util.List;
     
    158159  }
    159160 
     161  private static final int MAX_PARAMETERS_IN_QUERY = 10000;
    160162 
    161163  /**
     
    218220        */
    219221        query.setInteger("type", itemType);
    220         List<Integer> stray = HibernateUtil.loadList(Integer.class, query, null);
    221         if (stray.size() > 0)
     222        List<Integer> stray = new ArrayList<Integer>(HibernateUtil.loadList(Integer.class, query, null));
     223        int startIndex = 0;
     224        int endIndex = Math.min(MAX_PARAMETERS_IN_QUERY, stray.size());
     225        while (startIndex < stray.size())
    222226        {
    223           deleteQuery.setParameterList("ids", stray, TypeWrapper.INTEGER.getHibernateType());
     227          deleteQuery.setParameterList("ids", stray.subList(startIndex, endIndex), TypeWrapper.INTEGER.getHibernateType());
    224228          numDeleted += HibernateUtil.executeUpdate(deleteQuery);
     229          startIndex = endIndex;
     230          endIndex = Math.min(startIndex + MAX_PARAMETERS_IN_QUERY, stray.size());
    225231        }
    226232        index++;
Note: See TracChangeset for help on using the changeset viewer.