本文整理汇总了Java中me.prettyprint.hector.api.query.RangeSlicesQuery.setKeys方法的典型用法代码示例。如果您正苦于以下问题:Java RangeSlicesQuery.setKeys方法的具体用法?Java RangeSlicesQuery.setKeys怎么用?Java RangeSlicesQuery.setKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类me.prettyprint.hector.api.query.RangeSlicesQuery
的用法示例。
在下文中一共展示了RangeSlicesQuery.setKeys方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doScan
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected void doScan(byte[] beginKey, byte[] endKey,
IKeyValueCallback callback, boolean includeValue)
throws StorageException {
try {
RangeSlicesQuery<byte[], String, byte[]> query = prepareRangeQuery(
beginKey, endKey, includeValue);
byte[] lastKey = null;
while (true) {
if (lastKey != null) {
query.setKeys(lastKey, endKey);
}
OrderedRows<byte[], String, byte[]> rows = query.execute()
.get();
lastKey = reportScanData(rows, callback, endKey, includeValue);
if (rows.getCount() < MAX_SCAN_ROWS) {
break;
}
}
} catch (HectorException e) {
handleHectorException(e);
}
}
示例2: testGetRangeSlices
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
private void testGetRangeSlices() {
Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
RangeSlicesQuery<String, String, String> rangeSlicesQuery = HFactory.createRangeSlicesQuery(keyspace,
stringSerializer, stringSerializer, stringSerializer);
rangeSlicesQuery.setColumnFamily(COLUMN_FAMILY_NAME_1);
rangeSlicesQuery.setKeys("fake_key_", "");
rangeSlicesQuery.setColumnNames("birthdate");
rangeSlicesQuery.setReturnKeysOnly();
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);
}
}
示例3: 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();
}
示例4: prepareRangeQuery
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
/** Creates and initializes a range query. */
private RangeSlicesQuery<byte[], String, byte[]> prepareRangeQuery(
byte[] beginKey, byte[] endKey, boolean includeValue) {
RangeSlicesQuery<byte[], String, byte[]> query = HFactory
.createRangeSlicesQuery(keyspace, BytesArraySerializer.get(),
StringSerializer.get(), BytesArraySerializer.get());
query.setColumnFamily(CassandraStorageSystem.COLUMN_FAMILY_NAME);
query.setColumnNames(CassandraStorageSystem.COLUMN_NAME);
if (!includeValue) {
query.setReturnKeysOnly();
}
query.setRowCount(MAX_SCAN_ROWS);
query.setKeys(beginKey, endKey);
return query;
}
示例5: 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;
}
示例6: 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();
}
示例7: getRangeSlice
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
@Override
public <R, T> HerculesMultiQueryResult<R, T> getRangeSlice(Keyspace keyspace, String columnFamily, DataOperationsProfile dataOperationsProfile, RowSerializer<R, T> rowSerializer,
R rowFrom, R rowTo, Integer rowCount, SliceDataSpecificator<T> sliceDataSpecificator) {
RangeSlicesQuery<R, T, ByteBuffer> rangeSlicesQuery = HFactory.createRangeSlicesQuery(
keyspace,
rowSerializer.getRowKeySerializer(),
rowSerializer.getTopKeySerializer(),
ByteBufferSerializer.get());
rangeSlicesQuery.setColumnFamily(columnFamily);
rangeSlicesQuery.setRowCount(getBoundedRowCount(rowCount));
rangeSlicesQuery.setKeys(rowFrom, rowTo);
sliceDataSpecificator.fillRangeSliceQuery(rangeSlicesQuery);
QueryResult<OrderedRows<R, T, ByteBuffer>> result;
StopWatch monitor = monitoring.start(HerculesMonitoringGroup.HERCULES_DD, "Get range slice " + columnFamily);
try {
result = rangeSlicesQuery.execute();
} finally {
long time = monitor.stop();
if (dataOperationsProfile != null) {
dataOperationsProfile.ms += time;
dataOperationsProfile.dbQueries++;
}
}
return buildQueryResult(dataOperationsProfile, rowSerializer, result.get());
}
示例8: getKeyRange
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
@Override
public <R, T> List<R> getKeyRange(Keyspace keyspace, String columnFamily, DataOperationsProfile dataOperationsProfile, RowSerializer<R, T> rowSerializer,
R from, R to, Integer count) {
RangeSlicesQuery<R, T, ByteBuffer> query = HFactory.createRangeSlicesQuery(keyspace,
rowSerializer.getRowKeySerializer(),
rowSerializer.getTopKeySerializer(),
ByteBufferSerializer.get());
query.setColumnFamily(columnFamily);
query.setKeys(from, to);
query.setRowCount(getBoundedRowCount(count));
query.setReturnKeysOnly();
QueryResult<OrderedRows<R, T, ByteBuffer>> result;
StopWatch monitor = monitoring.start(HerculesMonitoringGroup.HERCULES_DD, "Get key range " + columnFamily);
try {
result = query.execute();
} finally {
long time = monitor.stop();
if (dataOperationsProfile != null) {
dataOperationsProfile.ms += time;
dataOperationsProfile.dbQueries++;
}
}
OrderedRows<R, T, ByteBuffer> rows = (result != null) ? result.get() : null;
List<R> keys = new ArrayList<R>(rows == null ? 0 : rows.getCount());
if (rows != null) {
for (Row<R, T, ByteBuffer> row : rows) {
keys.add(row.getKey());
}
}
return keys;
}
示例9: 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();
}
示例10: testGetRangeSlicesKeysOnly
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入方法依赖的package包/类
private void testGetRangeSlicesKeysOnly() {
Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
for (int i = 0; i < 5; 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("fake_key_", "");
rangeSlicesQuery.setColumnNames("birthdate");
rangeSlicesQuery.setReturnKeysOnly();
rangeSlicesQuery.setRowCount(5);
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);
}
}
示例11: 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());
}
示例12: 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]);
}
示例13: 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]);
}
示例14: 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);
}
}