summaryrefslogtreecommitdiffstats
path: root/archiva-database
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-04-09 16:39:58 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-04-09 16:39:58 +0000
commit0dc680c13e6845211715b7d9f7e397a24ffe3799 (patch)
tree9b8b8797cb179017ca4661f4c8f9ea69a29cb008 /archiva-database
parent3fddad3e8caf7d34755598234c21ec28e45bcde5 (diff)
downloadarchiva-0dc680c13e6845211715b7d9f7e397a24ffe3799.tar.gz
archiva-0dc680c13e6845211715b7d9f7e397a24ffe3799.zip
* 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
Diffstat (limited to 'archiva-database')
-rwxr-xr-xarchiva-database/pom.xml8
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java64
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java71
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/ProjectModelDAO.java68
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDAO.java71
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UnprocessedArtifactsConstraint.java54
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java2
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java143
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java92
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoProjectModelDAO.java80
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAO.java94
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseUpdater.java48
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java217
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java62
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAOTest.java95
15 files changed, 948 insertions, 221 deletions
diff --git a/archiva-database/pom.xml b/archiva-database/pom.xml
index 99b24f701..03387ca7f 100755
--- a/archiva-database/pom.xml
+++ b/archiva-database/pom.xml
@@ -31,6 +31,14 @@
<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>
</dependency>
<dependency>
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
index 34db1d9bb..d60a1642d 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
@@ -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.
- */
-
- /* .\ 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;
+ ArtifactDAO getArtifactDAO();
- public void deleteArtifact( ArchivaArtifactModel artifact )
- throws ArchivaDatabaseException;
+ ProjectModelDAO getProjectModelDAO();
+ RepositoryDAO getRepositoryDAO();
}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java
new file mode 100644
index 000000000..337b3df67
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java
@@ -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;
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/ProjectModelDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/ProjectModelDAO.java
new file mode 100644
index 000000000..942a8f087
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/ProjectModelDAO.java
@@ -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;
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDAO.java
new file mode 100644
index 000000000..b14a82777
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDAO.java
@@ -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;
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UnprocessedArtifactsConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UnprocessedArtifactsConstraint.java
new file mode 100644
index 000000000..4eb29ea59
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UnprocessedArtifactsConstraint.java
@@ -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";
+ }
+
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
index 2c4f5a3ec..83b2d3c66 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
@@ -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
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
index 4eb9cd06e..18b26f032 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
@@ -1,15 +1,30 @@
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.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.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;
-import java.util.List;
-
/**
* JdoArchivaDAO
*
@@ -23,108 +38,32 @@ public class JdoArchivaDAO
implements ArchivaDAO
{
/**
- * @plexus.requirement role-hint="default"
+ * @plexus.requirement role-hint="jdo"
*/
- 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 );
- }
-
- /* .\ 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;
- }
+ private ArtifactDAO artifactDAO;
+
+ /**
+ * @plexus.requirement role-hint="jdo"
+ */
+ private ProjectModelDAO projectModelDAO;
+
+ /**
+ * @plexus.requirement role-hint="jdo"
+ */
+ private RepositoryDAO repositoryDAO;
- public List queryArtifacts( Constraint constraint )
- throws ObjectNotFoundException, ArchivaDatabaseException
+ public ArtifactDAO getArtifactDAO()
{
- // TODO Auto-generated method stub
- return null;
+ return artifactDAO;
}
-
- public ArchivaArtifactModel saveArtifact( ArchivaArtifactModel artifact )
- throws ArchivaDatabaseException
+
+ public ProjectModelDAO getProjectModelDAO()
{
- // TODO Auto-generated method stub
- return null;
+ return projectModelDAO;
}
- public void deleteArtifact( ArchivaArtifactModel artifact )
- throws ArchivaDatabaseException
+ public RepositoryDAO getRepositoryDAO()
{
- // TODO Auto-generated method stub
-
+ return repositoryDAO;
}
-
}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java
new file mode 100644
index 000000000..ed3ae2174
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java
@@ -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
+
+ }
+
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoProjectModelDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoProjectModelDAO.java
new file mode 100644
index 000000000..2b134e182
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoProjectModelDAO.java
@@ -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
+
+ }
+
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAO.java
new file mode 100644
index 000000000..6316c8a18
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAO.java
@@ -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 );
+ }
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseUpdater.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseUpdater.java
new file mode 100644
index 000000000..8f395c9f6
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseUpdater.java
@@ -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;
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java
new file mode 100644
index 000000000..2900a43ae
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java
@@ -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 */
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java
index 5697afd11..a97492c24 100644
--- a/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java
@@ -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() );
}
}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAOTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAOTest.java
new file mode 100644
index 000000000..ed18c2560
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAOTest.java
@@ -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() );
+ }
+}