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 EmployeeToLocationReferenceChecker implements
13: ReferenceChecker<Identity, Location> {
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<Identity> check(Collection<Location> objects) {
24: try {
25: HibernateEnvironment.getInstance().beginTransaction();
26:
27: SimpleQueryCommand command = (SimpleQueryCommand) getPersistence()
28: .createCommand("list");
29:
30: command.setType(Employee.class);
31: command.clearFilters();
32: command.addFetch("general", Fetch.JOIN);
33: command.addFilter("location", Operator.IN, objects);
34: List<Employee> employees = command.execute();
35: List<Identity> identities = new ArrayList<Identity>(
36: employees.size());
37: for (Employee employee : employees)
38: identities.add(employee.getGeneral());
39:
40: return identities;
41: } finally {
42: HibernateEnvironment.getInstance().endTransaction();
43: }
44: }
45: }
|