本文整理了Java中com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery
类的一些代码示例,展示了KeySliceQuery
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeySliceQuery
类的具体详情如下:
包路径:com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery
类名称:KeySliceQuery
[英]Extends SliceQuery by a key that identifies the location of the slice in the key-ring.
[中]通过标识密钥环中切片位置的密钥扩展SliceQuery。
代码示例来源:origin: thinkaurelius/titan
final KVQuery convertQuery(final KeySliceQuery query) {
Predicate<StaticBuffer> filter = Predicates.alwaysTrue();
if (!hasFixedKeyLength()) filter = new Predicate<StaticBuffer>() {
@Override
public boolean apply(@Nullable StaticBuffer keyAndColumn) {
return equalKey(keyAndColumn, query.getKey());
}
};
return new KVQuery(
concatenatePrefix(query.getKey(), query.getSliceStart()),
concatenatePrefix(query.getKey(), query.getSliceEnd()),
filter,query.getLimit());
}
代码示例来源:origin: thinkaurelius/titan
@Override
public KeySliceQuery updateLimit(int newLimit) {
return new KeySliceQuery(key,this).setLimit(newLimit);
}
代码示例来源:origin: thinkaurelius/titan
@Override
public String toString() {
return String.format("KeySliceQuery(key: %s, start: %s, end: %s, limit:%d)", key, getSliceStart(), getSliceEnd(), getLimit());
}
}
代码示例来源:origin: thinkaurelius/titan
@Override
public Map<StaticBuffer,EntryList> getSlice(List<StaticBuffer> keys, SliceQuery query, StoreTransaction txh) throws BackendException {
Map<StaticBuffer,EntryList> result = Maps.newHashMap();
for (StaticBuffer key : keys) result.put(key,getSlice(new KeySliceQuery(key,query),txh));
return result;
}
代码示例来源:origin: thinkaurelius/titan
private boolean isExpired(final KeySliceQuery query) {
Long until = expiredKeys.get(query.getKey());
if (until==null) return false;
if (isBeyondExpirationTime(until)) {
expiredKeys.remove(query.getKey(),until);
return false;
}
//We suffer a cache miss, hence decrease the count down
penaltyCountdown.countDown();
return true;
}
代码示例来源:origin: thinkaurelius/titan
@Override
public boolean hasNext() {
ensureOpen();
if (null != nextRow)
return true;
while (rows.hasNext()) {
nextRow = rows.next();
List<Entry> ents = nextRow.getValue().getSlice(new KeySliceQuery(nextRow.getKey(), columnSlice), transaction);
if (null != ents && 0 < ents.size())
break;
}
return null != nextRow;
}
代码示例来源:origin: thinkaurelius/titan
@Override
public EntryList getSlice(KeySliceQuery query, StoreTransaction txh) throws BackendException {
Map<StaticBuffer, EntryList> result = getNamesSlice(query.getKey(), query, txh);
return Iterables.getOnlyElement(result.values(),EntryList.EMPTY_LIST);
}
代码示例来源:origin: com.thinkaurelius.titan/titan-core
@Override
public String toString() {
return String.format("KeySliceQuery(key: %s, start: %s, end: %s, limit:%d)", key, getSliceStart(), getSliceEnd(), getLimit());
}
}
代码示例来源:origin: thinkaurelius/titan
EntryList getSlice(KeySliceQuery query, StoreTransaction txh) {
Lock lock = getLock(txh);
lock.lock();
try {
Data datacp = data;
int start = datacp.getIndex(query.getSliceStart());
if (start < 0) start = (-start - 1);
int end = datacp.getIndex(query.getSliceEnd());
if (end < 0) end = (-end - 1);
if (start < end) {
MemoryEntryList result = new MemoryEntryList(end - start);
for (int i = start; i < end; i++) {
if (query.hasLimit() && result.size() >= query.getLimit()) break;
result.add(datacp.get(i));
}
return result;
} else {
return EntryList.EMPTY_LIST;
}
} finally {
lock.unlock();
}
}
代码示例来源:origin: thinkaurelius/titan
public static boolean containsKey(KeyColumnValueStore store, StaticBuffer key, int maxColumnLength, StoreTransaction txh) throws BackendException {
StaticBuffer start = START, end = END;
if (maxColumnLength>32) {
end = BufferUtil.oneBuffer(maxColumnLength);
}
return !store.getSlice(new KeySliceQuery(key, START, END).setLimit(1),txh).isEmpty();
}
代码示例来源:origin: thinkaurelius/titan
@Override
public Map<StaticBuffer,EntryList> getSlice(List<StaticBuffer> keys, SliceQuery query, StoreTransaction txh) throws BackendException {
List<KVQuery> queries = new ArrayList<KVQuery>(keys.size());
for (int i = 0; i < keys.size(); i++) {
queries.add(convertQuery(new KeySliceQuery(keys.get(i),query)));
}
Map<KVQuery,RecordIterator<KeyValueEntry>> results = store.getSlices(queries,txh);
Map<StaticBuffer,EntryList> convResults = new HashMap<StaticBuffer, EntryList>(keys.size());
assert queries.size()==keys.size();
for (int i = 0; i < queries.size(); i++) {
convResults.put(keys.get(i),convert(results.get(queries.get(i))));
}
return convResults;
}
代码示例来源:origin: thinkaurelius/titan
@Override
public EntryList getSlice(KeySliceQuery query, StoreTransaction txh) throws BackendException {
Map<StaticBuffer, EntryList> result = getHelper(Arrays.asList(query.getKey()), getFilter(query));
return Iterables.getOnlyElement(result.values(), EntryList.EMPTY_LIST);
}
代码示例来源:origin: org.hawkular.titan/titan-core
@Override
public String toString() {
return String.format("KeySliceQuery(key: %s, start: %s, end: %s, limit:%d)", key, getSliceStart(), getSliceEnd(), getLimit());
}
}
代码示例来源:origin: thinkaurelius/titan
Composite startComposite = CellNames.simpleDense(query.getSliceStart().asByteBuffer());
Composite endComposite = CellNames.simpleDense(query.getSliceEnd().asByteBuffer());
SliceQueryFilter sqf = new SliceQueryFilter(startComposite, endComposite,
false, query.getLimit() + (query.hasLimit()?1:0));
ReadCommand sliceCmd = new SliceFromReadCommand(keyspace, query.getKey().asByteBuffer(), columnFamily, nowMillis, sqf);
Iterables.filter(cf.getSortedColumns(), new FilterDeletedColumns(nowMillis)),
entryGetter,
query.getSliceEnd(),
query.getLimit());
代码示例来源:origin: thinkaurelius/titan
/**
* Retrieves the value for the specified column and key under the given transaction
* from the store if such exists, otherwise returns NULL
*
* @param store Store
* @param key Key
* @param column Column
* @param txh Transaction
* @return Value for key and column or NULL if such does not exist
*/
public static StaticBuffer get(KeyColumnValueStore store, StaticBuffer key, StaticBuffer column, StoreTransaction txh) throws BackendException {
KeySliceQuery query = new KeySliceQuery(key, column, BufferUtil.nextBiggerBuffer(column)).setLimit(2);
List<Entry> result = store.getSlice(query, txh);
if (result.size() > 1)
log.warn("GET query returned more than 1 result: store {} | key {} | column {}", new Object[]{store.getName(),
key, column});
if (result.isEmpty()) return null;
else return result.get(0).getValueAs(StaticBuffer.STATIC_FACTORY);
}
代码示例来源:origin: thinkaurelius/titan
public EntryList edgeQuery(long vid, SliceQuery query, BackendTransaction tx) {
Preconditions.checkArgument(vid > 0);
return tx.edgeStoreQuery(new KeySliceQuery(idManager.getKey(vid), query));
}
代码示例来源:origin: thinkaurelius/titan
/**
* Call Cassandra's Thrift get_slice() method.
* <p/>
* When columnEnd equals columnStart and either startInclusive
* or endInclusive is false (or both are false), then this
* method returns an empty list without making any Thrift calls.
* <p/>
* If columnEnd = columnStart + 1, and both startInclusive and
* startExclusive are false, then the arguments effectively form
* an empty interval. In this case, as in the one previous,
* an empty list is returned. However, it may not necessarily
* be handled efficiently; a Thrift call might still be made
* before returning the empty list.
*
* @throws com.thinkaurelius.titan.diskstorage.BackendException
* when columnEnd < columnStart
*/
@Override
public EntryList getSlice(KeySliceQuery query, StoreTransaction txh) throws BackendException {
Map<StaticBuffer, EntryList> result = getNamesSlice(query.getKey(), query, txh);
return Iterables.getOnlyElement(result.values(), EntryList.EMPTY_LIST);
}
代码示例来源:origin: com.thinkaurelius.titan/titan-core
final KVQuery convertQuery(final KeySliceQuery query) {
Predicate<StaticBuffer> filter = Predicates.alwaysTrue();
if (!hasFixedKeyLength()) filter = new Predicate<StaticBuffer>() {
@Override
public boolean apply(@Nullable StaticBuffer keyAndColumn) {
return equalKey(keyAndColumn, query.getKey());
}
};
return new KVQuery(
concatenatePrefix(query.getKey(), query.getSliceStart()),
concatenatePrefix(query.getKey(), query.getSliceEnd()),
filter,query.getLimit());
}
代码示例来源:origin: thinkaurelius/titan
StaticBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(cols);
List<Entry> result =
store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(cols), tx);
Assert.assertEquals(cols, result.size());
result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(cols + 10), tx);
Assert.assertEquals(cols, result.size());
Assert.assertEquals(entries, result);
result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(cols - 1), tx);
Assert.assertEquals(cols - 1, result.size());
entries.remove(entries.size() - 1);
Assert.assertEquals(entries, result);
result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(1), tx);
Assert.assertEquals(1, result.size());
List<Entry> firstEntrySingleton = Arrays.asList(entries.get(0));
代码示例来源:origin: thinkaurelius/titan
@Override
public RecordIterator<Entry> getEntries() {
ensureOpen();
if (columnSlice == null)
throw new IllegalStateException("getEntries() requires SliceQuery to be set.");
final KeySliceQuery keySlice = new KeySliceQuery(currentRow.getKey(), columnSlice);
return new RecordIterator<Entry>() {
private final Iterator<Entry> items = currentRow.getValue().getSlice(keySlice, transaction).iterator();
@Override
public boolean hasNext() {
ensureOpen();
return items.hasNext();
}
@Override
public Entry next() {
ensureOpen();
return items.next();
}
@Override
public void close() {
isClosed = true;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Column removal not supported");
}
};
}
内容来源于网络,如有侵权,请联系作者删除!