本文整理汇总了Java中me.prettyprint.hector.api.query.RangeSlicesQuery类的典型用法代码示例。如果您正苦于以下问题:Java RangeSlicesQuery类的具体用法?Java RangeSlicesQuery怎么用?Java RangeSlicesQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RangeSlicesQuery类属于me.prettyprint.hector.api.query包,在下文中一共展示了RangeSlicesQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeArtifact
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入依赖的package包/类
@Override
public void removeArtifact( final String repositoryId, final String namespace, final String project,
final String version, final MetadataFacet metadataFacet )
throws MetadataRepositoryException
{
RangeSlicesQuery<String, String, String> query = HFactory //
.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) //
.setColumnNames( NAMESPACE_ID.toString() ); //
query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) //
.addEqualsExpression( NAMESPACE_ID.toString(), namespace ) //
.addEqualsExpression( PROJECT.toString(), project ) //
.addEqualsExpression( VERSION.toString(), version );
QueryResult<OrderedRows<String, String, String>> result = query.execute();
for ( Row<String, String, String> row : result.get() )
{
this.artifactMetadataTemplate.deleteRow( row.getKey() );
}
}
示例2: getArtifacts
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入依赖的package包/类
@Override
public List<ArtifactMetadata> getArtifacts( final String repositoryId )
throws MetadataRepositoryException
{
RangeSlicesQuery<String, String, String> query = HFactory //
.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) //
.setColumnNames( ArtifactMetadataModel.COLUMNS ); //
query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId );
QueryResult<OrderedRows<String, String, String>> result = query.execute();
List<ArtifactMetadata> artifactMetadatas = new ArrayList<>( result.get().getCount() );
for ( Row<String, String, String> row : result.get() )
{
ColumnSlice<String, String> columnSlice = row.getColumnSlice();
artifactMetadatas.add( mapArtifactMetadataStringColumnSlice( columnSlice ) );
}
return artifactMetadatas;
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: getArtifactsByDateRange
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入依赖的package包/类
@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;
}
示例7: 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();
}
示例8: CAndPCSlicesQueryIterator
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入依赖的package包/类
/**
* Creates a new iterator iterating over the results of the given query.
*
* @param query The query.
* @param limit The maximum amount of results to return.
* @param cf The column family to query.
* @param keyspace The keyspace to use.
* @param dictionary the CumulusRDF dictionary.
* @param isPC True, if this is a PC query, false, if this is a C query.
*/
CAndPCSlicesQueryIterator(
final RangeSlicesQuery<byte[], Composite, byte[]> query,
final int limit,
final String cf,
final Keyspace keyspace,
final ITopLevelDictionary dictionary,
final boolean isPC) {
_rows = new RangeSlicesIterator<byte[], Composite, byte[]>(query, new byte[0], new byte[0]);
_limit = limit;
_cf = cf;
_keyspace = keyspace;
_dictionary = dictionary;
_isPC = isPC;
}
示例9: getKey
import me.prettyprint.hector.api.query.RangeSlicesQuery; //导入依赖的package包/类
@Override
public K getKey(final V value) throws DataAccessLayerException {
RangeSlicesQuery<K, byte[], V> rq = HFactory.createRangeSlicesQuery(
_keyspace,
_serializer_k,
BYTE_SERIALIZER,
_serializer_v);
rq.addEqualsExpression(COLUMN_NAME, value).setReturnKeysOnly()
.setColumnFamily(_cf_name)
.setColumnNames(COLUMN_NAME).setRowCount(1);
final List<Row<K, byte[], V>> rows = rq.execute().get().getList();
return rows.isEmpty() ? null : _serializer_k.fromBytes((byte[])rows.get(0).getKey());
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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();
}
示例14: 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());
}
示例15: 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;
}