01: package com.technoetic.xplanner.db;
02:
03: import com.technoetic.xplanner.domain.Iteration;
04: import com.technoetic.xplanner.domain.Project;
05: import com.technoetic.xplanner.domain.UserStory;
06: import com.technoetic.xplanner.domain.Task;
07: import com.technoetic.xplanner.domain.Person;
08: import com.technoetic.xplanner.domain.Note;
09: import com.technoetic.xplanner.domain.DomainObject;
10: import com.technoetic.xplanner.db.hibernate.ThreadSession;
11: import net.sf.hibernate.HibernateException;
12: import net.sf.hibernate.ObjectNotFoundException;
13:
14: public class IdSearchHelper {
15: private Class[] searchedDomainClasses = { Project.class,
16: Iteration.class, UserStory.class, Task.class, Person.class,
17: Note.class };
18:
19: public DomainObject search(int oid) throws HibernateException {
20: final Integer id = new Integer(oid);
21: for (int i = 0; i < searchedDomainClasses.length; i++) {
22: DomainObject o = null;
23: try {
24: o = (DomainObject) ThreadSession.get().load(
25: searchedDomainClasses[i], id);
26: } catch (ObjectNotFoundException e) {
27: // ignored
28: }
29: if (o != null) {
30: if (o instanceof Note)
31: o = ((Note) o).getParent();
32: return o;
33: }
34: }
35: return null;
36: }
37:
38: }
|