continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r219544 - in /maven/continuum/trunk/continuum-core/src: main/java/org/apache/maven/continuum/store/ test/java/org/apache/maven/continuum/store/
Date Mon, 18 Jul 2005 17:52:36 GMT
Author: jvanzyl
Date: Mon Jul 18 10:51:43 2005
New Revision: 219544

URL: http://svn.apache.org/viewcvs?rev=219544&view=rev
Log:
o adding methods to the store for schedules

Removed:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/store/ModelloJPoxContinuumStore.java
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=219544&r1=219543&r2=219544&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 10:51:43 2005
@@ -1,30 +1,26 @@
-/*
- * Copyright (c) 2005 Your Corporation. All Rights Reserved.
- */
 package org.apache.maven.continuum.store;
 
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jdo.Extent;
-import javax.jdo.JDOObjectNotFoundException;
-import javax.jdo.JDOUserException;
-import javax.jdo.PersistenceManager;
-import javax.jdo.PersistenceManagerFactory;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
 import org.apache.maven.continuum.project.ContinuumBuild;
 import org.apache.maven.continuum.project.ContinuumProject;
 import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.continuum.project.ContinuumSchedule;
 import org.apache.maven.continuum.scm.ScmResult;
-
 import org.codehaus.plexus.jdo.JdoFactory;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 
+import javax.jdo.Extent;
+import javax.jdo.JDOObjectNotFoundException;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
@@ -71,8 +67,6 @@
 
             Object object = makePersistent( pm, project );
 
-            object = pm.detachCopy( object );
-
             project = (ContinuumProject) object;
 
             commit( tx );
@@ -94,7 +88,33 @@
     public void updateProject( ContinuumProject project )
         throws ContinuumStoreException
     {
-        updateObject( project );
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            // ----------------------------------------------------------------------
+            // Work around for bug with M:N relationships
+            // ----------------------------------------------------------------------
+
+            if ( project.getSchedules() != null && project.getSchedules().size()
> 0 )
+            {
+                makePersistentAll( pm, project.getSchedules() );
+            }
+
+            pm.attachCopy( project, true );
+
+            commit( tx );
+        }
+        finally
+        {
+            rollback( tx );
+        }
+
+        //updateObject( project );
     }
 
     public Collection getAllProjects()
@@ -276,6 +296,88 @@
         }
     }
 
+    // ----------------------------------------------------------------------
+    // Schedules
+    // ----------------------------------------------------------------------
+
+    public ContinuumSchedule getSchedule( String projectId )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            ContinuumSchedule schedule = getContinuumSchedule( pm, projectId );
+
+            schedule = (ContinuumSchedule) pm.detachCopy( schedule );
+
+            commit( tx );
+
+            return schedule;
+        }
+        catch( JDOObjectNotFoundException e )
+        {
+            throw new ContinuumObjectNotFoundException( ContinuumProject.class.getName(),
projectId );
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+    private ContinuumSchedule getContinuumSchedule( PersistenceManager pm, String projectId
)
+    {
+        pm.getFetchPlan().addGroup( "schedule-detail" );
+
+        Object id = pm.newObjectIdInstance( ContinuumSchedule.class, projectId );
+
+        return (ContinuumSchedule) pm.getObjectById( id );
+    }
+
+    public Collection getSchedules()
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = pmf.getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( ContinuumSchedule.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.setOrdering( "name ascending" );
+
+            Collection result = (Collection) query.execute();
+
+            result = pm.detachCopyAll( result );
+
+            for ( Iterator it = result.iterator(); it.hasNext(); )
+            {
+                setProjectState( (ContinuumProject) it.next() );
+            }
+
+            commit( tx );
+
+            return result;
+        }
+        finally
+        {
+            rollback( tx );
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    // Builds
+    // ----------------------------------------------------------------------
+
     public String addBuild( String projectId, ContinuumBuild build )
         throws ContinuumStoreException
     {
@@ -515,6 +617,11 @@
         Object id = pm.getObjectId( object );
 
         return pm.getObjectById( id );
+    }
+
+    private void makePersistentAll( PersistenceManager pm, Collection object )
+    {
+        pm.makePersistentAll( object );
     }
 
     private void attachAndDelete( Object object )

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=219544&r1=219543&r2=219544&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 10:51:43 2005
@@ -11,8 +11,10 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 
 import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.scheduler.ContinuumSchedulerConstants;
 import org.apache.maven.continuum.execution.ContinuumBuildExecutionResult;
 import org.apache.maven.continuum.execution.maven.m2.MavenTwoBuildExecutor;
 import org.apache.maven.continuum.project.ContinuumBuild;
@@ -20,6 +22,7 @@
 import org.apache.maven.continuum.project.ContinuumProject;
 import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.apache.maven.continuum.project.MavenTwoProject;
+import org.apache.maven.continuum.project.ContinuumSchedule;
 import org.apache.maven.continuum.scm.ScmFile;
 import org.apache.maven.continuum.scm.ScmResult;
 
@@ -709,5 +712,80 @@
         configuration = notifier.getConfiguration();
 
         assertEquals( "foo", configuration.get( "moo" ) );
+    }
+
+    // ----------------------------------------------------------------------
+    // Schedules
+    // ----------------------------------------------------------------------
+
+    public void testSchedulesBeingAddedToProject()
+        throws Exception
+    {
+        String projectId = addMavenTwoProject( "Project Scheduling", "scm:scheduling" );
+
+        ContinuumProject project = store.getProject( projectId );
+
+        project.addSchedule( createStubSchedule( "schedule1" ) );
+
+        store.updateProject( project );
+
+        project = store.getProject( projectId );
+
+        assertNotNull( project );
+
+        Set schedules = project.getSchedules();
+
+        ContinuumSchedule schedule = (ContinuumSchedule) schedules.iterator().next();
+
+        assertEquals( "schedule1", schedule.getName() );
+
+        assertEquals( "schedule1", schedule.getDescription() );
+
+        assertTrue( schedule.isActive() );
+
+        assertEquals( ContinuumSchedulerConstants.SCM_MODE_UPDATE, schedule.getScmMode()
);
+
+        assertEquals( 3600, schedule.getDelay() );
+
+        assertEquals( "0 * * * * ?", schedule.getCronExpression() );
+
+        // ----------------------------------------------------------------------
+        //
+        // ----------------------------------------------------------------------
+
+        schedule = store.getSchedule( schedule.getId() );
+
+        assertNotNull( schedule );
+
+        project = (ContinuumProject) schedule.getProjects().iterator().next();
+
+        assertNotNull( project );
+    }
+
+    // ----------------------------------------------------------------------
+    // name
+    // description = name
+    // active = true
+    // scmMode = ContinuumSchedulerConstants.SCM_MODE_UPDATE
+    // delay = 3600
+    // cronExpression = 0 * * * * ?
+    // ----------------------------------------------------------------------
+    protected ContinuumSchedule createStubSchedule( String name )
+    {
+        ContinuumSchedule schedule = new ContinuumSchedule();
+
+        schedule.setName( name );
+
+        schedule.setDescription( name );
+
+        schedule.setActive( true );
+
+        schedule.setScmMode( ContinuumSchedulerConstants.SCM_MODE_UPDATE );
+
+        schedule.setDelay( 3600 );
+
+        schedule.setCronExpression( "0 * * * * ?" );
+
+        return schedule;
     }
 }



Mime
View raw message