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.project.ProjectScmRoot;
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   * @version $Id: $
37   * @plexus.component role="org.apache.continuum.dao.ProjectScmRootDao"
38   */
39  @Repository( "projectScmRootDao" )
40  public class ProjectScmRootDaoImpl
41      extends AbstractDao
42      implements ProjectScmRootDao
43  {
44      public ProjectScmRoot addProjectScmRoot( ProjectScmRoot projectScmRoot )
45          throws ContinuumStoreException
46      {
47          return (ProjectScmRoot) addObject( projectScmRoot );
48      }
49  
50      public List<ProjectScmRoot> getAllProjectScmRoots()
51      {
52          return getAllObjectsDetached( ProjectScmRoot.class );
53      }
54  
55      public List<ProjectScmRoot> getProjectScmRootByProjectGroup( int projectGroupId )
56      {
57          PersistenceManager pm = getPersistenceManager();
58  
59          Transaction tx = pm.currentTransaction();
60  
61          try
62          {
63              tx.begin();
64  
65              Extent extent = pm.getExtent( ProjectScmRoot.class, true );
66  
67              Query query = pm.newQuery( extent, "projectGroup.id == " + projectGroupId );
68  
69              List result = (List) query.execute();
70  
71              result = (List) pm.detachCopyAll( result );
72  
73              tx.commit();
74  
75              return result;
76          }
77          finally
78          {
79              rollback( tx );
80          }
81      }
82  
83      public void removeProjectScmRoot( ProjectScmRoot projectScmRoot )
84          throws ContinuumStoreException
85      {
86          removeObject( projectScmRoot );
87      }
88  
89      public void updateProjectScmRoot( ProjectScmRoot projectScmRoot )
90          throws ContinuumStoreException
91      {
92          updateObject( projectScmRoot );
93      }
94  
95      public ProjectScmRoot getProjectScmRootByProjectGroupAndScmRootAddress( int projectGroupId, String scmRootAddress )
96          throws ContinuumStoreException
97      {
98          PersistenceManager pm = getPersistenceManager();
99  
100         Transaction tx = pm.currentTransaction();
101 
102         try
103         {
104             tx.begin();
105 
106             Extent extent = pm.getExtent( ProjectScmRoot.class, true );
107 
108             Query query = pm.newQuery( extent );
109 
110             query.declareImports( "import java.lang.String" );
111 
112             query.declareParameters( "int projectGroupId, String scmRootAddress" );
113 
114             query.setFilter( "this.projectGroup.id == projectGroupId && this.scmRootAddress == scmRootAddress" );
115 
116             Object[] params = new Object[2];
117             params[0] = projectGroupId;
118             params[1] = scmRootAddress;
119 
120             Collection result = (Collection) query.executeWithArray( params );
121 
122             if ( result.size() == 0 )
123             {
124                 tx.commit();
125 
126                 return null;
127             }
128 
129             Object object = pm.detachCopy( result.iterator().next() );
130 
131             tx.commit();
132 
133             return (ProjectScmRoot) object;
134         }
135         finally
136         {
137             rollback( tx );
138         }
139     }
140 
141     public ProjectScmRoot getProjectScmRoot( int projectScmRootId )
142         throws ContinuumObjectNotFoundException, ContinuumStoreException
143     {
144         return (ProjectScmRoot) getObjectById( ProjectScmRoot.class, projectScmRootId );
145     }
146 }