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.continuum.model.release.ContinuumReleaseResult;
23  import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
24  import org.apache.maven.continuum.store.ContinuumStoreException;
25  import org.springframework.stereotype.Repository;
26  
27  import java.util.Collection;
28  import java.util.List;
29  import javax.jdo.Extent;
30  import javax.jdo.PersistenceManager;
31  import javax.jdo.Query;
32  import javax.jdo.Transaction;
33  
34  /**
35   * @author <a href="mailto:ctan@apache.org">Maria Catherine Tan</a>
36   * @plexus.component role="org.apache.continuum.dao.ContinuumReleaseResultDao"
37   */
38  @Repository( "continuumReleaseResultDao" )
39  public class ContinuumReleaseResultDaoImpl
40      extends AbstractDao
41      implements ContinuumReleaseResultDao
42  {
43      public ContinuumReleaseResult addContinuumReleaseResult( ContinuumReleaseResult releaseResult )
44          throws ContinuumStoreException
45      {
46          return (ContinuumReleaseResult) addObject( releaseResult );
47      }
48  
49      public List<ContinuumReleaseResult> getAllContinuumReleaseResults()
50      {
51          return getAllObjectsDetached( ContinuumReleaseResult.class );
52      }
53  
54      public ContinuumReleaseResult getContinuumReleaseResult( int releaseResultId )
55          throws ContinuumObjectNotFoundException, ContinuumStoreException
56      {
57          return (ContinuumReleaseResult) getObjectById( ContinuumReleaseResult.class, releaseResultId );
58      }
59  
60      public ContinuumReleaseResult getContinuumReleaseResult( int projectId, String releaseGoal, long startTime,
61                                                               long endTime )
62          throws ContinuumStoreException
63      {
64          PersistenceManager pm = getPersistenceManager();
65  
66          Transaction tx = pm.currentTransaction();
67  
68          try
69          {
70              tx.begin();
71  
72              Extent extent = pm.getExtent( ContinuumReleaseResult.class, true );
73  
74              Query query = pm.newQuery( extent );
75  
76              query.declareImports( "import java.lang.String" );
77  
78              query.declareParameters( "int projectId, String releaseGoal, long startTime, long endTime" );
79  
80              query.setFilter(
81                  "this.project.id == projectId && this.releaseGoal == releaseGoal && this.startTime == startTime && this.endTime == endTime" );
82  
83              Object[] params = new Object[4];
84              params[0] = projectId;
85              params[1] = releaseGoal;
86              params[2] = startTime;
87              params[3] = endTime;
88  
89              Collection result = (Collection) query.executeWithArray( params );
90  
91              if ( result.size() == 0 )
92              {
93                  tx.commit();
94  
95                  return null;
96              }
97  
98              Object object = pm.detachCopy( result.iterator().next() );
99  
100             tx.commit();
101 
102             return (ContinuumReleaseResult) object;
103         }
104         finally
105         {
106             rollback( tx );
107         }
108 
109     }
110 
111     public List<ContinuumReleaseResult> getContinuumReleaseResultsByProjectGroup( int projectGroupId )
112     {
113         PersistenceManager pm = getPersistenceManager();
114 
115         Transaction tx = pm.currentTransaction();
116 
117         try
118         {
119             tx.begin();
120 
121             Extent extent = pm.getExtent( ContinuumReleaseResult.class, true );
122 
123             Query query = pm.newQuery( extent, "projectGroup.id == " + projectGroupId );
124 
125             List result = (List) query.execute();
126 
127             result = (List) pm.detachCopyAll( result );
128 
129             tx.commit();
130 
131             return result;
132         }
133         finally
134         {
135             rollback( tx );
136         }
137     }
138 
139     public List<ContinuumReleaseResult> getContinuumReleaseResultsByProject( int projectId )
140     {
141         PersistenceManager pm = getPersistenceManager();
142 
143         Transaction tx = pm.currentTransaction();
144 
145         try
146         {
147             tx.begin();
148 
149             Extent extent = pm.getExtent( ContinuumReleaseResult.class, true );
150 
151             Query query = pm.newQuery( extent, "project.id == " + projectId );
152 
153             List result = (List) query.execute();
154 
155             result = (List) pm.detachCopyAll( result );
156 
157             tx.commit();
158 
159             return result;
160         }
161         finally
162         {
163             rollback( tx );
164         }
165     }
166 
167     public void removeContinuumReleaseResult( ContinuumReleaseResult releaseResult )
168         throws ContinuumStoreException
169     {
170         removeObject( releaseResult );
171     }
172 
173 }