EMMA Coverage Report (generated Sun Sep 18 11:34:27 PHT 2011)
[all classes][org.apache.continuum.dao]

COVERAGE SUMMARY FOR SOURCE FILE [BuildDefinitionDaoImpl.java]

nameclass, %method, %block, %line, %
BuildDefinitionDaoImpl.java100% (1/1)33%  (5/15)10%  (52/499)12%  (12.9/110)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BuildDefinitionDaoImpl100% (1/1)33%  (5/15)10%  (52/499)12%  (12.9/110)
getAllTemplates (): List 0%   (0/1)0%   (0/48)0%   (0/10)
getBuildDefinition (int): BuildDefinition 0%   (0/1)0%   (0/6)0%   (0/1)
getBuildDefinitionsBySchedule (int): List 0%   (0/1)0%   (0/53)0%   (0/11)
getDefaultBuildDefinition (int): BuildDefinition 0%   (0/1)0%   (0/58)0%   (0/13)
getDefaultBuildDefinitionForProject (Project): BuildDefinition 0%   (0/1)0%   (0/5)0%   (0/1)
getDefaultBuildDefinitionForProject (int): BuildDefinition 0%   (0/1)0%   (0/90)0%   (0/18)
getDefaultBuildDefinitions (): Map 0%   (0/1)0%   (0/92)0%   (0/21)
getDefaultBuildDefinitionsForProjectGroup (ProjectGroup): List 0%   (0/1)0%   (0/5)0%   (0/1)
getDefaultBuildDefinitionsForProjectGroup (int): List 0%   (0/1)0%   (0/76)0%   (0/18)
removeBuildDefinition (BuildDefinition): void 0%   (0/1)0%   (0/4)0%   (0/2)
getAllBuildDefinitions (): List 100% (1/1)78%  (35/45)88%  (7.9/9)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
BuildDefinitionDaoImpl (): void 100% (1/1)100% (3/3)100% (1/1)
addBuildDefinition (BuildDefinition): BuildDefinition 100% (1/1)100% (5/5)100% (1/1)
storeBuildDefinition (BuildDefinition): BuildDefinition 100% (1/1)100% (5/5)100% (2/2)

1package org.apache.continuum.dao;
2 
3/*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 
22import java.util.ArrayList;
23import java.util.Collections;
24import java.util.HashMap;
25import java.util.List;
26import java.util.Map;
27 
28import javax.annotation.Resource;
29import javax.jdo.Extent;
30import javax.jdo.PersistenceManager;
31import javax.jdo.Query;
32import javax.jdo.Transaction;
33 
34import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
35import org.apache.maven.continuum.model.project.BuildDefinition;
36import org.apache.maven.continuum.model.project.Project;
37import org.apache.maven.continuum.model.project.ProjectGroup;
38import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
39import org.apache.maven.continuum.store.ContinuumStoreException;
40import org.codehaus.plexus.util.StringUtils;
41import org.slf4j.Logger;
42import org.slf4j.LoggerFactory;
43import org.springframework.stereotype.Repository;
44 
45/**
46 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
47 * @version $Id: BuildDefinitionDaoImpl.java 765340 2009-04-15 20:22:00Z evenisse $
48 * @plexus.component role="org.apache.continuum.dao.BuildDefinitionDao"
49 */
50@Repository("buildDefinitionDao")
51public class BuildDefinitionDaoImpl
52    extends AbstractDao
53    implements BuildDefinitionDao
54{
55    private static final Logger log = LoggerFactory.getLogger( BuildDefinitionDaoImpl.class );
56 
57    /**
58     * @plexus.requirement role="org.apache.continuum.dao.ProjectDao"
59     */
60    @Resource
61    private ProjectDao projectDao;
62 
63    /**
64     * @plexus.requirement role="org.apache.continuum.dao.ProjectGroupDao"
65     */
66    @Resource
67    private ProjectGroupDao projectGroupDao;
68 
69    public BuildDefinition getBuildDefinition( int buildDefinitionId )
70        throws ContinuumStoreException
71    {
72        return (BuildDefinition) getObjectById( BuildDefinition.class, buildDefinitionId );
73    }
74 
75    public void removeBuildDefinition( BuildDefinition buildDefinition )
76        throws ContinuumStoreException
77    {
78        removeObject( buildDefinition );
79    }
80 
81    public BuildDefinition storeBuildDefinition( BuildDefinition buildDefinition )
82        throws ContinuumStoreException
83    {
84        updateObject( buildDefinition );
85 
86        return buildDefinition;
87    }
88 
89 
90    public BuildDefinition addBuildDefinition( BuildDefinition buildDefinition )
91        throws ContinuumStoreException
92    {
93        return (BuildDefinition) addObject( buildDefinition );
94    }
95 
96    public List<BuildDefinition> getAllBuildDefinitions()
97        throws ContinuumStoreException
98    {
99        PersistenceManager pm = getPersistenceManager();
100 
101        Transaction tx = pm.currentTransaction();
102 
103        try
104        {
105            tx.begin();
106 
107            Extent extent = pm.getExtent( BuildDefinition.class, true );
108 
109            Query query = pm.newQuery( extent );
110 
111            List result = (List) query.execute();
112 
113            return result == null ? Collections.EMPTY_LIST : (List<BuildDefinition>) pm.detachCopyAll( result );
114        }
115        finally
116        {
117            tx.commit();
118 
119            rollback( tx );
120        }
121    }
122 
123    public Map<Integer, Integer> getDefaultBuildDefinitions()
124    {
125        PersistenceManager pm = getPersistenceManager();
126 
127        Transaction tx = pm.currentTransaction();
128 
129        try
130        {
131            tx.begin();
132 
133            Extent extent = pm.getExtent( Project.class, true );
134 
135            Query query = pm.newQuery( extent );
136 
137            query.declareImports( "import org.apache.maven.continuum.model.project.BuildDefinition" );
138 
139            query.setFilter( "this.buildDefinitions.contains(buildDef) && buildDef.defaultForProject == true" );
140 
141            query.declareVariables( "BuildDefinition buildDef" );
142 
143            query.setResult( "this.id, buildDef.id" );
144 
145            List result = (List) query.execute();
146 
147            // result = (List) pm.detachCopyAll( result );
148 
149            Map<Integer, Integer> builds = new HashMap<Integer, Integer>();
150 
151            if ( result != null && !result.isEmpty() )
152            {
153                for ( Object aResult : result )
154                {
155                    Object[] obj = (Object[]) aResult;
156 
157                    builds.put( (Integer) obj[0], (Integer) obj[1] );
158                }
159 
160                return builds;
161            }
162        }
163        finally
164        {
165            tx.commit();
166 
167            rollback( tx );
168        }
169 
170        return null;
171    }
172 
173    public List<BuildDefinition> getDefaultBuildDefinitionsForProjectGroup( int projectGroupId )
174        throws ContinuumStoreException
175    {
176        PersistenceManager pm = getPersistenceManager();
177 
178        Transaction tx = pm.currentTransaction();
179 
180        try
181        {
182            tx.begin();
183 
184            Extent extent = pm.getExtent( ProjectGroup.class, true );
185 
186            Query query = pm.newQuery( extent );
187 
188            query.declareImports( "import " + BuildDefinition.class.getName() );
189 
190            query.declareParameters( "int projectGroupId" );
191 
192            query.setFilter(
193                "this.id == projectGroupId && this.buildDefinitions.contains(buildDef) && buildDef.defaultForProject == true" );
194 
195            query.declareVariables( "BuildDefinition buildDef" );
196 
197            query.setResult( "buildDef" );
198 
199            List<BuildDefinition> result = (List<BuildDefinition>) query.execute( projectGroupId );
200 
201            result = (List<BuildDefinition>) pm.detachCopyAll( result );
202 
203            tx.commit();
204 
205            if ( result != null )
206            {
207                return result;
208            }
209        }
210        finally
211        {
212            rollback( tx );
213        }
214 
215        return new ArrayList<BuildDefinition>();
216    }
217 
218    public List<BuildDefinition> getDefaultBuildDefinitionsForProjectGroup( ProjectGroup projectGroup )
219        throws ContinuumStoreException
220    {
221        return getDefaultBuildDefinitionsForProjectGroup( projectGroup.getId() );
222    }
223 
224    public BuildDefinition getDefaultBuildDefinitionForProject( int projectId )
225        throws ContinuumStoreException
226    {
227        PersistenceManager pm = getPersistenceManager();
228 
229        Transaction tx = pm.currentTransaction();
230 
231        try
232        {
233            tx.begin();
234 
235            Extent extent = pm.getExtent( BuildDefinition.class, true );
236 
237            Query query = pm.newQuery( extent );
238 
239            query.declareImports( "import " + Project.class.getName() );
240 
241            query.declareParameters( "int projectId" );
242 
243            query.setFilter(
244                "project.id == projectId && project.buildDefinitions.contains(this) && this.defaultForProject == true" );
245 
246            query.declareVariables( "Project project" );
247 
248            query.setResult( "this" );
249 
250            List<BuildDefinition> result = (List<BuildDefinition>) query.execute( projectId );
251 
252            result = (List<BuildDefinition>) pm.detachCopyAll( result );
253 
254            tx.commit();
255 
256            if ( result != null && !result.isEmpty() )
257            {
258                return result.get( 0 );
259            }
260        }
261        finally
262        {
263            rollback( tx );
264        }
265 
266        throw new ContinuumObjectNotFoundException( "no default build definition declared for project " + projectId );
267    }
268 
269    public BuildDefinition getDefaultBuildDefinitionForProject( Project project )
270        throws ContinuumStoreException
271    {
272        return getDefaultBuildDefinitionForProject( project.getId() );
273    }
274 
275    public BuildDefinition getDefaultBuildDefinition( int projectId )
276        throws ContinuumStoreException
277    {
278        //TODO: Move this method to a service class
279        BuildDefinition bd = null;
280 
281        try
282        {
283            bd = getDefaultBuildDefinitionForProject( projectId );
284        }
285        catch ( ContinuumObjectNotFoundException cne )
286        {
287            // ignore since we will try the project group
288            log.debug( "no default build definition on project, trying project group" );
289        }
290 
291        // project group should have default build definition defined
292        if ( bd == null )
293        {
294            ProjectGroup projectGroup = projectGroupDao.getProjectGroupByProjectId( projectId );
295 
296            Project p = projectDao.getProject( projectId );
297 
298            List<BuildDefinition> bds = getDefaultBuildDefinitionsForProjectGroup( projectGroup.getId() );
299 
300            for ( BuildDefinition bdef : bds )
301            {
302                if ( p.getExecutorId().equals( bdef.getType() ) || ( StringUtils.isEmpty( bdef.getType() ) &&
303                    ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR.equals( p.getExecutorId() ) ) )
304                {
305                    return bdef;
306                }
307            }
308        }
309 
310        return bd;
311    }
312 
313    public List<BuildDefinition> getAllTemplates()
314        throws ContinuumStoreException
315    {
316        PersistenceManager pm = getPersistenceManager();
317 
318        Transaction tx = pm.currentTransaction();
319 
320        try
321        {
322            tx.begin();
323 
324            Extent extent = pm.getExtent( BuildDefinition.class, true );
325 
326            Query query = pm.newQuery( extent );
327            query.setFilter( "this.template == true" );
328            List result = (List) query.execute();
329            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
330        }
331        finally
332        {
333            tx.commit();
334 
335            rollback( tx );
336        }
337    }
338 
339    public List<BuildDefinition> getBuildDefinitionsBySchedule( int scheduleId )
340    {
341        PersistenceManager pm = getPersistenceManager();
342 
343        Transaction tx = pm.currentTransaction();
344 
345        try
346        {
347            tx.begin();
348 
349            Extent extent = pm.getExtent( BuildDefinition.class, true );
350 
351            Query query = pm.newQuery( extent );
352 
353            query.declareParameters( "int scheduleId" );
354 
355            query.setFilter( "this.schedule.id == scheduleId" );
356 
357            List result = (List) query.execute( scheduleId );
358 
359            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
360        }
361        finally
362        {
363            tx.commit();
364 
365            rollback( tx );
366        }
367    }
368 
369}

[all classes][org.apache.continuum.dao]
EMMA 2.0.5312 (C) Vladimir Roubtsov