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 java.util.Collection;
23 import java.util.Collections;
24 import java.util.List;
25
26 import javax.jdo.Extent;
27 import javax.jdo.PersistenceManager;
28 import javax.jdo.Query;
29 import javax.jdo.Transaction;
30
31 import org.apache.maven.continuum.model.project.BuildQueue;
32 import org.apache.maven.continuum.store.ContinuumStoreException;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.stereotype.Repository;
36
37
38
39
40
41
42 @Repository("buildQueueDao")
43 public class BuildQueueDaoImpl
44 extends AbstractDao
45 implements BuildQueueDao
46 {
47 private static Logger log = LoggerFactory.getLogger( BuildQueueDaoImpl.class );
48
49 public BuildQueue addBuildQueue( BuildQueue buildQueue )
50 throws ContinuumStoreException
51 {
52 return (BuildQueue) addObject( buildQueue );
53 }
54
55 public List<BuildQueue> getAllBuildQueues()
56 throws ContinuumStoreException
57 {
58 PersistenceManager pm = getPersistenceManager();
59
60 Transaction tx = pm.currentTransaction();
61
62 try
63 {
64 tx.begin();
65
66 Extent extent = pm.getExtent( BuildQueue.class, true );
67
68 Query query = pm.newQuery( extent );
69
70 List result = (List) query.execute();
71
72 return result == null ? Collections.EMPTY_LIST : (List<BuildQueue>) pm.detachCopyAll( result );
73 }
74 finally
75 {
76 tx.commit();
77
78 rollback( tx );
79 }
80 }
81
82 public BuildQueue getBuildQueue( int buildQueueId )
83 throws ContinuumStoreException
84 {
85 return (BuildQueue) getObjectById( BuildQueue.class, buildQueueId );
86 }
87
88 public BuildQueue getBuildQueueByName( String name )
89 throws ContinuumStoreException
90 {
91 PersistenceManager pm = getPersistenceManager();
92
93 Transaction tx = pm.currentTransaction();
94
95 try
96 {
97 tx.begin();
98
99 Extent extent = pm.getExtent( BuildQueue.class, true );
100
101 Query query = pm.newQuery( extent );
102
103 query.declareImports( "import java.lang.String" );
104
105 query.declareParameters( "String name" );
106
107 query.setFilter( "this.name == name" );
108
109 Collection result = (Collection) query.execute( name );
110
111 if ( result.size() == 0 )
112 {
113 tx.commit();
114
115 return null;
116 }
117
118 Object object = pm.detachCopy( result.iterator().next() );
119
120 tx.commit();
121
122 return (BuildQueue) object;
123 }
124 finally
125 {
126 rollback( tx );
127 }
128 }
129
130 public void removeBuildQueue( BuildQueue buildQueue )
131 throws ContinuumStoreException
132 {
133 removeObject( buildQueue );
134 }
135
136 public BuildQueue storeBuildQueue( BuildQueue buildQueue )
137 throws ContinuumStoreException
138 {
139 updateObject( buildQueue );
140
141 return buildQueue;
142 }
143 }