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