16 #ifndef HAZELCAST_CLIENT_QUERY_PAGINGPREDICATE_H_ 
   17 #define HAZELCAST_CLIENT_QUERY_PAGINGPREDICATE_H_ 
   22 #include "hazelcast/client/exception/IllegalStateException.h" 
   23 #include "hazelcast/client/exception/IllegalArgumentException.h" 
   24 #include "hazelcast/util/Util.h" 
   25 #include "hazelcast/util/Comparator.h" 
   26 #include "hazelcast/client/query/Predicate.h" 
   27 #include "hazelcast/client/serialization/ObjectDataOutput.h" 
   28 #include "hazelcast/client/serialization/ObjectDataInput.h" 
   29 #include "hazelcast/client/exception/IException.h" 
   30 #include "hazelcast/client/query/impl/predicates/PredicateDataSerializerHook.h" 
   31 #include "hazelcast/client/query/EntryComparator.h" 
   33 #if  defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 
   35 #pragma warning(disable: 4251) //for dll export 
   45             enum HAZELCAST_API IterationType {
 
   60             template<
typename K, 
typename V>
 
   63                 int compare(
const std::pair<const K *, const V *> &lhs, 
const std::pair<const K *, const V *> &rhs)
 const {
 
   87             static const std::string IterationNames[] = {
"KEY", 
"VALUE", 
"ENTRY"};
 
  126             template<
typename K, 
typename V>
 
  137                 PagingPredicate(
size_t predicatePageSize) : pageSize(predicatePageSize), page(0),iterationType(VALUE) {
 
  150                 PagingPredicate(std::auto_ptr<Predicate> predicate, 
size_t predicatePageSize) : innerPredicate(predicate),
 
  151                                                                                              pageSize(predicatePageSize),
 
  153                                                                                              iterationType(VALUE) {
 
  166                         comparatorObj), pageSize(predicatePageSize), page(0), iterationType(VALUE) {
 
  181                                 size_t predicatePageSize) : innerPredicate(predicate), comparator(comparatorObj),
 
  182                                                          pageSize(predicatePageSize), page(0), iterationType(VALUE) {
 
  187                     for (
typename std::vector<std::pair<
size_t, std::pair<K *, V *> > >::const_iterator it = anchorList.begin();
 
  188                          it != anchorList.end(); ++it) {
 
  189                         delete it->second.first;
 
  190                         delete it->second.second;
 
  198                     iterationType = VALUE;
 
  199                     for (
typename std::vector<std::pair<
size_t, std::pair<K *, V *> > >::const_iterator it = anchorList.begin();
 
  200                          it != anchorList.end(); ++it) {
 
  201                         delete it->second.first;
 
  202                         delete it->second.second;
 
  224                 IterationType getIterationType()
 const {
 
  225                     return iterationType;
 
  228                 void setIterationType(IterationType type) {
 
  229                     iterationType = type;
 
  232                 size_t getPage()
 const {
 
  236                 void setPage(
size_t pageNumber) {
 
  240                 size_t getPageSize()
 const {
 
  244                 const Predicate *getPredicate()
 const {
 
  245                     return innerPredicate.get();
 
  248                 const query::EntryComparator<K, V> *getComparator()
 const {
 
  249                     return comparator.get();
 
  261                     if (0 == anchorList.size()) {
 
  262                         return (
const std::pair<K *, V *> *)NULL;
 
  265                     return &anchorList[page].second;
 
  278                     size_t anchorCount = anchorList.size();
 
  280                     if (page == 0 || anchorCount == 0) {
 
  281                         return (
const std::pair<
size_t, std::pair<K *, V *> > *) NULL;
 
  284                     if (page < anchorCount) {
 
  285                         return &anchorList[page - 1];
 
  287                         return &anchorList[anchorCount - 1];
 
  295                     return impl::predicates::F_ID;
 
  302                     return impl::predicates::PAGING_PREDICATE;
 
  314                     out.
writeUTF(&IterationNames[iterationType]);
 
  315                     out.
writeInt((
int) anchorList.size());
 
  316                     for (
typename std::vector<std::pair<
size_t, std::pair<K *, V *> > >::const_iterator it = anchorList.begin();
 
  317                          it != anchorList.end(); ++it) {
 
  331                                                 "Client should not need to use readData method!!!");
 
  334                 void setAnchor(
size_t page, 
const std::pair<K *, V *> &anchorEntry) {
 
  335                     size_t anchorCount = anchorList.size();
 
  336                     if (page < anchorCount) {
 
  338                         delete anchorList[page].second.first;
 
  339                         delete anchorList[page].second.second;
 
  340                         anchorList[page] = std::pair<size_t, std::pair<K *, V *> >(page, anchorEntry);
 
  341                     } 
else if (page == anchorCount) {
 
  342                         anchorList.push_back(std::pair<
size_t, std::pair<K *, V *> >(page, anchorEntry));
 
  345                         util::snprintf(msg, 200, 
"Anchor index is not correct, expected: %d but found: %d", page,
 
  347                         throw exception::IllegalArgumentException(
"PagingPredicate::setAnchor", msg);
 
  352                 std::auto_ptr<Predicate> innerPredicate;
 
  354                 std::vector<std::pair<size_t, std::pair<K *, V *> > > anchorList;
 
  355                 std::auto_ptr<query::EntryComparator<K, V> > comparator;
 
  358                 IterationType iterationType;
 
  364 #if  defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 
int getFactoryId() const 
Definition: PagingPredicate.h:294
 
PagingPredicate(std::auto_ptr< query::EntryComparator< K, V > > comparatorObj, size_t predicatePageSize)
Construct with a comparator and pageSize results will not be filtered results will be ordered via com...
Definition: PagingPredicate.h:165
 
Base class for all exception originated from Hazelcast methods. 
Definition: IException.h:49
 
void writeData(serialization::ObjectDataOutput &out) const 
Defines how this class will be written. 
Definition: PagingPredicate.h:309
 
Definition: PagingPredicate.h:61
 
void writeObject(const Portable *object)
Definition: ObjectDataOutput.h:181
 
void previousPage()
sets the page value to previous page 
Definition: PagingPredicate.h:218
 
void writeData(serialization::ObjectDataOutput &writer) const 
Defines how this class will be written. 
Definition: PagingPredicate.h:78
 
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables. 
Definition: ObjectDataOutput.h:51
 
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:42
 
NOTE: PagingPredicate can only be used with values(), keySet() and entries() methods!!! ...
Definition: PagingPredicate.h:127
 
void readData(serialization::ObjectDataInput &reader)
Defines how this class will be read. 
Definition: PagingPredicate.h:82
 
PagingPredicate(std::auto_ptr< Predicate > predicate, std::auto_ptr< query::EntryComparator< K, V > > comparatorObj, size_t predicatePageSize)
Construct with an inner predicate, comparator and pageSize results will be filtered via inner predica...
Definition: PagingPredicate.h:180
 
int getFactoryId() const 
Definition: PagingPredicate.h:68
 
int getClassId() const 
Definition: PagingPredicate.h:73
 
void readData(serialization::ObjectDataInput &in)
Defines how this class will be read. 
Definition: PagingPredicate.h:328
 
const std::pair< size_t, std::pair< K *, V * > > * getNearestAnchorEntry()
After each query, an anchor entry is set for that page. 
Definition: PagingPredicate.h:277
 
const std::pair< K *, V * > * getAnchor() const 
Retrieve the anchor object which is the last value object on the previous page. 
Definition: PagingPredicate.h:260
 
PagingPredicate(std::auto_ptr< Predicate > predicate, size_t predicatePageSize)
Construct with an inner predicate and pageSize results will be filtered via inner predicate results w...
Definition: PagingPredicate.h:150
 
This is a merker class for Predicate classes. 
Definition: Predicate.h:36
 
void nextPage()
sets the page value to next page 
Definition: PagingPredicate.h:211
 
int getClassId() const 
Definition: PagingPredicate.h:301
 
void writeUTF(const std::string *value)
Definition: ObjectDataOutput.cpp:95
 
void writeInt(int32_t value)
Definition: ObjectDataOutput.cpp:75
 
PagingPredicate(size_t predicatePageSize)
Construct with a pageSize results will not be filtered results will be natural ordered throws Illegal...
Definition: PagingPredicate.h:137
 
Definition: EntryComparator.h:31
 
void reset()
resets for reuse 
Definition: PagingPredicate.h:197