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.Schedule;
23  import org.apache.maven.continuum.store.ContinuumStoreException;
24  import org.springframework.stereotype.Repository;
25  
26  import java.util.Collection;
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: ScheduleDaoImpl.java 1372260 2012-08-13 04:29:09Z brett $
36   * @plexus.component role="org.apache.continuum.dao.ScheduleDao"
37   */
38  @Repository( "scheduleDao" )
39  public class ScheduleDaoImpl
40      extends AbstractDao
41      implements ScheduleDao
42  {
43      public List<Schedule> getAllSchedulesByName()
44      {
45          return getAllObjectsDetached( Schedule.class, "name ascending", null );
46      }
47  
48      public Schedule addSchedule( Schedule schedule )
49      {
50          return (Schedule) addObject( schedule );
51      }
52  
53      public Schedule getScheduleByName( String name )
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( Schedule.class, true );
65  
66              Query query = pm.newQuery( extent );
67  
68              query.declareImports( "import java.lang.String" );
69  
70              query.declareParameters( "String name" );
71  
72              query.setFilter( "this.name == name" );
73  
74              Collection result = (Collection) query.execute( name );
75  
76              if ( result.size() == 0 )
77              {
78                  tx.commit();
79  
80                  return null;
81              }
82  
83              Object object = pm.detachCopy( result.iterator().next() );
84  
85              tx.commit();
86  
87              return (Schedule) object;
88          }
89          finally
90          {
91              rollback( tx );
92          }
93      }
94  
95      public Schedule storeSchedule( Schedule schedule )
96          throws ContinuumStoreException
97      {
98          updateObject( schedule );
99  
100         return schedule;
101     }
102 
103     public void updateSchedule( Schedule schedule )
104         throws ContinuumStoreException
105     {
106         updateObject( schedule );
107     }
108 
109     public void removeSchedule( Schedule schedule )
110     {
111         removeObject( schedule );
112     }
113 
114     public Schedule getSchedule( int scheduleId )
115         throws ContinuumStoreException
116     {
117         return (Schedule) getObjectById( Schedule.class, scheduleId );
118     }
119 }