Changeset 7619
- Timestamp:
- Mar 4, 2019, 9:29:50 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/InternalIdMethod.java
r7610 r7619 22 22 package net.sf.basedb.plugins.batchimport; 23 23 24 import java.util.ArrayList;25 24 import java.util.List; 26 25 27 26 import net.sf.basedb.core.BasicItem; 28 27 import net.sf.basedb.core.DbControl; 29 import net.sf.basedb.core.ItemNotFoundException;30 28 import net.sf.basedb.core.ItemQuery; 29 import net.sf.basedb.core.Type; 30 import net.sf.basedb.core.query.Expressions; 31 import net.sf.basedb.core.query.Hql; 32 import net.sf.basedb.core.query.Restrictions; 31 33 import net.sf.basedb.util.Values; 32 34 … … 90 92 91 93 /** 92 Return the original query, unmodified. 94 Adds a restriction to the query: 95 <code>id = :identifier</code> 93 96 */ 94 97 @Override 95 98 public <I extends BasicItem> ItemQuery<I> prepareQuery(DbControl dc, ItemQuery<I> query) 96 99 { 100 query.restrictPermanent( 101 Restrictions.eq( 102 Hql.property("id"), 103 Expressions.parameter("identifier") 104 ) 105 ); 97 106 return query; 98 107 } 99 108 100 109 /** 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> 103 111 */ 104 112 @Override 105 113 public <I extends BasicItem> List<I> find(DbControl dc, ItemQuery<I> query, String identifier) 106 114 { 107 List<I> items = new ArrayList<I>(1);108 115 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); 120 118 } 121 119 // ---------------------------
Note: See TracChangeset
for help on using the changeset viewer.