* Adding boilerplate for DatabaseUpdater.

* Splitting ArchivaDAO into sub-DAO's to aide in maintenance.



git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@526822 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-04-09 16:39:58 +00:00
parent 3fddad3e8c
commit 0dc680c13e
18 changed files with 980 additions and 225 deletions

View File

@ -189,7 +189,7 @@ public class ArtifactUpdateDatabaseConsumer
artifact.getModel().setSize( artifactFile.length() );
artifact.getModel().setOrigin( "FileSystem" );
dao.saveArtifact( artifact.getModel() );
dao.getArtifactDAO().saveArtifact( artifact );
}
catch ( LayoutException e )
{

View File

@ -98,6 +98,7 @@
</dependency>
</dependencies>
<executions>
<!-- TODO: put this into a profile!
<execution>
<id>create-ddl</id>
<phase>generate-test-resources</phase>
@ -134,6 +135,7 @@
</toolProperties>
</configuration>
</execution>
-->
<execution>
<id>enhance</id>
<goals>

View File

@ -326,6 +326,16 @@
The timestamp when this artifact was indexed.
</description>
</field>
<field>
<name>whenProcessed</name>
<identifier>false</identifier>
<version>1.0.0+</version>
<type>Date</type>
<required>false</required>
<description>
When this artifact's contents was processed.
</description>
</field>
<field>
<name>origin</name>
<identifier>false</identifier>
@ -337,6 +347,22 @@
</description>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>1.0.0+</version>
<code><![CDATA[
/**
* Identify if this artifact's contents have been processed or not.
*
* @return true if the artifact's contents have been processed.
*/
public boolean isProcessed()
{
return (whenProcessed == null);
}
]]></code>
</codeSegment>
</codeSegments>
</class>
<class stash.storable="true"
jpox.table="JAVA_ARTIFACT"

View File

@ -29,6 +29,14 @@
<artifactId>archiva-database</artifactId>
<name>Archiva Database</name>
<dependencies>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-consumer-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-model</artifactId>

View File

@ -19,11 +19,6 @@ package org.apache.maven.archiva.database;
* under the License.
*/
import org.apache.maven.archiva.model.ArchivaArtifactModel;
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
import java.util.List;
/**
* ArchivaDAO - The interface for all content within the database.
*
@ -32,62 +27,9 @@ import java.util.List;
*/
public interface ArchivaDAO
{
/* NOTE TO ARCHIVA DEVELOPERS.
*
* Please keep this interface clean and lean.
* We don't want a repeat of the Continuum Store.
* You should have the following methods per object type ...
*
* (Required Methods)
*
* DatabaseObject .createDatabaseObject( Required Params ) ;
* List .queryDatabaseObject( Constraint ) throws ObjectNotFoundException, DatabaseException;
* DatabaseObject .saveDatabaseObject( DatabaseObject ) throws DatabaseException;
*
* (Optional Methods)
*
* DatabaseObject .getDatabaseObject( Id ) throws ObjectNotFoundException, DatabaseException;
* List .getDatabaseObjects() throws ObjectNotFoundException, DatabaseException;
* void .deleteDatabaseObject( DatabaseObject ) throws DatabaseException;
*
* This is the only list of options created in this DAO.
*/
ArtifactDAO getArtifactDAO();
/* .\ Archiva Repository \.____________________________________________________________ */
public ArchivaRepositoryModel createRepository( String id, String url );
public List /*<ArchivaRepositoryModel>*/getRepositories()
throws ObjectNotFoundException, ArchivaDatabaseException;
public ArchivaRepositoryModel getRepository( String id )
throws ObjectNotFoundException, ArchivaDatabaseException;
public List queryRepository( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException;
public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository )
throws ArchivaDatabaseException;
public void deleteRepository( ArchivaRepositoryModel repository )
throws ArchivaDatabaseException;
/* .\ Archiva Artifact \. _____________________________________________________________ */
public ArchivaArtifactModel createArtifact( String groupId, String artifactId, String version, String classifier,
String type );
public ArchivaArtifactModel getArtifact( String groupId, String artifactId, String version, String classifier,
String type )
throws ObjectNotFoundException, ArchivaDatabaseException;
public List /*<ArchivaArtifactModel>*/queryArtifacts( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException;
public ArchivaArtifactModel saveArtifact( ArchivaArtifactModel artifact )
throws ArchivaDatabaseException;
public void deleteArtifact( ArchivaArtifactModel artifact )
throws ArchivaDatabaseException;
ProjectModelDAO getProjectModelDAO();
RepositoryDAO getRepositoryDAO();
}

View File

@ -0,0 +1,71 @@
package org.apache.maven.archiva.database;
/*
* 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.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaArtifactModel;
import java.util.List;
/**
* ArtifactDAO
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public interface ArtifactDAO
{
/* NOTE TO ARCHIVA DEVELOPERS.
*
* Please keep this interface clean and lean.
* We don't want a repeat of the Continuum Store.
* You should have the following methods per object type ...
*
* (Required Methods)
*
* DatabaseObject .createDatabaseObject( Required Params ) ;
* List .queryDatabaseObject( Constraint ) throws ObjectNotFoundException, DatabaseException;
* DatabaseObject .saveDatabaseObject( DatabaseObject ) throws DatabaseException;
*
* (Optional Methods)
*
* DatabaseObject .getDatabaseObject( Id ) throws ObjectNotFoundException, DatabaseException;
* List .getDatabaseObjects() throws ObjectNotFoundException, DatabaseException;
* void .deleteDatabaseObject( DatabaseObject ) throws DatabaseException;
*
* This is the only list of options created in this DAO.
*/
public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier,
String type );
public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier,
String type )
throws ObjectNotFoundException, ArchivaDatabaseException;
public List /*<ArchivaArtifact>*/queryArtifacts( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException;
public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
throws ArchivaDatabaseException;
public void deleteArtifact( ArchivaArtifact artifact )
throws ArchivaDatabaseException;
}

View File

@ -0,0 +1,68 @@
package org.apache.maven.archiva.database;
/*
* 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.archiva.model.ArchivaProjectModel;
import java.util.List;
/**
* ProjectModelDAO
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public interface ProjectModelDAO
{
/* NOTE TO ARCHIVA DEVELOPERS.
*
* Please keep this interface clean and lean.
* We don't want a repeat of the Continuum Store.
* You should have the following methods per object type ...
*
* (Required Methods)
*
* DatabaseObject .createDatabaseObject( Required Params ) ;
* List .queryDatabaseObject( Constraint ) throws ObjectNotFoundException, DatabaseException;
* DatabaseObject .saveDatabaseObject( DatabaseObject ) throws DatabaseException;
*
* (Optional Methods)
*
* DatabaseObject .getDatabaseObject( Id ) throws ObjectNotFoundException, DatabaseException;
* List .getDatabaseObjects() throws ObjectNotFoundException, DatabaseException;
* void .deleteDatabaseObject( DatabaseObject ) throws DatabaseException;
*
* This is the only list of options created in this DAO.
*/
public ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version );
public ArchivaProjectModel getProjectModel( String groupId, String artifactId, String version )
throws ObjectNotFoundException, ArchivaDatabaseException;
public List /*<ArchivaProjectModel>*/queryProjectModel( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException;
public ArchivaProjectModel saveProjectModel( ArchivaProjectModel model )
throws ArchivaDatabaseException;
public void deleteProjectModel( ArchivaProjectModel model )
throws ArchivaDatabaseException;
}

View File

@ -0,0 +1,71 @@
package org.apache.maven.archiva.database;
/*
* 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.archiva.model.ArchivaRepositoryModel;
import java.util.List;
/**
* RepositoryDAO
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public interface RepositoryDAO
{
/* NOTE TO ARCHIVA DEVELOPERS.
*
* Please keep this interface clean and lean.
* We don't want a repeat of the Continuum Store.
* You should have the following methods per object type ...
*
* (Required Methods)
*
* DatabaseObject .createDatabaseObject( Required Params ) ;
* List .queryDatabaseObject( Constraint ) throws ObjectNotFoundException, DatabaseException;
* DatabaseObject .saveDatabaseObject( DatabaseObject ) throws DatabaseException;
*
* (Optional Methods)
*
* DatabaseObject .getDatabaseObject( Id ) throws ObjectNotFoundException, DatabaseException;
* List .getDatabaseObjects() throws ObjectNotFoundException, DatabaseException;
* void .deleteDatabaseObject( DatabaseObject ) throws DatabaseException;
*
* This is the only list of options created in this DAO.
*/
public ArchivaRepositoryModel createRepository( String id, String url );
public List /*<ArchivaRepositoryModel>*/getRepositories()
throws ObjectNotFoundException, ArchivaDatabaseException;
public ArchivaRepositoryModel getRepository( String id )
throws ObjectNotFoundException, ArchivaDatabaseException;
public List queryRepository( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException;
public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository )
throws ArchivaDatabaseException;
public void deleteRepository( ArchivaRepositoryModel repository )
throws ArchivaDatabaseException;
}

View File

@ -0,0 +1,54 @@
package org.apache.maven.archiva.database.constraints;
/*
* 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.archiva.database.Constraint;
/**
* UnprocessedArtifactsConstraint
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class UnprocessedArtifactsConstraint
implements Constraint
{
public String getFetchLimits()
{
return null;
}
public String getSortColumn()
{
return "groupId";
}
public String getSortDirection()
{
return Constraint.ASCENDING;
}
public String getWhereCondition()
{
return "whenProcessed == null";
}
}

View File

@ -51,7 +51,7 @@ import javax.jdo.spi.PersistenceCapable;
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
* @plexus.component role="org.apache.maven.archiva.database.jdo.JdoAccess" role-hint="default"
* @plexus.component role="org.apache.maven.archiva.database.jdo.JdoAccess" role-hint="archiva"
*/
public class JdoAccess
implements Initializable, InstanceLifecycleListener, StoreLifecycleListener

View File

@ -1,14 +1,29 @@
package org.apache.maven.archiva.database.jdo;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.model.ArchivaArtifactModel;
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
import org.codehaus.plexus.logging.AbstractLogEnabled;
/*
* 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 java.util.List;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.ProjectModelDAO;
import org.apache.maven.archiva.database.RepositoryDAO;
import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
* JdoArchivaDAO
@ -23,108 +38,32 @@ public class JdoArchivaDAO
implements ArchivaDAO
{
/**
* @plexus.requirement role-hint="default"
* @plexus.requirement role-hint="jdo"
*/
private JdoAccess jdo;
private ArtifactDAO artifactDAO;
/* .\ Archiva Repository \.____________________________________________________________ */
/**
* @plexus.requirement role-hint="jdo"
*/
private ProjectModelDAO projectModelDAO;
public ArchivaRepositoryModel createRepository( String id, String url )
/**
* @plexus.requirement role-hint="jdo"
*/
private RepositoryDAO repositoryDAO;
public ArtifactDAO getArtifactDAO()
{
ArchivaRepositoryModel repo;
return artifactDAO;
}
try
public ProjectModelDAO getProjectModelDAO()
{
repo = getRepository( id );
return projectModelDAO;
}
catch ( ArchivaDatabaseException e )
public RepositoryDAO getRepositoryDAO()
{
repo = new ArchivaRepositoryModel();
repo.setId( id );
repo.setUrl( url );
return repositoryDAO;
}
return repo;
}
public List getRepositories()
throws ObjectNotFoundException, ArchivaDatabaseException
{
return jdo.getAllObjects( ArchivaRepositoryModel.class );
}
public ArchivaRepositoryModel getRepository( String id )
throws ObjectNotFoundException, ArchivaDatabaseException
{
return (ArchivaRepositoryModel) jdo.getObjectById( ArchivaRepositoryModel.class, id, null );
}
public List queryRepository( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
return jdo.getAllObjects( ArchivaRepositoryModel.class, constraint );
}
public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository )
{
return (ArchivaRepositoryModel) jdo.saveObject( repository );
}
public void deleteRepository( ArchivaRepositoryModel repository )
throws ArchivaDatabaseException
{
jdo.removeObject( repository );
}
/* .\ Archiva Artifact \. _____________________________________________________________ */
public ArchivaArtifactModel createArtifact( String groupId, String artifactId, String version, String classifier, String type )
{
ArchivaArtifactModel artifact;
try
{
artifact = getArtifact( groupId, artifactId, version, classifier, type );
}
catch ( ArchivaDatabaseException e )
{
artifact = new ArchivaArtifactModel();
artifact.setGroupId( groupId );
artifact.setArtifactId( artifactId );
artifact.setVersion( version );
artifact.setClassifier( classifier );
artifact.setType( type );
}
return artifact;
}
public ArchivaArtifactModel getArtifact( String groupId, String artifactId, String version, String classifier, String type )
throws ObjectNotFoundException, ArchivaDatabaseException
{
return null;
}
public List queryArtifacts( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}
public ArchivaArtifactModel saveArtifact( ArchivaArtifactModel artifact )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}
public void deleteArtifact( ArchivaArtifactModel artifact )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,92 @@
package org.apache.maven.archiva.database.jdo;
/*
* 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.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.model.ArchivaArtifact;
import java.util.List;
/**
* JdoArtifactDAO
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*
* @plexus.component role-hint="jdo"
*/
public class JdoArtifactDAO
implements ArtifactDAO
{
/**
* @plexus.requirement role-hint="default"
*/
private JdoAccess jdo;
/* .\ Archiva Artifact \. _____________________________________________________________ */
public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier, String type )
{
ArchivaArtifact artifact;
try
{
artifact = getArtifact( groupId, artifactId, version, classifier, type );
}
catch ( ArchivaDatabaseException e )
{
artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
}
return artifact;
}
public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier, String type )
throws ObjectNotFoundException, ArchivaDatabaseException
{
return null;
}
public List queryArtifacts( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}
public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}
public void deleteArtifact( ArchivaArtifact artifact )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,80 @@
package org.apache.maven.archiva.database.jdo;
/*
* 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.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.ProjectModelDAO;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import java.util.List;
/**
* JdoProjectModelDAO
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*
* @plexus.component role-hint="jdo"
*/
public class JdoProjectModelDAO
implements ProjectModelDAO
{
/**
* @plexus.requirement role-hint="default"
*/
private JdoAccess jdo;
public ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
{
return null;
}
public ArchivaProjectModel getProjectModel( String groupId, String artifactId, String version )
throws ObjectNotFoundException, ArchivaDatabaseException
{
return null;
}
public List queryProjectModel( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}
public ArchivaProjectModel saveProjectModel( ArchivaProjectModel model )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub
return null;
}
public void deleteProjectModel( ArchivaProjectModel model )
throws ArchivaDatabaseException
{
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,94 @@
package org.apache.maven.archiva.database.jdo;
/*
* 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.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.RepositoryDAO;
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
import java.util.List;
/**
* JdoRepositoryDAO
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*
* @plexus.component role-hint="jdo"
*/
public class JdoRepositoryDAO
implements RepositoryDAO
{
/**
* @plexus.requirement role-hint="archiva"
*/
private JdoAccess jdo;
/* .\ Archiva Repository \.____________________________________________________________ */
public ArchivaRepositoryModel createRepository( String id, String url )
{
ArchivaRepositoryModel repo;
try
{
repo = getRepository( id );
}
catch ( ArchivaDatabaseException e )
{
repo = new ArchivaRepositoryModel();
repo.setId( id );
repo.setUrl( url );
}
return repo;
}
public List getRepositories()
throws ObjectNotFoundException, ArchivaDatabaseException
{
return jdo.getAllObjects( ArchivaRepositoryModel.class );
}
public ArchivaRepositoryModel getRepository( String id )
throws ObjectNotFoundException, ArchivaDatabaseException
{
return (ArchivaRepositoryModel) jdo.getObjectById( ArchivaRepositoryModel.class, id, null );
}
public List queryRepository( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
return jdo.getAllObjects( ArchivaRepositoryModel.class, constraint );
}
public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository )
{
return (ArchivaRepositoryModel) jdo.saveObject( repository );
}
public void deleteRepository( ArchivaRepositoryModel repository )
throws ArchivaDatabaseException
{
jdo.removeObject( repository );
}
}

View File

@ -0,0 +1,48 @@
package org.apache.maven.archiva.database.updater;
/*
* 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.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.model.ArchivaArtifact;
/**
* The database update component.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public interface DatabaseUpdater
{
/**
* Update all unprocessed content.
*
* @throws ArchivaDatabaseException if there was a fatal error with the database.
*/
public void updateAllUnprocessed()
throws ArchivaDatabaseException;
/**
* Update specific unprocessed content.
*
* @throws ArchivaDatabaseException if there was a fatal error with the database.
*/
public void updateUnprocessed( ArchivaArtifact artifact )
throws ArchivaDatabaseException;
}

View File

@ -0,0 +1,217 @@
package org.apache.maven.archiva.database.updater;
/*
* 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.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
import org.apache.maven.archiva.consumers.ArchivaArtifactConsumer;
import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.constraints.UnprocessedArtifactsConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
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 org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* JdoDatabaseUpdater
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*
* @plexus.component
*/
public class JdoDatabaseUpdater
extends AbstractLogEnabled
implements DatabaseUpdater, RegistryListener, Initializable
{
/**
* @plexus.requirement role-hint="jdo"
*/
private ArchivaDAO dao;
/**
* @plexus.requirement
*/
private ArchivaConfiguration configuration;
/**
* The collection of available consumers.
* @plexus.requirement role=""
*/
private Map availableConsumers;
/**
* The list of active consumers for unprocessed content.
*/
private List activeUnprocessedConsumers = new ArrayList();
/**
* The list of active consumers for processed content.
*/
private List activeProcessedConsumers = new ArrayList();
/**
* The list of registry (configuration) property names that will trigger a refresh of the activeConsumers list.
*/
private List propertyNameTriggers = new ArrayList();
public void updateAllUnprocessed()
throws ArchivaDatabaseException
{
List unprocessedArtifacts = dao.getArtifactDAO().queryArtifacts( new UnprocessedArtifactsConstraint() );
beginConsumerLifecycle( this.activeUnprocessedConsumers );
try
{
// Process each consumer.
Iterator it = unprocessedArtifacts.iterator();
while ( it.hasNext() )
{
ArchivaArtifact artifact = (ArchivaArtifact) it.next();
if ( !artifact.getModel().isProcessed() )
{
updateUnprocessed( artifact );
}
}
}
finally
{
consumerConsumerLifecycle( this.activeUnprocessedConsumers );
}
}
private void consumerConsumerLifecycle( List consumers )
{
Iterator it = consumers.iterator();
while ( it.hasNext() )
{
ArchivaArtifactConsumer consumer = (ArchivaArtifactConsumer) it.next();
consumer.completeScan();
}
}
private void beginConsumerLifecycle( List consumers )
{
Iterator it = consumers.iterator();
while ( it.hasNext() )
{
ArchivaArtifactConsumer consumer = (ArchivaArtifactConsumer) it.next();
consumer.beginScan();
}
}
public void updateUnprocessed( ArchivaArtifact artifact )
throws ArchivaDatabaseException
{
Iterator it = this.activeUnprocessedConsumers.iterator();
while ( it.hasNext() )
{
ArchivaArtifactConsumer consumer = (ArchivaArtifactConsumer) it.next();
try
{
consumer.processArchivaArtifact( artifact );
}
catch ( ConsumerException e )
{
getLogger().warn( "Unable to process artifact: " + artifact );
}
}
}
private void updateActiveConsumers()
{
this.activeUnprocessedConsumers.clear();
this.activeProcessedConsumers.clear();
DatabaseScanningConfiguration dbScanning = configuration.getConfiguration().getDatabaseScanning();
if ( dbScanning == null )
{
getLogger().error( "No Database Consumers found!" );
return;
}
this.activeUnprocessedConsumers.addAll( getActiveConsumerList( dbScanning.getUnprocessedConsumers() ) );
this.activeProcessedConsumers.addAll( getActiveConsumerList( dbScanning.getProcessedConsumers() ) );
}
private List getActiveConsumerList( List potentialConsumerList )
{
if ( ( potentialConsumerList == null ) || ( potentialConsumerList.isEmpty() ) )
{
return Collections.EMPTY_LIST;
}
List ret = new ArrayList();
Iterator it = potentialConsumerList.iterator();
while ( it.hasNext() )
{
String consumerName = (String) it.next();
if ( !availableConsumers.containsKey( consumerName ) )
{
getLogger().warn( "Requested Consumer [" + consumerName + "] does not exist. Disabling." );
continue;
}
ret.add( consumerName );
}
return ret;
}
public void initialize()
throws InitializationException
{
propertyNameTriggers = new ArrayList();
propertyNameTriggers.add( "databaseScanning" );
propertyNameTriggers.add( "unprocessedConsumers" );
propertyNameTriggers.add( "unprocessedConsumer" );
propertyNameTriggers.add( "processedConsumers" );
propertyNameTriggers.add( "processedConsumer" );
configuration.addChangeListener( this );
updateActiveConsumers();
}
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
if ( propertyNameTriggers.contains( propertyName ) )
{
updateActiveConsumers();
}
}
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
/* nothing to do here */
}
}

View File

@ -20,12 +20,6 @@ package org.apache.maven.archiva.database.jdo;
*/
import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
import java.util.List;
import javax.jdo.JDOHelper;
/**
* JdoArchivaDAOTest
@ -33,58 +27,12 @@ import javax.jdo.JDOHelper;
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class JdoArchivaDAOTest extends AbstractArchivaDatabaseTestCase
public class JdoArchivaDAOTest
extends AbstractArchivaDatabaseTestCase
{
public void testRepositoryCRUD() throws ArchivaDatabaseException
public void testSubDAOs()
{
// Create it
ArchivaRepositoryModel repo = dao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
assertNotNull( repo );
// Set some mandatory values
repo.setName( "The Test Repository." );
repo.setCreationSource( "Test Case" );
repo.setLayoutName( "default" );
// Save it.
ArchivaRepositoryModel repoSaved = dao.saveRepository( repo );
assertNotNull( repoSaved );
assertEquals( "testRepo", JDOHelper.getObjectId( repoSaved ).toString() );
// Test that something has been saved.
List repos = dao.getRepositories();
assertNotNull( repos );
assertEquals( 1, repos.size() );
// Test that retreived object is what we expect.
ArchivaRepositoryModel firstRepo = (ArchivaRepositoryModel) repos.get( 0 );
assertNotNull( firstRepo );
assertEquals( "testRepo", repo.getId() );
assertEquals( "The Test Repository.", repo.getName() );
assertEquals( "Test Case", repo.getCreationSource() );
assertEquals( "default", repo.getLayoutName() );
// Change value and save.
repoSaved.setName( "Saved Again" );
dao.saveRepository( repoSaved );
// Test that only 1 object is saved.
assertEquals( 1, dao.getRepositories().size() );
// Get the specific repo.
ArchivaRepositoryModel actualRepo = dao.getRepository( "testRepo" );
assertNotNull( actualRepo );
// Test expected values.
assertEquals( "testRepo", actualRepo.getId() );
assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() );
assertEquals( "Saved Again", actualRepo.getName() );
// Test that only 1 object is saved.
assertEquals( 1, dao.getRepositories().size() );
// Delete object.
dao.deleteRepository( actualRepo );
assertEquals( 0, dao.getRepositories().size() );
assertNotNull( "Artifact DAO", dao.getArtifactDAO() );
assertNotNull( "Repository DAO", dao.getRepositoryDAO() );
}
}

View File

@ -0,0 +1,95 @@
package org.apache.maven.archiva.database.jdo;
/*
* 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.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.RepositoryDAO;
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
import java.util.List;
import javax.jdo.JDOHelper;
/**
* JdoRepositoryDAOTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class JdoRepositoryDAOTest
extends AbstractArchivaDatabaseTestCase
{
public void testRepositoryCRUD()
throws ArchivaDatabaseException
{
RepositoryDAO repoDao = dao.getRepositoryDAO();
// Create it
ArchivaRepositoryModel repo = repoDao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
assertNotNull( repo );
// Set some mandatory values
repo.setName( "The Test Repository." );
repo.setCreationSource( "Test Case" );
repo.setLayoutName( "default" );
// Save it.
ArchivaRepositoryModel repoSaved = repoDao.saveRepository( repo );
assertNotNull( repoSaved );
assertEquals( "testRepo", JDOHelper.getObjectId( repoSaved ).toString() );
// Test that something has been saved.
List repos = repoDao.getRepositories();
assertNotNull( repos );
assertEquals( 1, repos.size() );
// Test that retreived object is what we expect.
ArchivaRepositoryModel firstRepo = (ArchivaRepositoryModel) repos.get( 0 );
assertNotNull( firstRepo );
assertEquals( "testRepo", repo.getId() );
assertEquals( "The Test Repository.", repo.getName() );
assertEquals( "Test Case", repo.getCreationSource() );
assertEquals( "default", repo.getLayoutName() );
// Change value and save.
repoSaved.setName( "Saved Again" );
repoDao.saveRepository( repoSaved );
// Test that only 1 object is saved.
assertEquals( 1, repoDao.getRepositories().size() );
// Get the specific repo.
ArchivaRepositoryModel actualRepo = repoDao.getRepository( "testRepo" );
assertNotNull( actualRepo );
// Test expected values.
assertEquals( "testRepo", actualRepo.getId() );
assertEquals( "http://localhost:8080/repository/foo", actualRepo.getUrl() );
assertEquals( "Saved Again", actualRepo.getName() );
// Test that only 1 object is saved.
assertEquals( 1, repoDao.getRepositories().size() );
// Delete object.
repoDao.deleteRepository( actualRepo );
assertEquals( 0, repoDao.getRepositories().size() );
}
}