Search in sources :

Example 1 with CompositeRangeBuilder

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()));
    }
}
Also used : CompositeIndexColumnName(com.emc.storageos.db.client.impl.CompositeIndexColumnName) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) Keyspace(com.netflix.astyanax.Keyspace) CompositeRangeBuilder(com.netflix.astyanax.serializers.CompositeRangeBuilder) FileShare(com.emc.storageos.db.client.model.FileShare) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Test(org.junit.Test)

Example 2 with CompositeRangeBuilder

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);
}
Also used : CompositeRangeBuilder(com.netflix.astyanax.serializers.CompositeRangeBuilder)

Example 3 with CompositeRangeBuilder

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());
}
Also used : ArrayList(java.util.ArrayList) CompositeRangeBuilder(com.netflix.astyanax.serializers.CompositeRangeBuilder)

Aggregations

CompositeRangeBuilder (com.netflix.astyanax.serializers.CompositeRangeBuilder)3 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)1 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)1 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)1 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)1 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 Keyspace (com.netflix.astyanax.Keyspace)1 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1