a bit more realistic test using actual metadata objects and testing getting the key from the key table, and we can actually directly influence performance by monkeying in xml files for sql..ibatis is pretty slick

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@512053 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jesse McConnell 2007-02-26 22:49:51 +00:00
parent 3c6c1e511d
commit 0ce8ca699c
6 changed files with 81 additions and 21 deletions

View File

@ -54,7 +54,7 @@ public class IbatisMetadataStore
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;
}
@ -102,7 +102,7 @@ public class IbatisMetadataStore
}
}
public void addMetadataKey( MetadataKey metadataKey )
public void addMetadata( Metadata metadata )
throws MetadataStoreException
{
SqlMapClient sqlMap = ibatisHelper.getSqlMapClient();
@ -112,7 +112,7 @@ public class IbatisMetadataStore
sqlMap.startTransaction();
getLogger().info( "Adding metadata key" );
sqlMap.update( "addMetadataKey", metadataKey );
sqlMap.update( "addMetadataKey", metadata );
sqlMap.commitTransaction();
}
@ -141,5 +141,46 @@ public class IbatisMetadataStore
}
}
}
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();
}
}
}
}

View File

@ -7,6 +7,8 @@ public interface MetadataStore
{
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;
}

View File

@ -5,7 +5,7 @@ public class MetadataKey {
private String groupId;
private String artifactId;
private String version;
private long id;
private int metadataKey;
public String getArtifactId() {
return artifactId;
@ -19,11 +19,11 @@ public class MetadataKey {
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;

View File

@ -7,6 +7,8 @@
<!--
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 (

View File

@ -7,18 +7,18 @@
<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>

View File

@ -1,6 +1,7 @@
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
@ -18,13 +19,27 @@ 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" );
testMetadataKey.setArtifactId( "testArtfiactId" );
testMetadataKey.setGroupId( "testGroupId" );
testMetadataKey.setVersion( "testVersion" );
Metadata metadata = new Metadata();
metadata.setArtifactId( "testArtifactId" );
metadata.setGroupId( "testGroupId" );
metadata.setVersion( "testVersion" );
store.addMetadata( metadata );
MetadataKey metadataKey = store.getMetadataKey( metadata );
assertTrue( metadataKey.getMetadataKey() > 0 );
assertEquals( metadataKey.getArtifactId(), metadata.getArtifactId() );
assertEquals( metadataKey.getGroupId(), metadata.getGroupId() );
assertEquals( metadataKey.getVersion(), metadata.getVersion() );
store.addMetadataKey( testMetadataKey );
}