aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-database/src
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-04-11 20:27:38 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-04-11 20:27:38 +0000
commit454fb5b0bebc465d1bbe623fb605ae419d8deb7f (patch)
treef627361da6fc04f75167845689a99dfdf1875dd8 /archiva-database/src
parent9e2d664ab31cbf39bf4409b60da8067ce706ffba (diff)
downloadarchiva-454fb5b0bebc465d1bbe623fb605ae419d8deb7f.tar.gz
archiva-454fb5b0bebc465d1bbe623fb605ae419d8deb7f.zip
Work towards compilable webapp
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@527650 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-database/src')
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java2
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDAO.java14
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsRelatedConstraint.java53
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java6
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAO.java52
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java1
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAOTest.java28
7 files changed, 114 insertions, 42 deletions
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 d60a1642d..7d62c93e1 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
@@ -27,6 +27,8 @@ package org.apache.maven.archiva.database;
*/
public interface ArchivaDAO
{
+ public static final String ROLE = ArchivaDAO.class.getName();
+
ArtifactDAO getArtifactDAO();
ProjectModelDAO getProjectModelDAO();
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
index b14a82777..baaaaa574 100644
--- 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
@@ -19,7 +19,7 @@ package org.apache.maven.archiva.database;
* under the License.
*/
-import org.apache.maven.archiva.model.ArchivaRepositoryModel;
+import org.apache.maven.archiva.model.ArchivaRepository;
import java.util.List;
@@ -52,20 +52,20 @@ public interface RepositoryDAO
* This is the only list of options created in this DAO.
*/
- public ArchivaRepositoryModel createRepository( String id, String url );
+ public ArchivaRepository createRepository( String id, String name, String url );
- public List /*<ArchivaRepositoryModel>*/getRepositories()
+ public List /*<ArchivaRepository>*/getRepositories()
throws ObjectNotFoundException, ArchivaDatabaseException;
- public ArchivaRepositoryModel getRepository( String id )
+ public ArchivaRepository getRepository( String id )
throws ObjectNotFoundException, ArchivaDatabaseException;
- public List queryRepository( Constraint constraint )
+ public List /*<ArchivaRepository>*/queryRepositories( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException;
- public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository )
+ public ArchivaRepository saveRepository( ArchivaRepository repository )
throws ArchivaDatabaseException;
- public void deleteRepository( ArchivaRepositoryModel repository )
+ public void deleteRepository( ArchivaRepository repository )
throws ArchivaDatabaseException;
}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsRelatedConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsRelatedConstraint.java
new file mode 100644
index 000000000..60c0461db
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsRelatedConstraint.java
@@ -0,0 +1,53 @@
+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.commons.lang.StringEscapeUtils;
+import org.apache.maven.archiva.database.Constraint;
+
+/**
+ * ArtifactsRelatedConstraint
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArtifactsRelatedConstraint
+ extends AbstractConstraint
+ implements Constraint
+{
+ private String whereClause;
+
+ public ArtifactsRelatedConstraint( String groupId, String artifactId, String version )
+ {
+ whereClause = "groupId == '" + StringEscapeUtils.escapeSql( groupId ) + "' AND artifactId == '"
+ + StringEscapeUtils.escapeSql( artifactId ) + "' AND version == '" + StringEscapeUtils.escapeSql( version )
+ + "'";
+ }
+
+ public String getSortColumn()
+ {
+ return "classifier";
+ }
+
+ public String getWhereCondition()
+ {
+ return whereClause;
+ }
+}
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
index 0980226c4..8ef9f39a3 100644
--- 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
@@ -62,12 +62,6 @@ public class JdoArtifactDAO
}
catch ( ArchivaDatabaseException e )
{
- if ( !( e instanceof ObjectNotFoundException ) )
- {
- getLogger().warn(
- "Unable to get artifact [" + groupId + ":" + artifactId + ":" + version + ":"
- + classifier + ":" + type + "]: " + e.getMessage(), e );
- }
artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
}
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
index 6316c8a18..169c1bcbf 100644
--- 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
@@ -23,8 +23,11 @@ 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.ArchivaRepository;
import org.apache.maven.archiva.model.ArchivaRepositoryModel;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
/**
@@ -42,12 +45,12 @@ public class JdoRepositoryDAO
* @plexus.requirement role-hint="archiva"
*/
private JdoAccess jdo;
-
+
/* .\ Archiva Repository \.____________________________________________________________ */
- public ArchivaRepositoryModel createRepository( String id, String url )
+ public ArchivaRepository createRepository( String id, String name, String url )
{
- ArchivaRepositoryModel repo;
+ ArchivaRepository repo;
try
{
@@ -55,9 +58,7 @@ public class JdoRepositoryDAO
}
catch ( ArchivaDatabaseException e )
{
- repo = new ArchivaRepositoryModel();
- repo.setId( id );
- repo.setUrl( url );
+ repo = new ArchivaRepository( id, name, url );
}
return repo;
@@ -69,26 +70,49 @@ public class JdoRepositoryDAO
return jdo.getAllObjects( ArchivaRepositoryModel.class );
}
- public ArchivaRepositoryModel getRepository( String id )
+ public ArchivaRepository getRepository( String id )
throws ObjectNotFoundException, ArchivaDatabaseException
{
- return (ArchivaRepositoryModel) jdo.getObjectById( ArchivaRepositoryModel.class, id, null );
+ ArchivaRepositoryModel model = (ArchivaRepositoryModel) jdo.getObjectById( ArchivaRepositoryModel.class, id,
+ null );
+ return new ArchivaRepository( model );
}
- public List queryRepository( Constraint constraint )
+ public List queryRepositories( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
- return jdo.getAllObjects( ArchivaRepositoryModel.class, constraint );
+ List results = jdo.getAllObjects( ArchivaRepositoryModel.class, constraint );
+
+ if ( ( results == null ) || results.isEmpty() )
+ {
+ return results;
+ }
+
+ List ret = new ArrayList();
+ Iterator it = results.iterator();
+ while ( it.hasNext() )
+ {
+ ArchivaRepositoryModel model = (ArchivaRepositoryModel) it.next();
+ ret.add( new ArchivaRepository( model ) );
+ }
+
+ return ret;
}
- public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository )
+ public ArchivaRepository saveRepository( ArchivaRepository repository )
{
- return (ArchivaRepositoryModel) jdo.saveObject( repository );
+ ArchivaRepositoryModel model = (ArchivaRepositoryModel) jdo.saveObject( repository.getModel() );
+ if ( model == null )
+ {
+ return null;
+ }
+
+ return new ArchivaRepository( model );
}
- public void deleteRepository( ArchivaRepositoryModel repository )
+ public void deleteRepository( ArchivaRepository repository )
throws ArchivaDatabaseException
{
- jdo.removeObject( repository );
+ jdo.removeObject( repository.getModel() );
}
}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java
index 4fd4e261c..f936bca5d 100644
--- a/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java
@@ -22,7 +22,6 @@ package org.apache.maven.archiva.database;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory;
import org.codehaus.plexus.jdo.JdoFactory;
-import org.codehaus.plexus.util.FileUtils;
import org.jpox.SchemaTool;
import java.io.File;
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
index ed18c2560..9f5fe4724 100644
--- 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
@@ -22,7 +22,7 @@ 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.database.RepositoryDAO;
-import org.apache.maven.archiva.model.ArchivaRepositoryModel;
+import org.apache.maven.archiva.model.ArchivaRepository;
import java.util.List;
@@ -41,18 +41,18 @@ public class JdoRepositoryDAOTest
throws ArchivaDatabaseException
{
RepositoryDAO repoDao = dao.getRepositoryDAO();
-
+
// Create it
- ArchivaRepositoryModel repo = repoDao.createRepository( "testRepo", "http://localhost:8080/repository/foo" );
+ ArchivaRepository repo = repoDao.createRepository( "testRepo", "Test Repository",
+ "http://localhost:8080/repository/foo" );
assertNotNull( repo );
// Set some mandatory values
- repo.setName( "The Test Repository." );
- repo.setCreationSource( "Test Case" );
- repo.setLayoutName( "default" );
+ repo.getModel().setCreationSource( "Test Case" );
+ repo.getModel().setLayoutName( "default" );
// Save it.
- ArchivaRepositoryModel repoSaved = repoDao.saveRepository( repo );
+ ArchivaRepository repoSaved = repoDao.saveRepository( repo );
assertNotNull( repoSaved );
assertEquals( "testRepo", JDOHelper.getObjectId( repoSaved ).toString() );
@@ -62,28 +62,28 @@ public class JdoRepositoryDAOTest
assertEquals( 1, repos.size() );
// Test that retreived object is what we expect.
- ArchivaRepositoryModel firstRepo = (ArchivaRepositoryModel) repos.get( 0 );
+ ArchivaRepository firstRepo = (ArchivaRepository) repos.get( 0 );
assertNotNull( firstRepo );
assertEquals( "testRepo", repo.getId() );
- assertEquals( "The Test Repository.", repo.getName() );
- assertEquals( "Test Case", repo.getCreationSource() );
- assertEquals( "default", repo.getLayoutName() );
+ assertEquals( "The Test Repository.", repo.getModel().getName() );
+ assertEquals( "Test Case", repo.getModel().getCreationSource() );
+ assertEquals( "default", repo.getModel().getLayoutName() );
// Change value and save.
- repoSaved.setName( "Saved Again" );
+ repoSaved.getModel().setCreationSource( "Changed" );
repoDao.saveRepository( repoSaved );
// Test that only 1 object is saved.
assertEquals( 1, repoDao.getRepositories().size() );
// Get the specific repo.
- ArchivaRepositoryModel actualRepo = repoDao.getRepository( "testRepo" );
+ ArchivaRepository 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() );
+ assertEquals( "Changed", actualRepo.getModel().getCreationSource() );
// Test that only 1 object is saved.
assertEquals( 1, repoDao.getRepositories().size() );