Changeset 7619


Ignore:
Timestamp:
Mar 4, 2019, 9:29:50 AM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2150: Batch item importers in item list members view

The "Internal ID" method need to use a query for finding items otherwise it will not work as expected in "Item list" mode.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/InternalIdMethod.java

    r7610 r7619  
    2222package net.sf.basedb.plugins.batchimport;
    2323
    24 import java.util.ArrayList;
    2524import java.util.List;
    2625
    2726import net.sf.basedb.core.BasicItem;
    2827import net.sf.basedb.core.DbControl;
    29 import net.sf.basedb.core.ItemNotFoundException;
    3028import net.sf.basedb.core.ItemQuery;
     29import net.sf.basedb.core.Type;
     30import net.sf.basedb.core.query.Expressions;
     31import net.sf.basedb.core.query.Hql;
     32import net.sf.basedb.core.query.Restrictions;
    3133import net.sf.basedb.util.Values;
    3234
     
    9092 
    9193  /**
    92     Return the original query, unmodified.
     94    Adds a restriction to the query:
     95    <code>id = :identifier</code>
    9396  */
    9497  @Override
    9598  public <I extends BasicItem> ItemQuery<I> prepareQuery(DbControl dc, ItemQuery<I> query)
    9699  {
     100    query.restrictPermanent(
     101      Restrictions.eq(
     102        Hql.property("id"),
     103        Expressions.parameter("identifier")
     104      )
     105    );
    97106    return query;
    98107  }
    99108
    100109  /**
    101     Use <code>getById</code> method to find an item. The query is not
    102     used except to find the type of item to load.
     110    Find the item with <code>id = identifier</code>
    103111  */
    104112  @Override
    105113  public <I extends BasicItem> List<I> find(DbControl dc, ItemQuery<I> query, String identifier)
    106114  {
    107     List<I> items = new ArrayList<I>(1);
    108115    int id = Values.getInt(identifier);
    109     if (id != 0)
    110     {
    111       try
    112       {
    113         I item = query.getItemType().getById(dc, id);
    114         items.add(item);
    115       }
    116       catch (ItemNotFoundException ex)
    117       {}
    118     }
    119     return items;
     116    query.setParameter("identifier", id, Type.INT);
     117    return query.list(dc);
    120118  }
    121119  // ---------------------------
Note: See TracChangeset for help on using the changeset viewer.