You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ev...@apache.org on 2008/08/06 00:01:31 UTC
svn commit: r682986 [2/2] - in
/continuum/branches/continuum-refactoring-evenisse:
continuum-api/src/main/java/org/apache/continuum/dao/
continuum-api/src/main/java/org/apache/maven/continuum/store/
continuum-core/src/main/java/org/apache/maven/continu...
Added: continuum/branches/continuum-refactoring-evenisse/continuum-store/src/main/java/org/apache/continuum/dao/DaoUtilsImpl.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-refactoring-evenisse/continuum-store/src/main/java/org/apache/continuum/dao/DaoUtilsImpl.java?rev=682986&view=auto
==============================================================================
--- continuum/branches/continuum-refactoring-evenisse/continuum-store/src/main/java/org/apache/continuum/dao/DaoUtilsImpl.java (added)
+++ continuum/branches/continuum-refactoring-evenisse/continuum-store/src/main/java/org/apache/continuum/dao/DaoUtilsImpl.java Tue Aug 5 15:01:30 2008
@@ -0,0 +1,323 @@
+package org.apache.continuum.dao;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
+import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.ProjectDependency;
+import org.apache.maven.continuum.model.project.ProjectDeveloper;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.apache.maven.continuum.model.project.ProjectNotifier;
+import org.apache.maven.continuum.model.project.Schedule;
+import org.apache.maven.continuum.model.scm.ChangeFile;
+import org.apache.maven.continuum.model.scm.ChangeSet;
+import org.apache.maven.continuum.model.scm.ScmResult;
+import org.apache.maven.continuum.model.system.Installation;
+import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.model.system.SystemConfiguration;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.codehaus.plexus.jdo.PlexusJdoUtils;
+
+import javax.jdo.Extent;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.continuum.dao.DaoUtils"
+ */
+public class DaoUtilsImpl
+ extends AbstractDao
+ implements DaoUtils
+{
+ /**
+ * @plexus.requirement role="org.apache.continuum.dao.ProjectDao"
+ */
+ private ProjectDao projectDao;
+
+ public void closeStore()
+ {
+ closePersistenceManagerFactory( getContinuumPersistenceManagerFactory(), 1 );
+ }
+
+ public void eraseDatabase()
+ {
+ PlexusJdoUtils.removeAll( getPersistenceManager(), BuildDefinitionTemplate.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), BuildResult.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), ProjectGroup.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), Project.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), BuildDefinition.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), Schedule.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), Profile.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), Installation.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), ScmResult.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), SystemConfiguration.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), ProjectNotifier.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), ProjectDeveloper.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), ProjectDependency.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), ChangeSet.class );
+ PlexusJdoUtils.removeAll( getPersistenceManager(), ChangeFile.class );
+ }
+
+ /**
+ * Close the PersistenceManagerFactory.
+ *
+ * @param numTry The number of try. The maximum try is 5.
+ */
+ private void closePersistenceManagerFactory( PersistenceManagerFactory pmf, int numTry )
+ {
+ if ( pmf != null )
+ {
+ if ( !pmf.isClosed() )
+ {
+ try
+ {
+ pmf.close();
+ }
+ catch ( SecurityException e )
+ {
+ throw e;
+ }
+ catch ( JDOUserException e )
+ {
+ if ( numTry < 5 )
+ {
+ try
+ {
+ Thread.currentThread().wait( 1000 );
+ }
+ catch ( InterruptedException ie )
+ {
+ // nothing to do
+ }
+
+ closePersistenceManagerFactory( pmf, numTry + 1 );
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * get the combined list of projectId and build definitions, including the
+ * ones inherited by their project group
+ *
+ * @param scheduleId
+ * @return
+ * @throws org.apache.maven.continuum.store.ContinuumStoreException
+ *
+ * @todo Move to a better place
+ */
+ public Map getAggregatedProjectIdsAndBuildDefinitionIdsBySchedule( int scheduleId )
+ throws ContinuumStoreException
+ {
+ Map projectSource = getProjectIdsAndBuildDefinitionsIdsBySchedule( scheduleId );
+ Map projectGroupSource = getProjectGroupIdsAndBuildDefinitionsIdsBySchedule( scheduleId );
+
+ Map aggregate = new HashMap();
+
+ // start out by checking if we have projects with this scheduleId
+ if ( projectSource != null )
+ {
+ aggregate.putAll( projectSource );
+ }
+
+ // iterate through the project groups and make sure we are not walking
+ // over projects that
+ // might define their own build definitions
+ if ( projectGroupSource != null )
+ {
+ for ( Iterator i = projectGroupSource.keySet().iterator(); i.hasNext(); )
+ {
+ Integer projectGroupId = (Integer) i.next();
+ List projectsInGroup = projectDao.getProjectsInGroup( projectGroupId.intValue() );
+
+ for ( Iterator j = projectsInGroup.iterator(); j.hasNext(); )
+ {
+ Integer projectId = new Integer( ( (Project) j.next() ).getId() );
+ if ( !aggregate.keySet().contains( projectId ) )
+ {
+ aggregate.put( projectId, projectGroupSource.get( projectGroupId ) );
+ }
+ }
+ }
+ }
+ return aggregate;
+ }
+
+ /**
+ * @param scheduleId
+ * @return
+ * @throws ContinuumStoreException
+ * @todo Move to a better place
+ */
+ public Map getProjectIdsAndBuildDefinitionsIdsBySchedule( int scheduleId )
+ throws ContinuumStoreException
+ {
+ PersistenceManager pm = getPersistenceManager();
+
+ Transaction tx = pm.currentTransaction();
+
+ try
+ {
+ tx.begin();
+
+ Extent extent = pm.getExtent( Project.class, true );
+
+ Query query = pm.newQuery( extent );
+
+ query.declareParameters( "int scheduleId" );
+
+ query.declareImports( "import org.apache.maven.continuum.model.project.BuildDefinition" );
+
+ query.declareVariables( "BuildDefinition buildDef" );
+
+ query.setFilter( "buildDefinitions.contains(buildDef) && buildDef.schedule.id == scheduleId" );
+
+ query.setResult( "this.id, buildDef.id" );
+
+ List result = (List) query.execute( new Integer( scheduleId ) );
+
+ Map projects = new HashMap();
+
+ if ( result != null && !result.isEmpty() )
+ {
+ for ( Iterator i = result.iterator(); i.hasNext(); )
+ {
+ Object[] obj = (Object[]) i.next();
+
+ List buildDefinitions;
+
+ if ( projects.get( obj[0] ) != null )
+ {
+ buildDefinitions = (List) projects.get( obj[0] );
+ }
+ else
+ {
+ buildDefinitions = new ArrayList();
+
+ projects.put( obj[0], buildDefinitions );
+ }
+
+ buildDefinitions.add( obj[1] );
+ }
+
+ return projects;
+ }
+ if ( !projects.isEmpty() )
+ {
+ return projects;
+ }
+ }
+ finally
+ {
+ tx.commit();
+
+ rollback( tx );
+ }
+
+ return null;
+ }
+
+ /**
+ * @param scheduleId
+ * @return
+ * @throws ContinuumStoreException
+ * @todo Move to a better place
+ */
+ public Map getProjectGroupIdsAndBuildDefinitionsIdsBySchedule( int scheduleId )
+ throws ContinuumStoreException
+ {
+ PersistenceManager pm = getPersistenceManager();
+
+ Transaction tx = pm.currentTransaction();
+
+ try
+ {
+ tx.begin();
+
+ Extent extent = pm.getExtent( ProjectGroup.class, true );
+
+ Query query = pm.newQuery( extent );
+
+ query.declareParameters( "int scheduleId" );
+
+ query.declareImports( "import org.apache.maven.continuum.model.project.BuildDefinition" );
+
+ query.declareVariables( "BuildDefinition buildDef" );
+
+ query.setFilter( "buildDefinitions.contains(buildDef) && buildDef.schedule.id == scheduleId" );
+
+ query.setResult( "this.id, buildDef.id" );
+
+ List result = (List) query.execute( scheduleId );
+
+ Map projectGroups = new HashMap();
+
+ if ( result != null && !result.isEmpty() )
+ {
+ for ( Iterator i = result.iterator(); i.hasNext(); )
+ {
+ Object[] obj = (Object[]) i.next();
+
+ List buildDefinitions;
+
+ if ( projectGroups.get( obj[0] ) != null )
+ {
+ buildDefinitions = (List) projectGroups.get( obj[0] );
+ }
+ else
+ {
+ buildDefinitions = new ArrayList();
+
+ projectGroups.put( obj[0], buildDefinitions );
+ }
+
+ buildDefinitions.add( obj[1] );
+ }
+
+ return projectGroups;
+ }
+ }
+ finally
+ {
+ tx.commit();
+
+ rollback( tx );
+ }
+ return null;
+ }
+
+}
Propchange: continuum/branches/continuum-refactoring-evenisse/continuum-store/src/main/java/org/apache/continuum/dao/DaoUtilsImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: continuum/branches/continuum-refactoring-evenisse/continuum-store/src/main/java/org/apache/continuum/dao/DaoUtilsImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: continuum/branches/continuum-refactoring-evenisse/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-refactoring-evenisse/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java?rev=682986&r1=682985&r2=682986&view=diff
==============================================================================
--- continuum/branches/continuum-refactoring-evenisse/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java (original)
+++ continuum/branches/continuum-refactoring-evenisse/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java Tue Aug 5 15:01:30 2008
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.continuum.dao.DaoUtils;
import org.apache.continuum.dao.InstallationDao;
import org.apache.continuum.dao.ProfileDao;
import org.apache.continuum.dao.ProjectDao;
@@ -56,7 +57,7 @@
public abstract class AbstractContinuumStoreTestCase
extends PlexusTestCase
{
- protected ContinuumStore store;
+ protected DaoUtils daoUtilsImpl;
protected InstallationDao installationDao;
@@ -111,7 +112,7 @@
{
super.setUp();
- store = createStore();
+ createStore();
installationDao = (InstallationDao) lookup( InstallationDao.class.getName() );
@@ -465,9 +466,9 @@
{
super.tearDown();
- store.eraseDatabase();
+ daoUtilsImpl.eraseDatabase();
- store.closeStore();
+ daoUtilsImpl.closeStore();
}
protected void assertBuildDatabase()
@@ -1115,7 +1116,7 @@
*
* @todo push down to a Jdo specific test
*/
- protected ContinuumStore createStore()
+ protected void createStore()
throws Exception
{
DefaultConfigurableJdoFactory jdoFactory =
@@ -1123,6 +1124,6 @@
jdoFactory.setUrl( "jdbc:hsqldb:mem:" + getName() );
- return (ContinuumStore) lookup( ContinuumStore.ROLE, "jdo" );
+ daoUtilsImpl = (DaoUtils) lookup( DaoUtils.class.getName() );
}
}
Modified: continuum/branches/continuum-refactoring-evenisse/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-refactoring-evenisse/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java?rev=682986&r1=682985&r2=682986&view=diff
==============================================================================
--- continuum/branches/continuum-refactoring-evenisse/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java (original)
+++ continuum/branches/continuum-refactoring-evenisse/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java Tue Aug 5 15:01:30 2008
@@ -21,6 +21,7 @@
import org.apache.continuum.dao.BuildDefinitionDao;
import org.apache.continuum.dao.BuildDefinitionTemplateDao;
+import org.apache.continuum.dao.BuildResultDao;
import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
import org.apache.maven.continuum.installation.InstallationService;
import org.apache.maven.continuum.model.project.BuildDefinition;
@@ -59,6 +60,8 @@
protected BuildDefinitionDao buildDefinitionDao;
+ protected BuildResultDao buildResultDao;
+
// ----------------------------------------------------------------------
// TEST METHODS
// ----------------------------------------------------------------------
@@ -637,7 +640,7 @@
assertEquals( "check size is now 1", 1, project.getBuildResults().size() );
assertBuildResultEquals( testBuildResult2, (BuildResult) project.getBuildResults().get( 0 ) );
- List results = store.getAllBuildsForAProjectByDate( testProject1.getId() );
+ List results = buildResultDao.getAllBuildsForAProjectByDate( testProject1.getId() );
assertEquals( "check item count", 1, results.size() );
assertBuildResultEquals( testBuildResult2, (BuildResult) results.get( 0 ) );
@@ -652,7 +655,7 @@
{
try
{
- store.getBuildResult( INVALID_ID );
+ buildResultDao.getBuildResult( INVALID_ID );
fail( "Should not find build result with invalid ID" );
}
catch ( ContinuumObjectNotFoundException expected )
@@ -663,7 +666,7 @@
public void testGetAllBuildsForAProject()
{
- List results = store.getAllBuildsForAProjectByDate( testProject1.getId() );
+ List results = buildResultDao.getAllBuildsForAProjectByDate( testProject1.getId() );
assertEquals( "check item count", 2, results.size() );
@@ -681,7 +684,7 @@
public void testGetBuildResult()
throws ContinuumStoreException
{
- BuildResult buildResult = store.getBuildResult( testBuildResult3.getId() );
+ BuildResult buildResult = buildResultDao.getBuildResult( testBuildResult3.getId() );
assertBuildResultEquals( testBuildResult3, buildResult );
assertScmResultEquals( testBuildResult3.getScmResult(), buildResult.getScmResult() );
assertProjectEquals( testProject2, buildResult.getProject() );
@@ -1166,6 +1169,8 @@
buildDefinitionTemplateDao = (BuildDefinitionTemplateDao) lookup( BuildDefinitionTemplateDao.class.getName() );
+ buildResultDao = (BuildResultDao) lookup( BuildResultDao.class.getName() );
+
createBuildDatabase();
}
Modified: continuum/branches/continuum-refactoring-evenisse/continuum-test/src/main/java/org/apache/maven/continuum/AbstractContinuumTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-refactoring-evenisse/continuum-test/src/main/java/org/apache/maven/continuum/AbstractContinuumTest.java?rev=682986&r1=682985&r2=682986&view=diff
==============================================================================
--- continuum/branches/continuum-refactoring-evenisse/continuum-test/src/main/java/org/apache/maven/continuum/AbstractContinuumTest.java (original)
+++ continuum/branches/continuum-refactoring-evenisse/continuum-test/src/main/java/org/apache/maven/continuum/AbstractContinuumTest.java Tue Aug 5 15:01:30 2008
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.continuum.dao.DaoUtils;
import org.apache.continuum.dao.ProjectDao;
import org.apache.continuum.dao.ProjectGroupDao;
import org.apache.continuum.dao.ScheduleDao;
@@ -32,7 +33,6 @@
import org.apache.maven.continuum.model.project.ProjectNotifier;
import org.apache.maven.continuum.model.scm.ScmResult;
import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
-import org.apache.maven.continuum.store.ContinuumStore;
import org.apache.maven.continuum.store.ContinuumStoreException;
import org.codehaus.plexus.jdo.JdoFactory;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
@@ -54,7 +54,7 @@
public abstract class AbstractContinuumTest
extends PlexusInSpringTestCase
{
- private ContinuumStore store;
+ private DaoUtils daoUtils;
private ProjectDao projectDao;
@@ -72,7 +72,7 @@
{
super.setUp();
- getStore();
+ init();
getProjectDao();
@@ -98,7 +98,7 @@
protected void tearDown()
throws Exception
{
- store.eraseDatabase();
+ daoUtils.eraseDatabase();
super.tearDown();
}
@@ -145,14 +145,9 @@
// Store
// ----------------------------------------------------------------------
- protected ContinuumStore getStore()
+ private void init()
throws Exception
{
- if ( store != null )
- {
- return store;
- }
-
// ----------------------------------------------------------------------
// Set up the JDO factory
// ----------------------------------------------------------------------
@@ -215,9 +210,7 @@
//
// ----------------------------------------------------------------------
- store = (ContinuumStore) lookup( ContinuumStore.ROLE, "jdo" );
-
- return store;
+ daoUtils = (DaoUtils) lookup( DaoUtils.class.getName() );
}
protected ProjectDao getProjectDao()
@@ -338,7 +331,7 @@
// Public utility methods
// ----------------------------------------------------------------------
- public Project addProject( ContinuumStore store, Project project )
+ public Project addProject( Project project )
throws Exception
{
ProjectGroup defaultProjectGroup = getDefaultProjectGroup();
@@ -368,26 +361,12 @@
return project;
}
- public Project addProject( ContinuumStore store, String name )
+ public Project addProject( String name )
throws Exception
{
- return addProject( store, makeStubProject( name ) );
+ return addProject( makeStubProject( name ) );
}
- public Project addProject( ContinuumStore store, String name, String nagEmailAddress, String version )
- throws Exception
- {
- return addProject( store, makeProject( name, nagEmailAddress, version ) );
- }
-
- /*public static void setCheckoutDone( ContinuumStore store, Project project, ScmResult scmResult )
- throws ContinuumStoreException
- {
- project.setCheckoutResult( scmResult );
-
- store.updateProject( project );
- }*/
-
// ----------------------------------------------------------------------
// Assertions
// ----------------------------------------------------------------------
Modified: continuum/branches/continuum-refactoring-evenisse/continuum-webapp/src/main/resources/META-INF/plexus/application.xml
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-refactoring-evenisse/continuum-webapp/src/main/resources/META-INF/plexus/application.xml?rev=682986&r1=682985&r2=682986&view=diff
==============================================================================
--- continuum/branches/continuum-refactoring-evenisse/continuum-webapp/src/main/resources/META-INF/plexus/application.xml (original)
+++ continuum/branches/continuum-refactoring-evenisse/continuum-webapp/src/main/resources/META-INF/plexus/application.xml Tue Aug 5 15:01:30 2008
@@ -51,8 +51,10 @@
<role>org.codehaus.plexus.velocity.VelocityComponent</role>
</requirement>
<requirement>
- <role>org.apache.maven.continuum.store.ContinuumStore</role>
- <role-hint>jdo</role-hint>
+ <role>org.apache.continuum.dao.ProjectDao</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.continuum.dao.BuildResultDao</role>
</requirement>
<requirement>
<role>org.codehaus.plexus.mailsender.MailSender</role>
@@ -135,8 +137,10 @@
<role>org.apache.maven.continuum.configuration.ConfigurationService</role>
</requirement>
<requirement>
- <role>org.apache.maven.continuum.store.ContinuumStore</role>
- <role-hint>jdo</role-hint>
+ <role>org.apache.continuum.dao.ProjectDao</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.continuum.dao.BuildResultDao</role>
</requirement>
</requirements>
<configuration>
@@ -169,8 +173,10 @@
<role>org.apache.maven.continuum.configuration.ConfigurationService</role>
</requirement>
<requirement>
- <role>org.apache.maven.continuum.store.ContinuumStore</role>
- <role-hint>jdo</role-hint>
+ <role>org.apache.continuum.dao.ProjectDao</role>
+ </requirement>
+ <requirement>
+ <role>org.apache.continuum.dao.BuildResultDao</role>
</requirement>
</requirements>
<configuration>