columnSlice = row.getColumnSlice();
- String repositoryName = getAsStringValue(columnSlice, REPOSITORY_NAME.toString());
- if (StringUtils.equals(repositoryName, repositoryId)) {
-
- artifactMetadatas.add(mapArtifactMetadataLongColumnSlice(key, columnSlice));
- }
- }
- }
-
- return artifactMetadatas;
}
/**
* For documentation see {@link MetadataRepository#getArtifactByDateRangeStream(RepositorySession, String, ZonedDateTime, ZonedDateTime, QueryParameter)}
- *
+ *
* This implementation orders the stream. It does not order the query in the backend.
*
- * @param session The repository session
- * @param repositoryId The repository id
- * @param startTime The start time, can be null
- * @param endTime The end time, can be null
+ * @param session The repository session
+ * @param repositoryId The repository id
+ * @param startTime The start time, can be null
+ * @param endTime The end time, can be null
* @param queryParameter Additional parameters for the query that affect ordering and number of returned results.
* @return
* @throws MetadataRepositoryException
* @see MetadataRepository#getArtifactByDateRangeStream
*/
@Override
- public Stream getArtifactByDateRangeStream( RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime, QueryParameter queryParameter) throws MetadataRepositoryException
+ public Stream getArtifactByDateRangeStream( RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime, QueryParameter queryParameter ) throws MetadataRepositoryException
{
- Comparator comp = getArtifactMetadataComparator(queryParameter, "whenGathered");
- return getArtifactsByDateRange(session, repositoryId, startTime, endTime, queryParameter).stream().sorted(comp).skip(queryParameter.getOffset()).limit(queryParameter.getLimit());
+ Comparator comp = getArtifactMetadataComparator( queryParameter, "whenGathered" );
+ return getArtifactsByDateRange( session, repositoryId, startTime, endTime, queryParameter ).stream( ).sorted( comp ).skip( queryParameter.getOffset( ) ).limit( queryParameter.getLimit( ) );
}
- protected ArtifactMetadata mapArtifactMetadataLongColumnSlice( String key, ColumnSlice columnSlice )
+ protected ArtifactMetadata mapArtifactMetadata( Row row )
{
- ArtifactMetadata artifactMetadata = new ArtifactMetadata();
- artifactMetadata.setNamespace( getAsStringValue( columnSlice, NAMESPACE_ID.toString() ) );
- artifactMetadata.setSize( getLongValue( columnSlice, SIZE.toString() ) );
- artifactMetadata.setId( getAsStringValue( columnSlice, ID.toString() ) );
- artifactMetadata.setFileLastModified( getLongValue( columnSlice, FILE_LAST_MODIFIED.toString() ) );
- artifactMetadata.setMd5( getAsStringValue( columnSlice, MD5.toString() ) );
- artifactMetadata.setProject( getAsStringValue( columnSlice, PROJECT.toString() ) );
- artifactMetadata.setProjectVersion( getAsStringValue( columnSlice, PROJECT_VERSION.toString() ) );
- artifactMetadata.setRepositoryId( getAsStringValue( columnSlice, REPOSITORY_NAME.toString() ) );
- artifactMetadata.setSha1( getAsStringValue( columnSlice, SHA1.toString() ) );
- artifactMetadata.setVersion( getAsStringValue( columnSlice, VERSION.toString() ) );
- Long whenGathered = getLongValue( columnSlice, WHEN_GATHERED.toString() );
+ ArtifactMetadata artifactMetadata = new ArtifactMetadata( );
+ artifactMetadata.setNamespace( row.getString( NAMESPACE_ID.toString( ) ) );
+ artifactMetadata.setSize( row.getLong( SIZE.toString( ) ) );
+ artifactMetadata.setId( row.getString( ID.toString( ) ) );
+ artifactMetadata.setFileLastModified( row.getLong( FILE_LAST_MODIFIED.toString( ) ) );
+ artifactMetadata.setMd5( row.getString( MD5.toString( ) ) );
+ artifactMetadata.setProject( row.getString( PROJECT_ID.toString( ) ) );
+ artifactMetadata.setProjectVersion( row.getString( PROJECT_VERSION.toString( ) ) );
+ artifactMetadata.setRepositoryId( row.getString( REPOSITORY_NAME.toString( ) ) );
+ artifactMetadata.setSha1( row.getString( SHA1.toString( ) ) );
+ artifactMetadata.setVersion( row.getString( VERSION.toString( ) ) );
+ Long whenGathered = row.getLong( WHEN_GATHERED.toString( ) );
if ( whenGathered != null )
{
- artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), STORAGE_TZ));
+ artifactMetadata.setWhenGathered( ZonedDateTime.ofInstant( Instant.ofEpochMilli( whenGathered ), STORAGE_TZ ) );
}
- artifactMetadata.setChecksums(mapChecksumsReverse(getChecksums(key)));
- return artifactMetadata;
- }
-
- protected ArtifactMetadata mapArtifactMetadataStringColumnSlice( String key, ColumnSlice columnSlice )
- {
- ArtifactMetadata artifactMetadata = new ArtifactMetadata();
- artifactMetadata.setNamespace( getStringValue( columnSlice, NAMESPACE_ID.toString() ) );
- artifactMetadata.setSize( getAsLongValue( columnSlice, SIZE.toString() ) );
- artifactMetadata.setId( getStringValue( columnSlice, ID.toString() ) );
- artifactMetadata.setFileLastModified( getAsLongValue( columnSlice, FILE_LAST_MODIFIED.toString() ) );
- artifactMetadata.setMd5( getStringValue( columnSlice, MD5.toString() ) );
- artifactMetadata.setProject( getStringValue( columnSlice, PROJECT.toString() ) );
- artifactMetadata.setProjectVersion( getStringValue( columnSlice, PROJECT_VERSION.toString() ) );
- artifactMetadata.setRepositoryId( getStringValue( columnSlice, REPOSITORY_NAME.toString() ) );
- artifactMetadata.setSha1( getStringValue( columnSlice, SHA1.toString() ) );
- artifactMetadata.setVersion( getStringValue( columnSlice, VERSION.toString() ) );
- Long whenGathered = getAsLongValue( columnSlice, WHEN_GATHERED.toString() );
- if ( whenGathered != null )
- {
- artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), STORAGE_TZ));
- }
- artifactMetadata.setChecksums(mapChecksumsReverse(getChecksums(key)));
+ artifactMetadata.setChecksums( mapChecksumsReverse( getChecksums( row.getString( DEFAULT_PRIMARY_KEY ) ) ) );
return artifactMetadata;
}
@Override
- public List getArtifactsByChecksum(RepositorySession session, final String repositoryId, final String checksum )
+ public List getArtifactsByChecksum( RepositorySession repositorySession, final String repositoryId, final String checksum )
throws MetadataRepositoryException
{
-
- // cql cannot run or in queries so running twice the query
- Map artifactMetadataMap = new HashMap<>();
-
- RangeSlicesQuery query = HFactory //
- .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getChecksumFamilyName()) //
- .setColumnNames(ARTIFACT_METADATA_MODEL_KEY); //
-
- query = query.addEqualsExpression( CHECKSUM_VALUE.toString(), checksum )
- .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId );
-
- QueryResult> result = query.execute();
-
- List artifactKeys = new ArrayList<>();
- for ( Row row : result.get() )
+ String table = cassandraArchivaManager.getChecksumFamilyName( );
+ CqlSession session = cassandraArchivaManager.getSession( );
{
- ColumnSlice columnSlice = row.getColumnSlice();
+ Select query = selectFrom( table )
+ .column( ARTIFACT_METADATA_MODEL_KEY.toString( ) )
+ .whereColumn( REPOSITORY_NAME.toString( ) ).isEqualTo( literal( repositoryId ) )
+ .whereColumn( CHECKSUM_VALUE.toString( ) ).isEqualTo( literal( checksum ) )
+ .allowFiltering();
+ ResultSet result = session.execute( query.build( ) );
+ List artifactKeys = StreamSupport.stream( result.spliterator( ), false )
+ .map( row -> row.getString( ARTIFACT_METADATA_MODEL_KEY.toString( ) ) )
+ .distinct( )
+ .collect( Collectors.toList( ) );
+ List metadataList = new ArrayList<>( );
+ for ( String key : artifactKeys )
+ {
+ table = cassandraArchivaManager.getArtifactMetadataFamilyName( );
+ query = selectFrom( table )
+ .all( )
+ .whereColumn( DEFAULT_PRIMARY_KEY.toString( ) ).isEqualTo( literal( key ) );
+ Row row = session.execute( query.build( ) ).one( );
+ if ( row != null )
+ {
+ metadataList.add( mapArtifactMetadata( row ) );
+ }
- artifactKeys.add(columnSlice.getColumnByName(ARTIFACT_METADATA_MODEL_KEY).getValue());
-
- }
-
- for (String key : artifactKeys) {
- query = HFactory //
- .createRangeSlicesQuery(keyspace, ss, ss, ss) //
- .setColumnFamily(cassandraArchivaManager.getArtifactMetadataFamilyName()) //
- .setColumnNames(NAMESPACE_ID.toString(), SIZE.toString(), ID.toString(), FILE_LAST_MODIFIED.toString(), MD5.toString(), PROJECT.toString(), PROJECT_VERSION.toString(),
- REPOSITORY_NAME.toString(), VERSION.toString(), WHEN_GATHERED.toString(), SHA1.toString())
- .setKeys(key, key);
- result = query.execute();
-
- for (Row row : result.get()) {
- ColumnSlice columnSlice = row.getColumnSlice();
-
- artifactMetadataMap.put(row.getKey(), mapArtifactMetadataStringColumnSlice(key, columnSlice));
}
- }
+ return metadataList;
- return new ArrayList<>(artifactMetadataMap.values());
+ }
}
/**
@@ -2030,349 +1685,329 @@ public class CassandraMetadataRepository
return this.getArtifactsByAttribute( session, key, value, repositoryId );
}
- @Override
- public List getArtifactsByAttribute( RepositorySession session, String key, String value, String repositoryId )
- throws MetadataRepositoryException
+ MetadataFacetModel mapMetadataFacet( Row row )
{
- RangeSlicesQuery query =
- HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) //
- .setColumnNames( MetadataFacetModel.COLUMNS ) //
- .addEqualsExpression( VALUE.toString(), value );
-
- if ( key != null )
- {
- query.addEqualsExpression( KEY.toString(), key ); //
- }
- if ( repositoryId != null )
- {
- query.addEqualsExpression( "repositoryName", repositoryId );
- }
-
- QueryResult> metadataFacetResult = query.execute();
- if ( metadataFacetResult.get() == null || metadataFacetResult.get().getCount() < 1 )
- {
- return Collections.emptyList();
- }
-
- List artifactMetadatas = new LinkedList<>( );
-
- // TODO doing multiple queries, there should be a way to get all the artifactMetadatas for any number of
- // projects
- for ( Row row : metadataFacetResult.get() )
- {
- QueryResult> artifactMetadataResult =
- HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) //
- .setColumnNames( ArtifactMetadataModel.COLUMNS ) //
- .setRowCount( Integer.MAX_VALUE ) //
- .addEqualsExpression( REPOSITORY_NAME.toString(),
- getStringValue( row.getColumnSlice(), REPOSITORY_NAME ) ) //
- .addEqualsExpression( NAMESPACE_ID.toString(), getStringValue( row.getColumnSlice(), NAMESPACE_ID ) ) //
- .addEqualsExpression( PROJECT.toString(), getStringValue( row.getColumnSlice(), PROJECT_ID ) ) //
- .addEqualsExpression( PROJECT_VERSION.toString(),
- getStringValue( row.getColumnSlice(), PROJECT_VERSION ) ) //
- .execute();
-
- if ( artifactMetadataResult.get() == null || artifactMetadataResult.get().getCount() < 1 )
- {
- return Collections.emptyList();
- }
-
- for ( Row artifactMetadataRow : artifactMetadataResult.get() )
- {
- String artifactKey = artifactMetadataRow.getKey();
- artifactMetadatas.add( mapArtifactMetadataStringColumnSlice( artifactKey, artifactMetadataRow.getColumnSlice() ) );
- }
- }
-
- return mapArtifactFacetToArtifact( metadataFacetResult, artifactMetadatas );
+ MetadataFacetModel metadataFacetModel = new MetadataFacetModel( );
+ metadataFacetModel.setFacetId( row.getString( FACET_ID.toString( ) ) );
+ metadataFacetModel.setName( row.getString( NAME.toString( ) ) );
+ metadataFacetModel.setValue( row.getString( VALUE.toString( ) ) );
+ metadataFacetModel.setKey( row.getString( KEY.toString( ) ) );
+ metadataFacetModel.setProjectVersion( row.getString( PROJECT_VERSION.toString( ) ) );
+ return metadataFacetModel;
}
@Override
- public List getArtifactsByProjectVersionAttribute( RepositorySession session, String key, String value, String repositoryId )
+ public List getArtifactsByAttribute( RepositorySession repositorySession, String key, String value, String repositoryId )
throws MetadataRepositoryException
{
- QueryResult> result =
- HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) //
- .setColumnNames( PROJECT_ID.toString(), REPOSITORY_NAME.toString(), NAMESPACE_ID.toString(),
- PROJECT_VERSION.toString() ) //
- .addEqualsExpression( key, value ) //
- .execute();
- int count = result.get().getCount();
-
- if ( count < 1 )
+ CqlSession session = cassandraArchivaManager.getSession( );
{
- return Collections.emptyList();
- }
-
- List artifacts = new LinkedList<>( );
-
- for ( Row row : result.get() )
- {
- // TODO doing multiple queries, there should be a way to get all the artifactMetadatas for any number of
- // projects
- try
+ String table = cassandraArchivaManager.getMetadataFacetFamilyName( );
+ Select query = selectFrom( table )
+ .all( )
+ .whereColumn( VALUE.toString( ) ).isEqualTo( literal( value ) )
+ .allowFiltering();
+ if ( key != null )
{
- artifacts.addAll( getArtifacts( session,
- getStringValue( row.getColumnSlice(), REPOSITORY_NAME ),
- getStringValue( row.getColumnSlice(), NAMESPACE_ID ),
- getStringValue( row.getColumnSlice(), PROJECT_ID ), getStringValue( row.getColumnSlice(), PROJECT_VERSION ) ) );
+ query = query.whereColumn( KEY.toString( ) ).isEqualTo( literal( key ) );
}
- catch ( MetadataResolutionException e )
+ if ( repositoryId != null )
{
- // never raised
- throw new IllegalStateException( e );
+ query = query.whereColumn( REPOSITORY_NAME.toString( ) ).isEqualTo( literal( repositoryId ) );
}
+
+
+ final List artifactMetadatas = new LinkedList<>( );
+ final List metadataFacetModels = new ArrayList<>( );
+ table = cassandraArchivaManager.getArtifactMetadataFamilyName( );
+ ResultSet result = session.execute( query.build( ) );
+ Iterator iterator = result.iterator( );
+ while ( iterator.hasNext( ) )
+ {
+ Row row = iterator.next( );
+ metadataFacetModels.add( mapMetadataFacet( row ) );
+
+ query = selectFrom( table )
+ .all( )
+ .whereColumn( REPOSITORY_NAME.toString( ) ).isEqualTo( literal( row.getString( REPOSITORY_NAME.toString( ) ) ) )
+ .whereColumn( NAMESPACE_ID.toString( ) ).isEqualTo( literal( row.getString( NAMESPACE_ID.toString( ) ) ) )
+ .whereColumn( PROJECT_ID.toString( ) ).isEqualTo( literal( row.getString( PROJECT_ID.toString( ) ) ) )
+ .whereColumn( PROJECT_VERSION.toString( ) ).isEqualTo( literal( row.getString( PROJECT_VERSION.toString( ) ) ) )
+ .allowFiltering();
+
+ ResultSet subResult = session.execute( query.build( ) );
+ subResult.forEach( sRow ->
+ artifactMetadatas.add( mapArtifactMetadata( sRow ) ) );
+
+ }
+
+ return mapArtifactFacetToArtifact( metadataFacetModels, artifactMetadatas );
+
}
- return artifacts;
}
@Override
- public void removeArtifact( RepositorySession session, final String repositoryId, final String namespace, final String project,
+ public List getArtifactsByProjectVersionAttribute( RepositorySession repositorySession, String key, String value, String repositoryId )
+ throws MetadataRepositoryException
+ {
+ CqlSession session = cassandraArchivaManager.getSession( );
+ {
+ String searchKey = StringUtils.wrapIfMissing( key, '"' );
+ String table = cassandraArchivaManager.getProjectVersionMetadataFamilyName( );
+ Select query = selectFrom( table )
+ .columns( PROJECT_ID.toString( ), REPOSITORY_NAME.toString( ), NAMESPACE_ID.toString( ),
+ PROJECT_VERSION.toString( ) ).allowFiltering();
+ if (Arrays.binarySearch( cassandraArchivaManager.getProjectVersionMetadataColumns(), key )>=0){
+ query = query.whereColumn( searchKey ).isEqualTo( literal( value ) );
+ } else {
+ query = query.whereMapValue( VERSION_PROPERTIES.toString( ), literal( key ) ).isEqualTo( literal( value ) );
+ }
+ ResultSet result = session.execute( query.build( ) );
+ List artifacts = new LinkedList<>( );
+ Iterator iterator = result.iterator( );
+ while ( iterator.hasNext( ) )
+ {
+ Row row = iterator.next( );
+ try
+ {
+ artifacts.addAll( getArtifacts( repositorySession,
+ row.getString( REPOSITORY_NAME.toString( ) ),
+ row.getString( NAMESPACE_ID.toString( ) ),
+ row.getString( PROJECT_ID.toString( ) ), row.getString( PROJECT_VERSION.toString( ) ) ) );
+ }
+ catch ( MetadataResolutionException e )
+ {
+ // never raised
+ throw new IllegalStateException( e );
+ }
+ }
+ return artifacts;
+
+ }
+ }
+
+ @Override
+ public void removeArtifact( RepositorySession repositorySession, final String repositoryId, final String namespace, final String project,
final String version, final String id )
throws MetadataRepositoryException
{
logger.debug( "removeTimestampedArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
- repositoryId, namespace, project, version, id );
- String key =
- new ArtifactMetadataModel.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespace ).withId(
- id ).withProjectVersion( version ).withProject( project ).build();
+ repositoryId, namespace, project, version, id );
- this.artifactMetadataTemplate.deleteRow( key );
+ CqlSession session = cassandraArchivaManager.getSession( );
+ {
+ String key =
+ new ArtifactMetadataModel.KeyBuilder( ).withRepositoryId( repositoryId ).withNamespace( namespace ).withId(
+ id ).withProjectVersion( version ).withProject( project ).build( );
+ String table = cassandraArchivaManager.getArtifactMetadataFamilyName( );
+ Delete delete = deleteFrom( table )
+ .whereColumn( DEFAULT_PRIMARY_KEY ).isEqualTo( literal( key ) );
+ session.execute( delete.build( ) );
- key = new ProjectVersionMetadataModel.KeyBuilder() //
- .withRepository( repositoryId ) //
- .withNamespace( namespace ) //
- .withProjectId( project ) //
- .withProjectVersion( version ) //
- .withId( id ) //
- .build();
+ key = new ProjectVersionMetadataModel.KeyBuilder( ) //
+ .withRepository( repositoryId ) //
+ .withNamespace( namespace ) //
+ .withProjectId( project ) //
+ .withProjectVersion( version ) //
+ .withId( id ) //
+ .build( );
+ table = cassandraArchivaManager.getProjectVersionMetadataFamilyName( );
+ delete = deleteFrom( table )
+ .whereColumn( DEFAULT_PRIMARY_KEY ).isEqualTo( literal( key ) );
+ session.execute( delete.build( ) );
+
+ }
- this.projectVersionMetadataTemplate.deleteRow( key );
}
@Override
- public void removeTimestampedArtifact( RepositorySession session, ArtifactMetadata artifactMetadata, String baseVersion )
+ public void removeTimestampedArtifact( RepositorySession repositorySession, ArtifactMetadata artifactMetadata, String baseVersion )
throws MetadataRepositoryException
{
logger.debug( "removeTimestampedArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
- artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(),
- artifactMetadata.getProject(), baseVersion, artifactMetadata.getId() );
- String key =
- new ArtifactMetadataModel.KeyBuilder().withRepositoryId( artifactMetadata.getRepositoryId() ).withNamespace(
- artifactMetadata.getNamespace() ).withId( artifactMetadata.getId() ).withProjectVersion(
- baseVersion ).withProject( artifactMetadata.getProject() ).build();
-
- this.artifactMetadataTemplate.deleteRow( key );
+ artifactMetadata.getRepositoryId( ), artifactMetadata.getNamespace( ),
+ artifactMetadata.getProject( ), baseVersion, artifactMetadata.getId( ) );
+ CqlSession session = cassandraArchivaManager.getSession( );
+ {
+ String key =
+ new ArtifactMetadataModel.KeyBuilder( ).withRepositoryId( artifactMetadata.getRepositoryId( ) ).withNamespace(
+ artifactMetadata.getNamespace( ) ).withId( artifactMetadata.getId( ) ).withProjectVersion(
+ baseVersion ).withProject( artifactMetadata.getProject( ) ).build( );
+ String table = cassandraArchivaManager.getArtifactMetadataFamilyName( );
+ Delete delete = deleteFrom( table )
+ .whereColumn( DEFAULT_PRIMARY_KEY ).isEqualTo( literal( key ) );
+ session.execute( delete.build( ) );
+ }
}
@Override
- public void removeFacetFromArtifact( RepositorySession session, final String repositoryId, final String namespace, final String project,
+ public void removeFacetFromArtifact( RepositorySession repositorySession, final String repositoryId, final String namespace, final String project,
final String version, final MetadataFacet metadataFacet )
throws MetadataRepositoryException
{
-
- RangeSlicesQuery query = HFactory //
- .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) //
- .setColumnNames( NAMESPACE_ID.toString() ); //
-
- query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) //
- .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) //
- .addEqualsExpression( PROJECT.toString(), project ) //
- .addEqualsExpression( VERSION.toString(), version );
-
- QueryResult> result = query.execute();
-
- for ( Row row : result.get() )
+ CqlSession session = cassandraArchivaManager.getSession( );
{
- this.artifactMetadataTemplate.deleteRow( row.getKey() );
+ String table = cassandraArchivaManager.getArtifactMetadataFamilyName( );
+ Delete delete = deleteFrom( table )
+ .whereColumn( REPOSITORY_NAME.toString( ) ).isEqualTo( literal( repositoryId ) )
+ .whereColumn( NAMESPACE_ID.toString( ) ).isEqualTo( literal( namespace ) )
+ .whereColumn( PROJECT.toString( ) ).isEqualTo( literal( project ) )
+ .whereColumn( VERSION.toString( ) ).isEqualTo( literal( version ) );
+ session.execute( delete.build( ) );
}
}
@Override
- public List getArtifacts( RepositorySession session, final String repositoryId )
+ public List getArtifacts( RepositorySession repositorySession, final String repositoryId )
throws MetadataRepositoryException
{
-
- RangeSlicesQuery query = HFactory //
- .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) //
- .setColumnNames( ArtifactMetadataModel.COLUMNS ); //
-
- query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId );
-
- QueryResult> result = query.execute();
-
-
-
- List artifactMetadatas = new ArrayList<>( result.get().getCount() );
-
- for ( Row row : result.get() )
+ CqlSession session = cassandraArchivaManager.getSession( );
{
- String key = row.getKey();
- ColumnSlice columnSlice = row.getColumnSlice();
- artifactMetadatas.add( mapArtifactMetadataStringColumnSlice( key, columnSlice ) );
-
+ String table = cassandraArchivaManager.getArtifactMetadataFamilyName( );
+ Select query = selectFrom( table )
+ .all( )
+ .whereColumn( REPOSITORY_NAME.toString( ) ).isEqualTo( literal( repositoryId ) )
+ .allowFiltering();
+ ResultSet result = session.execute( query.build( ) );
+ return StreamSupport.stream( result.spliterator( ), false )
+ .map( this::mapArtifactMetadata )
+ .collect( Collectors.toList( ) );
}
-
- return artifactMetadatas;
}
@Override
- public List getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId,
+ public List getProjectReferences( RepositorySession repositorySession, String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
- QueryResult> result = HFactory //
- .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getDependencyFamilyName() ) //
- .setColumnNames( "projectVersionMetadataModel.key" ) //
- .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) //
- .addEqualsExpression( GROUP_ID.toString(), namespace ) //
- .addEqualsExpression( ARTIFACT_ID.toString(), projectId ) //
- .addEqualsExpression( VERSION.toString(), projectVersion ) //
- .execute();
-
- List dependenciesIds = new ArrayList<>( result.get().getCount() );
-
- for ( Row row : result.get().getList() )
+ CqlSession session = cassandraArchivaManager.getSession( );
{
- dependenciesIds.add( getStringValue( row.getColumnSlice(), "projectVersionMetadataModel.key" ) );
+ String table = cassandraArchivaManager.getDependencyFamilyName( );
+ Select query = selectFrom( table )
+ .column( "\"projectVersionMetadataModel.key\"" )
+ .whereColumn( REPOSITORY_NAME.toString( ) ).isEqualTo( literal( repoId ) )
+ .whereColumn( GROUP_ID.toString( ) ).isEqualTo( literal( namespace ) )
+ .whereColumn( ARTIFACT_ID.toString( ) ).isEqualTo( literal( projectId ) )
+ .whereColumn( VERSION.toString( ) ).isEqualTo( literal( projectVersion ) )
+ .allowFiltering();
+ ResultSet result = session.execute( query.build( ) );
+ List dependenciesIds = StreamSupport.stream( result.spliterator( ), false )
+ .map( row -> row.getString( "\"projectVersionMetadataModel.key\"" ) )
+ .collect( Collectors.toList( ) );
+
+ List references = new ArrayList<>( );
+
+
+ table = cassandraArchivaManager.getProjectVersionMetadataFamilyName( );
+ for ( String key : dependenciesIds )
+ {
+ query = selectFrom( table )
+ .columns( PROJECT_ID.toString( ), NAMESPACE_ID.toString( ), PROJECT_VERSION.toString( ) )
+ .whereColumn( DEFAULT_PRIMARY_KEY ).isEqualTo( literal( key ) );
+ Row rowResult = session.execute( query.build( ) ).one( );
+ if ( rowResult != null )
+ {
+ references.add( new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY,
+ rowResult.getString( PROJECT_ID.toString( ) ),
+ rowResult.getString( NAMESPACE_ID.toString( ) ),
+ rowResult.getString( PROJECT_VERSION.toString( ) )
+ ) );
+ }
+
+ }
+ return references;
}
-
- List references = new ArrayList<>( result.get().getCount() );
-
- for ( String key : dependenciesIds )
- {
- ColumnFamilyResult columnFamilyResult =
- this.projectVersionMetadataTemplate.queryColumns( key );
- references.add( new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, //
- columnFamilyResult.getString( PROJECT_ID.toString() ), //
- columnFamilyResult.getString( NAMESPACE_ID.toString() ), //
- columnFamilyResult.getString( PROJECT_VERSION.toString() ) ) );
- }
-
- return references;
}
@Override
- public void removeProjectVersion( RepositorySession session, final String repoId, final String namespace, final String projectId,
+ public void removeProjectVersion( RepositorySession repositorySession, final String repoId, final String namespace, final String projectId,
final String projectVersion )
throws MetadataRepositoryException
{
-
- QueryResult> result = HFactory //
- .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) //
- .setColumnNames( VERSION.toString() ) //
- .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) //
- .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) //
- .addEqualsExpression( PROJECT_ID.toString(), projectId ) //
- .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ) //
- .execute();
-
- for ( Row row : result.get().getList() )
+ CqlSession session = cassandraArchivaManager.getSession( );
{
- this.projectVersionMetadataTemplate.deleteRow( row.getKey() );
- removeMailingList( row.getKey() );
- removeLicenses( row.getKey() );
- removeDependencies( row.getKey() );
- }
+ String table = cassandraArchivaManager.getProjectVersionMetadataFamilyName( );
+ Select query = selectFrom( table )
+ .columns( DEFAULT_PRIMARY_KEY, VERSION.toString( ) )
+ .whereColumn( REPOSITORY_NAME.toString( ) ).isEqualTo( literal( repoId ) )
+ .whereColumn( NAMESPACE_ID.toString( ) ).isEqualTo( literal( namespace ) )
+ .whereColumn( PROJECT_ID.toString( ) ).isEqualTo( literal( projectId ) )
+ .whereColumn( PROJECT_VERSION.toString( ) ).isEqualTo( literal( projectVersion ) )
+ .allowFiltering();
+ ResultSet result = session.execute( query.build( ) );
+ Iterator iterator = result.iterator( );
+ while ( iterator.hasNext( ) )
+ {
+ Row row = iterator.next( );
+ String key = row.getString( DEFAULT_PRIMARY_KEY );
+ session.execute( deleteFrom( table ).whereColumn( DEFAULT_PRIMARY_KEY ).isEqualTo( literal( key ) ).build( ) );
+ removeMailingList( key );
+ removeLicenses( key );
+ removeDependencies( key );
+ }
- RangeSlicesQuery query = HFactory //
- .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
- .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) //
- .setColumnNames( NAMESPACE_ID.toString() ); //
-
- query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) //
- .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) //
- .addEqualsExpression( PROJECT.toString(), projectId ) //
- .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion );
-
- result = query.execute();
-
- for ( Row row : result.get() )
- {
- this.artifactMetadataTemplate.deleteRow( row.getKey() );
+ final String deleteTable = cassandraArchivaManager.getArtifactMetadataFamilyName( );
+ Select deleteRows = selectFrom( deleteTable )
+ .column( DEFAULT_PRIMARY_KEY )
+ .whereColumn( REPOSITORY_NAME.toString( ) ).isEqualTo( literal( repoId ) )
+ .whereColumn( NAMESPACE_ID.toString( ) ).isEqualTo( literal( namespace ) )
+ .whereColumn( PROJECT_ID.toString( ) ).isEqualTo( literal( projectId ) )
+ .whereColumn( PROJECT_VERSION.toString( ) ).isEqualTo( literal( projectVersion ) )
+ .allowFiltering();
+ result = session.execute( deleteRows.build( ) );
+ StreamSupport.stream( result.spliterator( ), false )
+ .map( row -> row.getString( DEFAULT_PRIMARY_KEY ) )
+ .distinct( )
+ .forEach( delKey ->
+ session.execute( deleteFrom( deleteTable ).whereColumn( DEFAULT_PRIMARY_KEY ).isEqualTo( literal( delKey ) ).build( ) ) );
}
}
@Override
- public List getArtifacts( RepositorySession session, final String repoId, final String namespace,
+ public List