diff options
author | Olivier Lamy <olamy@apache.org> | 2014-03-24 01:37:12 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2014-03-24 01:37:12 +0000 |
commit | 7d10f63b87eb918253ee018d998975b9c0bbb63f (patch) | |
tree | a71da87d4a951cee9856d9763f33d3be3bc665d4 /archiva-modules | |
parent | ed0db11f65e5c67c68c8b5246f7c13c55f249502 (diff) | |
download | archiva-7d10f63b87eb918253ee018d998975b9c0bbb63f.tar.gz archiva-7d10f63b87eb918253ee018d998975b9c0bbb63f.zip |
use directly query filtering
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1580694 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r-- | archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java index 42b0e80fc..fd2eed936 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java @@ -1688,7 +1688,7 @@ public class CassandraMetadataRepository } - protected ArtifactMetadata mapArtifactMetadataLongColumnSlice( ColumnSlice<String,Long> columnSlice ) + protected ArtifactMetadata mapArtifactMetadataLongColumnSlice( ColumnSlice<String, Long> columnSlice ) { ArtifactMetadata artifactMetadata = new ArtifactMetadata(); artifactMetadata.setNamespace( getAsStringValue( columnSlice, "namespaceId" ) ); @@ -1709,7 +1709,7 @@ public class CassandraMetadataRepository return artifactMetadata; } - protected ArtifactMetadata mapArtifactMetadataStringColumnSlice( ColumnSlice<String,String> columnSlice ) + protected ArtifactMetadata mapArtifactMetadataStringColumnSlice( ColumnSlice<String, String> columnSlice ) { ArtifactMetadata artifactMetadata = new ArtifactMetadata(); artifactMetadata.setNamespace( getStringValue( columnSlice, "namespaceId" ) ); @@ -1802,19 +1802,16 @@ public class CassandraMetadataRepository .setColumnNames( "namespaceId", "size", "id", "fileLastModified", "md5", "project", "projectVersion", "repositoryName", "version", "whenGathered", "sha1" ); // - query = query.addEqualsExpression( "sha1", checksum ); + query = query.addEqualsExpression( "sha1", checksum ).addEqualsExpression( "repositoryName", repositoryId ); QueryResult<OrderedRows<String, String, String>> result = query.execute(); for ( Row<String, String, String> row : result.get() ) { ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - String repositoryName = getStringValue( columnSlice, "repositoryName" ); - if ( StringUtils.equals( repositoryName, repositoryId ) ) - { - artifactMetadataMap.put( row.getKey(), mapArtifactMetadataStringColumnSlice( columnSlice ) ); - } + artifactMetadataMap.put( row.getKey(), mapArtifactMetadataStringColumnSlice( columnSlice ) ); + } query = HFactory // @@ -1823,19 +1820,16 @@ public class CassandraMetadataRepository .setColumnNames( "namespaceId", "size", "id", "fileLastModified", "md5", "project", "projectVersion", "repositoryName", "version", "whenGathered", "sha1" ); // - query = query.addEqualsExpression( "md5", checksum ); + query = query.addEqualsExpression( "md5", checksum ).addEqualsExpression( "repositoryName", repositoryId ); result = query.execute(); for ( Row<String, String, String> row : result.get() ) { ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - String repositoryName = getStringValue( columnSlice, "repositoryName" ); - if ( StringUtils.equals( repositoryName, repositoryId ) ) - { - artifactMetadataMap.put( row.getKey(), mapArtifactMetadataStringColumnSlice( columnSlice ) ); - } + artifactMetadataMap.put( row.getKey(), mapArtifactMetadataStringColumnSlice( columnSlice ) ); + } return artifactMetadataMap.values(); @@ -1922,36 +1916,33 @@ public class CassandraMetadataRepository public List<ArtifactMetadata> getArtifacts( final String repositoryId ) throws MetadataRepositoryException { -/* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>(); - // FIXME use cql query ! - getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>() - { - @Override - public Boolean apply( ArtifactMetadataModel artifactMetadataModel ) - { - if ( artifactMetadataModel != null ) - { - if ( StringUtils.equals( repositoryId, artifactMetadataModel.getRepositoryId() ) ) - { - artifactMetadataModels.add( artifactMetadataModel ); - } - } + Keyspace keyspace = cassandraArchivaManager.getKeyspace(); + StringSerializer ss = StringSerializer.get(); - return Boolean.TRUE; - } - } ); + // cql cannot run or in queries so running twice the query - List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() ); - for ( ArtifactMetadataModel model : artifactMetadataModels ) + RangeSlicesQuery<String, String, String> query = HFactory // + .createRangeSlicesQuery( keyspace, ss, ss, ss ) // + .setColumnFamily( cassandraArchivaManager.getArtifactMetadataModelFamilyName() ) // + .setColumnNames( "namespaceId", "size", "id", "fileLastModified", "md5", "project", "projectVersion", + "repositoryName", "version", "whenGathered", "sha1" ); // + + query = query.addEqualsExpression( "repositoryName", repositoryId ); + + QueryResult<OrderedRows<String, String, String>> result = query.execute(); + + List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( result.get().getCount() ); + + for ( Row<String, String, String> row : result.get() ) { - ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class ); - populateFacets( artifactMetadata ); - artifactMetadatas.add( artifactMetadata ); + ColumnSlice<String, String> columnSlice = row.getColumnSlice(); + + artifactMetadatas.add( mapArtifactMetadataStringColumnSlice( columnSlice ) ); + } - return artifactMetadatas;*/ - return Collections.emptyList(); + return artifactMetadatas; } |