1 package org.apache.continuum.dao;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.continuum.model.project.Schedule;
23 import org.apache.maven.continuum.store.ContinuumStoreException;
24 import org.springframework.stereotype.Repository;
25
26 import java.util.Collection;
27 import java.util.List;
28 import javax.jdo.Extent;
29 import javax.jdo.PersistenceManager;
30 import javax.jdo.Query;
31 import javax.jdo.Transaction;
32
33
34
35
36
37
38 @Repository( "scheduleDao" )
39 public class ScheduleDaoImpl
40 extends AbstractDao
41 implements ScheduleDao
42 {
43 public List<Schedule> getAllSchedulesByName()
44 {
45 return getAllObjectsDetached( Schedule.class, "name ascending", null );
46 }
47
48 public Schedule addSchedule( Schedule schedule )
49 {
50 return (Schedule) addObject( schedule );
51 }
52
53 public Schedule getScheduleByName( String name )
54 throws ContinuumStoreException
55 {
56 PersistenceManager pm = getPersistenceManager();
57
58 Transaction tx = pm.currentTransaction();
59
60 try
61 {
62 tx.begin();
63
64 Extent extent = pm.getExtent( Schedule.class, true );
65
66 Query query = pm.newQuery( extent );
67
68 query.declareImports( "import java.lang.String" );
69
70 query.declareParameters( "String name" );
71
72 query.setFilter( "this.name == name" );
73
74 Collection result = (Collection) query.execute( name );
75
76 if ( result.size() == 0 )
77 {
78 tx.commit();
79
80 return null;
81 }
82
83 Object object = pm.detachCopy( result.iterator().next() );
84
85 tx.commit();
86
87 return (Schedule) object;
88 }
89 finally
90 {
91 rollback( tx );
92 }
93 }
94
95 public Schedule storeSchedule( Schedule schedule )
96 throws ContinuumStoreException
97 {
98 updateObject( schedule );
99
100 return schedule;
101 }
102
103 public void updateSchedule( Schedule schedule )
104 throws ContinuumStoreException
105 {
106 updateObject( schedule );
107 }
108
109 public void removeSchedule( Schedule schedule )
110 {
111 removeObject( schedule );
112 }
113
114 public Schedule getSchedule( int scheduleId )
115 throws ContinuumStoreException
116 {
117 return (Schedule) getObjectById( Schedule.class, scheduleId );
118 }
119 }