Changeset 6717


Ignore:
Timestamp:
Feb 4, 2015, 1:30:37 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1914: Exception from DbCleaner?

Same fix in for the query in AnyToAny.deleteStrayLinks().

Moved the max number of parameters to DbEngine interface. The default implementation set this to 10000 and there is no need for subclasses to override this unless they need a lower value.

Location:
branches/3.4-stable/src/core/net/sf/basedb/core
Files:
5 edited

Legend:

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

    r6716 r6717  
    204204  }
    205205 
    206   private static final int MAX_PARAMETERS_IN_QUERY = 10000;
    207206 
    208207  /**
     
    262261    // an arbitrary large number of parameters
    263262    int startIndex = 0;
    264     int endIndex = Math.min(MAX_PARAMETERS_IN_QUERY, allIds.size());
     263    int maxParameters = HibernateUtil.getDbEngine().getMaxParametersInQuery();
     264    int endIndex = Math.min(maxParameters, allIds.size());
    265265    while (startIndex < allIds.size())
    266266    {
     
    284284   
    285285      startIndex = endIndex;
    286       endIndex = Math.min(startIndex + MAX_PARAMETERS_IN_QUERY, allIds.size());
     286      endIndex = Math.min(startIndex + maxParameters, allIds.size());
    287287    }
    288288   
     
    326326
    327327      startIndex = 0;
    328       endIndex = Math.min(MAX_PARAMETERS_IN_QUERY, ids.size());
     328      endIndex = Math.min(maxParameters, ids.size());
    329329     
    330330      while (startIndex < ids.size())
     
    345345        numDeleted += sublist.size();
    346346        startIndex = endIndex;
    347         endIndex = Math.min(startIndex + MAX_PARAMETERS_IN_QUERY, ids.size());
     347        endIndex = Math.min(startIndex + maxParameters, ids.size());
    348348      }
    349349    }
  • branches/3.4-stable/src/core/net/sf/basedb/core/AnyToAny.java

    r6675 r6717  
    2323package net.sf.basedb.core;
    2424
     25import java.util.ArrayList;
    2526import java.util.List;
    2627
     
    378379      int index = 0;
    379380      int numItemTypes = itemTypes.size();
     381      int maxParameters = HibernateUtil.getDbEngine().getMaxParametersInQuery();
    380382      org.hibernate.Query deleteQuery =
    381383        HibernateUtil.getPredefinedQuery(session, "DELETE_STRAY_ANYTOANY");
     
    403405        */
    404406        query.setInteger("type", itemType);
    405         List<Integer> stray = HibernateUtil.loadList(Integer.class, query, null);
    406         if (stray.size() > 0)
     407       
     408        List<Integer> stray = new ArrayList<Integer>(HibernateUtil.loadList(Integer.class, query, null));
     409        int startIndex = 0;
     410        int endIndex = Math.min(maxParameters, stray.size());
     411        while (startIndex < stray.size())
    407412        {
    408           deleteQuery.setParameterList("ids", stray, TypeWrapper.INTEGER.getHibernateType());
     413          deleteQuery.setParameterList("ids", stray.subList(startIndex, endIndex), TypeWrapper.INTEGER.getHibernateType());
    409414          numDeleted += HibernateUtil.executeUpdate(deleteQuery);
     415          startIndex = endIndex;
     416          endIndex = Math.min(startIndex + maxParameters, stray.size());
    410417        }
    411418        index++;
  • branches/3.4-stable/src/core/net/sf/basedb/core/ChangeHistory.java

    r6714 r6717  
    158158    return query;   
    159159  }
    160  
    161   private static final int MAX_PARAMETERS_IN_QUERY = 10000;
    162  
     160   
    163161  /**
    164162    Delete all change history entries that are linking to non-existing items. This method
     
    195193      int index = 0;
    196194      int numItemTypes = itemTypes.size();
     195      int maxParameters = HibernateUtil.getDbEngine().getMaxParametersInQuery();
    197196      org.hibernate.Query deleteQuery =
    198197        HibernateUtil.getPredefinedQuery(session, "DELETE_STRAY_CHANGEHISTORY");
     
    222221        List<Integer> stray = new ArrayList<Integer>(HibernateUtil.loadList(Integer.class, query, null));
    223222        int startIndex = 0;
    224         int endIndex = Math.min(MAX_PARAMETERS_IN_QUERY, stray.size());
     223        int endIndex = Math.min(maxParameters, stray.size());
    225224        while (startIndex < stray.size())
    226225        {
     
    228227          numDeleted += HibernateUtil.executeUpdate(deleteQuery);
    229228          startIndex = endIndex;
    230           endIndex = Math.min(startIndex + MAX_PARAMETERS_IN_QUERY, stray.size());
     229          endIndex = Math.min(startIndex + maxParameters, stray.size());
    231230        }
    232231        index++;
  • branches/3.4-stable/src/core/net/sf/basedb/core/dbengine/AbstractDbEngine.java

    r6630 r6717  
    146146  }
    147147
     148  /**
     149    Returns 10000.
     150  */
     151  @Override
     152  public int getMaxParametersInQuery()
     153  {
     154    return 10000;
     155  }
     156 
    148157  /**
    149158    Return <code>LN(&lt;value&gt;)</code>.
  • branches/3.4-stable/src/core/net/sf/basedb/core/dbengine/DbEngine.java

    r6630 r6717  
    351351 
    352352  /**
     353    Get the maximum number of parameters that can be used in a prepared
     354    statement for a query.
     355    @return
     356    @since 3.4.1
     357  */
     358  public int getMaxParametersInQuery();
     359 
     360  /**
    353361    Get the function call that takes the natural logarithm
    354362    of a value. For example: <code>LN(value)</code>
Note: See TracChangeset for help on using the changeset viewer.