use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.
the class CassandraMetadataRepository method getMetadataFacet.
@Override
public MetadataFacet getMetadataFacet(final String repositoryId, final String facetId, final String name) throws MetadataRepositoryException {
MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(facetId);
if (metadataFacetFactory == null) {
return null;
}
QueryResult<OrderedRows<String, String, String>> result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(KEY.toString(), //
VALUE.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(FACET_ID.toString(), //
facetId).addEqualsExpression(NAME.toString(), //
name).execute();
MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet(repositoryId, name);
int size = result.get().getCount();
if (size < 1) {
return null;
}
Map<String, String> map = new HashMap<>(size);
for (Row<String, String, String> row : result.get()) {
ColumnSlice<String, String> columnSlice = row.getColumnSlice();
map.put(getStringValue(columnSlice, KEY.toString()), getStringValue(columnSlice, VALUE.toString()));
}
metadataFacet.fromProperties(map);
return metadataFacet;
}
use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.
the class CassandraMetadataRepository method getArtifactsByDateRange.
@Override
public List<ArtifactMetadata> getArtifactsByDateRange(final String repositoryId, final Date startTime, final Date endTime) throws MetadataRepositoryException {
LongSerializer ls = LongSerializer.get();
RangeSlicesQuery<String, String, Long> query = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ls).setColumnFamily(//
cassandraArchivaManager.getArtifactMetadataFamilyName()).setColumnNames(//
ArtifactMetadataModel.COLUMNS);
if (startTime != null) {
query = query.addGteExpression(WHEN_GATHERED.toString(), startTime.getTime());
}
if (endTime != null) {
query = query.addLteExpression(WHEN_GATHERED.toString(), endTime.getTime());
}
QueryResult<OrderedRows<String, String, Long>> result = query.execute();
List<ArtifactMetadata> artifactMetadatas = new ArrayList<>(result.get().getCount());
for (Row<String, String, Long> row : result.get()) {
ColumnSlice<String, Long> columnSlice = row.getColumnSlice();
String repositoryName = getAsStringValue(columnSlice, REPOSITORY_NAME.toString());
if (StringUtils.equals(repositoryName, repositoryId)) {
artifactMetadatas.add(mapArtifactMetadataLongColumnSlice(columnSlice));
}
}
return artifactMetadatas;
}
use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.
the class CassandraMetadataRepository method getDependencies.
protected List<Dependency> getDependencies(String projectVersionMetadataKey) {
List<Dependency> dependencies = new ArrayList<>();
QueryResult<OrderedRows<String, String, String>> result = //
HFactory.createRangeSlicesQuery(cassandraArchivaManager.getKeyspace(), ss, ss, ss).setColumnFamily(//
cassandraArchivaManager.getDependencyFamilyName()).setColumnNames(//
"projectVersionMetadataModel.key").setRowCount(//
Integer.MAX_VALUE).addEqualsExpression("projectVersionMetadataModel.key", //
projectVersionMetadataKey).execute();
for (Row<String, String, String> row : result.get()) {
ColumnFamilyResult<String, String> columnFamilyResult = this.dependencyTemplate.queryColumns(row.getKey());
Dependency dependency = new Dependency();
dependency.setClassifier(columnFamilyResult.getString("classifier"));
dependency.setOptional(Boolean.parseBoolean(columnFamilyResult.getString("optional")));
dependency.setScope(columnFamilyResult.getString("scope"));
dependency.setSystemPath(columnFamilyResult.getString("systemPath"));
dependency.setType(columnFamilyResult.getString("type"));
dependency.setArtifactId(columnFamilyResult.getString(ARTIFACT_ID.toString()));
dependency.setGroupId(columnFamilyResult.getString(GROUP_ID.toString()));
dependency.setVersion(columnFamilyResult.getString(VERSION.toString()));
dependencies.add(dependency);
}
return dependencies;
}
use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.
the class CassandraMetadataRepository method removeNamespace.
@Override
public void removeNamespace(String repositoryId, String namespaceId) throws MetadataRepositoryException {
try {
String key = //
new Namespace.KeyBuilder().withNamespace(//
namespaceId).withRepositoryId(//
repositoryId).build();
//
HFactory.createMutator(cassandraArchivaManager.getKeyspace(), new StringSerializer()).addDeletion(key, //
cassandraArchivaManager.getNamespaceFamilyName()).execute();
QueryResult<OrderedRows<String, String, String>> result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getProjectFamilyName()).setColumnNames(//
REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).execute();
for (Row<String, String, String> row : result.get()) {
this.projectTemplate.deleteRow(row.getKey());
}
result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(//
REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).execute();
for (Row<String, String, String> row : result.get()) {
this.projectVersionMetadataTemplate.deleteRow(row.getKey());
removeMailingList(row.getKey());
}
result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getArtifactMetadataFamilyName()).setColumnNames(//
REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).execute();
for (Row<String, String, String> row : result.get()) {
this.artifactMetadataTemplate.deleteRow(row.getKey());
}
result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(//
REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).execute();
for (Row<String, String, String> row : result.get()) {
this.metadataFacetTemplate.deleteRow(row.getKey());
}
} catch (HInvalidRequestException e) {
logger.error(e.getMessage(), e);
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.
the class CassandraMetadataRepository method updateProject.
@Override
public void updateProject(String repositoryId, ProjectMetadata projectMetadata) throws MetadataRepositoryException {
QueryResult<OrderedRows<String, String, String>> result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getProjectFamilyName()).setColumnNames(//
PROJECT_ID.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
projectMetadata.getNamespace()).addEqualsExpression(PROJECT_ID.toString(), //
projectMetadata.getId()).execute();
// project exists ? if yes return nothing to update here
if (result.get().getCount() > 0) {
return;
} else {
Namespace namespace = updateOrAddNamespace(repositoryId, projectMetadata.getNamespace());
String key = new Project.KeyBuilder().withProjectId(projectMetadata.getId()).withNamespace(namespace).build();
String cf = cassandraArchivaManager.getProjectFamilyName();
projectTemplate.createMutator().addInsertion(key, cf, //
CassandraUtils.column(PROJECT_ID.toString(), projectMetadata.getId())).addInsertion(key, cf, //
CassandraUtils.column(REPOSITORY_NAME.toString(), repositoryId)).addInsertion(key, cf, //
CassandraUtils.column(NAMESPACE_ID.toString(), projectMetadata.getNamespace())).execute();
}
}
Aggregations