]> source.dussan.org Git - archiva.git/commitdiff
* Adding boilerplate for DatabaseUpdater.
authorJoakim Erdfelt <joakime@apache.org>
Mon, 9 Apr 2007 16:39:58 +0000 (16:39 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Mon, 9 Apr 2007 16:39:58 +0000 (16:39 +0000)
* 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

18 files changed:
archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java
archiva-base/archiva-model/pom.xml
archiva-base/archiva-model/src/main/mdo/archiva-base.xml
archiva-database/pom.xml
archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/ProjectModelDAO.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDAO.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UnprocessedArtifactsConstraint.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoProjectModelDAO.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAO.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseUpdater.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java [new file with mode: 0644]
archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java
archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAOTest.java [new file with mode: 0644]

index 75c8b1f6f8cb9014bcc7f3a65453cc3c4eaf2a5f..7eae0bf6e98a434a0ff9d170a307e1b8784402c1 100644 (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 )
         {
index 52c185ea706a5855acec976d039618057c7db7f9..f8b378a61f81205d9cf0e89861e8283975f61a1c 100755 (executable)
@@ -98,6 +98,7 @@
           </dependency>
         </dependencies>
         <executions>
+        <!-- TODO: put this into a profile!
           <execution>
             <id>create-ddl</id>
             <phase>generate-test-resources</phase>
               </toolProperties>
             </configuration>
           </execution>
+             -->
           <execution>
             <id>enhance</id>
             <goals>
index 06a07f732f651811864dd4672e7eb0d987113311..0f6587666a7e06b4a4515dbe59f60bffb3bf98c2 100644 (file)
             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>
           </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"
index 99b24f701af16100f2691c01565dab93f266cc1a..03387ca7f5834483205ffa93171343a2ec9ae2b3 100755 (executable)
   <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>
index 34db1d9bb401bbc76540dd14a1848d868ee1c5f5..d60a1642d22d6864d1f121363f3676735fb45932 100644 (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.
-     */
-
-    /* .\ 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 (file)
index 0000000..337b3df
--- /dev/null
@@ -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 (file)
index 0000000..942a8f0
--- /dev/null
@@ -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 (file)
index 0000000..b14a827
--- /dev/null
@@ -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 (file)
index 0000000..4eb29ea
--- /dev/null
@@ -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";
+    }
+
+}
index 2c4f5a3ece8ec8b32b753c157995ad26382122f1..83b2d3c6611eb3edc6ec3f8af9757f6b0f5db568 100644 (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
index 4eb9cd06e609bcbed0d749205bceab88e9a497e0..18b26f0327f4a3497f51dd43258cd4be205f955d 100644 (file)
@@ -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 (file)
index 0000000..ed3ae21
--- /dev/null
@@ -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 (file)
index 0000000..2b134e1
--- /dev/null
@@ -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 (file)
index 0000000..6316c8a
--- /dev/null
@@ -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 (file)
index 0000000..8f395c9
--- /dev/null
@@ -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 (file)
index 0000000..2900a43
--- /dev/null
@@ -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 */
+    }
+}
index 5697afd1115b11b1aa0a52a10b5d8459e942ffba..a97492c2466795973b5f923553e9fc883facfb3a 100644 (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() );
     }
 }
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 (file)
index 0000000..ed18c25
--- /dev/null
@@ -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() );
+    }
+}