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 java.util.Collection;
23 import java.util.List;
24
25 import javax.jdo.Extent;
26 import javax.jdo.PersistenceManager;
27 import javax.jdo.Query;
28 import javax.jdo.Transaction;
29
30 import org.apache.continuum.model.project.ProjectScmRoot;
31 import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
32 import org.apache.maven.continuum.store.ContinuumStoreException;
33 import org.springframework.stereotype.Repository;
34
35
36
37
38
39
40 @Repository("projectScmRootDao")
41 public class ProjectScmRootDaoImpl
42 extends AbstractDao
43 implements ProjectScmRootDao
44 {
45 public ProjectScmRoot addProjectScmRoot( ProjectScmRoot projectScmRoot )
46 throws ContinuumStoreException
47 {
48 return (ProjectScmRoot) addObject( projectScmRoot );
49 }
50
51 public List<ProjectScmRoot> getAllProjectScmRoots()
52 {
53 return getAllObjectsDetached( ProjectScmRoot.class );
54 }
55
56 public List<ProjectScmRoot> getProjectScmRootByProjectGroup( int projectGroupId )
57 {
58 PersistenceManager pm = getPersistenceManager();
59
60 Transaction tx = pm.currentTransaction();
61
62 try
63 {
64 tx.begin();
65
66 Extent extent = pm.getExtent( ProjectScmRoot.class, true );
67
68 Query query = pm.newQuery( extent, "projectGroup.id == " + projectGroupId );
69
70 List result = (List) query.execute();
71
72 result = (List) pm.detachCopyAll( result );
73
74 tx.commit();
75
76 return result;
77 }
78 finally
79 {
80 rollback( tx );
81 }
82 }
83
84 public void removeProjectScmRoot( ProjectScmRoot projectScmRoot )
85 throws ContinuumStoreException
86 {
87 removeObject( projectScmRoot );
88 }
89
90 public void updateProjectScmRoot( ProjectScmRoot projectScmRoot )
91 throws ContinuumStoreException
92 {
93 updateObject( projectScmRoot );
94 }
95
96 public ProjectScmRoot getProjectScmRootByProjectGroupAndScmRootAddress( int projectGroupId, String scmRootAddress )
97 throws ContinuumStoreException
98 {
99 PersistenceManager pm = getPersistenceManager();
100
101 Transaction tx = pm.currentTransaction();
102
103 try
104 {
105 tx.begin();
106
107 Extent extent = pm.getExtent( ProjectScmRoot.class, true );
108
109 Query query = pm.newQuery( extent );
110
111 query.declareImports( "import java.lang.String" );
112
113 query.declareParameters( "int projectGroupId, String scmRootAddress" );
114
115 query.setFilter( "this.projectGroup.id == projectGroupId && this.scmRootAddress == scmRootAddress" );
116
117 Object[] params = new Object[2];
118 params[0] = projectGroupId;
119 params[1] = scmRootAddress;
120
121 Collection result = (Collection) query.executeWithArray( params );
122
123 if ( result.size() == 0 )
124 {
125 tx.commit();
126
127 return null;
128 }
129
130 Object object = pm.detachCopy( result.iterator().next() );
131
132 tx.commit();
133
134 return (ProjectScmRoot) object;
135 }
136 finally
137 {
138 rollback( tx );
139 }
140 }
141
142 public ProjectScmRoot getProjectScmRoot( int projectScmRootId )
143 throws ContinuumObjectNotFoundException, ContinuumStoreException
144 {
145 return (ProjectScmRoot) getObjectById( ProjectScmRoot.class, projectScmRootId );
146 }
147 }