You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by jv...@apache.org on 2005/07/18 20:41:49 UTC
svn commit: r219549 - in /maven/continuum/trunk/continuum-core/src:
main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java
Author: jvanzyl
Date: Mon Jul 18 11:41:35 2005
New Revision: 219549
URL: http://svn.apache.org/viewcvs?rev=219549&view=rev
Log:
o augmenting tests for the schedule/project relationship.
Modified:
maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java
Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java?rev=219549&r1=219548&r2=219549&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java Mon Jul 18 11:41:35 2005
@@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
@@ -82,7 +83,48 @@
public void removeProject( String projectId )
throws ContinuumStoreException
{
- deletePersistentById( ContinuumProject.class, projectId );
+ PersistenceManager pm = pmf.getPersistenceManager();
+
+ Transaction tx = pm.currentTransaction();
+
+ try
+ {
+ tx.begin();
+
+ Object id = pm.newObjectIdInstance( ContinuumProject.class, projectId );
+
+ ContinuumProject project = (ContinuumProject) pm.getObjectById( id );
+
+ // ----------------------------------------------------------------------
+ // We need to remove this project reference from any schedule in the
+ // system. So grab the list of schedules this project belongs to
+ // then iterate through the collection of schedules removing the
+ // reference to this project. This seems like a bit much but the
+ // only thing that works.
+ // ----------------------------------------------------------------------
+
+ if ( project.getSchedules() != null && project.getSchedules().size() > 0 )
+ {
+ Set schedules = project.getSchedules();
+
+ for ( Iterator i = schedules.iterator(); i.hasNext(); )
+ {
+ ContinuumSchedule schedule = (ContinuumSchedule) i.next();
+
+ schedule.getProjects().remove( project );
+ }
+
+ makePersistentAll( pm, project.getSchedules() );
+ }
+
+ pm.deletePersistent( project );
+
+ commit( tx );
+ }
+ finally
+ {
+ rollback( tx );
+ }
}
public void updateProject( ContinuumProject project )
@@ -113,8 +155,6 @@
{
rollback( tx );
}
-
- //updateObject( project );
}
public Collection getAllProjects()
@@ -372,6 +412,18 @@
{
rollback( tx );
}
+ }
+
+ public void updateSchedule( ContinuumSchedule schedule )
+ throws ContinuumStoreException
+ {
+ updateObject( schedule );
+ }
+
+ public void removeSchedule( ContinuumSchedule schedule )
+ throws ContinuumStoreException
+ {
+ attachAndDelete( schedule );
}
// ----------------------------------------------------------------------
Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java?rev=219549&r1=219548&r2=219549&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java (original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTest.java Mon Jul 18 11:41:35 2005
@@ -1,6 +1,3 @@
-/*
- * Copyright (c) 2005 Your Corporation. All Rights Reserved.
- */
package org.apache.maven.continuum.store;
import java.util.ArrayList;
@@ -750,16 +747,32 @@
assertEquals( "0 * * * * ?", schedule.getCronExpression() );
// ----------------------------------------------------------------------
- //
+ // Now lookup the schedule on its own and make sure the project is
+ // present within the schedule.
// ----------------------------------------------------------------------
- schedule = store.getSchedule( schedule.getId() );
+ String scheduleId = schedule.getId();
+
+ schedule = store.getSchedule( scheduleId );
assertNotNull( schedule );
project = (ContinuumProject) schedule.getProjects().iterator().next();
assertNotNull( project );
+
+ assertEquals( "Project Scheduling", project.getName() );
+
+ // ----------------------------------------------------------------------
+ // Now delete the project from the store and make sure that the schedule
+ // still remains in the store.
+ // ----------------------------------------------------------------------
+
+ store.removeProject( projectId );
+
+ schedule = store.getSchedule( scheduleId );
+
+ assertNotNull( schedule );
}
// ----------------------------------------------------------------------