View Javadoc
1 package com.gotjava.system.calendar.hibernate;
2
3 import java.util.Date;
4 import java.util.List;
5
6 import com.gotjava.infrastructure.persistence.hibernate.AbstractHibernateDAO;
7 import com.gotjava.model.calendar.CalendarEvent;
8 import com.gotjava.model.calendar.CalendarSpan;
9 import com.gotjava.system.calendar.exceptions.CalendarException;
10 import com.gotjava.system.calendar.CalendarDAO;
11 import com.gotjava.model.signon.JLCPUser;
12
13 import net.sf.hibernate.Hibernate;
14 import net.sf.hibernate.Session;
15
16
17
18 /***
19 * Hibernate Implementation for CalendarDAO interface.
20 * Handles Database access for CalendarDAO objects.
21 * @author J Aaron Farr
22 */
23
24 public class CalendarDAO_Impl extends AbstractHibernateDAO implements CalendarDAO {
25
26
27 /***
28 * Used to ADD, DELETE, or MODIFY an existing event.
29 */
30 public long addEvent(CalendarEvent event) throws CalendarException {
31 long id = 0;
32 Session session = null;
33
34 try {
35 session = this.sessionManager.getHibernateSession();
36 id = ((Long) session.save(event)).longValue();
37 } catch (Exception he) {
38 he.printStackTrace();
39 throw new CalendarException(he);
40 } finally {
41 this.sessionManager.commitCloseSession(session);
42 }
43
44 return id;
45 }
46
47 public void deleteEvent(CalendarEvent event) throws CalendarException {
48
49 Session session = null;
50
51 try {
52
53 session = this.sessionManager.getHibernateSession();
54 session.delete(event);
55
56 } catch (Exception e) {
57 e.printStackTrace();
58 throw new CalendarException(e);
59 } finally {
60 this.sessionManager.commitCloseSession(session);
61 }
62
63 }
64
65 public void modifyEvent(CalendarEvent event) throws CalendarException {
66
67
68 Session session = null;
69
70 try {
71
72 session = this.sessionManager.getHibernateSession();
73 session.update(event);
74
75 } catch (Exception e) {
76 e.printStackTrace();
77 throw new CalendarException(e);
78 } finally {
79 this.sessionManager.commitCloseSession(session);
80 }
81
82 }
83
84
85 public CalendarEvent getEvent(long id) throws CalendarException {
86
87
88 Session session = null;
89 CalendarEvent event = null;
90
91 try {
92
93 session = this.sessionManager.getHibernateSession();
94 event = (CalendarEvent) session.load(CalendarEvent.class,new Long(id));
95
96 return event;
97 } catch (Exception e) {
98 e.printStackTrace();
99 throw new CalendarException(e);
100 } finally {
101 this.sessionManager.commitCloseSession(session);
102 }
103
104 }
105
106
107 /***
108 * returns a calendar span for the given 'span' and date.
109 * @see CalendarSpan
110 */
111 public CalendarSpan getSpan(JLCPUser user, int span, Date date) throws CalendarException {
112
113 Session session = null;
114 CalendarSpan cspan = new CalendarSpan(span, date);
115
116
117 try {
118
119 session = this.sessionManager.getHibernateSession();
120
121
122 List events = session.find(
123 " from calendar in class com.gotjava.model.calendar.CalendarEvent " +
124 " where calendar.user = ?", new Long(user.getId()), Hibernate.LONG);
125
126
127
128 for (int i = 0; i < events.size(); i++) {
129 cspan.addEvent((CalendarEvent) events.get(i));
130 }
131
132 // System.err.println("Getting Span from DAO "+span+" size = "+events.size()+" "+cspan.getEvents().length);
133
134 return cspan;
135 } catch (Exception e) {
136 e.printStackTrace();
137 throw new CalendarException(e);
138 } finally {
139 this.sessionManager.commitCloseSession(session);
140 }
141 }
142
143
144 }
This page was automatically generated by Maven