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.BuildDefinitionTemplate;
23 import org.apache.maven.continuum.store.ContinuumStoreException;
24 import org.springframework.stereotype.Repository;
25
26 import java.util.Collections;
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( "buildDefinitionTemplateDao" )
39 public class BuildDefinitionTemplateDaoImpl
40 extends AbstractDao
41 implements BuildDefinitionTemplateDao
42 {
43 public List<BuildDefinitionTemplate> getAllBuildDefinitionTemplate()
44 throws ContinuumStoreException
45 {
46 return getAllObjectsDetached( BuildDefinitionTemplate.class, BUILD_TEMPLATE_BUILD_DEFINITIONS );
47 }
48
49 public List<BuildDefinitionTemplate> getContinuumBuildDefinitionTemplates()
50 throws ContinuumStoreException
51 {
52 PersistenceManager pm = getPersistenceManager();
53
54 Transaction tx = pm.currentTransaction();
55
56 try
57 {
58 tx.begin();
59
60 Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true );
61
62 Query query = pm.newQuery( extent );
63 query.setFilter( "continuumDefault == true" );
64 pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS );
65 List result = (List) query.execute();
66 return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
67 }
68 finally
69 {
70 tx.commit();
71
72 rollback( tx );
73 }
74 }
75
76 public BuildDefinitionTemplate getBuildDefinitionTemplate( int id )
77 throws ContinuumStoreException
78 {
79 return (BuildDefinitionTemplate) getObjectById( BuildDefinitionTemplate.class, id,
80 BUILD_TEMPLATE_BUILD_DEFINITIONS );
81 }
82
83 public BuildDefinitionTemplate addBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate )
84 throws ContinuumStoreException
85 {
86 return (BuildDefinitionTemplate) addObject( buildDefinitionTemplate );
87 }
88
89 public BuildDefinitionTemplate updateBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate )
90 throws ContinuumStoreException
91 {
92 updateObject( buildDefinitionTemplate );
93
94 return buildDefinitionTemplate;
95 }
96
97 public void removeBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate )
98 throws ContinuumStoreException
99 {
100 removeObject( buildDefinitionTemplate );
101 }
102
103 public List<BuildDefinitionTemplate> getBuildDefinitionTemplatesWithType( String type )
104 throws ContinuumStoreException
105 {
106 PersistenceManager pm = getPersistenceManager();
107
108 Transaction tx = pm.currentTransaction();
109
110 try
111 {
112 tx.begin();
113
114 Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true );
115
116 Query query = pm.newQuery( extent );
117 query.declareImports( "import java.lang.String" );
118 query.declareParameters( "String type" );
119 query.setFilter( "this.type == type" );
120 pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS );
121 List result = (List) query.execute( type );
122 return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
123 }
124 finally
125 {
126 tx.commit();
127
128 rollback( tx );
129 }
130 }
131
132 public BuildDefinitionTemplate getContinuumBuildDefinitionTemplateWithType( String type )
133 throws ContinuumStoreException
134 {
135 PersistenceManager pm = getPersistenceManager();
136
137 Transaction tx = pm.currentTransaction();
138
139 try
140 {
141 tx.begin();
142
143 Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true );
144
145 Query query = pm.newQuery( extent );
146 query.declareImports( "import java.lang.String" );
147 query.declareParameters( "String type" );
148 query.setFilter( "continuumDefault == true && this.type == type" );
149 pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS );
150 List result = (List) query.execute( type );
151 if ( result == null || result.isEmpty() )
152 {
153 return null;
154 }
155 return (BuildDefinitionTemplate) pm.detachCopy( result.get( 0 ) );
156 }
157 finally
158 {
159 tx.commit();
160
161 rollback( tx );
162 }
163 }
164
165 public List<BuildDefinitionTemplate> getContinuumDefaultdDefinitions()
166 throws ContinuumStoreException
167 {
168 PersistenceManager pm = getPersistenceManager();
169
170 Transaction tx = pm.currentTransaction();
171
172 try
173 {
174 tx.begin();
175
176 Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true );
177
178 Query query = pm.newQuery( extent );
179 query.setFilter( "continuumDefault == true" );
180
181 List result = (List) query.execute();
182
183 return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
184 }
185 finally
186 {
187 tx.commit();
188
189 rollback( tx );
190 }
191 }
192 }