String tableName = rs.getString( "TABLE_NAME" );
// if it does then we are already initialized
- if ( tableName.toLowerCase().equals( "MetadataKeys" ) )
+ if ( tableName.toLowerCase().equals( "metadatakeys" ) )
{
return;
}
}
}
- public void addMetadataKey( MetadataKey metadataKey )
+ public void addMetadata( Metadata metadata )
throws MetadataStoreException
{
SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
sqlMap.startTransaction();
getLogger().info( "Adding metadata key" );
- sqlMap.update( "addMetadataKey", metadataKey );
+ sqlMap.update( "addMetadataKey", metadata );
sqlMap.commitTransaction();
}
}
}
}
+
+ public MetadataKey getMetadataKey( Metadata metadata )
+ throws MetadataStoreException
+ {
+ SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
+
+ try
+ {
+ sqlMap.startTransaction();
+
+ getLogger().info( "Getting metadata key" );
+ MetadataKey newMetadataKey = (MetadataKey) sqlMap.queryForObject( "getMetadataKey", metadata );
+
+ return newMetadataKey;
+
+ }
+ catch ( SQLException e )
+ {
+ getLogger().error( "Error while adding metadata, showing all linked exceptions in SQLException." );
+
+ while ( e != null )
+ {
+ getLogger().error( e.getMessage(), e );
+
+ e = e.getNextException();
+ }
+
+ throw new MetadataStoreException ( "Error while interacting with the database.", e );
+ }
+ finally
+ {
+ try
+ {
+ sqlMap.endTransaction();
+ }
+ catch ( SQLException e )
+ {
+ e.printStackTrace();
+ }
+ }
+}
}
{
public static final String ROLE = MetadataStore.class.getName();
- public void addMetadataKey( MetadataKey metadataKey ) throws MetadataStoreException;
+ public void addMetadata( Metadata metadata ) throws MetadataStoreException;
+
+ public MetadataKey getMetadataKey( Metadata metadata ) throws MetadataStoreException;
}
private String groupId;
private String artifactId;
private String version;
- private long id;
+ private int metadataKey;
public String getArtifactId() {
return artifactId;
public void setGroupId(String groupId) {
this.groupId = groupId;
}
- public long getId() {
- return id;
+ public int getMetadataKey() {
+ return metadataKey;
}
- public void setId(long id) {
- this.id = id;
+ public void setMetadataKey(int id) {
+ this.metadataKey = id;
}
public String getVersion() {
return version;
<!--
METADATA_KEYS is the index table for all other tables
+
+need to make the lookup on this table fast, perhaps by indexing the combination of g:a:v in a lookup column
-->
<statement id="initializeMetadataKeyTable">
CREATE TABLE MetadataKeys (
<select id="getMetadataKey" resultClass="org.apache.maven.archiva.database.key.MetadataKey">
SELECT
- metadataKey as id
- groupId as groupId,
- artifactId as artifactId,
- version as version,
+ metadataKey,
+ groupId,
+ artifactId,
+ version
FROM MetadataKeys
- WHERE metadataKey = #value#
+ WHERE groupId = #groupId# and artifactId = #artifactId# and version = #version#
</select>
-<insert id="addMetadataKey" parameterClass="org.apache.maven.archiva.database.key.MetadataKey">
+<insert id="addMetadataKey" parameterClass="org.apache.maven.artifact.repository.metadata.Metadata">
INSERT INTO
MetadataKeys ( groupId, artifactId, version )
- VALUES (#groupId#, #artifactId#, #version# )
+ VALUES ( #groupId#, #artifactId#, #version# )
</insert>
</sqlMap>
\ No newline at end of file
package org.apache.maven.archiva.database;
import org.apache.maven.archiva.database.key.MetadataKey;
+import org.apache.maven.artifact.repository.metadata.Metadata;
import org.codehaus.plexus.PlexusTestCase;
public class IbatisMetadataStoreTest
{
MetadataStore store = (MetadataStore) lookup( MetadataStore.ROLE, "ibatis" );
- MetadataKey testMetadataKey = new MetadataKey();
+ assertNotNull( store );
+ }
+
+ public void testMetadataKeyRetrieval() throws Exception
+ {
+ MetadataStore store = (MetadataStore) lookup( MetadataStore.ROLE, "ibatis" );
+
+ Metadata metadata = new Metadata();
+ metadata.setArtifactId( "testArtifactId" );
+ metadata.setGroupId( "testGroupId" );
+ metadata.setVersion( "testVersion" );
+
+ store.addMetadata( metadata );
+
+ MetadataKey metadataKey = store.getMetadataKey( metadata );
- testMetadataKey.setArtifactId( "testArtfiactId" );
- testMetadataKey.setGroupId( "testGroupId" );
- testMetadataKey.setVersion( "testVersion" );
+ assertTrue( metadataKey.getMetadataKey() > 0 );
+ assertEquals( metadataKey.getArtifactId(), metadata.getArtifactId() );
+ assertEquals( metadataKey.getGroupId(), metadata.getGroupId() );
+ assertEquals( metadataKey.getVersion(), metadata.getVersion() );
- store.addMetadataKey( testMetadataKey );
}