1 package org.apache.maven.archiva.database;
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.key.MetadataKey;
25 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
26 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
28 import java.sql.SQLException;
31 * RepositoryMetadataDatabase
33 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
36 * @plexus.component role="org.apache.maven.archiva.database.RepositoryMetadataDatabase" role-hint="default"
38 public class RepositoryMetadataDatabase extends AbstractMetadataKeyDatabase
40 public void create( RepositoryMetadata metadata )
41 throws ArchivaDatabaseException
44 SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
48 sqlMap.startTransaction();
50 getLogger().info( "Adding repository metadata" );
51 sqlMap.update( "addRepositoryMetadata", metadata );
53 sqlMap.commitTransaction();
55 catch ( SQLException e )
57 getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
61 getLogger().error( e.getMessage(), e );
63 e = e.getNextException();
66 throw new ArchivaDatabaseException( "Error while executing statement.", e );
72 sqlMap.endTransaction();
74 catch ( SQLException e )
82 public RepositoryMetadata read( String groupId, String artifactId, String version )
83 throws ArchivaDatabaseException
86 SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
90 sqlMap.startTransaction();
92 getLogger().info( "Reading repository metadata" );
93 RepositoryMetadata repositoryMetadata = (RepositoryMetadata) sqlMap.queryForObject( "getRepositoryMetadata", new MetadataKey( groupId, artifactId, version ) );
95 return repositoryMetadata;
97 catch ( SQLException e )
99 getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
103 getLogger().error( e.getMessage(), e );
105 e = e.getNextException();
108 throw new ArchivaDatabaseException( "Error while executing statement.", e );
114 sqlMap.endTransaction();
116 catch ( SQLException e )
124 * not implemented yet
127 * @throws ArchivaDatabaseException
129 public void update( RepositoryMetadata metadata )
130 throws ArchivaDatabaseException
133 SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
137 sqlMap.startTransaction();
139 getLogger().info( "Updating repository metadata" );
140 sqlMap.update( "updateRepositoryMetadata", metadata );
142 sqlMap.commitTransaction();
144 catch ( SQLException e )
146 getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
150 getLogger().error( e.getMessage(), e );
152 e = e.getNextException();
155 throw new ArchivaDatabaseException( "Error while executing statement.", e );
161 sqlMap.endTransaction();
163 catch ( SQLException e )
170 public void delete( RepositoryMetadata metadata )
171 throws ArchivaDatabaseException
173 // FIXME is this right? baseVersion seems wrong but I don't know enough about the metadata to say
174 delete( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion() );
177 public void delete( String groupId, String artifactId, String version )
178 throws ArchivaDatabaseException
180 SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
184 sqlMap.startTransaction();
186 getLogger().info( "Removing repository metadata" );
187 sqlMap.update( "removeRepositoryMetadata", new MetadataKey( groupId, artifactId, version ) );
189 sqlMap.commitTransaction();
191 catch ( SQLException e )
193 getLogger().error( "Error while executing statement, showing all linked exceptions in SQLException." );
197 getLogger().error( e.getMessage(), e );
199 e = e.getNextException();
202 throw new ArchivaDatabaseException( "Error while executing statement.", e );
208 sqlMap.endTransaction();
210 catch ( SQLException e )
217 public void initialize()
218 throws InitializationException
223 initializeTable( "RepositoryMetadata" );
225 catch ( ArchivaDatabaseException ade )
227 throw new InitializationException( "unable to initialize repository metadata table", ade );