Changeset 5127


Ignore:
Timestamp:
Oct 12, 2009, 2:41:06 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1400: Store the item id together with annotation sets

The production server has a lot of (600K+) annotation sets. This will not fit in memory. Trying to use an iterator + stateless session instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Update.java

    r5118 r5127  
    2929import java.util.HashMap;
    3030import java.util.HashSet;
     31import java.util.Iterator;
    3132import java.util.List;
    3233import java.util.Map;
     
    25452546    final int schemaVersion = 76;
    25462547    org.hibernate.Transaction tx = null;
     2548    org.hibernate.StatelessSession ss = null;
    25472549    try
    25482550    {
    25492551      tx = HibernateUtil.newTransaction(session);
     2552      ss = HibernateUtil.newStatelessSession(session);
    25502553     
    25512554      // Load all annotation sets with a null id
    2552       org.hibernate.Query query = HibernateUtil.createQuery(session,
     2555      org.hibernate.Query query = HibernateUtil.createQuery(ss,
    25532556        "SELECT a FROM AnnotationSetData a WHERE a.itemId IS NULL");
    2554       List<AnnotationSetData> annotationSets =
    2555         HibernateUtil.loadList(AnnotationSetData.class, query, null);
     2557      Iterator<AnnotationSetData> annotationSets =
     2558        HibernateUtil.loadIterator(AnnotationSetData.class, query, null);
    25562559      Map<Item, org.hibernate.Query> itemQueries = new HashMap<Item, org.hibernate.Query>();
    2557       for (AnnotationSetData a : annotationSets)
    2558       {
     2560      while (annotationSets.hasNext())
     2561      {
     2562        AnnotationSetData a = annotationSets.next();
    25592563        Item itemType = Item.fromValue(a.getItemType());
    25602564        org.hibernate.Query findItem = itemQueries.get(itemType);
     
    25692573        findItem.setInteger("annotationSet", a.getId());
    25702574        a.setItemId(HibernateUtil.loadData(Integer.class, findItem));
     2575        ss.update(a);
    25712576      }
    25722577 
     
    25812586    {
    25822587      if (tx != null) HibernateUtil.rollback(tx);
     2588      if (ss != null) HibernateUtil.close(ss);
    25832589      log.error("updateToSchemaVersion76: FAILED", ex);
    25842590      throw ex;
Note: See TracChangeset for help on using the changeset viewer.