use of com.persistit.exception.PersistitException in project titan by thinkaurelius.
the class PersistitKeyValueStore method clear.
/**
* Clears the contents of this kv store
*/
public void clear() throws StorageException {
try {
Exchange exchange = persistit.getExchange(VOLUME_NAME, name, true);
exchange.removeTree();
} catch (PersistitException ex) {
throw new PermanentStorageException(ex);
}
}
use of com.persistit.exception.PersistitException in project titan by thinkaurelius.
the class PersistitKeyValueStore method get.
@Override
public StaticBuffer get(final StaticBuffer key, StoreTransaction txh) throws StorageException {
final PersistitTransaction tx = (PersistitTransaction) txh;
synchronized (tx) {
tx.assign();
final Exchange exchange = tx.getExchange(name);
try {
toKey(exchange, key);
exchange.fetch();
if (exchange.getValue().isDefined()) {
return getValue(exchange);
} else {
return null;
}
} catch (PersistitException ex) {
throw new PermanentStorageException(ex);
} finally {
tx.releaseExchange(exchange);
}
}
}
use of com.persistit.exception.PersistitException in project titan by thinkaurelius.
the class PersistitKeyValueStore method containsKey.
@Override
public boolean containsKey(final StaticBuffer key, StoreTransaction txh) throws StorageException {
final PersistitTransaction tx = (PersistitTransaction) txh;
synchronized (tx) {
tx.assign();
final Exchange exchange = tx.getExchange(name);
try {
toKey(exchange, key);
return exchange.isValueDefined();
} catch (PersistitException ex) {
throw new PermanentStorageException(ex);
} finally {
tx.releaseExchange(exchange);
}
}
}
use of com.persistit.exception.PersistitException in project titan by thinkaurelius.
the class PersistitKeyValueStore method getSlice.
/**
* Runs all getSlice queries
*
* The keyStart & keyEnd are not guaranteed to exist
* if keyStart is after keyEnd, an empty list is returned
*
* @param keyStart
* @param keyEnd
* @param selector
* @param limit
* @param txh
* @return
* @throws StorageException
*/
private RecordIterator<KeyValueEntry> getSlice(final StaticBuffer keyStart, final StaticBuffer keyEnd, final KeySelector selector, final Integer limit, StoreTransaction txh) throws StorageException {
PersistitTransaction tx = (PersistitTransaction) txh;
final List<KeyValueEntry> results = new ArrayList<KeyValueEntry>();
synchronized (tx) {
tx.assign();
Exchange exchange = tx.getExchange(name);
try {
byte[] start = getArray(keyStart);
byte[] end = getArray(keyEnd);
// bail out if the start key comes after the end
if (compare(start, end) > 0) {
return KVUtil.EMPTY_ITERATOR;
}
KeyFilter.Term[] terms = { KeyFilter.rangeTerm(start, end, true, false, null) };
KeyFilter keyFilter = new KeyFilter(terms);
int i = 0;
while (exchange.next(keyFilter)) {
StaticBuffer k = getKey(exchange);
// check the key against the selector, and that is has a corresponding value
if (exchange.getValue().isDefined() && (selector == null || selector.include(k))) {
StaticBuffer v = getValue(exchange);
KeyValueEntry kv = new KeyValueEntry(k, v);
results.add(kv);
i++;
if (limit != null && limit >= 0 && i >= limit)
break;
if (selector != null && selector.reachedLimit())
break;
}
}
} catch (PersistitException ex) {
throw new PermanentStorageException(ex);
} finally {
tx.releaseExchange(exchange);
}
}
// on heap for at least 2 collections.
return new RecordIterator<KeyValueEntry>() {
private final Iterator<KeyValueEntry> entries = results.iterator();
@Override
public boolean hasNext() {
return entries.hasNext();
}
@Override
public KeyValueEntry next() {
return entries.next();
}
@Override
public void close() {
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of com.persistit.exception.PersistitException in project titan by thinkaurelius.
the class PersistitKeyValueStore method delete.
@Override
public void delete(final StaticBuffer key, StoreTransaction txh) throws StorageException {
final PersistitTransaction tx = (PersistitTransaction) txh;
synchronized (tx) {
tx.assign();
final Exchange exchange = tx.getExchange(name);
try {
toKey(exchange, key);
exchange.remove();
} catch (PersistitException ex) {
throw new PermanentStorageException(ex);
} finally {
tx.releaseExchange(exchange);
}
}
}
Aggregations