You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/09/03 11:28:36 UTC
[08/14] ignite git commit: IGNITE-1364: WIP.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/cache.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/cache.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/cache.h
new file mode 100644
index 0000000..18f57dc
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/cache.h
@@ -0,0 +1,1145 @@
+/*
+ * Copyright (C) GridGain Systems. All Rights Reserved.
+ * _________ _____ __________________ _____
+ * __ ____/___________(_)______ /__ ____/______ ____(_)_______
+ * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+ * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+ * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+ */
+
+#ifndef _GRIDGAIN_CACHE
+#define _GRIDGAIN_CACHE
+
+#include <map>
+#include <set>
+
+#include <ignite/common/common.h>
+#include <ignite/common/concurrent.h>
+
+#include "gridgain/cache/cache_peek_mode.h"
+#include "gridgain/cache/query/query_cursor.h"
+#include "gridgain/cache/query/query_scan.h"
+#include "gridgain/cache/query/query_sql.h"
+#include "gridgain/cache/query/query_text.h"
+#include "gridgain/impl/cache/cache_impl.h"
+#include "gridgain/impl/operations.h"
+#include "gridgain/grid_error.h"
+
+namespace gridgain
+{
+ namespace cache
+ {
+ /**
+ * Main entry point for all Data Grid APIs.
+ */
+ template<typename K, typename V>
+ class IGNITE_IMPORT_EXPORT Cache
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ Cache(impl::cache::CacheImpl* impl) : impl(ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl>(impl))
+ {
+ // No-op.
+ }
+
+ /**
+ * Name of this cache (null for default cache).
+ */
+ char* GetName()
+ {
+ return impl.Get()->GetName();
+ }
+
+ /**
+ * Checks whether this cache contains no key-value mappings.
+ * Semantically equals to Cache.Size(GG_PEEK_MODE_PRIMARY) == 0.
+ *
+ * @return True if cache is empty.
+ */
+ bool IsEmpty()
+ {
+ GridError err;
+
+ bool res = IsEmpty(err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Checks whether this cache contains no key-value mappings.
+ * Semantically equals to Cache.Size(GG_PEEK_MODE_PRIMARY) == 0.
+ *
+ * @param err Error.
+ * @return True if cache is empty.
+ */
+ bool IsEmpty(GridError& err)
+ {
+ return impl.Get()->IsEmpty(&err);
+ }
+
+ /**
+ * Check if cache contains mapping for this key.
+ *
+ * @param key Key.
+ * @return True if cache contains mapping for this key.
+ */
+ bool ContainsKey(const K& key)
+ {
+ GridError err;
+
+ bool res = ContainsKey(key, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Check if cache contains mapping for this key.
+ *
+ * @param key Key.
+ * @param err Error.
+ * @return True if cache contains mapping for this key.
+ */
+ bool ContainsKey(const K& key, GridError& err)
+ {
+ impl::In1Operation<K> op(&key);
+
+ return impl.Get()->ContainsKey(op, &err);
+ }
+
+ /**
+ * Check if cache contains mapping for these keys.
+ *
+ * @param keys Keys.
+ * @return True if cache contains mapping for all these keys.
+ */
+ bool ContainsKeys(const std::set<K>& keys)
+ {
+ GridError err;
+
+ bool res = ContainsKeys(keys, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Check if cache contains mapping for these keys.
+ *
+ * @param keys Keys.
+ * @param err Error.
+ * @return True if cache contains mapping for all these keys.
+ */
+ bool ContainsKeys(const std::set<K>& keys, GridError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ return impl.Get()->ContainsKeys(op, &err);
+ }
+
+ /**
+ * Peeks at cached value using optional set of peek modes. This method will sequentially
+ * iterate over given peek modes, and try to peek at value using each peek mode. Once a
+ * non-null value is found, it will be immediately returned.
+ * This method does not participate in any transactions, however, it may peek at transactional
+ * value depending on the peek modes used.
+ *
+ * @param key Key.
+ * @param peekModes Peek modes.
+ * @return Value.
+ */
+ V LocalPeek(const K& key, int32_t peekModes)
+ {
+ GridError err;
+
+ V res = LocalPeek(key, peekModes, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Peeks at cached value using optional set of peek modes. This method will sequentially
+ * iterate over given peek modes, and try to peek at value using each peek mode. Once a
+ * non-null value is found, it will be immediately returned.
+ * This method does not participate in any transactions, however, it may peek at transactional
+ * value depending on the peek modes used.
+ *
+ * @param key Key.
+ * @param peekModes Peek modes.
+ * @param err Error.
+ * @return Value.
+ */
+ V LocalPeek(const K& key, int32_t peekModes, GridError& err)
+ {
+ impl::InCacheLocalPeekOperation<K> inOp(&key, peekModes);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->LocalPeek(inOp, outOp, peekModes, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Retrieves value mapped to the specified key from cache.
+ * If the value is not present in cache, then it will be looked up from swap storage. If
+ * it's not present in swap, or if swap is disabled, and if read-through is allowed, value
+ * will be loaded from persistent store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key.
+ * @return Value.
+ */
+ V Get(const K& key)
+ {
+ GridError err;
+
+ V res = Get(key, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Retrieves value mapped to the specified key from cache.
+ * If the value is not present in cache, then it will be looked up from swap storage. If
+ * it's not present in swap, or if swap is disabled, and if read-through is allowed, value
+ * will be loaded from persistent store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key.
+ * @param err Error.
+ * @return Value.
+ */
+ V Get(const K& key, GridError& err)
+ {
+ impl::In1Operation<K> inOp(&key);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->Get(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Retrieves values mapped to the specified keys from cache.
+ * If some value is not present in cache, then it will be looked up from swap storage. If
+ * it's not present in swap, or if swap is disabled, and if read-through is allowed, value
+ * will be loaded from persistent store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param keys Keys.
+ * @return Map of key-value pairs.
+ */
+ std::map<K, V> GetAll(const std::set<K>& keys)
+ {
+ GridError err;
+
+ std::map<K, V> res = GetAll(keys, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Retrieves values mapped to the specified keys from cache.
+ * If some value is not present in cache, then it will be looked up from swap storage. If
+ * it's not present in swap, or if swap is disabled, and if read-through is allowed, value
+ * will be loaded from persistent store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param keys Keys.
+ * @param err Error.
+ * @return Map of key-value pairs.
+ */
+ std::map<K, V> GetAll(const std::set<K>& keys, GridError& err)
+ {
+ impl::InSetOperation<K> inOp(&keys);
+ impl::OutMapOperation<K, V> outOp;
+
+ impl.Get()->GetAll(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Associates the specified value with the specified key in the cache.
+ * If the cache previously contained a mapping for the key,
+ * the old value is replaced by the specified value.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ */
+ void Put(const K& key, const V& val)
+ {
+ GridError err;
+
+ Put(key, val, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Associates the specified value with the specified key in the cache.
+ * If the cache previously contained a mapping for the key,
+ * the old value is replaced by the specified value.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @param err Error.
+ */
+ void Put(const K& key, const V& val, GridError& err)
+ {
+ impl::In2Operation<K, V> op(&key, &val);
+
+ impl.Get()->Put(op, &err);
+ }
+
+ /**
+ * Stores given key-value pairs in cache.
+ * If write-through is enabled, the stored values will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param vals Key-value pairs to store in cache.
+ */
+ void PutAll(const std::map<K, V>& vals)
+ {
+ GridError err;
+
+ PutAll(vals, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Stores given key-value pairs in cache.
+ * If write-through is enabled, the stored values will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param vals Key-value pairs to store in cache.
+ * @param err Error.
+ */
+ void PutAll(const std::map<K, V>& vals, GridError& err)
+ {
+ impl::InMapOperation<K, V> op(&vals);
+
+ impl.Get()->PutAll(op, &err);
+ }
+
+ /**
+ * Associates the specified value with the specified key in this cache,
+ * returning an existing value if one existed.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @return The value associated with the key at the start of the
+ * operation or null if none was associated.
+ */
+ V GetAndPut(const K& key, const V& val)
+ {
+ GridError err;
+
+ V res = GetAndPut(key, val, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Associates the specified value with the specified key in this cache,
+ * returning an existing value if one existed.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @param err Error.
+ * @return The value associated with the key at the start of the
+ * operation or null if none was associated.
+ */
+ V GetAndPut(const K& key, const V& val, GridError& err)
+ {
+ impl::In2Operation<K, V> inOp(&key, &val);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->GetAndPut(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Atomically replaces the value for a given key if and only if there is
+ * a value currently mapped by the key.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @return The previous value associated with the specified key, or
+ * null if there was no mapping for the key.
+ */
+ V GetAndReplace(const K& key, const V& val)
+ {
+ GridError err;
+
+ V res = GetAndReplace(key, val, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Atomically replaces the value for a given key if and only if there is
+ * a value currently mapped by the key.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @param err Error.
+ * @return The previous value associated with the specified key, or
+ * null if there was no mapping for the key.
+ */
+ V GetAndReplace(const K& key, const V& val, GridError& err)
+ {
+ impl::In2Operation<K, V> inOp(&key, &val);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->GetAndReplace(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Atomically removes the entry for a key only if currently mapped to some value.
+ *
+ * @param key Key with which the specified value is associated.
+ * @return The value if one existed or null if no mapping existed for this key.
+ */
+ V GetAndRemove(const K& key)
+ {
+ GridError err;
+
+ V res = GetAndRemove(key, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Atomically removes the entry for a key only if currently mapped to some value.
+ *
+ * @param key Key with which the specified value is associated.
+ * @param err Error.
+ * @return The value if one existed or null if no mapping existed for this key.
+ */
+ V GetAndRemove(const K& key, GridError& err)
+ {
+ impl::In1Operation<K> inOp(&key);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->GetAndRemove(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Atomically associates the specified key with the given value if it is not
+ * already associated with a value.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @return True if a value was set.
+ */
+ bool PutIfAbsent(const K& key, const V& val)
+ {
+ GridError err;
+
+ bool res = PutIfAbsent(key, val, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Atomically associates the specified key with the given value if it is not
+ * already associated with a value.
+ *
+ * @param key Key with which the specified value is to be associated.
+ * @param val Value to be associated with the specified key.
+ * @param err Error.
+ * @return True if a value was set.
+ */
+ bool PutIfAbsent(const K& key, const V& val, GridError& err)
+ {
+ impl::In2Operation<K, V> op(&key, &val);
+
+ return impl.Get()->PutIfAbsent(op, &err);
+ }
+
+ /**
+ * Stores given key-value pair in cache only if cache had no previous mapping for it.
+ * If cache previously contained value for the given key, then this value is returned.
+ * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node,
+ * which in its turn may load the value from the swap storage, and consecutively, if it's not
+ * in swap, from the underlying persistent storage.
+ * If the returned value is not needed, method putxIfAbsent() should be used instead of this one to
+ * avoid the overhead associated with returning of the previous value.
+ * If write-through is enabled, the stored value will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param val Value to be associated with the given key.
+ * @return Previously contained value regardless of whether put happened or not
+ * (null if there was no previous value).
+ */
+ V GetAndPutIfAbsent(const K& key, const V& val)
+ {
+ GridError err;
+
+ V res = GetAndPutIfAbsent(key, val, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Stores given key-value pair in cache only if cache had no previous mapping for it.
+ * If cache previously contained value for the given key, then this value is returned.
+ * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node,
+ * which in its turn may load the value from the swap storage, and consecutively, if it's not
+ * in swap, from the underlying persistent storage.
+ * If the returned value is not needed, method putxIfAbsent() should be used instead of this one to
+ * avoid the overhead associated with returning of the previous value.
+ * If write-through is enabled, the stored value will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param val Value to be associated with the given key.
+ * @param err Error.
+ * @return Previously contained value regardless of whether put happened or not
+ * (null if there was no previous value).
+ */
+ V GetAndPutIfAbsent(const K& key, const V& val, GridError& err)
+ {
+ impl::In2Operation<K, V> inOp(&key, &val);
+ impl::Out1Operation<V> outOp;
+
+ impl.Get()->GetAndPutIfAbsent(inOp, outOp, &err);
+
+ return outOp.GetResult();
+ }
+
+ /**
+ * Stores given key-value pair in cache only if there is a previous mapping for it.
+ * If cache previously contained value for the given key, then this value is returned.
+ * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node,
+ * which in its turn may load the value from the swap storage, and consecutively, if it's not
+ * in swap, rom the underlying persistent storage.
+ * If write-through is enabled, the stored value will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param val Value to be associated with the given key.
+ * @return True if the value was replaced.
+ */
+ bool Replace(const K& key, const V& val)
+ {
+ GridError err;
+
+ bool res = Replace(key, val, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Stores given key-value pair in cache only if there is a previous mapping for it.
+ * If cache previously contained value for the given key, then this value is returned.
+ * In case of PARTITIONED or REPLICATED caches, the value will be loaded from the primary node,
+ * which in its turn may load the value from the swap storage, and consecutively, if it's not
+ * in swap, rom the underlying persistent storage.
+ * If write-through is enabled, the stored value will be persisted to store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param val Value to be associated with the given key.
+ * @param err Error.
+ * @return True if the value was replaced.
+ */
+ bool Replace(const K& key, const V& val, GridError& err)
+ {
+ impl::In2Operation<K, V> op(&key, &val);
+
+ return impl.Get()->Replace(op, &err);
+ }
+
+ /**
+ * Stores given key-value pair in cache only if only if the previous value is equal to the
+ * old value passed as argument.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param oldVal Old value to match.
+ * @param newVal Value to be associated with the given key.
+ * @return True if replace happened, false otherwise.
+ */
+ bool Replace(const K& key, const V& oldVal, const V& newVal)
+ {
+ GridError err;
+
+ bool res = Replace(key, oldVal, newVal, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Stores given key-value pair in cache only if only if the previous value is equal to the
+ * old value passed as argument.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key to store in cache.
+ * @param oldVal Old value to match.
+ * @param newVal Value to be associated with the given key.
+ * @param err Error.
+ * @return True if replace happened, false otherwise.
+ */
+ bool Replace(const K& key, const V& oldVal, const V& newVal, GridError& err)
+ {
+ impl::In3Operation<K, V, V> op(&key, &oldVal, &newVal);
+
+ return impl.Get()->ReplaceIfEqual(op, &err);
+ }
+
+ /**
+ * Attempts to evict all entries associated with keys. Note, that entry will be evicted only
+ * if it's not used (not participating in any locks or transactions).
+ *
+ * @param keys Keys to evict from cache.
+ */
+ void LocalEvict(const std::set<K>& keys)
+ {
+ GridError err;
+
+ LocalEvict(keys, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Attempts to evict all entries associated with keys. Note, that entry will be evicted only
+ * if it's not used (not participating in any locks or transactions).
+ *
+ * @param keys Keys to evict from cache.
+ * @param err Error.
+ */
+ void LocalEvict(const std::set<K>& keys, GridError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ impl.Get()->LocalEvict(op, &err);
+ }
+
+ /**
+ * Clear cache.
+ */
+ void Clear()
+ {
+ GridError err;
+
+ Clear(err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear cache.
+ *
+ * @param err Error.
+ */
+ void Clear(GridError& err)
+ {
+ impl.Get()->Clear(&err);
+ }
+
+ /**
+ * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ *
+ * @param key Key to clear.
+ */
+ void Clear(const K& key)
+ {
+ GridError err;
+
+ Clear(key, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ *
+ * @param key Key to clear.
+ * @param err Error.
+ */
+ void Clear(const K& key, GridError& err)
+ {
+ impl::In1Operation<K> op(&key);
+
+ impl.Get()->Clear(op, &err);
+ }
+
+ /**
+ * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ *
+ * @param keys Keys to clear.
+ */
+ void ClearAll(const std::set<K>& keys)
+ {
+ GridError err;
+
+ ClearAll(keys, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ *
+ * @param keys Keys to clear.
+ * @param err Error.
+ */
+ void ClearAll(const std::set<K>& keys, GridError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ impl.Get()->ClearAll(op, &err);
+ }
+
+ /**
+ * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ * Note that this operation is local as it merely clears an entry from local cache, it does not
+ * remove entries from remote caches.
+ *
+ * @param key Key to clear.
+ */
+ void LocalClear(const K& key)
+ {
+ GridError err;
+
+ LocalClear(key, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ * Note that this operation is local as it merely clears an entry from local cache, it does not
+ * remove entries from remote caches.
+ *
+ * @param key Key to clear.
+ * @param err Error.
+ */
+ void LocalClear(const K& key, GridError& err)
+ {
+ impl::In1Operation<K> op(&key);
+
+ impl.Get()->LocalClear(op, &err);
+ }
+
+ /**
+ * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ * Note that this operation is local as it merely clears entries from local cache, it does not
+ * remove entries from remote caches.
+ *
+ * @param keys Keys to clear.
+ */
+ void LocalClearAll(const std::set<K>& keys)
+ {
+ GridError err;
+
+ LocalClearAll(keys, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
+ * Entry is cleared only if it is not currently locked, and is not participating in a transaction.
+ * Note that this operation is local as it merely clears entries from local cache, it does not
+ * remove entries from remote caches.
+ *
+ * @param keys Keys to clear.
+ * @param err Error.
+ */
+ void LocalClearAll(const std::set<K>& keys, GridError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ impl.Get()->LocalClearAll(op, &err);
+ }
+
+ /**
+ * Removes given key mapping from cache. If cache previously contained value for the given key,
+ * then this value is returned. In case of PARTITIONED or REPLICATED caches, the value will be
+ * loaded from the primary node, which in its turn may load the value from the disk-based swap
+ * storage, and consecutively, if it's not in swap, from the underlying persistent storage.
+ * If the returned value is not needed, method removex() should always be used instead of this
+ * one to avoid the overhead associated with returning of the previous value.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key whose mapping is to be removed from cache.
+ * @return False if there was no matching key.
+ */
+ bool Remove(const K& key)
+ {
+ GridError err;
+
+ bool res = Remove(key, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Removes given key mapping from cache. If cache previously contained value for the given key,
+ * then this value is returned. In case of PARTITIONED or REPLICATED caches, the value will be
+ * loaded from the primary node, which in its turn may load the value from the disk-based swap
+ * storage, and consecutively, if it's not in swap, from the underlying persistent storage.
+ * If the returned value is not needed, method removex() should always be used instead of this
+ * one to avoid the overhead associated with returning of the previous value.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key whose mapping is to be removed from cache.
+ * @param err Error.
+ * @return False if there was no matching key.
+ */
+ bool Remove(const K& key, GridError& err)
+ {
+ impl::In1Operation<K> op(&key);
+
+ return impl.Get()->Remove(op, &err);
+ }
+
+ /**
+ * Removes given key mapping from cache if one exists and value is equal to the passed in value.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key whose mapping is to be removed from cache.
+ * @param val Value to match against currently cached value.
+ * @return True if entry was removed, false otherwise.
+ */
+ bool Remove(const K& key, const V& val)
+ {
+ GridError err;
+
+ bool res = Remove(key, val, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Removes given key mapping from cache if one exists and value is equal to the passed in value.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param key Key whose mapping is to be removed from cache.
+ * @param val Value to match against currently cached value.
+ * @param err Error.
+ * @return True if entry was removed, false otherwise.
+ */
+ bool Remove(const K& key, const V& val, GridError& err)
+ {
+ impl::In2Operation<K, V> op(&key, &val);
+
+ return impl.Get()->RemoveIfEqual(op, &err);
+ }
+
+ /**
+ * Removes given key mappings from cache.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param keys Keys whose mappings are to be removed from cache.
+ */
+ void RemoveAll(const std::set<K>& keys)
+ {
+ GridError err;
+
+ RemoveAll(keys, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Removes given key mappings from cache.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param keys Keys whose mappings are to be removed from cache.
+ * @param err Error.
+ */
+ void RemoveAll(const std::set<K>& keys, GridError& err)
+ {
+ impl::InSetOperation<K> op(&keys);
+
+ impl.Get()->RemoveAll(op, &err);
+ }
+
+ /**
+ * Removes all mappings from cache.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param err Error.
+ */
+ void RemoveAll()
+ {
+ GridError err;
+
+ RemoveAll(err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Removes all mappings from cache.
+ * If write-through is enabled, the value will be removed from store.
+ * This method is transactional and will enlist the entry into ongoing transaction if there is one.
+ *
+ * @param err Error.
+ */
+ void RemoveAll(GridError& err)
+ {
+ return impl.Get()->RemoveAll(&err);
+ }
+
+ /**
+ * Gets the number of all entries cached on this node.
+ *
+ * @return Cache size on this node.
+ */
+ int32_t LocalSize()
+ {
+ return LocalSize(GG_PEEK_MODE_ALL);
+ }
+
+ /**
+ * Gets the number of all entries cached on this node.
+ *
+ * @param err Error.
+ * @return Cache size on this node.
+ */
+ int32_t LocalSize(GridError& err)
+ {
+ return LocalSize(GG_PEEK_MODE_ALL, err);
+ }
+
+ /**
+ * Gets the number of all entries cached on this node.
+ *
+ * @param Peek modes.
+ * @return Cache size on this node.
+ */
+ int32_t LocalSize(int32_t peekModes)
+ {
+ GridError err;
+
+ int32_t res = LocalSize(peekModes, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Gets the number of all entries cached on this node.
+ *
+ * @param Peek modes.
+ * @param err Error.
+ * @return Cache size on this node.
+ */
+ int32_t LocalSize(int32_t peekModes, GridError& err)
+ {
+ return impl.Get()->LocalSize(peekModes, &err);
+ }
+
+ /**
+ * Gets the number of all entries cached across all nodes.
+ * NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
+ *
+ * @return Cache size across all nodes.
+ */
+ int32_t Size()
+ {
+ return Size(gridgain::cache::GG_PEEK_MODE_ALL);
+ }
+
+ /**
+ * Gets the number of all entries cached across all nodes.
+ * NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
+ *
+ * @param err Error.
+ * @return Cache size across all nodes.
+ */
+ int32_t Size(GridError& err)
+ {
+ return Size(gridgain::cache::GG_PEEK_MODE_ALL, err);
+ }
+
+ /**
+ * Gets the number of all entries cached across all nodes.
+ * NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
+ *
+ * @param Peek modes.
+ * @return Cache size across all nodes.
+ */
+ int32_t Size(int32_t peekModes)
+ {
+ GridError err;
+
+ int32_t res = Size(peekModes, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Gets the number of all entries cached across all nodes.
+ * NOTE: this operation is distributed and will query all participating nodes for their cache sizes.
+ *
+ * @param Peek modes.
+ * @param err Error.
+ * @return Cache size across all nodes.
+ */
+ int32_t Size(int32_t peekModes, GridError& err)
+ {
+ return impl.Get()->Size(peekModes, &err);
+ }
+
+ /**
+ * Perform SQL query.
+ *
+ * @param qry Query.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::SqlQuery& qry)
+ {
+ GridError err;
+
+ query::QueryCursor<K, V> res = Query(qry, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Perform SQL query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::SqlQuery& qry, GridError& err)
+ {
+ impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QuerySql(qry, &err);
+
+ return query::QueryCursor<K, V>(cursorImpl);
+ }
+
+ /*
+ * Perform text query.
+ *
+ * @param qry Query.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::TextQuery& qry)
+ {
+ GridError err;
+
+ query::QueryCursor<K, V> res = Query(qry, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /*
+ * Perform text query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::TextQuery& qry, GridError& err)
+ {
+ impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryText(qry, &err);
+
+ return query::QueryCursor<K, V>(cursorImpl);
+ }
+
+ /*
+ * Perform scan query.
+ *
+ * @param qry Query.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::ScanQuery& qry)
+ {
+ GridError err;
+
+ query::QueryCursor<K, V> res = Query(qry, err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /*
+ * Perform scan query.
+ *
+ * @param qry Query.
+ * @param err Error.
+ * @return Query cursor.
+ */
+ query::QueryCursor<K, V> Query(const query::ScanQuery& qry, GridError& err)
+ {
+ impl::cache::query::QueryCursorImpl* cursorImpl = impl.Get()->QueryScan(qry, &err);
+
+ return query::QueryCursor<K, V>(cursorImpl);
+ }
+
+ private:
+ /** Implementation delegate. */
+ ignite::common::concurrent::SharedPointer<impl::cache::CacheImpl> impl;
+ };
+ }
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/cache_entry.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/cache_entry.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/cache_entry.h
new file mode 100644
index 0000000..837a1ae
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/cache_entry.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) GridGain Systems. All Rights Reserved.
+ * _________ _____ __________________ _____
+ * __ ____/___________(_)______ /__ ____/______ ____(_)_______
+ * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+ * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+ * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+ */
+
+#ifndef _GRIDGAIN_CACHE_ENTRY
+#define _GRIDGAIN_CACHE_ENTRY
+
+#include <ignite/common/common.h>
+
+namespace gridgain
+{
+ namespace cache
+ {
+ /**
+ * Cache entry.
+ */
+ template<typename K, typename V>
+ class IGNITE_IMPORT_EXPORT CacheEntry
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ CacheEntry() : key(K()), val(V())
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param key Key.
+ * @param val Value.
+ */
+ CacheEntry(const K& key, const V& val) : key(key), val(val)
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other Other instance.
+ */
+ CacheEntry(const CacheEntry& other)
+ {
+ key = other.key;
+ val = other.val;
+ }
+
+ /**
+ * Assignment operator.
+ *
+ * @param other Other instance.
+ */
+ CacheEntry& operator=(const CacheEntry& other)
+ {
+ if (this != &other)
+ {
+ CacheEntry tmp(other);
+
+ K& key0 = key;
+ V& val0 = val;
+
+ key = tmp.key;
+ val = tmp.val;
+
+ tmp.key = key0;
+ tmp.val = val0;
+ }
+
+ return *this;
+ }
+
+ /**
+ * Get key.
+ *
+ * @return Key.
+ */
+ K GetKey()
+ {
+ return key;
+ }
+
+ /**
+ * Get value.
+ *
+ * @return Value.
+ */
+ V GetValue()
+ {
+ return val;
+ }
+
+ private:
+ /** Key. */
+ K key;
+
+ /** Value. */
+ V val;
+ };
+ }
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/cache_peek_mode.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/cache_peek_mode.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/cache_peek_mode.h
new file mode 100644
index 0000000..818cada
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/cache_peek_mode.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) GridGain Systems. All Rights Reserved.
+ * _________ _____ __________________ _____
+ * __ ____/___________(_)______ /__ ____/______ ____(_)_______
+ * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+ * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+ * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+ */
+
+#ifndef _GRIDGAIN_CACHE_PEEK_MODE
+#define _GRIDGAIN_CACHE_PEEK_MODE
+
+namespace gridgain
+{
+ namespace cache
+ {
+ /**
+ * Enumeration of all supported cache peek modes.
+ */
+ enum CachePeekMode
+ {
+ /**
+ * Peeks into all available cache storages.
+ */
+ GG_PEEK_MODE_ALL = 0x01,
+
+ /**
+ * Peek into near cache only (don't peek into partitioned cache).
+ * In case of LOCAL cache, behaves as GG_PEEK_MODE_ALL mode.
+ */
+ GG_PEEK_MODE_NEAR = 0x02,
+
+ /**
+ * Peek value from primary copy of partitioned cache only (skip near cache).
+ * In case of LOCAL cache, behaves as GG_PEEK_MODE_ALL mode.
+ */
+ GG_PEEK_MODE_PRIMARY = 0x04,
+
+ /**
+ * Peek value from backup copies of partitioned cache only (skip near cache).
+ * In case of LOCAL cache, behaves as GG_PEEK_MODE_ALL mode.
+ */
+ GG_PEEK_MODE_BACKUP = 0x08,
+
+ /**
+ * Peeks value from the on-heap storage only.
+ */
+ GG_PEEK_MODE_ONHEAP = 0x10,
+
+ /**
+ * Peeks value from the off-heap storage only, without loading off-heap value into cache.
+ */
+ GG_PEEK_MODE_OFFHEAP = 0x20,
+
+ /**
+ * Peeks value from the swap storage only, without loading swapped value into cache.
+ */
+ GG_PEEK_MODE_SWAP = 0x40
+ };
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query.h
new file mode 100644
index 0000000..0934032
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) GridGain Systems. All Rights Reserved.
+ * _________ _____ __________________ _____
+ * __ ____/___________(_)______ /__ ____/______ ____(_)_______
+ * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+ * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+ * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+ */
+
+#ifndef _GRIDGAIN_QUERY
+#define _GRIDGAIN_QUERY
+
+#include "gridgain/cache/query/query_argument.h"
+#include "gridgain/cache/query/query_cursor.h"
+#include "gridgain/cache/query/query_scan.h"
+#include "gridgain/cache/query/query_sql.h"
+#include "gridgain/cache/query/query_text.h"
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_argument.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_argument.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_argument.h
new file mode 100644
index 0000000..d1d236d
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_argument.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) GridGain Systems. All Rights Reserved.
+ * _________ _____ __________________ _____
+ * __ ____/___________(_)______ /__ ____/______ ____(_)_______
+ * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+ * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+ * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+ */
+
+#ifndef _GRIDGAIN_CACHE_QUERY_ARGUMENT
+#define _GRIDGAIN_CACHE_QUERY_ARGUMENT
+
+#include "gridgain/portable/portable_raw_writer.h"
+
+namespace gridgain
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /**
+ * Base class for all query arguments.
+ */
+ class QueryArgumentBase
+ {
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~QueryArgumentBase()
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy argument.
+ *
+ * @return Copy.
+ */
+ virtual QueryArgumentBase* Copy() = 0;
+
+ /**
+ * Write argument.
+ */
+ virtual void Write(gridgain::portable::PortableRawWriter& writer) = 0;
+ };
+
+ /**
+ * Query argument.
+ */
+ template<typename T>
+ class QueryArgument : public QueryArgumentBase
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param val Value.
+ */
+ QueryArgument(const T& val) : val(val)
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other Other instance.
+ */
+ QueryArgument(const QueryArgument& other)
+ {
+ val = other.val;
+ }
+
+ /**
+ * Assignment operator.
+ *
+ * @param other Other instance.
+ */
+ QueryArgument& operator=(const QueryArgument& other)
+ {
+ if (this != &other)
+ {
+ QueryArgument tmp(other);
+
+ T val0 = val;
+ val = tmp.val;
+ tmp.val = val0;
+ }
+
+ return *this;
+ }
+
+ ~QueryArgument()
+ {
+ // No-op.
+ }
+
+ QueryArgumentBase* Copy()
+ {
+ return new QueryArgument(val);
+ }
+
+ void Write(gridgain::portable::PortableRawWriter& writer)
+ {
+ writer.WriteObject<T>(val);
+ }
+
+ private:
+ /** Value. */
+ T val;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_cursor.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_cursor.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_cursor.h
new file mode 100644
index 0000000..d72d910
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_cursor.h
@@ -0,0 +1,183 @@
+/*
+* Copyright (C) GridGain Systems. All Rights Reserved.
+* _________ _____ __________________ _____
+* __ ____/___________(_)______ /__ ____/______ ____(_)_______
+* _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+* / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+* \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+*/
+
+#ifndef _GRIDGAIN_CACHE_QUERY_CURSOR
+#define _GRIDGAIN_CACHE_QUERY_CURSOR
+
+#include <vector>
+
+#include <ignite/common/concurrent.h>
+
+#include "gridgain/cache/cache_entry.h"
+#include "gridgain/grid_error.h"
+#include "gridgain/impl/cache/query/query_impl.h"
+#include "gridgain/impl/operations.h"
+
+namespace gridgain
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /**
+ * Query cursor.
+ */
+ template<typename K, typename V>
+ class QueryCursor
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ QueryCursor() : impl(NULL)
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param impl Implementation.
+ */
+ QueryCursor(impl::cache::query::QueryCursorImpl* impl) :
+ impl(ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl>(impl))
+ {
+ // No-op.
+ }
+
+ /**
+ * Check whether next entry exists.
+ *
+ * @return True if next entry exists.
+ */
+ bool HasNext()
+ {
+ GridError err;
+
+ bool res = HasNext(err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Check whether next entry exists.
+ *
+ * @param err Error.
+ * @return True if next entry exists.
+ */
+ bool HasNext(GridError& err)
+ {
+ impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
+
+ if (impl0)
+ return impl0->HasNext(&err);
+ else
+ {
+ err = GridError(GridError::GG_ERR_GENERIC,
+ "Instance is not usable (did you check for error?).");
+
+ return false;
+ }
+ }
+
+ /**
+ * Get next entry.
+ *
+ * @return Next entry.
+ */
+ CacheEntry<K, V> GetNext()
+ {
+ GridError err;
+
+ CacheEntry<K, V> res = GetNext(err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Get next entry.
+ *
+ * @param err Error.
+ * @return Next entry.
+ */
+ CacheEntry<K, V> GetNext(GridError& err)
+ {
+ impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
+
+ if (impl0) {
+ impl::Out2Operation<K, V> outOp;
+
+ impl0->GetNext(outOp, &err);
+
+ if (err.GetCode() == GridError::GG_SUCCESS)
+ {
+ K& key = outOp.Get1();
+ V& val = outOp.Get2();
+
+ return CacheEntry<K, V>(key, val);
+ }
+ else
+ return CacheEntry<K, V>();
+ }
+ else
+ {
+ err = GridError(GridError::GG_ERR_GENERIC,
+ "Instance is not usable (did you check for error?).");
+
+ return CacheEntry<K, V>();
+ }
+ }
+
+ /**
+ * Get all entries.
+ *
+ * @param Vector where query entries will be stored.
+ */
+ void GetAll(std::vector<CacheEntry<K, V>>& res)
+ {
+ GridError err;
+
+ GetAll(res, err);
+
+ GridError::ThrowIfNeeded(err);
+ }
+
+ /**
+ * Get all entries.
+ *
+ * @param Vector where query entries will be stored.
+ * @param err Error.
+ */
+ void GetAll(std::vector<CacheEntry<K, V>>& res, GridError& err)
+ {
+ impl::cache::query::QueryCursorImpl* impl0 = impl.Get();
+
+ if (impl0) {
+ impl::OutQueryGetAllOperation<K, V> outOp(&res);
+
+ impl0->GetAll(outOp, &err);
+ }
+ else
+ err = GridError(GridError::GG_ERR_GENERIC,
+ "Instance is not usable (did you check for error?).");
+ }
+
+ private:
+ /** Implementation delegate. */
+ ignite::common::concurrent::SharedPointer<impl::cache::query::QueryCursorImpl> impl;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_scan.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_scan.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_scan.h
new file mode 100644
index 0000000..a6def1b
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_scan.h
@@ -0,0 +1,143 @@
+/*
+* Copyright (C) GridGain Systems. All Rights Reserved.
+* _________ _____ __________________ _____
+* __ ____/___________(_)______ /__ ____/______ ____(_)_______
+* _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+* / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+* \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+*/
+
+#ifndef _GRIDGAIN_CACHE_QUERY_SCAN
+#define _GRIDGAIN_CACHE_QUERY_SCAN
+
+#include <stdint.h>
+#include <string>
+
+#include "gridgain/portable/portable_raw_writer.h"
+
+namespace gridgain
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /*
+ * Scab query.
+ */
+ class ScanQuery
+ {
+ public:
+ /*
+ * Constructor.
+ */
+ ScanQuery() : part(-1), pageSize(1024), loc(false)
+ {
+ // No-op.
+ }
+
+ /*
+ * Constructor.
+ *
+ * @param part Partition.
+ */
+ ScanQuery(int32_t part) : part(part), pageSize(1024), loc(false)
+ {
+ // No-op.
+ }
+
+ /*
+ * Get partition to scan.
+ *
+ * @return Partition to scan.
+ */
+ int32_t GetPartition()
+ {
+ return part;
+ }
+
+ /*
+ * Set partition to scan.
+ *
+ * @param part Partition to scan.
+ */
+ void SetPartition(int32_t part)
+ {
+ this->part = part;
+ }
+
+ /*
+ * Get page size.
+ *
+ * @return Page size.
+ */
+ int32_t GetPageSize()
+ {
+ return pageSize;
+ }
+
+ /*
+ * Set page size.
+ *
+ * @param pageSize Page size.
+ */
+ void SetPageSize(int32_t pageSize)
+ {
+ this->pageSize = pageSize;
+ }
+
+ /*
+ * Get local flag.
+ *
+ * @return Local flag.
+ */
+ bool IsLocal()
+ {
+ return loc;
+ }
+
+ /*
+ * Set local flag.
+ *
+ * @param loc Local flag.
+ */
+ void SetLocal(bool loc)
+ {
+ this->loc = loc;
+ }
+
+ /*
+ * Write query info to the stream.
+ *
+ * @param writer Writer.
+ */
+ void Write(portable::PortableRawWriter& writer) const
+ {
+ writer.WriteBool(loc);
+ writer.WriteInt32(pageSize);
+
+ if (part < 0)
+ writer.WriteBool(false);
+ else
+ {
+ writer.WriteBool(true);
+ writer.WriteInt32(part);
+ }
+
+ writer.WriteNull(); // Predicates are not supported yet.
+ }
+
+ private:
+ /* Partition. */
+ int32_t part;
+
+ /* Page size. */
+ int32_t pageSize;
+
+ /* Local flag. */
+ bool loc;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_sql.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_sql.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_sql.h
new file mode 100644
index 0000000..8d471b6
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_sql.h
@@ -0,0 +1,245 @@
+/*
+* Copyright (C) GridGain Systems. All Rights Reserved.
+* _________ _____ __________________ _____
+* __ ____/___________(_)______ /__ ____/______ ____(_)_______
+* _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+* / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+* \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+*/
+
+#ifndef _GRIDGAIN_CACHE_QUERY_SQL
+#define _GRIDGAIN_CACHE_QUERY_SQL
+
+#include <stdint.h>
+#include <string>
+#include <vector>
+
+#include "gridgain/cache/query/query_argument.h"
+#include "gridgain/portable/portable_raw_writer.h"
+
+namespace gridgain
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /**
+ * Sql query.
+ */
+ class SqlQuery
+ {
+ public:
+ /**
+ * Constructor.
+ *
+ * @param type Type name.
+ * @param sql SQL string.
+ */
+ SqlQuery(std::string type, std::string sql) : type(type), sql(sql), pageSize(1024),
+ loc(false), args(NULL)
+ {
+ // No-op.
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param other Other instance.
+ */
+ SqlQuery(const SqlQuery& other)
+ {
+ type = other.type;
+ sql = other.sql;
+ pageSize = other.pageSize;
+ loc = other.loc;
+
+ if (other.args)
+ {
+ args = new std::vector<QueryArgumentBase*>();
+
+ for (std::vector<QueryArgumentBase*>::iterator it = other.args->begin();
+ it != other.args->end(); ++it)
+ args->push_back((*it)->Copy());
+ }
+ else
+ args = NULL;
+ }
+
+ /**
+ * Assignment operator.
+ *
+ * @param other Other instance.
+ */
+ SqlQuery& operator=(const SqlQuery& other)
+ {
+ if (this != &other)
+ {
+ type = other.type;
+ sql = other.sql;
+ pageSize = other.pageSize;
+ loc = other.loc;
+
+ SqlQuery tmp(other);
+
+ std::vector<QueryArgumentBase*>* args0 = args;
+
+ args = tmp.args;
+
+ tmp.args = args0;
+ }
+
+ return *this;
+ }
+
+ /**
+ * Destructor.
+ */
+ ~SqlQuery()
+ {
+ if (args)
+ {
+ for (std::vector<QueryArgumentBase*>::iterator it = args->begin(); it != args->end(); ++it)
+ delete (*it);
+
+ delete args;
+ }
+ }
+
+ /**
+ * Get type name.
+ *
+ * @return Type name.
+ */
+ std::string GetType()
+ {
+ return type;
+ }
+
+ /**
+ * Set type name.
+ *
+ * @param sql Type name.
+ */
+ void SetType(std::string type)
+ {
+ this->type = type;
+ }
+
+ /**
+ * Get SQL string.
+ *
+ * @return SQL string.
+ */
+ std::string GetSql()
+ {
+ return sql;
+ }
+
+ /**
+ * Set SQL string.
+ *
+ * @param sql SQL string.
+ */
+ void SetSql(std::string sql)
+ {
+ this->sql = sql;
+ }
+
+ /**
+ * Get page size.
+ *
+ * @return Page size.
+ */
+ int32_t GetPageSize()
+ {
+ return pageSize;
+ }
+
+ /**
+ * Set page size.
+ *
+ * @param pageSize Page size.
+ */
+ void SetPageSize(int32_t pageSize)
+ {
+ this->pageSize = pageSize;
+ }
+
+ /**
+ * Get local flag.
+ *
+ * @return Local flag.
+ */
+ bool IsLocal()
+ {
+ return loc;
+ }
+
+ /**
+ * Set local flag.
+ *
+ * @param loc Local flag.
+ */
+ void SetLocal(bool loc)
+ {
+ this->loc = loc;
+ }
+
+ /**
+ * Add argument.
+ *
+ * @param arg Argument.
+ */
+ template<typename T>
+ void AddArgument(const T& arg)
+ {
+ if (!args)
+ args = new std::vector<QueryArgumentBase*>();
+
+ args->push_back(new QueryArgument<T>(arg));
+ }
+
+ /**
+ * Write query info to the stream.
+ *
+ * @param writer Writer.
+ */
+ void Write(portable::PortableRawWriter& writer) const
+ {
+ writer.WriteBool(loc);
+ writer.WriteString(sql);
+ writer.WriteString(type);
+ writer.WriteInt32(pageSize);
+
+ if (args)
+ {
+ writer.WriteInt32(static_cast<int32_t>(args->size()));
+
+ for (std::vector<QueryArgumentBase*>::iterator it = args->begin(); it != args->end(); ++it)
+ (*it)->Write(writer);
+ }
+ else
+ writer.WriteInt32(0);
+ }
+
+ private:
+ /** Type name. */
+ std::string type;
+
+ /** SQL string. */
+ std::string sql;
+
+ /** Page size. */
+ int32_t pageSize;
+
+ /** Local flag. */
+ bool loc;
+
+ /** Arguments. */
+ std::vector<QueryArgumentBase*>* args;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_text.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_text.h b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_text.h
new file mode 100644
index 0000000..15d3cdf
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/cache/query/query_text.h
@@ -0,0 +1,151 @@
+/*
+* Copyright (C) GridGain Systems. All Rights Reserved.
+* _________ _____ __________________ _____
+* __ ____/___________(_)______ /__ ____/______ ____(_)_______
+* _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+* / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+* \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+*/
+
+#ifndef _GRIDGAIN_CACHE_QUERY_TEXT
+#define _GRIDGAIN_CACHE_QUERY_TEXT
+
+#include <stdint.h>
+#include <string>
+
+#include "gridgain/portable/portable_raw_writer.h"
+
+namespace gridgain
+{
+ namespace cache
+ {
+ namespace query
+ {
+ /*
+ * Text query.
+ */
+ class TextQuery
+ {
+ public:
+ /*
+ * Constructor.
+ *
+ * @param type Type name.
+ * @param text Text string.
+ */
+ TextQuery(std::string type, std::string text) : type(type), text(text), pageSize(1024), loc(false)
+ {
+ // No-op.
+ }
+
+ /*
+ * Get type name.
+ *
+ * @return Type name.
+ */
+ std::string GetType()
+ {
+ return type;
+ }
+
+ /*
+ * Set type name.
+ *
+ * @param sql Type name.
+ */
+ void SetType(std::string type)
+ {
+ this->type = type;
+ }
+
+ /*
+ * Get text string.
+ *
+ * @return text string.
+ */
+ std::string GetText()
+ {
+ return text;
+ }
+
+ /*
+ * Set text string.
+ *
+ * @param text Text string.
+ */
+ void SetText(std::string text)
+ {
+ this->text = text;
+ }
+
+ /*
+ * Get page size.
+ *
+ * @return Page size.
+ */
+ int32_t GetPageSize()
+ {
+ return pageSize;
+ }
+
+ /*
+ * Set page size.
+ *
+ * @param pageSize Page size.
+ */
+ void SetPageSize(int32_t pageSize)
+ {
+ this->pageSize = pageSize;
+ }
+
+ /*
+ * Get local flag.
+ *
+ * @return Local flag.
+ */
+ bool IsLocal()
+ {
+ return loc;
+ }
+
+ /*
+ * Set local flag.
+ *
+ * @param loc Local flag.
+ */
+ void SetLocal(bool loc)
+ {
+ this->loc = loc;
+ }
+
+ /*
+ * Write query info to the stream.
+ *
+ * @param writer Writer.
+ */
+ void Write(portable::PortableRawWriter& writer) const
+ {
+ writer.WriteBool(loc);
+ writer.WriteString(text);
+ writer.WriteString(type);
+ writer.WriteInt32(pageSize);
+ }
+
+ private:
+ /* Type name. */
+ std::string type;
+
+ /* Text string. */
+ std::string text;
+
+ /* Page size. */
+ int32_t pageSize;
+
+ /* Local flag. */
+ bool loc;
+ };
+ }
+ }
+}
+
+#endif
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/grid.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/grid.h b/modules/platform/src/main/cpp/core/include/gridgain/grid.h
new file mode 100644
index 0000000..a063406
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/grid.h
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) GridGain Systems. All Rights Reserved.
+ * _________ _____ __________________ _____
+ * __ ____/___________(_)______ /__ ____/______ ____(_)_______
+ * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+ * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+ * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+ */
+
+#ifndef _GRIDGAIN_GRID
+#define _GRIDGAIN_GRID
+
+#include "gridgain/cache/cache.h"
+#include "gridgain/impl/grid_impl.h"
+#include "gridgain/grid_configuration.h"
+
+namespace gridgain
+{
+ /**
+ * Main interface to operate with GridGain.
+ */
+ class IGNITE_IMPORT_EXPORT Grid
+ {
+ public:
+ /**
+ * Default constructor.
+ */
+ Grid();
+
+ /**
+ * Constructor.
+ */
+ Grid(impl::GridImpl* impl);
+
+ /**
+ * Get name of the grid.
+ *
+ * @return Name.
+ */
+ char* GetName();
+
+ /**
+ * Get cache.
+ *
+ * @param name Cache name.
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> GetCache(const char* name)
+ {
+ GridError err;
+
+ cache::Cache<K, V> res = GetCache<K, V>(name, &err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Get cache.
+ *
+ * @param name Cache name.
+ * @param err Error;
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> GetCache(const char* name, GridError* err)
+ {
+ impl::cache::CacheImpl* cacheImpl = impl.Get()->GetCache<K, V>(name, err);
+
+ return cache::Cache<K, V>(cacheImpl);
+ }
+
+ /**
+ * Get or create cache.
+ *
+ * @param name Cache name.
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> GetOrCreateCache(const char* name)
+ {
+ GridError err;
+
+ cache::Cache<K, V> res = GetOrCreateCache<K, V>(name, &err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Get or create cache.
+ *
+ * @param name Cache name.
+ * @param err Error;
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> GetOrCreateCache(const char* name, GridError* err)
+ {
+ impl::cache::CacheImpl* cacheImpl = impl.Get()->GetOrCreateCache<K, V>(name, err);
+
+ return cache::Cache<K, V>(cacheImpl);
+ }
+
+ /**
+ * Create cache.
+ *
+ * @param name Cache name.
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> CreateCache(const char* name)
+ {
+ GridError err;
+
+ cache::Cache<K, V> res = CreateCache<K, V>(name, &err);
+
+ GridError::ThrowIfNeeded(err);
+
+ return res;
+ }
+
+ /**
+ * Create cache.
+ *
+ * @param name Cache name.
+ * @param err Error;
+ * @return Cache.
+ */
+ template<typename K, typename V>
+ cache::Cache<K, V> CreateCache(const char* name, GridError* err)
+ {
+ impl::cache::CacheImpl* cacheImpl = impl.Get()->CreateCache<K, V>(name, err);
+
+ return cache::Cache<K, V>(cacheImpl);
+ }
+ private:
+ /** Implementation delegate. */
+ ignite::common::concurrent::SharedPointer<impl::GridImpl> impl;
+ };
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e18fa32/modules/platform/src/main/cpp/core/include/gridgain/grid_configuration.h
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/cpp/core/include/gridgain/grid_configuration.h b/modules/platform/src/main/cpp/core/include/gridgain/grid_configuration.h
new file mode 100644
index 0000000..a8cd61c
--- /dev/null
+++ b/modules/platform/src/main/cpp/core/include/gridgain/grid_configuration.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) GridGain Systems. All Rights Reserved.
+ * _________ _____ __________________ _____
+ * __ ____/___________(_)______ /__ ____/______ ____(_)_______
+ * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
+ * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
+ * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
+ */
+
+#ifndef _GRIDGAIN_GRID_CONFIGURATION
+#define _GRIDGAIN_GRID_CONFIGURATION
+
+#include <stdint.h>
+
+namespace gridgain
+{
+ /**
+ * Single JVM option.
+ */
+ struct GridJvmOption
+ {
+ /** Option. */
+ char* opt;
+
+ /**
+ * Default constructor.
+ */
+ GridJvmOption() : opt(NULL)
+ {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param opt Option.
+ */
+ GridJvmOption(char* opt) : opt(opt)
+ {
+ // No-op.
+ }
+ };
+
+ /**
+ * Grid configuration.
+ */
+ struct GridConfiguration
+ {
+ /** Path to GridGain home. */
+ char* gridGainHome;
+
+ /** Path to Spring configuration file. */
+ char* springCfgPath;
+
+ /** Path ot JVM libbrary. */
+ char* jvmLibPath;
+
+ /** JVM classpath. */
+ char* jvmClassPath;
+
+ /** Initial amount of JVM memory. */
+ int32_t jvmInitMem;
+
+ /** Maximum amount of JVM memory. */
+ int32_t jvmMaxMem;
+
+ /** Additional JVM options. */
+ GridJvmOption* jvmOpts;
+
+ /** Additional JVM options count. */
+ int32_t jvmOptsLen;
+
+ /**
+ * Constructor.
+ */
+ GridConfiguration() : gridGainHome(NULL), springCfgPath(NULL), jvmLibPath(NULL), jvmClassPath(NULL),
+ jvmInitMem(512), jvmMaxMem(1024), jvmOpts(NULL), jvmOptsLen(0)
+ {
+ // No-op.
+ }
+ };
+}
+
+#endif
\ No newline at end of file