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