01: package com.technoetic.xplanner.domain.repository;
02:
03: import net.sf.hibernate.Hibernate;
04: import net.sf.hibernate.HibernateException;
05: import org.springframework.orm.ObjectRetrievalFailureException;
06: import org.springframework.orm.hibernate.support.HibernateDaoSupport;
07: import org.springframework.orm.hibernate.HibernateObjectRetrievalFailureException;
08: import org.springframework.dao.DataAccessException;
09:
10: import com.technoetic.xplanner.domain.DomainObject;
11: import com.technoetic.xplanner.domain.NoteAttachable;
12:
13: public class HibernateObjectRepository extends HibernateDaoSupport
14: implements ObjectRepository {
15: private Class objectClass;
16: private final String deletionQuery;
17:
18: public HibernateObjectRepository(Class objectClass)
19: throws HibernateException {
20: this .objectClass = objectClass;
21: deletionQuery = "from object in " + objectClass
22: + " where id = ?";
23: }
24:
25: public void delete(final int objectIdentifier)
26: throws RepositoryException {
27: try {
28: if (NoteAttachable.class.isAssignableFrom(objectClass)) {
29: // FIXME This unfortunately is not enough. we have cascade delete on from project down to time entry. Any of these contained entity could have notes that have files. These files won't be deleted
30: // NoteHelper.deleteNotesFor(objectClass, objectIdentifier, getHibernateTemplate());
31: }
32: getHibernateTemplate().delete(deletionQuery,
33: new Integer(objectIdentifier), Hibernate.INTEGER);
34: } catch (HibernateObjectRetrievalFailureException e) {
35: throw new ObjectNotFoundException(e.getMessage());
36: } catch (DataAccessException ex) {
37: throw new RepositoryException(ex);
38: }
39: }
40:
41: public Object load(final int objectIdentifier)
42: throws RepositoryException {
43: try {
44: return getHibernateTemplate().load(objectClass,
45: new Integer(objectIdentifier));
46:
47: } catch (HibernateObjectRetrievalFailureException e) {
48: throw new ObjectNotFoundException(e.getMessage());
49: } catch (DataAccessException ex) {
50: throw new RepositoryException(ex);
51: }
52: }
53:
54: public int insert(final DomainObject object)
55: throws RepositoryException {
56: try {
57: Integer id = (Integer) getHibernateTemplate().save(object);
58: return id.intValue();
59:
60: } catch (HibernateObjectRetrievalFailureException e) {
61: throw new ObjectNotFoundException(e.getMessage());
62: } catch (DataAccessException ex) {
63: throw new RepositoryException(ex);
64: }
65: }
66:
67: public void update(DomainObject object)
68: throws DuplicateUserIdException {
69: // empty
70: }
71: }
|