Search in sources :

Example 1 with PersistitException

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);
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) PersistitException(com.persistit.exception.PersistitException)

Example 2 with PersistitException

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);
        }
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) PersistitException(com.persistit.exception.PersistitException)

Example 3 with PersistitException

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);
        }
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) PersistitException(com.persistit.exception.PersistitException)

Example 4 with PersistitException

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();
        }
    };
}
Also used : RecordIterator(com.thinkaurelius.titan.diskstorage.util.RecordIterator) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) RecordIterator(com.thinkaurelius.titan.diskstorage.util.RecordIterator) PersistitException(com.persistit.exception.PersistitException) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KeyValueEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)

Example 5 with PersistitException

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);
        }
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) PersistitException(com.persistit.exception.PersistitException)

Aggregations

PersistitException (com.persistit.exception.PersistitException)9 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)9 Exchange (com.persistit.Exchange)2 Transaction (com.persistit.Transaction)1 Volume (com.persistit.Volume)1 RollbackException (com.persistit.exception.RollbackException)1 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)1 AbstractStoreTransaction (com.thinkaurelius.titan.diskstorage.common.AbstractStoreTransaction)1 KeyValueEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)1 RecordIterator (com.thinkaurelius.titan.diskstorage.util.RecordIterator)1