View Javadoc

1   package 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  
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   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
35   * @version $Id: BuildDefinitionTemplateDaoImpl.java 1372260 2012-08-13 04:29:09Z brett $
36   * @plexus.component role="org.apache.continuum.dao.BuildDefinitionTemplateDao"
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 }