diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-06-29 18:52:49 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-06-29 18:52:49 +0000 |
commit | 029c0c9789006f8aa942742681ff28f6867e3bca (patch) | |
tree | 8bb82cec367cef14aca982cade4c1bf9da6692a9 /archiva-database/src/main | |
parent | cd0a9d9d8b816290928c0322df9a7bbf6ab3c6d7 (diff) | |
download | archiva-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/src/main')
3 files changed, 30 insertions, 108 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; - } - -} |