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 org.apache.maven.archiva.database.ArchivaDatabaseException;
23 import org.apache.maven.archiva.database.ArtifactDAO;
24 import org.apache.maven.archiva.database.Constraint;
25 import org.apache.maven.archiva.database.ObjectNotFoundException;
26 import org.apache.maven.archiva.model.ArchivaArtifact;
27 import org.apache.maven.archiva.model.ArchivaArtifactModel;
28 import org.apache.maven.archiva.model.jpox.ArchivaArtifactModelKey;
30 import java.util.ArrayList;
31 import java.util.Iterator;
32 import java.util.List;
39 * @plexus.component role-hint="jdo"
41 public class JdoArtifactDAO
42 implements ArtifactDAO
45 * @plexus.requirement role-hint="archiva"
47 private JdoAccess jdo;
49 /* .\ Archiva Artifact \. _____________________________________________________________ */
51 public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier,
52 String type, String repositoryId )
54 ArchivaArtifact artifact;
58 artifact = getArtifact( groupId, artifactId, version, classifier, type, repositoryId );
60 catch ( ArchivaDatabaseException e )
62 artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type, repositoryId );
68 public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier,
69 String type, String repositoryId )
70 throws ObjectNotFoundException, ArchivaDatabaseException
72 ArchivaArtifactModelKey key = new ArchivaArtifactModelKey();
73 key.setGroupId( groupId );
74 key.setArtifactId( artifactId );
75 key.setVersion( version );
76 key.setClassifier( classifier );
78 key.setRepositoryId( repositoryId );
80 ArchivaArtifactModel model = (ArchivaArtifactModel) jdo.getObjectById( ArchivaArtifactModel.class, key, null );
82 return new ArchivaArtifact( model );
85 public List queryArtifacts( Constraint constraint )
86 throws ObjectNotFoundException, ArchivaDatabaseException
88 List results = jdo.queryObjects( ArchivaArtifactModel.class, constraint );
89 if ( ( results == null ) || results.isEmpty() )
94 List ret = new ArrayList();
95 Iterator it = results.iterator();
96 while ( it.hasNext() )
98 ArchivaArtifactModel model = (ArchivaArtifactModel) it.next();
99 ret.add( new ArchivaArtifact( model ) );
105 public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
106 throws ArchivaDatabaseException
108 ArchivaArtifactModel model = (ArchivaArtifactModel) jdo.saveObject( artifact.getModel() );
114 return new ArchivaArtifact( model );
117 public void deleteArtifact( ArchivaArtifact artifact )
118 throws ArchivaDatabaseException
120 jdo.removeObject( artifact.getModel() );