aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-database/src/main/java
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-04-09 21:28:30 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-04-09 21:28:30 +0000
commit84e5e12ca820af1557ad20c67bcb8fc4b69184aa (patch)
treea2cc21c3f33c8b3cf807e8b2cc636b1396ac6d74 /archiva-database/src/main/java
parentede71ae385a96bb65744992e71535ac11bdf3bcf (diff)
downloadarchiva-84e5e12ca820af1557ad20c67bcb8fc4b69184aa.tar.gz
archiva-84e5e12ca820af1557ad20c67bcb8fc4b69184aa.zip
* More unit testing of the archiva-database.
* Added CompoundKey tag to help JdoAccess process compound keys more intelligently. * Updates to keys to honor CompoundKey identity. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@526927 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-database/src/main/java')
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/ProjectModelDAO.java2
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java22
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java20
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoProjectModelDAO.java38
4 files changed, 58 insertions, 24 deletions
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
index 942a8f087..210c18982 100644
--- 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
@@ -57,7 +57,7 @@ public interface ProjectModelDAO
public ArchivaProjectModel getProjectModel( String groupId, String artifactId, String version )
throws ObjectNotFoundException, ArchivaDatabaseException;
- public List /*<ArchivaProjectModel>*/queryProjectModel( Constraint constraint )
+ public List /*<ArchivaProjectModel>*/queryProjectModels( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException;
public ArchivaProjectModel saveProjectModel( ArchivaProjectModel model )
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 bd5bf7af9..73c262cec 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
@@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils;
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.CompoundKey;
import org.codehaus.plexus.jdo.JdoFactory;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
@@ -299,7 +300,16 @@ public class JdoAccess
pm.getFetchPlan().addGroup( fetchGroup );
}
- Object objectId = pm.newObjectIdInstance( clazz, id );
+ Object objectId = null;
+
+ if ( id instanceof CompoundKey )
+ {
+ objectId = pm.newObjectIdInstance( clazz, id.toString() );
+ }
+ else
+ {
+ objectId = pm.newObjectIdInstance( clazz, id );
+ }
Object object = pm.getObjectById( objectId );
@@ -311,13 +321,15 @@ public class JdoAccess
}
catch ( JDOObjectNotFoundException e )
{
- throw new ObjectNotFoundException( "Unable to find Database Object '" + id + "' of type " + clazz.getName()
- + " using fetch-group '" + fetchGroup + "'", e, id );
+ throw new ObjectNotFoundException( "Unable to find Database Object [" + id + "] of type " + clazz.getName()
+ + " using " + ( ( fetchGroup == null ) ? "no fetch-group" : "a fetch-group of [" + fetchGroup + "]" ),
+ e, id );
}
catch ( JDOException e )
{
- throw new ArchivaDatabaseException( "Error in JDO during get of Database object id '" + id + "' of type "
- + clazz.getName() + " using fetch-group '" + fetchGroup + "'", e );
+ throw new ArchivaDatabaseException( "Error in JDO during get of Database object id [" + id + "] of type "
+ + clazz.getName() + " using "
+ + ( ( fetchGroup == null ) ? "no fetch-group" : "a fetch-group of [" + fetchGroup + "]" ), e );
}
finally
{
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 841494753..0980226c4 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
@@ -26,6 +26,7 @@ import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaArtifactModel;
import org.apache.maven.archiva.model.jpox.ArchivaArtifactModelKey;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.util.ArrayList;
import java.util.Iterator;
@@ -40,6 +41,7 @@ import java.util.List;
* @plexus.component role-hint="jdo"
*/
public class JdoArtifactDAO
+ extends AbstractLogEnabled
implements ArtifactDAO
{
/**
@@ -60,6 +62,12 @@ 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 );
}
@@ -71,14 +79,14 @@ public class JdoArtifactDAO
throws ObjectNotFoundException, ArchivaDatabaseException
{
ArchivaArtifactModelKey key = new ArchivaArtifactModelKey();
- key.groupId = groupId;
- key.artifactId = artifactId;
- key.version = version;
- key.classifier = classifier;
- key.type = type;
+ key.setGroupId( groupId );
+ key.setArtifactId( artifactId );
+ key.setVersion( version );
+ key.setClassifier( classifier );
+ key.setType( type );
ArchivaArtifactModel model = (ArchivaArtifactModel) jdo.getObjectById( ArchivaArtifactModel.class, key, null );
-
+
return new ArchivaArtifact( model );
}
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
index 495d1184e..f5d8cbe4f 100644
--- 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
@@ -24,6 +24,7 @@ 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 org.apache.maven.archiva.model.jpox.ArchivaProjectModelKey;
import java.util.List;
@@ -45,36 +46,49 @@ public class JdoProjectModelDAO
public ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
{
-
- return null;
+ ArchivaProjectModel model;
+
+ try
+ {
+ model = getProjectModel( groupId, artifactId, version );
+ }
+ catch ( ArchivaDatabaseException e )
+ {
+ model = new ArchivaProjectModel();
+ model.setGroupId( groupId );
+ model.setArtifactId( artifactId );
+ model.setVersion( version );
+ }
+
+ return model;
}
public ArchivaProjectModel getProjectModel( String groupId, String artifactId, String version )
throws ObjectNotFoundException, ArchivaDatabaseException
{
-
- return null;
+ ArchivaProjectModelKey key = new ArchivaProjectModelKey();
+ key.groupId = groupId;
+ key.artifactId = artifactId;
+ key.version = version;
+
+ return (ArchivaProjectModel) jdo.getObjectById( ArchivaProjectModel.class, key, null );
}
- public List queryProjectModel( Constraint constraint )
+ public List queryProjectModels( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
- // TODO Auto-generated method stub
- return null;
+ return jdo.getAllObjects( ArchivaProjectModel.class, constraint );
}
public ArchivaProjectModel saveProjectModel( ArchivaProjectModel model )
throws ArchivaDatabaseException
{
- // TODO Auto-generated method stub
- return null;
+ return (ArchivaProjectModel) jdo.saveObject( model );
}
public void deleteProjectModel( ArchivaProjectModel model )
throws ArchivaDatabaseException
{
- // TODO Auto-generated method stub
-
+ jdo.removeObject( model );
}
-
}