01: package org.osbl.inventory;
02:
03: import org.osbl.inventory.model.*;
04: import org.osbl.ReferenceChecker;
05: import org.osbl.ServiceProvider;
06: import org.osbl.identity.model.Identity;
07: import org.osbl.persistence.*;
08: import org.conform.hibernate.HibernateEnvironment;
09:
10: import java.util.*;
11:
12: public class InventoryToIdentityReferenceChecker implements
13: ReferenceChecker<Inventory, Identity> {
14: private Persistence persistence;
15:
16: public Persistence getPersistence() {
17: if (persistence == null)
18: persistence = (Persistence) ServiceProvider.getInstance()
19: .getService("InventoryPersistence");
20: return persistence;
21: }
22:
23: public Collection<Inventory> check(Collection<Identity> objects) {
24: try {
25: HibernateEnvironment.getInstance().beginTransaction();
26:
27: JoinedQueryCommand command = (JoinedQueryCommand) getPersistence()
28: .createCommand("list");
29: command.setType(Inventory.class);
30: command.addFilter("employee", Operator.IN, objects);
31: List<Inventory> inventoriesByEmployee = command.execute();
32:
33: command.setType(Inventory.class);
34: command.clearFilters();
35: command.addFilter("supplier", Operator.IN, objects);
36: List<Inventory> inventoriesBySupplier = command.execute();
37:
38: /*
39: command.setType(Inventory.class);
40: command.addJoin("allocations", "a");
41: command.addFilter("a.costCenter", Operator.IN, objects);
42: List inventoriesByCostCenter = command.execute();
43: */
44:
45: List<Inventory> list = new ArrayList<Inventory>(
46: inventoriesByEmployee.size()
47: + inventoriesBySupplier.size());// + inventoriesByCostCenter.size());
48: list.addAll(inventoriesByEmployee);
49: list.addAll(inventoriesBySupplier);
50: //list.addAll(inventoriesByCostCenter);
51: return list;
52: } finally {
53: HibernateEnvironment.getInstance().endTransaction();
54: }
55: }
56: }
|