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.system.Profile; |
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.List; |
32 | |
33 | /** |
34 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
35 | * @version $Id: ProfileDaoImpl.java 735074 2009-01-16 18:13:10Z oching $ |
36 | * @plexus.component role="org.apache.continuum.dao.ProfileDao" |
37 | */ |
38 | @Repository("profileDao") |
39 | public class ProfileDaoImpl |
40 | extends AbstractDao |
41 | implements ProfileDao |
42 | { |
43 | public Profile getProfileByName( String profileName ) |
44 | throws ContinuumStoreException |
45 | { |
46 | PersistenceManager pm = getPersistenceManager(); |
47 | |
48 | Transaction tx = pm.currentTransaction(); |
49 | |
50 | try |
51 | { |
52 | tx.begin(); |
53 | |
54 | Extent extent = pm.getExtent( Profile.class, true ); |
55 | |
56 | Query query = pm.newQuery( extent ); |
57 | |
58 | query.declareImports( "import java.lang.String" ); |
59 | |
60 | query.declareParameters( "String name" ); |
61 | |
62 | query.setFilter( "this.name == name" ); |
63 | |
64 | Collection result = (Collection) query.execute( profileName ); |
65 | |
66 | if ( result.size() == 0 ) |
67 | { |
68 | tx.commit(); |
69 | |
70 | return null; |
71 | } |
72 | |
73 | Object object = pm.detachCopy( result.iterator().next() ); |
74 | |
75 | tx.commit(); |
76 | |
77 | return (Profile) object; |
78 | } |
79 | finally |
80 | { |
81 | rollback( tx ); |
82 | } |
83 | } |
84 | |
85 | public List<Profile> getAllProfilesByName() |
86 | { |
87 | return getAllObjectsDetached( Profile.class, "name ascending", null ); |
88 | } |
89 | |
90 | public Profile addProfile( Profile profile ) |
91 | { |
92 | return (Profile) addObject( profile ); |
93 | } |
94 | |
95 | public Profile getProfile( int profileId ) |
96 | throws ContinuumStoreException |
97 | { |
98 | return (Profile) getObjectById( Profile.class, profileId ); |
99 | } |
100 | |
101 | public void updateProfile( Profile profile ) |
102 | throws ContinuumStoreException |
103 | { |
104 | updateObject( profile ); |
105 | } |
106 | |
107 | public void removeProfile( Profile profile ) |
108 | { |
109 | removeObject( profile ); |
110 | } |
111 | } |