more impl with Hector

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1579829 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2014-03-20 23:23:56 +00:00
parent c3bb4dc714
commit e016747888
5 changed files with 429 additions and 239 deletions

View File

@ -44,4 +44,8 @@ public interface CassandraArchivaManager
String getProjectFamilyName(); String getProjectFamilyName();
String getProjectVersionMetadataModelFamilyName();
String getArtifactMetadataModelFamilyName();
} }

View File

@ -20,6 +20,9 @@ package org.apache.archiva.metadata.repository.cassandra;
*/ */
import me.prettyprint.cassandra.serializers.StringSerializer; import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate;
import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater;
import me.prettyprint.cassandra.service.template.ThriftColumnFamilyTemplate;
import me.prettyprint.hector.api.Keyspace; import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.ColumnSlice; import me.prettyprint.hector.api.beans.ColumnSlice;
import me.prettyprint.hector.api.beans.OrderedRows; import me.prettyprint.hector.api.beans.OrderedRows;
@ -42,6 +45,7 @@ import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel; import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel;
import org.apache.archiva.metadata.repository.cassandra.model.Namespace; import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
import org.apache.archiva.metadata.repository.cassandra.model.Project; import org.apache.archiva.metadata.repository.cassandra.model.Project;
import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel;
import org.apache.archiva.metadata.repository.cassandra.model.Repository; import org.apache.archiva.metadata.repository.cassandra.model.Repository;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
@ -72,7 +76,9 @@ public class CassandraMetadataRepository
private final Map<String, MetadataFacetFactory> metadataFacetFactories; private final Map<String, MetadataFacetFactory> metadataFacetFactories;
private CassandraArchivaManager cassandraArchivaManager; private final CassandraArchivaManager cassandraArchivaManager;
private final ColumnFamilyTemplate<String, String> projectVersionMetadataModelTemplate;
public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories, public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
ArchivaConfiguration configuration, ArchivaConfiguration configuration,
@ -81,6 +87,12 @@ public class CassandraMetadataRepository
this.metadataFacetFactories = metadataFacetFactories; this.metadataFacetFactories = metadataFacetFactories;
this.configuration = configuration; this.configuration = configuration;
this.cassandraArchivaManager = cassandraArchivaManager; this.cassandraArchivaManager = cassandraArchivaManager;
this.projectVersionMetadataModelTemplate =
new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
cassandraArchivaManager.getProjectVersionMetadataModelFamilyName(),
StringSerializer.get(), //
StringSerializer.get() );
} }
@ -650,48 +662,314 @@ public class CassandraMetadataRepository
public Collection<String> getProjectVersions( final String repoId, final String namespace, final String projectId ) public Collection<String> getProjectVersions( final String repoId, final String namespace, final String projectId )
throws MetadataResolutionException throws MetadataResolutionException
{ {
return null;
/* final Set<String> versions = new HashSet<String>(); Keyspace keyspace = cassandraArchivaManager.getKeyspace();
getProjectVersionMetadataModelEntityManager().visitAll( new Function<ProjectVersionMetadataModel, Boolean>()
QueryResult<OrderedRows<String, String, String>> result = HFactory //
.createRangeSlicesQuery( keyspace, //
StringSerializer.get(), //
StringSerializer.get(), //
StringSerializer.get() ) //
.setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataModelFamilyName() ) //
.setColumnNames( "id" ) //
.addEqualsExpression( "repositoryName", repoId ) //
.addEqualsExpression( "namespaceId", namespace ) //
.addEqualsExpression( "projectId", projectId ) //
.execute();
int count = result.get().getCount();
if ( count < 1 )
{ {
@Override return Collections.emptyList();
public Boolean apply( ProjectVersionMetadataModel projectVersionMetadataModel ) }
{
if ( projectVersionMetadataModel != null ) Set<String> versions = new HashSet<String>( count );
{
if ( StringUtils.equals( repoId, for ( Row<String, String, String> orderedRows : result.get() )
projectVersionMetadataModel.getNamespace().getRepository().getName() ) {
&& StringUtils.startsWith( projectVersionMetadataModel.getNamespace().getName(), namespace ) versions.add( orderedRows.getColumnSlice().getColumnByName( "id" ).getValue() );
&& StringUtils.equals( projectId, projectVersionMetadataModel.getProjectId() ) ) }
{
versions.add( projectVersionMetadataModel.getId() ); return versions;
}
} }
return Boolean.TRUE;
} @Override
} ); public ProjectMetadata getProject( final String repoId, final String namespace, final String id )
throws MetadataResolutionException
{
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
QueryResult<OrderedRows<String, String, String>> result = HFactory //
.createRangeSlicesQuery( keyspace, //
StringSerializer.get(), //
StringSerializer.get(), //
StringSerializer.get() ) //
.setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
.setColumnNames( "projectId" ) //
.addEqualsExpression( "repositoryName", repoId ) //
.addEqualsExpression( "namespaceId", namespace ) //
.addEqualsExpression( "projectId", id ) //
.execute();
int count = result.get().getCount();
if ( count < 1 )
{
return null;
}
ProjectMetadata projectMetadata = new ProjectMetadata();
projectMetadata.setId( id );
projectMetadata.setNamespace( namespace );
logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id,
projectMetadata );
return projectMetadata;
/* //basically just checking it exists
// FIXME use cql query // FIXME use cql query
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
final BooleanHolder booleanHolder = new BooleanHolder();
getProjectEntityManager().visitAll( new Function<Project, Boolean>()
{ {
@Override @Override
public Boolean apply( ArtifactMetadataModel artifactMetadataModel ) public Boolean apply( Project project )
{ {
if ( artifactMetadataModel != null ) if ( project != null )
{ {
if ( StringUtils.equals( repoId, artifactMetadataModel.getRepositoryId() ) && StringUtils.equals( if ( StringUtils.equals( repoId, project.getNamespace().getRepository().getName() )
namespace, artifactMetadataModel.getNamespace() ) && StringUtils.equals( projectId, && StringUtils.equals( namespace, project.getNamespace().getName() ) && StringUtils.equals( id,
artifactMetadataModel.getProject() ) ) project.getProjectId() ) )
{ {
versions.add( artifactMetadataModel.getProjectVersion() ); booleanHolder.value = true;
} }
} }
return Boolean.TRUE; return Boolean.TRUE;
} }
} ); } );
return versions;*/ if ( !booleanHolder.value )
{
return null;
}
ProjectMetadata projectMetadata = new ProjectMetadata();
projectMetadata.setId( id );
projectMetadata.setNamespace( namespace );
logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id,
projectMetadata );
return projectMetadata;*/
} }
protected ProjectVersionMetadataModel map( ColumnSlice<String, String> columnSlice )
{
ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
projectVersionMetadataModel.setId( columnSlice.getColumnByName( "id" ).getValue() );
projectVersionMetadataModel.setDescription( columnSlice.getColumnByName( "description" ).getValue() );
projectVersionMetadataModel.setName( columnSlice.getColumnByName( "name" ).getValue() );
projectVersionMetadataModel.setNamespace(
new Namespace( columnSlice.getColumnByName( "namespaceId" ).getValue(), //
new Repository( columnSlice.getColumnByName( "repositoryName" ).getValue() ) )
);
projectVersionMetadataModel.setIncomplete(
Boolean.parseBoolean( columnSlice.getColumnByName( "incomplete" ).getValue() ) );
projectVersionMetadataModel.setProjectId( columnSlice.getColumnByName( "projectId" ).getValue() );
projectVersionMetadataModel.setUrl( columnSlice.getColumnByName( "url" ).getValue() );
return projectVersionMetadataModel;
}
@Override
public void updateProjectVersion( String repositoryId, String namespaceId, String projectId,
ProjectVersionMetadata versionMetadata )
throws MetadataRepositoryException
{
try
{
Namespace namespace = getNamespace( repositoryId, namespaceId );
if ( namespace == null )
{
namespace = updateOrAddNamespace( repositoryId, namespaceId );
}
if ( getProject( repositoryId, namespaceId, projectId ) == null )
{
ProjectMetadata projectMetadata = new ProjectMetadata();
projectMetadata.setNamespace( namespaceId );
projectMetadata.setId( projectId );
updateProject( repositoryId, projectMetadata );
}
}
catch ( MetadataResolutionException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
QueryResult<OrderedRows<String, String, String>> result = HFactory //
.createRangeSlicesQuery( keyspace, //
StringSerializer.get(), //
StringSerializer.get(), //
StringSerializer.get() ) //
.setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataModelFamilyName() ) //
.setColumnNames( "id" ) //
.addEqualsExpression( "repositoryName", repositoryId ) //
.addEqualsExpression( "namespaceId", namespaceId ) //
.addEqualsExpression( "projectId", projectId ) //
.addEqualsExpression( "id", versionMetadata.getId() ).execute();
ProjectVersionMetadataModel projectVersionMetadataModel = null;
boolean creation = true;
if ( result.get().getCount() > 0 )
{
projectVersionMetadataModel = map( result.get().getList().get( 0 ).getColumnSlice() );
creation = false;
}
else
{
projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
}
projectVersionMetadataModel.setProjectId( projectId );
projectVersionMetadataModel.setNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) );
projectVersionMetadataModel.setCiManagement( versionMetadata.getCiManagement() );
projectVersionMetadataModel.setIssueManagement( versionMetadata.getIssueManagement() );
projectVersionMetadataModel.setOrganization( versionMetadata.getOrganization() );
projectVersionMetadataModel.setScm( versionMetadata.getScm() );
projectVersionMetadataModel.setMailingLists( versionMetadata.getMailingLists() );
projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() );
projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() );
// we don't test of repository and namespace really exist !
String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build();
// FIXME nested objects to store!!!
if ( creation )
{
String cf = cassandraArchivaManager.getProjectFamilyName();
projectVersionMetadataModelTemplate.createMutator()
// values
.addInsertion( key, //
cf, //
CassandraUtils.column( "projectId", projectId ) ) //
.addInsertion( key, //
cf, //
CassandraUtils.column( "repositoryName", repositoryId ) ) //
.addInsertion( key, //
cf, //
CassandraUtils.column( "namespaceId", namespaceId ) )//
.addInsertion( key, //
cf, //
CassandraUtils.column( "id", versionMetadata.getVersion() ) ) //
.addInsertion( key, //
cf, //
CassandraUtils.column( "description", versionMetadata.getDescription() ) ) //
.addInsertion( key, //
cf, //
CassandraUtils.column( "name", versionMetadata.getName() ) ) //
.addInsertion( key, //
cf, //
CassandraUtils.column( "incomplete",
Boolean.toString( versionMetadata.isIncomplete() ) ) ) //
.addInsertion( key, //
cf, //
CassandraUtils.column( "url", versionMetadata.getUrl() ) ) //
.execute();
}
else
{
ColumnFamilyUpdater<String, String> updater = projectVersionMetadataModelTemplate.createUpdater( key );
updater.setString( "projectId", projectId );
updater.setString( "repositoryName", repositoryId );
updater.setString( "namespaceId", namespaceId );
updater.setString( "id", versionMetadata.getVersion() );
updater.setString( "description", versionMetadata.getDescription() );
updater.setString( "name", versionMetadata.getName() );
updater.setString( "incomplete", Boolean.toString( versionMetadata.isIncomplete() ) );
updater.setString( "url", versionMetadata.getUrl() );
projectVersionMetadataModelTemplate.update( updater );
}
// FIXME
//updateFacets( versionMetadata, artifactMetadataModel );
/* String namespaceKey =
new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
if ( namespace == null )
{
namespace = updateOrAddNamespace( repositoryId, namespaceId );
}
String key = new Project.KeyBuilder().withNamespace( namespace ).withProjectId( projectId ).build();
Project project = getProjectEntityManager().get( key );
if ( project == null )
{
project = new Project( key, projectId, namespace );
getProjectEntityManager().put( project );
}
// we don't test of repository and namespace really exist !
key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build();
ProjectVersionMetadataModel projectVersionMetadataModel =
getProjectVersionMetadataModelEntityManager().get( key );
if ( projectVersionMetadataModel == null )
{
projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
projectVersionMetadataModel.setRowId( key );
}
projectVersionMetadataModel.setProjectId( projectId );
projectVersionMetadataModel.setNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) );
projectVersionMetadataModel.setCiManagement( versionMetadata.getCiManagement() );
projectVersionMetadataModel.setIssueManagement( versionMetadata.getIssueManagement() );
projectVersionMetadataModel.setOrganization( versionMetadata.getOrganization() );
projectVersionMetadataModel.setScm( versionMetadata.getScm() );
projectVersionMetadataModel.setMailingLists( versionMetadata.getMailingLists() );
projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() );
projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() );
try
{
getProjectVersionMetadataModelEntityManager().put( projectVersionMetadataModel );
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
artifactMetadataModel.setArtifactMetadataModelId(
new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
repositoryId ).withNamespace( namespaceId ).withProjectVersion(
versionMetadata.getVersion() ).withProject( projectId ).build()
);
artifactMetadataModel.setRepositoryId( repositoryId );
artifactMetadataModel.setNamespace( namespaceId );
artifactMetadataModel.setProject( projectId );
artifactMetadataModel.setProjectVersion( versionMetadata.getVersion() );
artifactMetadataModel.setVersion( versionMetadata.getVersion() );
// facets etc...
updateFacets( versionMetadata, artifactMetadataModel );
}
catch ( PersistenceException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}*/
}
@Override @Override
public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion, public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
ArtifactMetadata artifactMeta ) ArtifactMetadata artifactMeta )
@ -868,80 +1146,6 @@ public class CassandraMetadataRepository
}*/ }*/
} }
@Override
public void updateProjectVersion( String repositoryId, String namespaceId, String projectId,
ProjectVersionMetadata versionMetadata )
throws MetadataRepositoryException
{
/* String namespaceKey =
new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
if ( namespace == null )
{
namespace = updateOrAddNamespace( repositoryId, namespaceId );
}
String key = new Project.KeyBuilder().withNamespace( namespace ).withProjectId( projectId ).build();
Project project = getProjectEntityManager().get( key );
if ( project == null )
{
project = new Project( key, projectId, namespace );
getProjectEntityManager().put( project );
}
// we don't test of repository and namespace really exist !
key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build();
ProjectVersionMetadataModel projectVersionMetadataModel =
getProjectVersionMetadataModelEntityManager().get( key );
if ( projectVersionMetadataModel == null )
{
projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
projectVersionMetadataModel.setRowId( key );
}
projectVersionMetadataModel.setProjectId( projectId );
projectVersionMetadataModel.setNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) );
projectVersionMetadataModel.setCiManagement( versionMetadata.getCiManagement() );
projectVersionMetadataModel.setIssueManagement( versionMetadata.getIssueManagement() );
projectVersionMetadataModel.setOrganization( versionMetadata.getOrganization() );
projectVersionMetadataModel.setScm( versionMetadata.getScm() );
projectVersionMetadataModel.setMailingLists( versionMetadata.getMailingLists() );
projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() );
projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() );
try
{
getProjectVersionMetadataModelEntityManager().put( projectVersionMetadataModel );
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
artifactMetadataModel.setArtifactMetadataModelId(
new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
repositoryId ).withNamespace( namespaceId ).withProjectVersion(
versionMetadata.getVersion() ).withProject( projectId ).build()
);
artifactMetadataModel.setRepositoryId( repositoryId );
artifactMetadataModel.setNamespace( namespaceId );
artifactMetadataModel.setProject( projectId );
artifactMetadataModel.setProjectVersion( versionMetadata.getVersion() );
artifactMetadataModel.setVersion( versionMetadata.getVersion() );
// facets etc...
updateFacets( versionMetadata, artifactMetadataModel );
}
catch ( PersistenceException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}*/
}
private static class BooleanHolder
{
private boolean value = false;
}
@Override @Override
public List<String> getMetadataFacets( final String repositoryId, final String facetId ) public List<String> getMetadataFacets( final String repositoryId, final String facetId )
@ -1423,49 +1627,6 @@ public class CassandraMetadataRepository
return Collections.emptyList(); return Collections.emptyList();
} }
@Override
public ProjectMetadata getProject( final String repoId, final String namespace, final String id )
throws MetadataResolutionException
{
/* //basically just checking it exists
// FIXME use cql query
final BooleanHolder booleanHolder = new BooleanHolder();
getProjectEntityManager().visitAll( new Function<Project, Boolean>()
{
@Override
public Boolean apply( Project project )
{
if ( project != null )
{
if ( StringUtils.equals( repoId, project.getNamespace().getRepository().getName() )
&& StringUtils.equals( namespace, project.getNamespace().getName() ) && StringUtils.equals( id,
project.getProjectId() ) )
{
booleanHolder.value = true;
}
}
return Boolean.TRUE;
}
} );
if ( !booleanHolder.value )
{
return null;
}
ProjectMetadata projectMetadata = new ProjectMetadata();
projectMetadata.setId( id );
projectMetadata.setNamespace( namespace );
logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id,
projectMetadata );
return projectMetadata;*/
return null;
}
@Override @Override
public ProjectVersionMetadata getProjectVersion( final String repoId, final String namespace, public ProjectVersionMetadata getProjectVersion( final String repoId, final String namespace,

View File

@ -75,6 +75,10 @@ public class DefaultCassandraArchivaManager
private String projectFamilyName = "project"; private String projectFamilyName = "project";
private String projectVersionMetadataModelFamilyName = "projectversionmetadatamodel";
private String artifactMetadataModelFamilyName = "artifactmetadatamodel";
@PostConstruct @PostConstruct
public void initialize() public void initialize()
@ -152,10 +156,9 @@ public class DefaultCassandraArchivaManager
// project table // project table
{ {
final ColumnFamilyDefinition project = final ColumnFamilyDefinition project = HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // getProjectFamilyName(), //
getProjectFamilyName(), // ComparatorType.UTF8TYPE );
ComparatorType.UTF8TYPE );
cfds.add( project ); cfds.add( project );
// creating indexes for cql query // creating indexes for cql query
@ -182,6 +185,102 @@ public class DefaultCassandraArchivaManager
project.addColumnDefinition( namespaceIdColumn ); project.addColumnDefinition( namespaceIdColumn );
} }
//projectversionmetadatamodel
{
final ColumnFamilyDefinition projectVersionMetadataModel =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getProjectVersionMetadataModelFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( projectVersionMetadataModel );
// creating indexes for cql query
BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition();
namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( "namespaceId" ) );
namespaceIdColumn.setIndexName( "namespaceId" );
namespaceIdColumn.setIndexType( ColumnIndexType.KEYS );
namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
projectVersionMetadataModel.addColumnDefinition( namespaceIdColumn );
BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition();
repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( "repositoryName" ) );
repositoryNameColumn.setIndexName( "repositoryName" );
repositoryNameColumn.setIndexType( ColumnIndexType.KEYS );
repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
projectVersionMetadataModel.addColumnDefinition( repositoryNameColumn );
BasicColumnDefinition idColumn = new BasicColumnDefinition();
idColumn.setName( StringSerializer.get().toByteBuffer( "id" ) );
idColumn.setIndexName( "id" );
idColumn.setIndexType( ColumnIndexType.KEYS );
idColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
projectVersionMetadataModel.addColumnDefinition( idColumn );
BasicColumnDefinition projectIdColumn = new BasicColumnDefinition();
projectIdColumn.setName( StringSerializer.get().toByteBuffer( "projectId" ) );
projectIdColumn.setIndexName( "projectId" );
projectIdColumn.setIndexType( ColumnIndexType.KEYS );
projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
projectVersionMetadataModel.addColumnDefinition( projectIdColumn );
}
// artifactmetadatamodel table
{
final ColumnFamilyDefinition artifactMetadataModel =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getArtifactMetadataModelFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( artifactMetadataModel );
// creating indexes for cql query
BasicColumnDefinition idColumn = new BasicColumnDefinition();
idColumn.setName( StringSerializer.get().toByteBuffer( "id" ) );
idColumn.setIndexName( "id" );
idColumn.setIndexType( ColumnIndexType.KEYS );
idColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( idColumn );
BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition();
repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( "repositoryName" ) );
repositoryNameColumn.setIndexName( "repositoryName" );
repositoryNameColumn.setIndexType( ColumnIndexType.KEYS );
repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( repositoryNameColumn );
BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition();
namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( "namespaceId" ) );
namespaceIdColumn.setIndexName( "namespaceId" );
namespaceIdColumn.setIndexType( ColumnIndexType.KEYS );
namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( namespaceIdColumn );
BasicColumnDefinition projectColumn = new BasicColumnDefinition();
projectColumn.setName( StringSerializer.get().toByteBuffer( "project" ) );
projectColumn.setIndexName( "project" );
projectColumn.setIndexType( ColumnIndexType.KEYS );
projectColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( projectColumn );
BasicColumnDefinition projectVersionColumn = new BasicColumnDefinition();
projectVersionColumn.setName( StringSerializer.get().toByteBuffer( "project" ) );
projectVersionColumn.setIndexName( "projectVersion" );
projectVersionColumn.setIndexType( ColumnIndexType.KEYS );
projectVersionColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( projectVersionColumn );
BasicColumnDefinition versionColumn = new BasicColumnDefinition();
versionColumn.setName( StringSerializer.get().toByteBuffer( "project" ) );
versionColumn.setIndexName( "version" );
versionColumn.setIndexType( ColumnIndexType.KEYS );
versionColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( versionColumn );
}
{ // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist { // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
if ( cluster.describeKeyspace( keyspaceName ) == null ) if ( cluster.describeKeyspace( keyspaceName ) == null )
{ {
@ -238,4 +337,14 @@ public class DefaultCassandraArchivaManager
{ {
return projectFamilyName; return projectFamilyName;
} }
public String getProjectVersionMetadataModelFamilyName()
{
return projectVersionMetadataModelFamilyName;
}
public String getArtifactMetadataModelFamilyName()
{
return artifactMetadataModelFamilyName;
}
} }

View File

@ -22,7 +22,6 @@ package org.apache.archiva.metadata.repository.cassandra.model;
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Id;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -36,17 +35,13 @@ public class ArtifactMetadataModel
implements Serializable implements Serializable
{ {
// repositoryId + namespaceId + project + projectVersion + id
@Id
private String artifactMetadataModelId;
@Column(name = "id") @Column(name = "id")
private String id; private String id;
@Column(name = "repositoryId") @Column(name = "repositoryName")
private String repositoryId; private String repositoryId;
@Column(name = "namespace") @Column(name = "namespaceId")
private String namespace; private String namespace;
@Column(name = "project") @Column(name = "project")
@ -78,11 +73,10 @@ public class ArtifactMetadataModel
// no op // no op
} }
public ArtifactMetadataModel( String artifactMetadataModelId, String id, String repositoryId, String namespace, public ArtifactMetadataModel( String id, String repositoryId, String namespace, String project,
String project, String projectVersion, String version, Date fileLastModified, String projectVersion, String version, Date fileLastModified, long size, String md5,
long size, String md5, String sha1, Date whenGathered ) String sha1, Date whenGathered )
{ {
this.artifactMetadataModelId = artifactMetadataModelId;
this.id = id; this.id = id;
this.repositoryId = repositoryId; this.repositoryId = repositoryId;
this.namespace = namespace; this.namespace = namespace;
@ -96,15 +90,6 @@ public class ArtifactMetadataModel
this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime(); this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime();
} }
public String getArtifactMetadataModelId()
{
return artifactMetadataModelId;
}
public void setArtifactMetadataModelId( String artifactMetadataModelId )
{
this.artifactMetadataModelId = artifactMetadataModelId;
}
public String getId() public String getId()
{ {
@ -216,39 +201,11 @@ public class ArtifactMetadataModel
this.whenGathered = whenGathered; this.whenGathered = whenGathered;
} }
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ArtifactMetadataModel that = (ArtifactMetadataModel) o;
if ( !artifactMetadataModelId.equals( that.artifactMetadataModelId ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return artifactMetadataModelId.hashCode();
}
@Override @Override
public String toString() public String toString()
{ {
final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" ); final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" );
sb.append( "artifactMetadataModelId='" ).append( artifactMetadataModelId ).append( '\'' );
sb.append( ", id='" ).append( id ).append( '\'' ); sb.append( ", id='" ).append( id ).append( '\'' );
sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' ); sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
sb.append( ", namespace='" ).append( namespace ).append( '\'' ); sb.append( ", namespace='" ).append( namespace ).append( '\'' );

View File

@ -29,7 +29,6 @@ import org.apache.archiva.metadata.model.Scm;
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Id;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -39,9 +38,7 @@ import java.util.List;
*/ */
public class ProjectVersionMetadataModel public class ProjectVersionMetadataModel
{ {
// repositoryName + namespace + projectId + id (version)
@Id
private String rowId;
@Column(name = "namespace") @Column(name = "namespace")
private Namespace namespace; private Namespace namespace;
@ -99,16 +96,6 @@ public class ProjectVersionMetadataModel
this.projectId = projectId; this.projectId = projectId;
} }
public String getRowId()
{
return rowId;
}
public void setRowId( String rowId )
{
this.rowId = rowId;
}
// FIXME must be renamed getVersion !!! // FIXME must be renamed getVersion !!!
public String getId() public String getId()
{ {
@ -245,7 +232,6 @@ public class ProjectVersionMetadataModel
public String toString() public String toString()
{ {
final StringBuilder sb = new StringBuilder( "ProjectVersionMetadataModel{" ); final StringBuilder sb = new StringBuilder( "ProjectVersionMetadataModel{" );
sb.append( "rowId='" ).append( rowId ).append( '\'' );
sb.append( ", namespace=" ).append( namespace ); sb.append( ", namespace=" ).append( namespace );
sb.append( ", id='" ).append( id ).append( '\'' ); sb.append( ", id='" ).append( id ).append( '\'' );
sb.append( ", projectId='" ).append( projectId ).append( '\'' ); sb.append( ", projectId='" ).append( projectId ).append( '\'' );
@ -261,34 +247,7 @@ public class ProjectVersionMetadataModel
return sb.toString(); return sb.toString();
} }
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ProjectVersionMetadataModel that = (ProjectVersionMetadataModel) o;
if ( !rowId.equals( that.rowId ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return rowId.hashCode();
}
public static class KeyBuilder public static class KeyBuilder
{ {