use of com.netflix.astyanax.serializers.CompositeRangeBuilder in project coprhd-controller by CoprHD.
the class DbConsistencyCheckerHelperTest method testIsIndexExists.
@Test
public void testIsIndexExists() throws Exception {
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("path1");
testData.setMountPath("mountPath1");
getDbClient().createObject(testData);
ColumnFamily<String, IndexColumnName> indexCF = new ColumnFamily<String, IndexColumnName>("AltIdIndex", StringSerializer.get(), IndexColumnNameSerializer.get());
Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
CompositeRangeBuilder builder = IndexColumnNameSerializer.get().buildRange();
builder.withPrefix("FileShare").greaterThanEquals(testData.getId().toString()).lessThanEquals(testData.getId().toString());
Rows<String, IndexColumnName> result = keyspace.prepareQuery(indexCF).getAllRows().withColumnRange(builder).execute().getResult();
for (Row<String, IndexColumnName> row : result) {
System.out.println(row.getColumns().getColumnByIndex(0).getName());
assertTrue(helper.isIndexExists(keyspace, indexCF, row.getKey(), row.getColumns().getColumnByIndex(0).getName()));
}
((DbClientImpl) getDbClient()).internalRemoveObjects(testData);
for (Row<String, IndexColumnName> row : result) {
assertFalse(helper.isIndexExists(keyspace, indexCF, row.getKey(), row.getColumns().getColumnByIndex(0).getName()));
}
}
use of com.netflix.astyanax.serializers.CompositeRangeBuilder in project coprhd-controller by CoprHD.
the class ConstraintImpl method queryOnePageWithAutoPaginate.
protected <T1> void queryOnePageWithAutoPaginate(RowQuery<String, T> query, String prefix, final QueryResult<T1> result) throws ConnectionException {
CompositeRangeBuilder range = indexSerializer.buildRange().greaterThanEquals(prefix).lessThanEquals(prefix).limit(pageCount);
query.withColumnRange(range);
queryOnePageWithAutoPaginate(query, result);
}
use of com.netflix.astyanax.serializers.CompositeRangeBuilder in project coprhd-controller by CoprHD.
the class ConstraintImpl method queryOnePageWithoutAutoPaginate.
protected <T1> void queryOnePageWithoutAutoPaginate(RowQuery<String, T> query, String prefix, final QueryResult<T1> result) throws ConnectionException {
CompositeRangeBuilder builder = indexSerializer.buildRange().greaterThanEquals(prefix).lessThanEquals(prefix).reverse().limit(1);
query.withColumnRange(builder);
ColumnList<T> columns = query.execute().getResult();
List<T1> ids = new ArrayList();
if (columns.isEmpty()) {
result.setResult(ids.iterator());
// not found
return;
}
Column<T> lastColumn = columns.getColumnByIndex(0);
String endId = lastColumn.getName().getTwo();
builder = indexSerializer.buildRange();
if (startId == null) {
// query first page
builder.greaterThanEquals(prefix).lessThanEquals(prefix).limit(pageCount);
} else {
builder.withPrefix(prefix).greaterThan(startId).lessThanEquals(endId).limit(pageCount);
}
query = query.withColumnRange(builder);
columns = query.execute().getResult();
for (Column<T> col : columns) {
T1 obj = createQueryHit(result, col);
if (obj != null && !ids.contains(obj)) {
ids.add(createQueryHit(result, col));
}
}
result.setResult(ids.iterator());
}
Aggregations