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.maven.continuum.model.system.Profile;
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
35
36
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 }