1 package org.apache.maven.archiva.database.artifact;
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 com.ibatis.sqlmap.client.SqlMapClient;
24 import org.apache.maven.archiva.database.AbstractIbatisStore;
25 import org.apache.maven.archiva.database.ArchivaDatabaseException;
26 import org.apache.maven.artifact.Artifact;
28 import java.sql.SQLException;
33 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
36 * @plexus.component role="org.apache.maven.archiva.database.artifact.ArtifactPersistence"
38 public class ArtifactPersistence
39 extends AbstractIbatisStore
41 protected String[] getTableNames()
43 return new String[] { "ArtifactKeys" };
46 private ArtifactKey toKey( Artifact artifact )
48 ArtifactKey key = new ArtifactKey();
49 key.setGroupId( artifact.getGroupId() );
50 key.setArtifactId( artifact.getArtifactId() );
51 key.setVersion( artifact.getVersion() );
52 key.setClassifier( artifact.getClassifier() );
53 key.setType( artifact.getType() );
57 public void create( Artifact artifact )
58 throws ArchivaDatabaseException
60 SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
64 sqlMap.startTransaction();
66 getLogger().info( "Adding artifact." );
67 sqlMap.update( "addArtifact", artifact );
69 sqlMap.commitTransaction();
71 catch ( SQLException e )
73 getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
77 getLogger().error( e.getMessage(), e );
79 e = e.getNextException();
82 throw new ArchivaDatabaseException( "Error while executing statement.", e );
88 sqlMap.endTransaction();
90 catch ( SQLException e )
97 public Artifact read( String groupId, String artifactId, String version )
102 public Artifact read( String groupId, String artifactId, String version, String type )
107 public Artifact read( String groupId, String artifactId, String version, String classifier, String type )
112 public void update( Artifact artifact )
117 public void delete( Artifact artifact )
122 public void delete( String groupId, String artifactId, String version )
127 public void delete( String groupId, String artifactId, String version, String type )
132 public void delete( String groupId, String artifactId, String version, String classifier, String type )