All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.archinnov.achilles.proxy.wrapper.ThriftAbstractWideMapWrapper Maven / Gradle / Ivy

package info.archinnov.achilles.proxy.wrapper;

import info.archinnov.achilles.context.ThriftPersistenceContext;
import info.archinnov.achilles.context.execution.SafeExecutionContext;
import info.archinnov.achilles.entity.operations.EntityValidator;
import info.archinnov.achilles.entity.operations.ThriftEntityProxifier;
import info.archinnov.achilles.proxy.ThriftEntityInterceptor;
import info.archinnov.achilles.type.ConsistencyLevel;
import info.archinnov.achilles.type.KeyValue;
import info.archinnov.achilles.type.KeyValueIterator;
import info.archinnov.achilles.type.WideMap;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ThriftAbstractWideMapWrapper
 * 
 * @author DuyHai DOAN
 * 
 */
public abstract class ThriftAbstractWideMapWrapper implements WideMap
{
	private static final Logger log = LoggerFactory.getLogger(ThriftAbstractWideMapWrapper.class);

	protected ThriftPersistenceContext context;
	protected ThriftEntityInterceptor interceptor;
	protected EntityValidator validator = new EntityValidator(
			new ThriftEntityProxifier());

	protected static final int DEFAULT_COUNT = 100;

	@Override
	public V get(final K key, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public V execute()
			{
				return get(key);
			}
		}, readLevel);
	}

	@Override
	public void insert(final K key, final V value, final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				insert(key, value);
				return null;
			}
		}, writeLevel);
	}

	@Override
	public void insert(final K key, final V value, final int ttl, final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				insert(key, value, ttl);
				return null;
			}
		}, writeLevel);
	}

	@Override
	public KeyValue findFirstMatching(final K key)
	{
		List> found = find(key, key, 1, BoundingMode.INCLUSIVE_BOUNDS,
				OrderingMode.ASCENDING);

		return found.size() > 0 ? found.get(0) : null;
	}

	@Override
	public KeyValue findFirstMatching(final K key, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public KeyValue execute()
			{
				return findFirstMatching(key);
			}
		}, readLevel);
	}

	@Override
	public KeyValue findLastMatching(final K key)
	{
		List> found = find(key, key, 1, BoundingMode.INCLUSIVE_BOUNDS,
				OrderingMode.DESCENDING);

		return found.size() > 0 ? found.get(0) : null;
	}

	@Override
	public KeyValue findLastMatching(final K key, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public KeyValue execute()
			{
				return findLastMatching(key);
			}
		}, readLevel);
	}

	@Override
	public List> find(final K start, final K end, final int count)
	{
		return find(start, end, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public List> find(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>>()
				{
					@Override
					public List> execute()
					{
						return find(start, end, count, BoundingMode.INCLUSIVE_BOUNDS,
								OrderingMode.ASCENDING);
					}
				}, readLevel);

	}

	@Override
	public List> find(final K start, final K end, final int count,
			final BoundingMode bounds, final OrderingMode ordering, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>>()
				{
					@Override
					public List> execute()
					{
						return find(start, end, count, bounds, ordering);
					}
				}, readLevel);
	}

	@Override
	public List> findBoundsExclusive(final K start, final K end, final int count)
	{
		return find(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public List> findBoundsExclusive(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>>()
				{
					@Override
					public List> execute()
					{
						return find(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS,
								OrderingMode.ASCENDING);
					}
				}, readLevel);

	}

	@Override
	public List> findReverse(final K start, final K end, final int count)
	{
		return find(start, end, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public List> findReverse(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>>()
				{
					@Override
					public List> execute()
					{
						return find(start, end, count, BoundingMode.INCLUSIVE_BOUNDS,
								OrderingMode.DESCENDING);
					}
				}, readLevel);
	}

	@Override
	public List> findReverseBoundsExclusive(final K start, final K end,
			final int count)
	{
		return find(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public List> findReverseBoundsExclusive(final K start, final K end,
			final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>>()
				{
					@Override
					public List> execute()
					{
						return find(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS,
								OrderingMode.DESCENDING);
					}
				}, readLevel);
	}

	@Override
	public KeyValue findFirst()
	{
		List> result = this.find(null, null, 1);

		KeyValue keyValue = null;
		if (result.size() > 0)
		{
			keyValue = result.get(0);
		}

		return keyValue;
	}

	@Override
	public KeyValue findFirst(final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public KeyValue execute()
			{
				return findFirst();
			}
		}, readLevel);
	}

	@Override
	public List> findFirst(final int count)
	{
		return find(null, null, count);
	}

	@Override
	public List> findFirst(final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>>()
				{
					@Override
					public List> execute()
					{
						return find(null, null, count);
					}
				}, readLevel);
	}

	@Override
	public KeyValue findLast()
	{
		List> result = this.findReverse(null, null, 1);

		KeyValue keyValue = null;
		if (result.size() > 0)
		{
			keyValue = result.get(0);
		}

		return keyValue;
	}

	@Override
	public KeyValue findLast(final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public KeyValue execute()
			{
				return findLast();
			}
		}, readLevel);
	}

	@Override
	public List> findLast(final int count)
	{
		return findReverse(null, null, count);
	}

	@Override
	public List> findLast(final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>>()
				{
					@Override
					public List> execute()
					{
						return findReverse(null, null, count);
					}
				}, readLevel);
	}

	@Override
	public V findValue(final K key)
	{
		List found = findValues(key, key, 1, BoundingMode.INCLUSIVE_BOUNDS,
				OrderingMode.ASCENDING);

		return found.size() > 0 ? found.get(0) : null;
	}

	@Override
	public V findValue(final K key, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public V execute()
			{
				return findValue(key);
			}
		}, readLevel);
	}

	@Override
	public List findValues(final K start, final K end, final int count)
	{
		return findValues(start, end, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public List findValues(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findValues(start, end, count, BoundingMode.INCLUSIVE_BOUNDS,
						OrderingMode.ASCENDING);
			}
		}, readLevel);
	}

	@Override
	public List findValues(final K start, final K end, final int count,
			final BoundingMode bounds, final OrderingMode ordering, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findValues(start, end, count, bounds, ordering);
			}
		}, readLevel);

	}

	@Override
	public List findBoundsExclusiveValues(final K start, final K end, final int count)
	{
		return findValues(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public List findBoundsExclusiveValues(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findValues(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS,
						OrderingMode.ASCENDING);
			}
		}, readLevel);
	}

	@Override
	public List findReverseBoundsExclusiveValues(final K start, final K end, final int count)
	{
		return findValues(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public List findReverseBoundsExclusiveValues(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findValues(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS,
						OrderingMode.DESCENDING);
			}
		}, readLevel);
	}

	@Override
	public List findReverseValues(final K start, final K end, final int count)
	{
		return findValues(start, end, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public List findReverseValues(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findValues(start, end, count, BoundingMode.INCLUSIVE_BOUNDS,
						OrderingMode.DESCENDING);
			}
		}, readLevel);
	}

	@Override
	public V findFirstValue()
	{
		List result = this.findValues(null, null, 1);

		V value = null;
		if (result.size() > 0)
		{
			value = result.get(0);
		}

		return value;
	}

	@Override
	public V findFirstValue(final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public V execute()
			{
				return findFirstValue();
			}
		}, readLevel);
	}

	@Override
	public List findFirstValues(final int count)
	{
		return findValues(null, null, count);
	}

	@Override
	public List findFirstValues(final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findValues(null, null, count);
			}
		}, readLevel);
	}

	@Override
	public V findLastValue()
	{
		List result = this.findReverseValues(null, null, 1);

		V value = null;
		if (result.size() > 0)
		{
			value = result.get(0);
		}

		return value;
	}

	@Override
	public V findLastValue(final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public V execute()
			{
				return findLastValue();
			}
		}, readLevel);
	}

	@Override
	public List findLastValues(final int count)
	{
		return findReverseValues(null, null, count);
	}

	@Override
	public List findLastValues(final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findReverseValues(null, null, count);
			}
		}, readLevel);
	}

	@Override
	public K findKey(final K key)
	{
		List found = findKeys(key, key, 1, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.ASCENDING);

		return found.size() > 0 ? found.get(0) : null;
	}

	@Override
	public K findKey(final K key, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public K execute()
			{
				return findKey(key);
			}
		}, readLevel);
	}

	@Override
	public List findKeys(final K start, final K end, final int count)
	{
		return findKeys(start, end, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public List findKeys(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findKeys(start, end, count, BoundingMode.INCLUSIVE_BOUNDS,
						OrderingMode.ASCENDING);
			}
		}, readLevel);
	}

	@Override
	public List findKeys(final K start, final K end, final int count, final BoundingMode bounds,
			final OrderingMode ordering, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findKeys(start, end, count, bounds, ordering);
			}
		}, readLevel);
	}

	@Override
	public List findBoundsExclusiveKeys(final K start, final K end, final int count)
	{
		return findKeys(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public List findBoundsExclusiveKeys(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findKeys(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS,
						OrderingMode.ASCENDING);
			}
		}, readLevel);
	}

	@Override
	public List findReverseKeys(final K start, final K end, final int count)
	{
		return findKeys(start, end, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public List findReverseKeys(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findKeys(start, end, count, BoundingMode.INCLUSIVE_BOUNDS,
						OrderingMode.DESCENDING);
			}
		}, readLevel);
	}

	@Override
	public List findReverseBoundsExclusiveKeys(final K start, final K end, final int count)
	{
		return findKeys(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public List findReverseBoundsExclusiveKeys(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findKeys(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS,
						OrderingMode.DESCENDING);
			}
		}, readLevel);
	}

	@Override
	public K findFirstKey()
	{
		List result = this.findKeys(null, null, 1);

		K key = null;
		if (result.size() > 0)
		{
			key = result.get(0);
		}

		return key;
	}

	@Override
	public K findFirstKey(final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public K execute()
			{
				return findFirstKey();
			}
		}, readLevel);
	}

	@Override
	public List findFirstKeys(final int count)
	{
		return findKeys(null, null, count);
	}

	@Override
	public List findFirstKeys(final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findKeys(null, null, count);
			}
		}, readLevel);
	}

	@Override
	public K findLastKey()
	{
		List result = this.findReverseKeys(null, null, 1);

		K key = null;
		if (result.size() > 0)
		{
			key = result.get(0);
		}

		return key;
	}

	@Override
	public K findLastKey(final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public K execute()
			{
				return findLastKey();
			}
		}, readLevel);
	}

	@Override
	public List findLastKeys(final int count)
	{
		return findReverseKeys(null, null, count);
	}

	@Override
	public List findLastKeys(final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(new SafeExecutionContext>()
		{
			@Override
			public List execute()
			{
				return findReverseKeys(null, null, count);
			}
		}, readLevel);
	}

	@Override
	public KeyValueIterator iterator()
	{
		return iterator(null, null, DEFAULT_COUNT, BoundingMode.INCLUSIVE_BOUNDS,
				OrderingMode.ASCENDING);
	}

	@Override
	public KeyValueIterator iterator(final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(null, null, DEFAULT_COUNT, BoundingMode.INCLUSIVE_BOUNDS,
								OrderingMode.ASCENDING);
					}
				}, readLevel);
	}

	@Override
	public KeyValueIterator iterator(final K start, final K end, final int count,
			final BoundingMode bounds, final OrderingMode ordering, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(null, null, count, bounds, ordering);
					}
				}, readLevel);
	}

	@Override
	public KeyValueIterator iterator(final int count)
	{
		return iterator(null, null, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public KeyValueIterator iterator(final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(null, null, count, BoundingMode.INCLUSIVE_BOUNDS,
								OrderingMode.ASCENDING);
					}
				}, readLevel);
	}

	@Override
	public KeyValueIterator iterator(final K start, final K end, final int count)
	{
		return iterator(start, end, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public KeyValueIterator iterator(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(start, end, count, BoundingMode.INCLUSIVE_BOUNDS,
								OrderingMode.ASCENDING);
					}
				}, readLevel);
	}

	@Override
	public KeyValueIterator iteratorBoundsExclusive(final K start, final K end,
			final int count)
	{
		return iterator(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS, OrderingMode.ASCENDING);
	}

	@Override
	public KeyValueIterator iteratorBoundsExclusive(final K start, final K end,
			final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS,
								OrderingMode.ASCENDING);
					}
				}, readLevel);
	}

	@Override
	public KeyValueIterator iteratorReverse()
	{
		return iterator(null, null, DEFAULT_COUNT, BoundingMode.INCLUSIVE_BOUNDS,
				OrderingMode.DESCENDING);
	}

	@Override
	public KeyValueIterator iteratorReverse(final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(null, null, DEFAULT_COUNT, BoundingMode.INCLUSIVE_BOUNDS,
								OrderingMode.DESCENDING);
					}
				}, readLevel);
	}

	@Override
	public KeyValueIterator iteratorReverse(final int count)
	{
		return iterator(null, null, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public KeyValueIterator iteratorReverse(final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(null, null, count, BoundingMode.INCLUSIVE_BOUNDS,
								OrderingMode.DESCENDING);
					}
				}, readLevel);
	}

	@Override
	public KeyValueIterator iteratorReverse(final K start, final K end, final int count)
	{
		return iterator(start, end, count, BoundingMode.INCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public KeyValueIterator iteratorReverse(final K start, final K end, final int count,
			final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(start, end, count, BoundingMode.INCLUSIVE_BOUNDS,
								OrderingMode.DESCENDING);
					}
				}, readLevel);
	}

	@Override
	public KeyValueIterator iteratorReverseBoundsExclusive(final K start, final K end,
			final int count)
	{
		return iterator(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS, OrderingMode.DESCENDING);
	}

	@Override
	public KeyValueIterator iteratorReverseBoundsExclusive(final K start, final K end,
			final int count, final ConsistencyLevel readLevel)
	{
		ensureNoPendingBatch();
		return context.executeWithReadConsistencyLevel(
				new SafeExecutionContext>()
				{
					@Override
					public KeyValueIterator execute()
					{
						return iterator(start, end, count, BoundingMode.EXCLUSIVE_BOUNDS,
								OrderingMode.DESCENDING);
					}
				}, readLevel);
	}

	@Override
	public void remove(final K key, final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				remove(key);
				return null;
			}
		}, writeLevel);

	}

	@Override
	public void remove(final K start, final K end)
	{
		remove(start, end, BoundingMode.INCLUSIVE_BOUNDS);
	}

	@Override
	public void remove(final K start, final K end, final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				remove(start, end, BoundingMode.INCLUSIVE_BOUNDS);
				return null;
			}
		}, writeLevel);
	}

	@Override
	public void remove(final K start, final K end, final BoundingMode bounds,
			final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				remove(start, end, bounds);
				return null;
			}
		}, writeLevel);
	}

	@Override
	public void removeBoundsExclusive(final K start, final K end)
	{
		remove(start, end, BoundingMode.EXCLUSIVE_BOUNDS);
	}

	@Override
	public void removeBoundsExclusive(final K start, final K end, final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				remove(start, end, BoundingMode.EXCLUSIVE_BOUNDS);
				return null;
			}
		}, writeLevel);
	}

	@Override
	public void removeFirst()
	{
		removeFirst(1);
	}

	@Override
	public void removeFirst(final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				removeFirst(1);
				return null;
			}
		}, writeLevel);
	}

	@Override
	public void removeFirst(final int count, final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				removeFirst(count);
				return null;
			}
		}, writeLevel);
	}

	@Override
	public void removeLast()
	{
		removeLast(1);
	}

	@Override
	public void removeLast(final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				removeLast(1);
				return null;
			}
		}, writeLevel);
	}

	@Override
	public void removeLast(final int count, final ConsistencyLevel writeLevel)
	{
		ensureNoPendingBatch();
		context.executeWithWriteConsistencyLevel(new SafeExecutionContext()
		{
			@Override
			public Void execute()
			{
				removeLast(count);
				return null;
			}
		}, writeLevel);
	}

	private void ensureNoPendingBatch() throws Error
	{
		validator.validateNoPendingBatch(context);
	}

	public ThriftEntityInterceptor getInterceptor()
	{
		return interceptor;
	}

	public void setInterceptor(final ThriftEntityInterceptor interceptor)
	{
		this.interceptor = interceptor;
	}

	public void setContext(final ThriftPersistenceContext context)
	{
		this.context = context;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy