1 package org.apache.maven.archiva.database.jdo;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.apache.maven.archiva.database.ArchivaDatabaseException;
26 import org.apache.maven.archiva.database.ArtifactDAO;
27 import org.apache.maven.archiva.database.Constraint;
28 import org.apache.maven.archiva.database.ObjectNotFoundException;
29 import org.apache.maven.archiva.model.ArchivaArtifact;
30 import org.apache.maven.archiva.model.ArchivaArtifactModel;
31 import org.apache.maven.archiva.model.jpox.ArchivaArtifactModelKey;
38 * @plexus.component role-hint="jdo"
40 public class JdoArtifactDAO
41 implements ArtifactDAO
44 * @plexus.requirement role-hint="archiva"
46 private JdoAccess jdo;
48 /* .\ Archiva Artifact \. _____________________________________________________________ */
50 public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier,
51 String type, String repositoryId )
53 ArchivaArtifact artifact;
57 artifact = getArtifact( groupId, artifactId, version, classifier, type, repositoryId );
59 catch ( ArchivaDatabaseException e )
61 artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type, repositoryId );
67 public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier,
68 String type, String repositoryId )
69 throws ObjectNotFoundException, ArchivaDatabaseException
71 ArchivaArtifactModelKey key = new ArchivaArtifactModelKey();
72 key.setGroupId( groupId );
73 key.setArtifactId( artifactId );
74 key.setVersion( version );
75 key.setClassifier( classifier );
77 key.setRepositoryId( repositoryId );
79 ArchivaArtifactModel model = (ArchivaArtifactModel) jdo.getObjectById( ArchivaArtifactModel.class, key, null );
81 return new ArchivaArtifact( model );
84 @SuppressWarnings("unchecked")
85 public List<ArchivaArtifact> queryArtifacts( Constraint constraint )
86 throws ObjectNotFoundException, ArchivaDatabaseException
88 List<ArchivaArtifactModel> results = (List<ArchivaArtifactModel>) jdo.queryObjects( ArchivaArtifactModel.class, constraint );
89 if ( results == null )
94 List<ArchivaArtifact> ret = new ArrayList<ArchivaArtifact>();
95 for ( ArchivaArtifactModel model : results )
97 ret.add( new ArchivaArtifact( model ) );
103 public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
104 throws ArchivaDatabaseException
106 ArchivaArtifactModel model = (ArchivaArtifactModel) jdo.saveObject( artifact.getModel() );
112 return new ArchivaArtifact( model );
115 public void deleteArtifact( ArchivaArtifact artifact )
116 throws ArchivaDatabaseException
118 jdo.removeObject( artifact.getModel() );