diff options
author | Jesse McConnell <jmcconnell@apache.org> | 2007-02-26 22:49:51 +0000 |
---|---|---|
committer | Jesse McConnell <jmcconnell@apache.org> | 2007-02-26 22:49:51 +0000 |
commit | 0ce8ca699c1f849f897731a3f426182163edbf91 (patch) | |
tree | f96a9cb8d897a7d0a47cadd5ccf9899dd17403f4 /archiva-database/src | |
parent | 3c6c1e511d3eea8b599a75e3b54f9cf9bc31e011 (diff) | |
download | archiva-0ce8ca699c1f849f897731a3f426182163edbf91.tar.gz archiva-0ce8ca699c1f849f897731a3f426182163edbf91.zip |
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
Diffstat (limited to 'archiva-database/src')
6 files changed, 81 insertions, 21 deletions
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/IbatisMetadataStore.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/IbatisMetadataStore.java index 781b2fe30..e65841bb7 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/IbatisMetadataStore.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/IbatisMetadataStore.java @@ -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(); + } + } +} } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/MetadataStore.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/MetadataStore.java index ccf5f8fda..deb4590c7 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/MetadataStore.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/MetadataStore.java @@ -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; } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/key/MetadataKey.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/key/MetadataKey.java index 2bdf072e4..7a60dad83 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/key/MetadataKey.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/key/MetadataKey.java @@ -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; diff --git a/archiva-database/src/main/resources/org/apache/maven/archiva/database/CreateTables.xml b/archiva-database/src/main/resources/org/apache/maven/archiva/database/CreateTables.xml index 800e855d9..ef518fc96 100644 --- a/archiva-database/src/main/resources/org/apache/maven/archiva/database/CreateTables.xml +++ b/archiva-database/src/main/resources/org/apache/maven/archiva/database/CreateTables.xml @@ -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 ( diff --git a/archiva-database/src/main/resources/org/apache/maven/archiva/database/MetadataKey.xml b/archiva-database/src/main/resources/org/apache/maven/archiva/database/MetadataKey.xml index 06bce40e0..5d18d0d86 100644 --- a/archiva-database/src/main/resources/org/apache/maven/archiva/database/MetadataKey.xml +++ b/archiva-database/src/main/resources/org/apache/maven/archiva/database/MetadataKey.xml @@ -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>
\ No newline at end of file diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/IbatisMetadataStoreTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/IbatisMetadataStoreTest.java index 3526ead2c..0fdd9df0d 100644 --- a/archiva-database/src/test/java/org/apache/maven/archiva/database/IbatisMetadataStoreTest.java +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/IbatisMetadataStoreTest.java @@ -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" ); + + 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 ); } |