summaryrefslogtreecommitdiffstats
path: root/archiva-database
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-06-29 18:52:49 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-06-29 18:52:49 +0000
commit029c0c9789006f8aa942742681ff28f6867e3bca (patch)
tree8bb82cec367cef14aca982cade4c1bf9da6692a9 /archiva-database
parentcd0a9d9d8b816290928c0322df9a7bbf6ab3c6d7 (diff)
downloadarchiva-029c0c9789006f8aa942742681ff28f6867e3bca.tar.gz
archiva-029c0c9789006f8aa942742681ff28f6867e3bca.zip
* Fixing ArtifactsByChecksumConstraint for null types.
* Adding anonymous type constructor for ArtifactsByChecksumConstraint. * Removing DatabaseSearch. (We don't want a repeat of the mess that exists within continuum!) git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@551997 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-database')
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java36
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/search/DatabaseSearch.java44
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/search/DefaultDatabaseSearch.java58
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java18
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/search/DatabaseSearchTest.java85
5 files changed, 39 insertions, 202 deletions
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java
index 91bdf87a8..397ff44a9 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java
@@ -19,6 +19,7 @@ package org.apache.maven.archiva.database.constraints;
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.database.Constraint;
/**
@@ -33,19 +34,42 @@ public class ArtifactsByChecksumConstraint
{
private String whereClause;
- public static final String SHA1_CONDITION = "SHA1";
+ public static final String SHA1 = "SHA1";
- public static final String MD5_CONDITION = "MD5";
+ public static final String MD5 = "MD5";
+
+ /**
+ * Create constraint for checksum (without providing type)
+ *
+ * @param desiredChecksum the checksum (either SHA1 or MD5)
+ */
+ public ArtifactsByChecksumConstraint( String desiredChecksum )
+ {
+ this( desiredChecksum, null );
+ }
- public ArtifactsByChecksumConstraint( String desiredChecksum, String condition )
+ /**
+ * Create constraint for specific checksum.
+ *
+ * @param desiredChecksum the checksum (either SHA1 or MD5)
+ * @param type the type of checksum (either {@link #SHA1} or {@link #MD5})
+ */
+ public ArtifactsByChecksumConstraint( String desiredChecksum, String type )
{
- if ( !condition.equals( SHA1_CONDITION ) && !condition.equals( MD5_CONDITION ) )
+ if( StringUtils.isEmpty( type ) )
+ {
+ // default for no specified type.
+ whereClause = "this.checksumSHA1 == desiredChecksum || this.checksumMD5 == desiredChecksum";
+ }
+ else if ( !type.equals( SHA1 ) && !type.equals( MD5 ) )
{
+ // default for type that isn't recognized.
whereClause = "this.checksumSHA1 == desiredChecksum || this.checksumMD5 == desiredChecksum";
}
- else if ( condition.equals( SHA1_CONDITION ) || condition.equals( MD5_CONDITION ) )
+ else if ( type.equals( SHA1 ) || type.equals( MD5 ) )
{
- whereClause = "this.checksum" + condition.trim() + " == desiredChecksum";
+ // specific type.
+ whereClause = "this.checksum" + type.trim() + " == desiredChecksum";
}
declParams = new String[]{ "String desiredChecksum" };
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DatabaseSearch.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DatabaseSearch.java
deleted file mode 100644
index b14d8be60..000000000
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DatabaseSearch.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.apache.maven.archiva.database.search;
-
-/*
-* 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.ObjectNotFoundException;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-
-import java.util.List;
-
-/**
- * Class for searching the database.
- *
- * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
- */
-public interface DatabaseSearch
-{
-
- /**
- * Get artifact(s) with the specified checksum
- *
- * @param checksum
- * @return
- */
- public List searchArtifactsByChecksum( String checksum )
- throws ObjectNotFoundException, ArchivaDatabaseException;
-
-}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DefaultDatabaseSearch.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DefaultDatabaseSearch.java
deleted file mode 100644
index 06c1a1586..000000000
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DefaultDatabaseSearch.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.apache.maven.archiva.database.search;
-
-/*
-* 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.Constraint;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
- * @plexus.component role="org.apache.maven.archiva.database.search.DatabaseSearch" role-hint="default"
- */
-public class DefaultDatabaseSearch
- extends AbstractLogEnabled
- implements DatabaseSearch
-{
- /**
- * @plexus.requirement role-hint="jdo"
- */
- private ArchivaDAO dao;
-
- public List searchArtifactsByChecksum( String checksum )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- Constraint constraint = new ArtifactsByChecksumConstraint( checksum.toLowerCase().trim(), "" );
- List results = dao.getArtifactDAO().queryArtifacts( constraint );
-
- if ( results != null )
- {
- getLogger().info( "Number of database hits : " + results.size() );
- }
-
- return results;
- }
-
-}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java
index d7751b7e0..d5004c5b3 100644
--- a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java
@@ -105,11 +105,11 @@ public class ArtifactsByChecksumConstraintTest
artifactDao.saveArtifact( artifact );
assertConstraint( "Artifacts by SHA1 Checksum", 4,
- new ArtifactsByChecksumConstraint( SHA1_HASH1, ArtifactsByChecksumConstraint.SHA1_CONDITION ) );
+ new ArtifactsByChecksumConstraint( SHA1_HASH1, ArtifactsByChecksumConstraint.SHA1 ) );
assertConstraint( "Artifacts by SHA1 Checksum", 2,
- new ArtifactsByChecksumConstraint( SHA1_HASH2, ArtifactsByChecksumConstraint.SHA1_CONDITION ) );
+ new ArtifactsByChecksumConstraint( SHA1_HASH2, ArtifactsByChecksumConstraint.SHA1 ) );
assertConstraint( "Artifacts by SHA1 Checksum", 1,
- new ArtifactsByChecksumConstraint( SHA1_HASH3, ArtifactsByChecksumConstraint.SHA1_CONDITION ) );
+ new ArtifactsByChecksumConstraint( SHA1_HASH3, ArtifactsByChecksumConstraint.SHA1 ) );
}
public void testConstraintMD5()
@@ -146,11 +146,11 @@ public class ArtifactsByChecksumConstraintTest
artifactDao.saveArtifact( artifact );
assertConstraint( "Artifacts by MD5 Checksum", 4,
- new ArtifactsByChecksumConstraint( MD5_HASH1, ArtifactsByChecksumConstraint.MD5_CONDITION ) );
+ new ArtifactsByChecksumConstraint( MD5_HASH1, ArtifactsByChecksumConstraint.MD5 ) );
assertConstraint( "Artifacts by MD5 Checksum", 2,
- new ArtifactsByChecksumConstraint( MD5_HASH2, ArtifactsByChecksumConstraint.MD5_CONDITION ) );
+ new ArtifactsByChecksumConstraint( MD5_HASH2, ArtifactsByChecksumConstraint.MD5 ) );
assertConstraint( "Artifacts by MD5 Checksum", 1,
- new ArtifactsByChecksumConstraint( MD5_HASH3, ArtifactsByChecksumConstraint.MD5_CONDITION ) );
+ new ArtifactsByChecksumConstraint( MD5_HASH3, ArtifactsByChecksumConstraint.MD5 ) );
}
public void testConstraintOR()
@@ -186,9 +186,9 @@ public class ArtifactsByChecksumConstraintTest
artifact.getModel().setChecksumMD5( MD5_HASH2 );
artifactDao.saveArtifact( artifact );
- assertConstraint( "Artifacts by MD5 Checksum", 4, new ArtifactsByChecksumConstraint( MD5_HASH1, "" ) );
- assertConstraint( "Artifacts by MD5 Checksum", 2, new ArtifactsByChecksumConstraint( MD5_HASH2, "" ) );
- assertConstraint( "Artifacts by MD5 Checksum", 1, new ArtifactsByChecksumConstraint( MD5_HASH3, "" ) );
+ assertConstraint( "Artifacts by MD5 Checksum", 4, new ArtifactsByChecksumConstraint( MD5_HASH1 ) );
+ assertConstraint( "Artifacts by MD5 Checksum", 2, new ArtifactsByChecksumConstraint( MD5_HASH2 ) );
+ assertConstraint( "Artifacts by MD5 Checksum", 1, new ArtifactsByChecksumConstraint( MD5_HASH3 ) );
}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/search/DatabaseSearchTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/search/DatabaseSearchTest.java
deleted file mode 100644
index 8583950a3..000000000
--- a/archiva-database/src/test/java/org/apache/maven/archiva/database/search/DatabaseSearchTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.apache.maven.archiva.database.search;
-
-/*
- * 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.ArtifactDAO;
-import org.apache.maven.archiva.database.ArchivaDAO;
-import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-import java.util.Date;
-import java.util.List;
-
-/**
- * DatabaseSearchTest
- *
- * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
- * @version
- */
-public class DatabaseSearchTest
- extends AbstractArchivaDatabaseTestCase
-{
- private ArtifactDAO artifactDao;
-
- private static final String MD5_HASH1 = "53e3b856aa1a3f3cb7fe0f7ac6163aaf";
-
- private static final String SHA1_HASH1 = "232f01b24b1617c46a3d4b0ab3415bc9237dcdec";
-
- private DatabaseSearch dbSearch;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
- artifactDao = ( ( ArchivaDAO ) lookup( ArchivaDAO.ROLE, "jdo" ) ).getArtifactDAO();
- dbSearch = (DatabaseSearch) lookup( DatabaseSearch.class.getName() );
- }
-
- public ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
- {
- ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar" );
- artifact.getModel().setLastModified( new Date() );
- artifact.getModel().setRepositoryId( "testable_repo" );
- return artifact;
- }
-
- public void testSearchByChecksum()
- throws Exception
- {
- ArchivaArtifact artifact;
-
- // Setup artifacts in fresh DB.
- artifact = createArtifact( "org.apache.maven.test", "test-one", "1.2" );
- artifact.getModel().setChecksumMD5( MD5_HASH1 );
- artifactDao.saveArtifact( artifact );
-
- artifact = createArtifact( "org.apache.maven.test.foo", "test-two", "1.0" );
- artifact.getModel().setChecksumSHA1( SHA1_HASH1 );
- artifactDao.saveArtifact( artifact );
-
- List results = dbSearch.searchArtifactsByChecksum( MD5_HASH1 );
- assertEquals( 1, results.size() );
-
- results = dbSearch.searchArtifactsByChecksum( SHA1_HASH1 );
- assertEquals( 1, results.size() );
- }
-
-}