1 package org.apache.continuum.dao;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 java.util.Collection;
27 import java.util.Collections;
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
36
37
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 }