http://git-wip-us.apache.org/repos/asf/ignite/blob/0d70d547/modules/platform/src/main/cpp/core/include/gridgain/portable/portable_type.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/gridgain/portable/portable_type.h b/modules/platform/src/main/cpp/core/include/gridgain/portable/portable_type.h deleted file mode 100644 index c5c1cdb..0000000 --- a/modules/platform/src/main/cpp/core/include/gridgain/portable/portable_type.h +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _IGNITE_PORTABLE_TYPE -#define _IGNITE_PORTABLE_TYPE - -#include <stdint.h> - -#include <ignite/common/common.h> - -#include "gridgain/grid_error.h" - -/** - * Start portable type definition. - */ -#define IGNITE_PORTABLE_TYPE_START(T) \ -template<> \ -struct PortableType<T> \ -{ - -/** - * End portable type definition. - */ -#define IGNITE_PORTABLE_TYPE_END \ -}; - -/** - * Implementation of GetTypeId() which returns predefined constant. - */ -#define IGNITE_PORTABLE_GET_TYPE_ID_AS_CONST(id) \ -int32_t GetTypeId() \ -{ \ - return id; \ -} - -/** - * Implementation of GetTypeId() which returns hash of passed type name. - */ -#define IGNITE_PORTABLE_GET_TYPE_ID_AS_HASH(typeName) \ -int32_t GetTypeId() \ -{ \ - return GetPortableStringHashCode(#typeName); \ -} - -/** - * Implementation of GetTypeName() which returns type name as is. - */ -#define IGNITE_PORTABLE_GET_TYPE_NAME_AS_IS(typeName) \ -std::string GetTypeName() \ -{ \ - return #typeName; \ -} - -/** - * Default implementation of GetFieldId() function which returns Java-way hash code of the string. - */ -#define IGNITE_PORTABLE_GET_FIELD_ID_AS_HASH \ -int32_t GetFieldId(const char* name) \ -{ \ - return GetPortableStringHashCode(name); \ -} - -/** - * Implementation of GetHashCode() function which always returns 0. - */ -#define IGNITE_PORTABLE_GET_HASH_CODE_ZERO(T) \ -int32_t GetHashCode(const T& obj) \ -{ \ - return 0; \ -} - -/** - * Implementation of IsNull() function which always returns false. - */ -#define IGNITE_PORTABLE_IS_NULL_FALSE(T) \ -bool IsNull(const T& obj) \ -{ \ - return false; \ -} - -/** - * Implementation of IsNull() function which return true if passed object is null pointer. - */ -#define IGNITE_PORTABLE_IS_NULL_IF_NULLPTR(T) \ -bool IsNull(const T& obj) \ -{ \ - return obj; \ -} - -/** - * Implementation of GetNull() function which returns an instance created with defult constructor. - */ -#define IGNITE_PORTABLE_GET_NULL_DEFAULT_CTOR(T) \ -T GetNull() \ -{ \ - return T(); \ -} - -/** - * Implementation of GetNull() function which returns NULL pointer. - */ -#define IGNITE_PORTABLE_GET_NULL_NULLPTR(T) \ -T GetNull() \ -{ \ - return NULL; \ -} - -namespace ignite -{ - namespace portable - { - class PortableWriter; - class PortableReader; - - /** - * Get portable string hash code. - * - * @param val Value. - * @return Hash code. - */ - IGNITE_IMPORT_EXPORT int32_t GetPortableStringHashCode(const char* val); - - /** - * Portable type structure. Defines a set of functions required for type to be serialized and deserialized. - */ - template<typename T> - struct IGNITE_IMPORT_EXPORT PortableType - { - /** - * Get portable object type ID. - * - * @return Type ID. - */ - int32_t GetTypeId() - { - IGNITE_ERROR_1(GridError::IGNITE_ERR_PORTABLE, "GetTypeId function is not defined for portable type."); - } - - /** - * Get portable object type name. - * - * @return Type name. - */ - std::string GetTypeName() - { - IGNITE_ERROR_1(GridError::IGNITE_ERR_PORTABLE, "GetTypeName function is not defined for portable type."); - } - - /** - * Get portable object field ID. - * - * @param name Field name. - * @return Field ID. - */ - int32_t GetFieldId(const char* name) - { - return GetPortableStringHashCode(name); - } - - /** - * Get portable object hash code. - * - * @param obj Portable object. - * @return Hash code. - */ - int32_t GetHashCode(const T& obj) - { - return 0; - } - - /** - * Write portable object. - * - * @param writer Writer. - * @param obj Object. - */ - void Write(PortableWriter& writer, const T& obj) - { - IGNITE_ERROR_1(GridError::IGNITE_ERR_PORTABLE, "Write function is not defined for portable type."); - } - - /** - * Read portable object. - * - * @param reader Reader. - * @return Object. - */ - T Read(PortableReader& reader) - { - IGNITE_ERROR_1(GridError::IGNITE_ERR_PORTABLE, "Read function is not defined for portable type."); - } - - /** - * Check whether passed portable object should be interpreted as NULL. - * - * @param obj Portable object to test. - * @return True if portable object should be interpreted as NULL. - */ - bool IsNull(const T& obj) - { - return false; - } - - /** - * Get NULL value for the given portable type. - * - * @return NULL value. - */ - T GetNull() - { - IGNITE_ERROR_1(GridError::IGNITE_ERR_PORTABLE, "GetNull function is not defined for portable type."); - } - }; - - /* - * Templated portable type for pointers. - */ - template <typename T> - struct IGNITE_IMPORT_EXPORT PortableType<T*> - { - /** Actual type. */ - PortableType<T> typ; - - /** - * Constructor. - */ - PortableType() - { - typ = PortableType<T>(); - } - - int32_t GetTypeId() - { - return typ.GetTypeId(); - } - - std::string GetTypeName() - { - return typ.GetTypeName(); - } - - int32_t GetFieldId(const char* name) - { - return typ.GetFieldId(name); - } - - int32_t GetHashCode(T* const& obj) - { - return typ.GetHashCode(*obj); - } - - void Write(PortableWriter& writer, T* const& obj) - { - typ.Write(writer, *obj); - } - - T* Read(PortableReader& reader) - { - T* res = new T(); - - *res = typ.Read(reader); - - return res; - } - - bool IsNull(T* const& obj) - { - return !obj || typ.IsNull(*obj); - } - - T* GetNull() - { - return NULL; - } - }; - } -} - -#endif
http://git-wip-us.apache.org/repos/asf/ignite/blob/0d70d547/modules/platform/src/main/cpp/core/include/gridgain/portable/portable_writer.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/gridgain/portable/portable_writer.h b/modules/platform/src/main/cpp/core/include/gridgain/portable/portable_writer.h deleted file mode 100644 index 9d3a281..0000000 --- a/modules/platform/src/main/cpp/core/include/gridgain/portable/portable_writer.h +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _IGNITE_PORTABLE_WRITER -#define _IGNITE_PORTABLE_WRITER - -#include <string> -#include <stdint.h> - -#include <ignite/common/common.h> - -#include "gridgain/portable/portable_raw_writer.h" - -namespace ignite -{ - namespace portable - { - /** - * Portable writer. - */ - class IGNITE_IMPORT_EXPORT PortableWriter - { - public: - /** - * Constructor. - * - * @param impl Implementation. - */ - PortableWriter(ignite::impl::portable::PortableWriterImpl* impl); - - /** - * Write 8-byte signed integer. Maps to "byte" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteInt8(const char* fieldName, const int8_t val); - - /** - * Write array of 8-byte signed integers. Maps to "byte[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteInt8Array(const char* fieldName, const int8_t* val, const int32_t len); - - /** - * Write bool. Maps to "short" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteBool(const char* fieldName, const bool val); - - /** - * Write array of bools. Maps to "bool[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteBoolArray(const char* fieldName, const bool* val, const int32_t len); - - /** - * Write 16-byte signed integer. Maps to "short" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteInt16(const char* fieldName, const int16_t val); - - /** - * Write array of 16-byte signed integers. Maps to "short[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteInt16Array(const char* fieldName, const int16_t* val, const int32_t len); - - /** - * Write 16-byte unsigned integer. Maps to "char" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteUInt16(const char* fieldName, const uint16_t val); - - /** - * Write array of 16-byte unsigned integers. Maps to "char[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteUInt16Array(const char* fieldName, const uint16_t* val, const int32_t len); - - /** - * Write 32-byte signed integer. Maps to "int" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteInt32(const char* fieldName, const int32_t val); - - /** - * Write array of 32-byte signed integers. Maps to "int[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteInt32Array(const char* fieldName, const int32_t* val, const int32_t len); - - /** - * Write 64-byte signed integer. Maps to "long" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteInt64(const char* fieldName, const int64_t val); - - /** - * Write array of 64-byte signed integers. Maps to "long[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteInt64Array(const char* fieldName, const int64_t* val, const int32_t len); - - /** - * Write float. Maps to "float" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteFloat(const char* fieldName, const float val); - - /** - * Write array of floats. Maps to "float[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteFloatArray(const char* fieldName, const float* val, const int32_t len); - - /** - * Write double. Maps to "double" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteDouble(const char* fieldName, const double val); - - /** - * Write array of doubles. Maps to "double[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteDoubleArray(const char* fieldName, const double* val, const int32_t len); - - /** - * Write Guid. Maps to "UUID" type in Java. - * - * @param fieldName Field name. - * @param val Value. - */ - void WriteGuid(const char* fieldName, const Guid val); - - /** - * Write array of Guids. Maps to "UUID[]" type in Java. - * - * @param fieldName Field name. - * @param val Array. - * @param len Array length. - */ - void WriteGuidArray(const char* fieldName, const Guid* val, const int32_t len); - - /** - * Write string. - * - * @param fieldName Field name. - * @param val Null-terminated character sequence. - */ - void WriteString(const char* fieldName, const char* val); - - /** - * Write string. - * - * @param fieldName Field name. - * @param val String. - * @param len String length (characters). - */ - void WriteString(const char* fieldName, const char* val, const int32_t len); - - /** - * Write string. - * - * @param fieldName Field name. - * @param val String. - */ - void WriteString(const char* fieldName, const std::string& val) - { - WriteString(fieldName, val.c_str()); - } - - /** - * Start string array write. - * - * @param fieldName Field name. - * @return String array writer. - */ - PortableStringArrayWriter WriteStringArray(const char* fieldName); - - /** - * Write NULL value. - * - * @param fieldName Field name. - */ - void WriteNull(const char* fieldName); - - /** - * Start array write. - * - * @param fieldName Field name. - * @return Array writer. - */ - template<typename T> - PortableArrayWriter<T> WriteArray(const char* fieldName) - { - int32_t id = impl->WriteArray(fieldName); - - return PortableArrayWriter<T>(impl, id); - } - - /** - * Start collection write. - * - * @param fieldName Field name. - * @return Collection writer. - */ - template<typename T> - PortableCollectionWriter<T> WriteCollection(const char* fieldName) - { - return WriteCollection<T>(fieldName, IGNITE_COLLECTION_UNDEFINED); - } - - /** - * Start collection write. - * - * @param fieldName Field name. - * @param type Collection type. - * @return Collection writer. - */ - template<typename T> - PortableCollectionWriter<T> WriteCollection(const char* fieldName, ignite::portable::CollectionType typ) - { - int32_t id = impl->WriteCollection(fieldName, typ); - - return PortableCollectionWriter<T>(impl, id); - } - - /** - * Start map write. - * - * @param fieldName Field name. - * @param typ Map type. - * @return Map writer. - */ - template<typename K, typename V> - PortableMapWriter<K, V> WriteMap(const char* fieldName) - { - return WriteMap<K, V>(fieldName, IGNITE_MAP_UNDEFINED); - } - - /** - * Start map write. - * - * @param fieldName Field name. - * @param typ Map type. - * @return Map writer. - */ - template<typename K, typename V> - PortableMapWriter<K, V> WriteMap(const char* fieldName, ignite::portable::MapType typ) - { - int32_t id = impl->WriteMap(fieldName, typ); - - return PortableMapWriter<K, V>(impl, id); - } - - /** - * Write object. - * - * @param fieldName Field name. - * @param val Value. - */ - template<typename T> - void WriteObject(const char* fieldName, T val) - { - impl->WriteObject<T>(fieldName, val); - } - - /** - * Get raw writer for this reader. - * - * @return Raw writer. - */ - PortableRawWriter RawWriter(); - private: - /** Implementation delegate. */ - ignite::impl::portable::PortableWriterImpl* impl; - }; - } -} - -#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/0d70d547/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h new file mode 100644 index 0000000..628caa8 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache.h @@ -0,0 +1,1153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_CACHE +#define _IGNITE_CACHE + +#include <map> +#include <set> + +#include <ignite/common/common.h> +#include <ignite/common/concurrent.h> + +#include "ignite/cache/cache_peek_mode.h" +#include "ignite/cache/query/query_cursor.h" +#include "ignite/cache/query/query_scan.h" +#include "ignite/cache/query/query_sql.h" +#include "ignite/cache/query/query_text.h" +#include "ignite/impl/cache/cache_impl.h" +#include "ignite/impl/operations.h" +#include "ignite/grid_error.h" + +namespace ignite +{ + 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(IGNITE_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(IGNITE_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(IGNITE_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(IGNITE_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(ignite::cache::IGNITE_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(ignite::cache::IGNITE_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/0d70d547/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h new file mode 100644 index 0000000..2b6c785 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_entry.h @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_CACHE_ENTRY +#define _IGNITE_CACHE_ENTRY + +#include <ignite/common/common.h> + +namespace ignite +{ + 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/0d70d547/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h new file mode 100644 index 0000000..be61887 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/cache_peek_mode.h @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_CACHE_PEEK_MODE +#define _IGNITE_CACHE_PEEK_MODE + +namespace ignite +{ + namespace cache + { + /** + * Enumeration of all supported cache peek modes. + */ + enum CachePeekMode + { + /** + * Peeks into all available cache storages. + */ + IGNITE_PEEK_MODE_ALL = 0x01, + + /** + * Peek into near cache only (don't peek into partitioned cache). + * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode. + */ + IGNITE_PEEK_MODE_NEAR = 0x02, + + /** + * Peek value from primary copy of partitioned cache only (skip near cache). + * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode. + */ + IGNITE_PEEK_MODE_PRIMARY = 0x04, + + /** + * Peek value from backup copies of partitioned cache only (skip near cache). + * In case of LOCAL cache, behaves as IGNITE_PEEK_MODE_ALL mode. + */ + IGNITE_PEEK_MODE_BACKUP = 0x08, + + /** + * Peeks value from the on-heap storage only. + */ + IGNITE_PEEK_MODE_ONHEAP = 0x10, + + /** + * Peeks value from the off-heap storage only, without loading off-heap value into cache. + */ + IGNITE_PEEK_MODE_OFFHEAP = 0x20, + + /** + * Peeks value from the swap storage only, without loading swapped value into cache. + */ + IGNITE_PEEK_MODE_SWAP = 0x40 + }; + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/0d70d547/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h new file mode 100644 index 0000000..f2d19cd --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query.h @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_QUERY +#define _IGNITE_QUERY + +#include "ignite/cache/query/query_argument.h" +#include "ignite/cache/query/query_cursor.h" +#include "ignite/cache/query/query_scan.h" +#include "ignite/cache/query/query_sql.h" +#include "ignite/cache/query/query_text.h" + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/0d70d547/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h new file mode 100644 index 0000000..0f41c56 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_argument.h @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_CACHE_QUERY_ARGUMENT +#define _IGNITE_CACHE_QUERY_ARGUMENT + +#include "ignite/portable/portable_raw_writer.h" + +namespace ignite +{ + 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(ignite::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(ignite::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/0d70d547/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_cursor.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_cursor.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_cursor.h new file mode 100644 index 0000000..7860676 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_cursor.h @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_CACHE_QUERY_CURSOR +#define _IGNITE_CACHE_QUERY_CURSOR + +#include <vector> + +#include <ignite/common/concurrent.h> + +#include "ignite/cache/cache_entry.h" +#include "ignite/grid_error.h" +#include "ignite/impl/cache/query/query_impl.h" +#include "ignite/impl/operations.h" + +namespace ignite +{ + 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::IGNITE_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::IGNITE_SUCCESS) + { + K& key = outOp.Get1(); + V& val = outOp.Get2(); + + return CacheEntry<K, V>(key, val); + } + else + return CacheEntry<K, V>(); + } + else + { + err = GridError(GridError::IGNITE_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::IGNITE_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/0d70d547/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_scan.h ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_scan.h b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_scan.h new file mode 100644 index 0000000..c3ec845 --- /dev/null +++ b/modules/platform/src/main/cpp/core/include/ignite/cache/query/query_scan.h @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_CACHE_QUERY_SCAN +#define _IGNITE_CACHE_QUERY_SCAN + +#include <stdint.h> +#include <string> + +#include "ignite/portable/portable_raw_writer.h" + +namespace ignite +{ + 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
