当前位置: 首页>>代码示例>>Java>>正文


Java RangeSlicesQuery.setRange方法代码示例

本文整理汇总了Java中me.prettyprint.hector.api.query.RangeSlicesQuery.setRange方法的典型用法代码示例。如果您正苦于以下问题:Java RangeSlicesQuery.setRange方法的具体用法?Java RangeSlicesQuery.setRange怎么用?Java RangeSlicesQuery.setRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在me.prettyprint.hector.api.query.RangeSlicesQuery的用法示例。


在下文中一共展示了RangeSlicesQuery.setRange方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fillRangeSliceQuery

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
public <K, V> void fillRangeSliceQuery(RangeSlicesQuery<K, N, V> sliceQuery) {
    if (type == SliceDataSpecificatorType.COLUMNS) {
        if (columnsArray != null) {
            sliceQuery.setColumnNames(columnsArray);
        }  else {
            ((ThriftRangeSlicesQuery) sliceQuery).setColumnNames(columnsCollection);
        }
    } else if (type == SliceDataSpecificatorType.RANGE) {
        if (orderDesc) { // Cassandra's WTF requirement
            sliceQuery.setRange(highEnd, lowEnd, orderDesc, limit);
        } else {
            sliceQuery.setRange(lowEnd, highEnd, orderDesc, limit);
        }

    } else {
        throw new IllegalStateException("Invalid type: " + type);
    }
}
 
开发者ID:appmetr,项目名称:hercules,代码行数:19,代码来源:SliceDataSpecificator.java

示例2: execute

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
/**
 * Select a family column in the keyspace.
 * @param cassandraQuery a wrapper of the query
 * @param family the family name to be queried
 * @return a list of family rows
 */
public List<Row<K, ByteBuffer, ByteBuffer>> execute(CassandraQuery<K, T> cassandraQuery, String family) {
  
  String[] columnNames = cassandraQuery.getColumns(family);
  ByteBuffer[] columnNameByteBuffers = new ByteBuffer[columnNames.length];
  for (int i = 0; i < columnNames.length; i++) {
    columnNameByteBuffers[i] = StringSerializer.get().toByteBuffer(columnNames[i]);
  }
  Query<K, T> query = cassandraQuery.getQuery();
  int limit = (int) query.getLimit();
  if (limit < 1) {
    limit = Integer.MAX_VALUE;
  }
  K startKey = query.getStartKey();
  K endKey = query.getEndKey();
  
  RangeSlicesQuery<K, ByteBuffer, ByteBuffer> rangeSlicesQuery = HFactory.createRangeSlicesQuery
      (this.keyspace, this.keySerializer, ByteBufferSerializer.get(), ByteBufferSerializer.get());
  rangeSlicesQuery.setColumnFamily(family);
  rangeSlicesQuery.setKeys(startKey, endKey);
  rangeSlicesQuery.setRange(ByteBuffer.wrap(new byte[0]), ByteBuffer.wrap(new byte[0]), false, GoraRecordReader.BUFFER_LIMIT_READ_VALUE);
  rangeSlicesQuery.setRowCount(limit);
  rangeSlicesQuery.setColumnNames(columnNameByteBuffers);
  
  QueryResult<OrderedRows<K, ByteBuffer, ByteBuffer>> queryResult = rangeSlicesQuery.execute();
  OrderedRows<K, ByteBuffer, ByteBuffer> orderedRows = queryResult.get();
  
  return orderedRows.getList();
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:35,代码来源:CassandraClient.java

示例3: getCFData

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
public CassandraCFData getCFData(String columnFamily, String start, int limit) {
	int columnLimit = 100;
	CassandraCFData data = new CassandraCFData();
	String lastEnd = null;
	
	Map<String, Map<String, String>> cfData = new HashMap<String, Map<String, String>>();
	RangeSlicesQuery<String, String, String> query = HFactory.createRangeSlicesQuery(keyspace, STR, STR, STR);
	query.setColumnFamily(columnFamily);
	query.setKeys(start, "");
	query.setRange("", "", false, columnLimit);
	query.setRowCount(limit);
	OrderedRows<String, String, String> rows = query.execute().get();
	if (rows.getCount() != 1) {
		lastEnd = rows.peekLast().getKey();
		data.start = lastEnd;
	} else {
		data.start = null;
		return data;
	}
	
	for(Row<String,String,String> row  : rows.getList()){
		Map<String, String> columnMap = new HashMap<String, String>();
		ColumnSlice<String, String> columnData = row.getColumnSlice();
		for (HColumn<String, String> column : columnData.getColumns()){
			columnMap.put(column.getName(), column.getValue());
		}
		
		cfData.put(row.getKey(), columnMap);
	}
	
	data.rowColumnMap = cfData;
	return data;
}
 
开发者ID:eBay,项目名称:cassandra-river,代码行数:34,代码来源:CassandraDB.java

示例4: readRowsAsMap

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
@Override
public Map<K,Map<N,V>> readRowsAsMap() {
    Map<K,Map<N,V>> resultMap = new HashMap<K,Map<N,V>>();
    RangeSlicesQuery<K, N, V> rangeSlicesQuery = HFactory.createRangeSlicesQuery(getKeyspace(),
                                                                                 getKeySerializer(),
                                                                                 getColumnNameSerializer(),
                                                                                 getValueSerializer());
    rangeSlicesQuery.setColumnFamily(getColumnFamily());
    rangeSlicesQuery.setRange(null, null, false, ALL);
    rangeSlicesQuery.setRowCount(ALL);
    QueryResult<OrderedRows<K, N, V>> result = rangeSlicesQuery.execute();
    for (Row<K,N,V> row : result.get()) {
        K key = row.getKey();
        ColumnSlice<N,V> slice = row.getColumnSlice();
        Map<N,V> columns = new HashMap<N,V>();
        for (HColumn<N,V> column : slice.getColumns()) {
            V value = column.getValue();
            columns.put(column.getName(), value);
        }
        resultMap.put(key, columns);
    }

    // we used to translate hector exceptions into spring exceptions here, but spring dependency was removed

    if (LOG.isDebugEnabled()) {
        LOG.debug("Returning result from multiGetColumnsAsMap: " + resultMap);
    }
    return resultMap;
}
 
开发者ID:ezoerner,项目名称:c-star-path-j,代码行数:30,代码来源:ColumnFamilyTemplate.java

示例5: getRowCount

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
@Override
public <R, T> int getRowCount(Keyspace keyspace, String columnFamily, DataOperationsProfile dataOperationsProfile, RowSerializer<R, T> rowSerializer, R from, R to, Integer count) {

    RangeSlicesQuery<R, T, ByteBuffer> rangeSlicesQuery = HFactory.createRangeSlicesQuery(
            keyspace,
            rowSerializer.getRowKeySerializer(),
            rowSerializer.getTopKeySerializer(),
            ByteBufferSerializer.get());
    rangeSlicesQuery.setColumnFamily(columnFamily);

    rangeSlicesQuery.setKeys(from, to);
    rangeSlicesQuery.setRange(null, null, false, 1);
    rangeSlicesQuery.setRowCount(getBoundedRowCount(count));
    rangeSlicesQuery.setReturnKeysOnly();

    QueryResult<OrderedRows<R, T, ByteBuffer>> result;
    StopWatch monitor = monitoring.start(HerculesMonitoringGroup.HERCULES_DD, "Get row count " + columnFamily);

    try {
        result = rangeSlicesQuery.execute();
    } finally {
        long time = monitor.stop();
        if (dataOperationsProfile != null) {
            dataOperationsProfile.ms += time;
            dataOperationsProfile.dbQueries++;
        }
    }

    return result.get().getCount();
}
 
开发者ID:appmetr,项目名称:hercules,代码行数:31,代码来源:ThriftDataDriver.java

示例6: execute

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
/**
 * Select a family column in the keyspace.
 * @param cassandraQuery a wrapper of the query
 * @param family the family name to be queried
 * @return a list of family rows
 */
public List<Row<K, ByteBuffer, ByteBuffer>> execute(CassandraQuery<K, T> cassandraQuery, String family) {
  
  String[] columnNames = cassandraQuery.getColumns(family);
  ByteBuffer[] columnNameByteBuffers = new ByteBuffer[columnNames.length];
  for (int i = 0; i < columnNames.length; i++) {
    columnNameByteBuffers[i] = StringSerializer.get().toByteBuffer(columnNames[i]);
  }
  Query<K, T> query = cassandraQuery.getQuery();
  int limit = (int) query.getLimit();
  if (limit < 1) {
    limit = Integer.MAX_VALUE;
  }
  K startKey = query.getStartKey();
  K endKey = query.getEndKey();
  
  RangeSlicesQuery<K, ByteBuffer, ByteBuffer> rangeSlicesQuery = HFactory.createRangeSlicesQuery(this.keyspace, this.keySerializer, ByteBufferSerializer.get(), ByteBufferSerializer.get());
  rangeSlicesQuery.setColumnFamily(family);
  rangeSlicesQuery.setKeys(startKey, endKey);
  rangeSlicesQuery.setRange(ByteBuffer.wrap(new byte[0]), ByteBuffer.wrap(new byte[0]), false, GoraRecordReader.BUFFER_LIMIT_READ_VALUE);
  rangeSlicesQuery.setRowCount(limit);
  rangeSlicesQuery.setColumnNames(columnNameByteBuffers);
  
  QueryResult<OrderedRows<K, ByteBuffer, ByteBuffer>> queryResult = rangeSlicesQuery.execute();
  OrderedRows<K, ByteBuffer, ByteBuffer> orderedRows = queryResult.get();
  
  
  return orderedRows.getList();
}
 
开发者ID:maestros,项目名称:gora-oraclenosql,代码行数:35,代码来源:CassandraClient.java

示例7: testResultDetail

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
private void testResultDetail() {

        Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
        // add 10 rows
        for (int i = 0; i < 10; i++) {
            mutator.addInsertion("fake_key_" + i, COLUMN_FAMILY_NAME_1,
                    HFactory.createStringColumn("fake_column_0", "fake_value_0_" + i))
                    .addInsertion("fake_key_" + i, COLUMN_FAMILY_NAME_1,
                            HFactory.createStringColumn("fake_column_1", "fake_value_1_" + i))
                    .addInsertion("fake_key_" + i, COLUMN_FAMILY_NAME_1,
                            HFactory.createStringColumn("fake_column_2", "fake_value_2_" + i));
        }
        MutationResult me = mutator.execute();
        System.out.println("MutationResult from 10 row insertion: " + me);

        RangeSlicesQuery<String, String, String> rangeSlicesQuery = HFactory.createRangeSlicesQuery(keyspace,
                stringSerializer, stringSerializer, stringSerializer);
        rangeSlicesQuery.setColumnFamily(COLUMN_FAMILY_NAME_1);
        rangeSlicesQuery.setKeys("", "");
        rangeSlicesQuery.setRange("", "", false, 3);

        rangeSlicesQuery.setRowCount(10);
        QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
        System.out.println("Result from rangeSlices query: " + result.toString());

        ColumnQuery<String, String, String> columnQuery = HFactory.createStringColumnQuery(keyspace);
        columnQuery.setColumnFamily(COLUMN_FAMILY_NAME_1).setKey("fake_key_0").setName("fake_column_0");
        QueryResult<HColumn<String, String>> colResult = columnQuery.execute();
        System.out.println("Execution time: " + colResult.getExecutionTimeMicro());
        System.out.println("CassandraHost used: " + colResult.getHostUsed());
        System.out.println("Query Execute: " + colResult.getQuery());

    }
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:34,代码来源:HectorCassandraTest.java

示例8: doListUsers

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
/**
 * Lists the users in the user store.
 */
@Override
protected String[] doListUsers(String filter, int maxItemLimit) throws UserStoreException {

    List<String> users = new ArrayList<String>();
    int arrayLength = 0;

    if (maxItemLimit == 0) {
        return new String[0];
    }

    int givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

    try {
        givenMax = Integer.parseInt(realmConfig
                .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST));
    } catch (Exception e) {
        givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

        if (log.isDebugEnabled()) {
            log.debug("Realm configuration maximum not set : Using User Core Constant value instead!", e);
        }
    }

    if (maxItemLimit < 0 || maxItemLimit > givenMax) {
        maxItemLimit = givenMax;
    }

    RangeSlicesQuery<String, String, String> rangeSliceQuery = HFactory.createRangeSlicesQuery(keyspace,
            stringSerializer, stringSerializer, stringSerializer);

    rangeSliceQuery.setColumnFamily(CFConstants.UM_USER);
    rangeSliceQuery.setRange(filter, null, false, Integer.MAX_VALUE);
    rangeSliceQuery.addEqualsExpression(CFConstants.UM_TENANT_ID, tenantIdString);

    // TODO - Need to check how to use the filter for range
    rangeSliceQuery.setKeys("", "");
    rangeSliceQuery.setRowCount(maxItemLimit);
    QueryResult<OrderedRows<String, String, String>> result = rangeSliceQuery.execute();
    if (result != null) {
        OrderedRows<String, String, String> rows = result.get();
        if (rows.getCount() <= 0) {
            // reformatted to avoid nesting too many blocks
            return users.toArray(new String[arrayLength]);

        }
        arrayLength = rows.getCount();

        Iterator<Row<String, String, String>> rowsIterator = rows.iterator();

        while (rowsIterator.hasNext()) {
            Row<String, String, String> row = rowsIterator.next();
            if (row.getColumnSlice().getColumnByName(CFConstants.UM_USER_ID).getValue() != null) {
                String name = row.getColumnSlice().getColumnByName(CFConstants.UM_USER_NAME).getValue();
                // append the domain if exist
                name = UserCoreUtil.addDomainToName(name, domain);
                users.add(name);
            }
        }

    }
    return users.toArray(new String[arrayLength]);

}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:67,代码来源:CassandraUserStoreManager.java

示例9: doGetRoleNames

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
/**
 * Get the role names in the roles store.
 */
@Override
public String[] doGetRoleNames(String filter, int maxItemLimit) throws UserStoreException {
    List<String> roles = new ArrayList<String>();

    if (maxItemLimit == 0) {
        return new String[0];
    }

    int givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

    try {
        givenMax = Integer.parseInt(realmConfig
                .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_ROLE_LIST));
    } catch (Exception e) {
        givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

        if (log.isDebugEnabled()) {
            log.debug("Realm configuration maximum not set : Using User Core Constant value instead!", e);
        }
    }

    if (maxItemLimit < 0 || maxItemLimit > givenMax) {
        maxItemLimit = givenMax;
    }

    int arrayLength = 0;
    String domain = realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
    RangeSlicesQuery<String, String, String> rangeSliceQuery = HFactory.createRangeSlicesQuery(keyspace,
            stringSerializer, stringSerializer, stringSerializer);
    rangeSliceQuery.setColumnFamily(CFConstants.UM_ROLES);
    rangeSliceQuery.setRange(null, null, false, Integer.MAX_VALUE);
    rangeSliceQuery.addEqualsExpression(CFConstants.UM_TENANT_ID, tenantIdString);
    rangeSliceQuery.setKeys("", "");
    rangeSliceQuery.setRowCount(maxItemLimit);
    QueryResult<OrderedRows<String, String, String>> result = rangeSliceQuery.execute();
    if (result != null) {
        OrderedRows<String, String, String> rows = result.get();
        if (rows.getCount() <= 0) {
            return roles.toArray(new String[arrayLength]);
        }
        arrayLength = rows.getCount();

        Iterator<Row<String, String, String>> rowsIterator = rows.iterator();

        while (rowsIterator.hasNext()) {
            Row<String, String, String> row = rowsIterator.next();
            if (row.getColumnSlice().getColumnByName(CFConstants.UM_ROLE_NAME).getValue() != null) {
                String name = row.getColumnSlice().getColumnByName(CFConstants.UM_ROLE_NAME).getValue();
                // append the domain if exist
                name = UserCoreUtil.addDomainToName(name, domain);
                roles.add(name);
            }
        }

    }
    return roles.toArray(new String[arrayLength]);
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:61,代码来源:CassandraUserStoreManager.java

示例10: testGetRangeSlicesPaginate

import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
private void testGetRangeSlicesPaginate() {

        Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);

        for (int i = 0; i < 20; i++) {
            mutator.addInsertion("fake_key_" + i, COLUMN_FAMILY_NAME_1,
                    HFactory.createStringColumn("fake_column_0", "fake_value_0_" + i))
                    .addInsertion("fake_key_" + i, COLUMN_FAMILY_NAME_1,
                            HFactory.createStringColumn("fake_column_1", "fake_value_1_" + i))
                    .addInsertion("fake_key_" + i, COLUMN_FAMILY_NAME_1,
                            HFactory.createStringColumn("fake_column_2", "fake_value_2_" + i));
        }
        mutator.execute();

        RangeSlicesQuery<String, String, String> rangeSlicesQuery = HFactory.createRangeSlicesQuery(keyspace,
                stringSerializer, stringSerializer, stringSerializer);
        rangeSlicesQuery.setColumnFamily(COLUMN_FAMILY_NAME_1);
        rangeSlicesQuery.setKeys("", "");
        rangeSlicesQuery.setRange("", "", false, 3);

        rangeSlicesQuery.setRowCount(11);
        QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
        OrderedRows<String, String, String> orderedRows = result.get();

        Row<String, String, String> lastRow = orderedRows.peekLast();

        System.out.println("Contents of rows: \n");
        for (Row<String, String, String> r : orderedRows) {
            System.out.println("   " + r);
        }
        System.out.println("Should have 11 rows: " + orderedRows.getCount());

        rangeSlicesQuery.setKeys(lastRow.getKey(), "");
        orderedRows = rangeSlicesQuery.execute().get();

        System.out.println("2nd page Contents of rows: \n");
        for (Row<String, String, String> row : orderedRows) {
            System.out.println("   " + row);
        }

    }
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:42,代码来源:HectorCassandraTest.java


注:本文中的me.prettyprint.hector.api.query.RangeSlicesQuery.setRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。