import org.apache.archiva.metadata.repository.MetadataResolutionException;
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.Project;
import org.apache.archiva.metadata.repository.cassandra.model.Repository;
import org.apache.commons.lang.StringUtils;
import org.modelmapper.ModelMapper;
public void updateProject( String repositoryId, ProjectMetadata projectMetadata )
throws MetadataRepositoryException
{
-/*
- // project exists ? if yes return
- String projectKey = new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace(
- new Namespace( projectMetadata.getNamespace(), new Repository( repositoryId ) ) ).build();
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
- Project project = getProjectEntityManager().get( projectKey );
- if ( project != null )
+ QueryResult<OrderedRows<String, String, String>> result = HFactory //
+ .createRangeSlicesQuery( keyspace, //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
+ .setColumnNames( "projectId" ) //
+ .addEqualsExpression( "repositoryId", repositoryId ) //
+ .addEqualsExpression( "namespaceId", projectMetadata.getNamespace() ) //
+ .addEqualsExpression( "projectId", projectMetadata.getId() ) //
+ .execute();
+
+ // project exists ? if yes return
+ if ( result.get().getCount() > 0 )
{
return;
}
- String namespaceKey = new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace(
- projectMetadata.getNamespace() ).build();
- Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
- if ( namespace == null )
- {
- namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() );
- }
+ Namespace namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() );
- project = new Project( projectKey, projectMetadata.getId(), namespace );
+ String key =
+ new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace( namespace ).build();
+
+ HFactory.createMutator( keyspace, StringSerializer.get() )
+ // values
+ .addInsertion( key, //
+ cassandraArchivaManager.getProjectFamilyName(), //
+ CassandraUtils.column( "projectId", projectMetadata.getId() ) ) //
+ .addInsertion( key, //
+ cassandraArchivaManager.getProjectFamilyName(), //
+ CassandraUtils.column( "repositoryId", repositoryId ) ) //
+ .addInsertion( key, //
+ cassandraArchivaManager.getProjectFamilyName(), //
+ CassandraUtils.column( "namespaceId", projectMetadata.getNamespace() ) )//
+ .execute();
+ }
- try
+ @Override
+ public Collection<String> getProjects( final String repoId, final String namespace )
+ 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( "repositoryId", repoId ) //
+ .addEqualsExpression( "namespaceId", namespace ) //
+ .execute();
+
+ final Set<String> projects = new HashSet<String>( result.get().getCount() );
+
+ for ( Row<String, String, String> row : result.get() )
{
- getProjectEntityManager().put( project );
+ projects.add( row.getColumnSlice().getColumnByName( "projectId" ).getValue() );
}
- catch ( PersistenceException e )
- {
- throw new MetadataRepositoryException( e.getMessage(), e );
- }*/
+ return projects;
}
@Override
return Collections.emptyList();
}
- @Override
- public Collection<String> getProjects( final String repoId, final String namespace )
- throws MetadataResolutionException
- {
- final Set<String> projects = new HashSet<String>();
-
-/* // FIXME use cql query
- getProjectEntityManager().visitAll( new Function<Project, Boolean>()
- {
- @Override
- public Boolean apply( Project project )
- {
- if ( project != null )
- {
- if ( StringUtils.equals( repoId, project.getNamespace().getRepository().getName() )
- && StringUtils.startsWith( project.getNamespace().getName(), namespace ) )
- {
- projects.add( project.getProjectId() );
- }
- }
- return Boolean.TRUE;
- }
- } );*/
-
- return projects;
- }
-
-
@Override
public void removeProjectVersion( final String repoId, final String namespace, final String projectId,
final String projectVersion )
private String namespaceFamilyName = "namespace";
+ private String projectFamilyName = "project";
+
@PostConstruct
public void initialize()
// namespace table
{
- final ColumnFamilyDefinition namespaces =
+ final ColumnFamilyDefinition namespace =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getNamespaceFamilyName(), //
ComparatorType.UTF8TYPE );
- cfds.add( namespaces );
+ cfds.add( namespace );
// creating indexes for cql query
nameColumn.setIndexName( "name" );
nameColumn.setIndexType( ColumnIndexType.KEYS );
nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
- namespaces.addColumnDefinition( nameColumn );
+ namespace.addColumnDefinition( nameColumn );
BasicColumnDefinition repositoryIdColumn = new BasicColumnDefinition();
repositoryIdColumn.setName( StringSerializer.get().toByteBuffer( "repositoryId" ) );
repositoryIdColumn.setIndexName( "repositoryId" );
repositoryIdColumn.setIndexType( ColumnIndexType.KEYS );
repositoryIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
- namespaces.addColumnDefinition( repositoryIdColumn );
+ namespace.addColumnDefinition( repositoryIdColumn );
}
+ // repository table
{
final ColumnFamilyDefinition repository =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
repository.addColumnDefinition( nameColumn );
}
+ // project table
+ {
+
+ final ColumnFamilyDefinition project =
+ HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
+ getProjectFamilyName(), //
+ ComparatorType.UTF8TYPE );
+ cfds.add( project );
+
+ // creating indexes for cql query
+
+ BasicColumnDefinition projectIdColumn = new BasicColumnDefinition();
+ projectIdColumn.setName( StringSerializer.get().toByteBuffer( "projectId" ) );
+ projectIdColumn.setIndexName( "projectId" );
+ projectIdColumn.setIndexType( ColumnIndexType.KEYS );
+ projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+ project.addColumnDefinition( projectIdColumn );
+
+ BasicColumnDefinition repositoryIdColumn = new BasicColumnDefinition();
+ repositoryIdColumn.setName( StringSerializer.get().toByteBuffer( "repositoryId" ) );
+ repositoryIdColumn.setIndexName( "repositoryId" );
+ repositoryIdColumn.setIndexType( ColumnIndexType.KEYS );
+ repositoryIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+ project.addColumnDefinition( repositoryIdColumn );
+
+ BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition();
+ namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( "namespaceId" ) );
+ namespaceIdColumn.setIndexName( "namespaceId" );
+ namespaceIdColumn.setIndexType( ColumnIndexType.KEYS );
+ namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+ project.addColumnDefinition( namespaceIdColumn );
+ }
+
{ // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
if ( cluster.describeKeyspace( keyspaceName ) == null )
{
{
return namespaceFamilyName;
}
+
+ public String getProjectFamilyName()
+ {
+ return projectFamilyName;
+ }
}