01: package org.osbl.inventory;
02:
03: import org.osbl.ReferenceChecker;
04: import org.osbl.ServiceProvider;
05: import org.osbl.identity.model.Identity;
06: import org.osbl.persistence.*;
07: import org.osbl.inventory.model.*;
08: import org.conform.hibernate.HibernateEnvironment;
09:
10: import java.util.*;
11:
12: public class InventoryToLocationReferenceChecker implements
13: ReferenceChecker<Inventory, 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<Inventory> check(Collection<Location> objects) {
24: try {
25: HibernateEnvironment.getInstance().beginTransaction();
26:
27: SimpleQueryCommand command = (SimpleQueryCommand) getPersistence()
28: .createCommand("list");
29: command.setType(Inventory.class);
30: command.addFilter("location", Operator.IN, objects);
31: return (List<Inventory>) command.execute();
32: } finally {
33: HibernateEnvironment.getInstance().endTransaction();
34: }
35: }
36: }
|