2 * Created on 2005-04-25
5 package drno
.server
.database
.broker
;
7 import java
.sql
.Timestamp
;
8 import java
.util
.GregorianCalendar
;
9 import java
.util
.HashMap
;
10 import java
.util
.Iterator
;
11 import java
.util
.Vector
;
13 import drno
.exception
.ConsistanceException
;
14 import drno
.exception
.DatabaseDisconnectedException
;
15 import drno
.exception
.MappingException
;
16 import drno
.exception
.ObjectLockException
;
17 import drno
.exception
.UnkErrException
;
18 import drno
.server
.database
.persistence
.LockObject
;
19 import drno
.server
.database
.persistence
.repository
.MapperFacade
;
20 import drno
.server
.database
.persistence
.repository
.ObjectMapper
;
21 import drno
.server
.model
.EmployeeImpl
;
22 import drno
.server
.model
.Patient
;
23 import drno
.server
.model
.Tidsreservation
;
30 * Vedligeholder alle mappings for de enkelte Tidsreservation objekter og dets felter.
31 * Når den bliver instantieret, forsøger den at oprette en ny tabel til at indeholde
34 public class TidsreservationBroker
{
36 TidsreservationBroker() {
37 ObjectMapper mp
= new ObjectMapper("Tidsreservation",Tidsreservation
.class);
39 mp
.map("Emne","Emne");
40 mp
.map("Doctor","Employee").setClass(EmployeeImpl
.class);
41 mp
.map("Patient","Patient").setClass(Patient
.class);
42 mp
.map("Reel_start","ReelTidStart");
43 mp
.map("Reel_slut","ReelTidSlut");
44 mp
.map("Slut","TidSlut");
45 mp
.map("Start","TidStart");
46 mp
.map("Type","Type");
48 } catch (MappingException e
) {
53 MapperFacade
.instance().addMapper(mp
);
54 MapperFacade
.instance().CreateTable(mp
);
55 } catch (Exception ex
) {
60 public Vector
getAll() throws UnkErrException
{
61 MapperFacade mf
= MapperFacade
.instance();
62 return mf
.find(Tidsreservation
.class,"");
65 public Vector
getFromDate(Timestamp ts
) throws UnkErrException
{
66 Vector all
= new Vector();
68 Vector span
= getBeginAndEndOfDateVector(ts
);
71 MapperFacade mf
= MapperFacade
.instance();
72 return mf
.find(Tidsreservation
.class,"Start between \"" + span
.get(0) +
73 "\" and \"" + span
.get(1) + "\";");
80 private Vector
getBeginAndEndOfDateVector(Timestamp ts
)
82 GregorianCalendar cal
= new GregorianCalendar();
83 Vector span
= new Vector(2);
85 System
.out
.println(cal
);
90 System
.out
.println(ts
);
99 public Vector
getTRsFromDateAndDoctor(Timestamp ts
,EmployeeImpl e
) throws UnkErrException
{
100 Vector all
= new Vector();
101 Vector span
= getBeginAndEndOfDateVector(ts
);
103 MapperFacade mf
= MapperFacade
.instance();
104 return mf
.find(Tidsreservation
.class,"Start between \"" + span
.get(0) + "\" and \""
105 + span
.get(1) + "\" and Doctor=" + e
.getOId() + ";");
111 * @throws UnkErrException
113 public Vector
getTRsFromPatient(Patient patient
) throws UnkErrException
{
114 MapperFacade mf
= MapperFacade
.instance();
115 return mf
.find(Tidsreservation
.class,"Patient=" + patient
.getOId());
118 public void deletePatientsReservationer(Patient pat
) throws UnkErrException
, ObjectLockException
120 Vector pats
= new Vector();
121 HashMap keys
= new HashMap();
122 Vector LockedTid
= new Vector();
123 MapperFacade mf
= MapperFacade
.instance();
124 pats
= mf
.find(Tidsreservation
.class,"Patient=" + pat
.getOId());
125 Iterator it
= pats
.iterator();
127 while(it
.hasNext()) {
128 Tidsreservation tid
= (Tidsreservation
)it
.next();
129 keys
.put(tid
,tid
.save());
132 } catch(ObjectLockException ex
) {
133 it
= LockedTid
.iterator();
134 while(it
.hasNext()) {
135 Tidsreservation tid
= (Tidsreservation
)it
.next();
136 tid
.rollback((LockObject
)keys
.get(pat
));
141 it
= pats
.iterator();
145 while(it
.hasNext()) {
146 Tidsreservation tid
= (Tidsreservation
)it
.next();
147 tid
.delete((LockObject
)keys
.get(tid
));
148 try { tid
.commit((LockObject
)keys
.get(tid
)); }
149 catch (ConsistanceException newer_happens
) { }