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.BuildQueue;
23  import org.apache.maven.continuum.store.ContinuumStoreException;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  import org.springframework.stereotype.Repository;
27  
28  import java.util.Collection;
29  import java.util.Collections;
30  import java.util.List;
31  import javax.jdo.Extent;
32  import javax.jdo.PersistenceManager;
33  import javax.jdo.Query;
34  import javax.jdo.Transaction;
35  
36  /**
37   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
38   * @plexus.component role="org.apache.continuum.dao.BuildQueueDao"
39   */
40  @Repository( "buildQueueDao" )
41  public class BuildQueueDaoImpl
42      extends AbstractDao
43      implements BuildQueueDao
44  {
45      private static Logger log = LoggerFactory.getLogger( BuildQueueDaoImpl.class );
46  
47      public BuildQueue addBuildQueue( BuildQueue buildQueue )
48          throws ContinuumStoreException
49      {
50          return (BuildQueue) addObject( buildQueue );
51      }
52  
53      public List<BuildQueue> getAllBuildQueues()
54          throws ContinuumStoreException
55      {
56          PersistenceManager pm = getPersistenceManager();
57  
58          Transaction tx = pm.currentTransaction();
59  
60          try
61          {
62              tx.begin();
63  
64              Extent extent = pm.getExtent( BuildQueue.class, true );
65  
66              Query query = pm.newQuery( extent );
67  
68              List result = (List) query.execute();
69  
70              return result == null ? Collections.EMPTY_LIST : (List<BuildQueue>) pm.detachCopyAll( result );
71          }
72          finally
73          {
74              tx.commit();
75  
76              rollback( tx );
77          }
78      }
79  
80      public BuildQueue getBuildQueue( int buildQueueId )
81          throws ContinuumStoreException
82      {
83          return (BuildQueue) getObjectById( BuildQueue.class, buildQueueId );
84      }
85  
86      public BuildQueue getBuildQueueByName( String name )
87          throws ContinuumStoreException
88      {
89          PersistenceManager pm = getPersistenceManager();
90  
91          Transaction tx = pm.currentTransaction();
92  
93          try
94          {
95              tx.begin();
96  
97              Extent extent = pm.getExtent( BuildQueue.class, true );
98  
99              Query query = pm.newQuery( extent );
100 
101             query.declareImports( "import java.lang.String" );
102 
103             query.declareParameters( "String name" );
104 
105             query.setFilter( "this.name == name" );
106 
107             Collection result = (Collection) query.execute( name );
108 
109             if ( result.size() == 0 )
110             {
111                 tx.commit();
112 
113                 return null;
114             }
115 
116             Object object = pm.detachCopy( result.iterator().next() );
117 
118             tx.commit();
119 
120             return (BuildQueue) object;
121         }
122         finally
123         {
124             rollback( tx );
125         }
126     }
127 
128     public void removeBuildQueue( BuildQueue buildQueue )
129         throws ContinuumStoreException
130     {
131         removeObject( buildQueue );
132     }
133 
134     public BuildQueue storeBuildQueue( BuildQueue buildQueue )
135         throws ContinuumStoreException
136     {
137         updateObject( buildQueue );
138 
139         return buildQueue;
140     }
141 }