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.repository.DirectoryPurgeConfiguration; |
23 | import org.apache.maven.continuum.store.ContinuumStoreException; |
24 | import org.springframework.stereotype.Repository; |
25 | |
26 | import javax.jdo.Extent; |
27 | import javax.jdo.PersistenceManager; |
28 | import javax.jdo.Query; |
29 | import javax.jdo.Transaction; |
30 | import java.util.Collections; |
31 | import java.util.List; |
32 | |
33 | /** |
34 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
35 | * @version $Id: DirectoryPurgeConfigurationDaoImpl.java 776907 2009-05-21 01:01:43Z jmorales $ |
36 | * @plexus.component role="org.apache.continuum.dao.DirectoryPurgeConfigurationDao" |
37 | */ |
38 | @Repository("directoryPurgeConfigurationDao") |
39 | public class DirectoryPurgeConfigurationDaoImpl |
40 | extends AbstractDao |
41 | implements DirectoryPurgeConfigurationDao |
42 | { |
43 | public List<DirectoryPurgeConfiguration> getAllDirectoryPurgeConfigurations() |
44 | { |
45 | return getAllObjectsDetached( DirectoryPurgeConfiguration.class ); |
46 | } |
47 | |
48 | public List<DirectoryPurgeConfiguration> getDirectoryPurgeConfigurationsBySchedule( int scheduleId ) |
49 | { |
50 | PersistenceManager pm = getPersistenceManager(); |
51 | |
52 | Transaction tx = pm.currentTransaction(); |
53 | |
54 | try |
55 | { |
56 | tx.begin(); |
57 | |
58 | Extent extent = pm.getExtent( DirectoryPurgeConfiguration.class, true ); |
59 | |
60 | Query query = pm.newQuery( extent ); |
61 | |
62 | query.declareParameters( "int scheduleId" ); |
63 | |
64 | query.setFilter( "this.schedule.id == scheduleId" ); |
65 | |
66 | List result = (List) query.execute( scheduleId ); |
67 | |
68 | return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); |
69 | } |
70 | finally |
71 | { |
72 | tx.commit(); |
73 | |
74 | rollback( tx ); |
75 | } |
76 | } |
77 | |
78 | public List<DirectoryPurgeConfiguration> getEnableDirectoryPurgeConfigurationsBySchedule( int scheduleId ) |
79 | { |
80 | PersistenceManager pm = getPersistenceManager(); |
81 | |
82 | Transaction tx = pm.currentTransaction(); |
83 | |
84 | try |
85 | { |
86 | tx.begin(); |
87 | |
88 | Extent extent = pm.getExtent( DirectoryPurgeConfiguration.class, true ); |
89 | |
90 | Query query = pm.newQuery( extent ); |
91 | |
92 | query.declareParameters( "int scheduleId" ); |
93 | |
94 | query.setFilter( "this.schedule.id == scheduleId && this.enabled == true" ); |
95 | |
96 | List result = (List) query.execute( scheduleId ); |
97 | |
98 | return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); |
99 | } |
100 | finally |
101 | { |
102 | tx.commit(); |
103 | |
104 | rollback( tx ); |
105 | } |
106 | } |
107 | |
108 | public List<DirectoryPurgeConfiguration> getDirectoryPurgeConfigurationsByLocation( String location ) |
109 | { |
110 | PersistenceManager pm = getPersistenceManager(); |
111 | |
112 | Transaction tx = pm.currentTransaction(); |
113 | |
114 | try |
115 | { |
116 | tx.begin(); |
117 | |
118 | Extent extent = pm.getExtent( DirectoryPurgeConfiguration.class, true ); |
119 | |
120 | Query query = pm.newQuery( extent ); |
121 | |
122 | query.declareImports( "import java.lang.String" ); |
123 | |
124 | query.declareParameters( "String location" ); |
125 | |
126 | query.setFilter( "this.location == location" ); |
127 | |
128 | List result = (List) query.execute( location ); |
129 | |
130 | return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); |
131 | } |
132 | finally |
133 | { |
134 | tx.commit(); |
135 | |
136 | rollback( tx ); |
137 | } |
138 | } |
139 | |
140 | public List<DirectoryPurgeConfiguration> getDirectoryPurgeConfigurationsByType( String type ) |
141 | { |
142 | PersistenceManager pm = getPersistenceManager(); |
143 | |
144 | Transaction tx = pm.currentTransaction(); |
145 | |
146 | try |
147 | { |
148 | tx.begin(); |
149 | |
150 | Extent extent = pm.getExtent( DirectoryPurgeConfiguration.class, true ); |
151 | |
152 | Query query = pm.newQuery( extent ); |
153 | |
154 | query.declareImports( "import java.lang.String" ); |
155 | |
156 | query.declareParameters( "String type" ); |
157 | |
158 | query.setFilter( "this.directoryType == type" ); |
159 | |
160 | List result = (List) query.execute( type ); |
161 | |
162 | return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); |
163 | } |
164 | finally |
165 | { |
166 | tx.commit(); |
167 | |
168 | rollback( tx ); |
169 | } |
170 | } |
171 | |
172 | public DirectoryPurgeConfiguration getDirectoryPurgeConfiguration( int configurationId ) |
173 | throws ContinuumStoreException |
174 | { |
175 | return (DirectoryPurgeConfiguration) getObjectById( DirectoryPurgeConfiguration.class, configurationId ); |
176 | } |
177 | |
178 | public DirectoryPurgeConfiguration addDirectoryPurgeConfiguration( DirectoryPurgeConfiguration purgeConfiguration ) |
179 | throws ContinuumStoreException |
180 | { |
181 | return (DirectoryPurgeConfiguration) addObject( purgeConfiguration ); |
182 | } |
183 | |
184 | public void updateDirectoryPurgeConfiguration( DirectoryPurgeConfiguration purgeConfiguration ) |
185 | throws ContinuumStoreException |
186 | { |
187 | updateObject( purgeConfiguration ); |
188 | } |
189 | |
190 | public void removeDirectoryPurgeConfiguration( DirectoryPurgeConfiguration purgeConfiguration ) |
191 | throws ContinuumStoreException |
192 | { |
193 | removeObject( purgeConfiguration ); |
194 | } |
195 | } |