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.LocalRepository; |
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.Collection; |
31 | import java.util.Collections; |
32 | import java.util.List; |
33 | |
34 | /** |
35 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
36 | * @version $Id: LocalRepositoryDaoImpl.java 735074 2009-01-16 18:13:10Z oching $ |
37 | * @plexus.component role="org.apache.continuum.dao.LocalRepositoryDao" |
38 | */ |
39 | @Repository("localRepositoryDao") |
40 | public class LocalRepositoryDaoImpl |
41 | extends AbstractDao |
42 | implements LocalRepositoryDao |
43 | { |
44 | public LocalRepository addLocalRepository( LocalRepository repository ) |
45 | throws ContinuumStoreException |
46 | { |
47 | return (LocalRepository) addObject( repository ); |
48 | } |
49 | |
50 | public void updateLocalRepository( LocalRepository repository ) |
51 | throws ContinuumStoreException |
52 | { |
53 | updateObject( repository ); |
54 | } |
55 | |
56 | public void removeLocalRepository( LocalRepository repository ) |
57 | throws ContinuumStoreException |
58 | { |
59 | removeObject( repository ); |
60 | } |
61 | |
62 | public List<LocalRepository> getAllLocalRepositories() |
63 | { |
64 | return getAllObjectsDetached( LocalRepository.class ); |
65 | } |
66 | |
67 | public List<LocalRepository> getLocalRepositoriesByLayout( String layout ) |
68 | { |
69 | PersistenceManager pm = getPersistenceManager(); |
70 | |
71 | Transaction tx = pm.currentTransaction(); |
72 | |
73 | try |
74 | { |
75 | tx.begin(); |
76 | |
77 | Extent extent = pm.getExtent( LocalRepository.class, true ); |
78 | |
79 | Query query = pm.newQuery( extent ); |
80 | |
81 | query.declareImports( "import java.lang.String" ); |
82 | |
83 | query.declareParameters( "String layout" ); |
84 | |
85 | query.setFilter( "this.layout == layout" ); |
86 | |
87 | List result = (List) query.execute( layout ); |
88 | |
89 | return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); |
90 | } |
91 | finally |
92 | { |
93 | tx.commit(); |
94 | |
95 | rollback( tx ); |
96 | } |
97 | } |
98 | |
99 | public LocalRepository getLocalRepository( int repositoryId ) |
100 | throws ContinuumStoreException |
101 | { |
102 | return (LocalRepository) getObjectById( LocalRepository.class, repositoryId ); |
103 | } |
104 | |
105 | public LocalRepository getLocalRepositoryByName( String name ) |
106 | throws ContinuumStoreException |
107 | { |
108 | PersistenceManager pm = getPersistenceManager(); |
109 | |
110 | Transaction tx = pm.currentTransaction(); |
111 | |
112 | try |
113 | { |
114 | tx.begin(); |
115 | |
116 | Extent extent = pm.getExtent( LocalRepository.class, true ); |
117 | |
118 | Query query = pm.newQuery( extent ); |
119 | |
120 | query.declareImports( "import java.lang.String" ); |
121 | |
122 | query.declareParameters( "String name" ); |
123 | |
124 | query.setFilter( "this.name == name" ); |
125 | |
126 | Collection result = (Collection) query.execute( name ); |
127 | |
128 | if ( result.size() == 0 ) |
129 | { |
130 | tx.commit(); |
131 | |
132 | return null; |
133 | } |
134 | |
135 | Object object = pm.detachCopy( result.iterator().next() ); |
136 | |
137 | tx.commit(); |
138 | |
139 | return (LocalRepository) object; |
140 | } |
141 | finally |
142 | { |
143 | rollback( tx ); |
144 | } |
145 | } |
146 | |
147 | public LocalRepository getLocalRepositoryByLocation( String location ) |
148 | throws ContinuumStoreException |
149 | { |
150 | PersistenceManager pm = getPersistenceManager(); |
151 | |
152 | Transaction tx = pm.currentTransaction(); |
153 | |
154 | try |
155 | { |
156 | tx.begin(); |
157 | |
158 | Extent extent = pm.getExtent( LocalRepository.class, true ); |
159 | |
160 | Query query = pm.newQuery( extent ); |
161 | |
162 | query.declareImports( "import java.lang.String" ); |
163 | |
164 | query.declareParameters( "String location" ); |
165 | |
166 | query.setFilter( "this.location == location" ); |
167 | |
168 | Collection result = (Collection) query.execute( location ); |
169 | |
170 | if ( result.size() == 0 ) |
171 | { |
172 | tx.commit(); |
173 | |
174 | return null; |
175 | } |
176 | |
177 | Object object = pm.detachCopy( result.iterator().next() ); |
178 | |
179 | tx.commit(); |
180 | |
181 | return (LocalRepository) object; |
182 | } |
183 | finally |
184 | { |
185 | rollback( tx ); |
186 | } |
187 | } |
188 | } |