From: Joakim Erdfelt Date: Mon, 9 Apr 2007 16:39:58 +0000 (+0000) Subject: * Adding boilerplate for DatabaseUpdater. X-Git-Tag: archiva-1.0-alpha-1~113^2~75 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0dc680c13e6845211715b7d9f7e397a24ffe3799;p=archiva.git * Adding boilerplate for DatabaseUpdater. * 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 --- diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java index 75c8b1f6f..7eae0bf6e 100644 --- a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java +++ b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ArtifactUpdateDatabaseConsumer.java @@ -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 ) { diff --git a/archiva-base/archiva-model/pom.xml b/archiva-base/archiva-model/pom.xml index 52c185ea7..f8b378a61 100755 --- a/archiva-base/archiva-model/pom.xml +++ b/archiva-base/archiva-model/pom.xml @@ -98,6 +98,7 @@ + enhance diff --git a/archiva-base/archiva-model/src/main/mdo/archiva-base.xml b/archiva-base/archiva-model/src/main/mdo/archiva-base.xml index 06a07f732..0f6587666 100644 --- a/archiva-base/archiva-model/src/main/mdo/archiva-base.xml +++ b/archiva-base/archiva-model/src/main/mdo/archiva-base.xml @@ -326,6 +326,16 @@ The timestamp when this artifact was indexed. + + whenProcessed + false + 1.0.0+ + Date + false + + When this artifact's contents was processed. + + origin false @@ -337,6 +347,22 @@ + + + 1.0.0+ + + + archiva-database Archiva Database + + org.apache.maven.archiva + archiva-consumer-api + + + org.apache.maven.archiva + archiva-configuration + org.apache.maven.archiva archiva-model 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 34db1d9bb..d60a1642d 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 @@ -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 /**/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 /**/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 index 000000000..337b3df67 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java @@ -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 Joakim Erdfelt + * @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 /**/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 index 000000000..942a8f087 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/ProjectModelDAO.java @@ -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 Joakim Erdfelt + * @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 /**/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 index 000000000..b14a82777 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryDAO.java @@ -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 Joakim Erdfelt + * @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 /**/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 index 000000000..4eb29ea59 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UnprocessedArtifactsConstraint.java @@ -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 Joakim Erdfelt + * @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"; + } + +} 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 2c4f5a3ec..83b2d3c66 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 @@ -51,7 +51,7 @@ import javax.jdo.spi.PersistenceCapable; * * @author Joakim Erdfelt * @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 diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java index 4eb9cd06e..18b26f032 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java @@ -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 index 000000000..ed3ae2174 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java @@ -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 Joakim Erdfelt + * @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 index 000000000..2b134e182 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoProjectModelDAO.java @@ -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 Joakim Erdfelt + * @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 index 000000000..6316c8a18 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAO.java @@ -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 Joakim Erdfelt + * @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 index 000000000..8f395c9f6 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/DatabaseUpdater.java @@ -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 Joakim Erdfelt + * @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 index 000000000..2900a43ae --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/updater/JdoDatabaseUpdater.java @@ -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 Joakim Erdfelt + * @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 */ + } +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java index 5697afd11..a97492c24 100644 --- a/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAOTest.java @@ -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 Joakim Erdfelt * @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 index 000000000..ed18c2560 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryDAOTest.java @@ -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 Joakim Erdfelt + * @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() ); + } +}