Skip to content

Commit

Permalink
Backport of PR hazelcast#89.
Browse files Browse the repository at this point in the history
Predicates implementation (hazelcast#89)

* Added builtin predicates
* Added and predicate.
* Added missing methods in ObjectDataOutput and ObjectDataInput for read/writeObject and added BetweenPredicate.
* EqualPredicate
* GreaterLessPredicate
* LikePredicate
* InPredicate
* InstanceOfPredicate
* Not and NotEqual
* OrPredicate
* RegExPredicate
* Added Predicate interface, ClientMapTest not compiling due to PagingPredicate.
* PagingPredicate
* Predicate with EntryListener is added.
* Added values with predicate test
* testEntrySetWithPredicateTest and testKeySetWithPredicateTest added
* RawPointerMap API is corrected.
* Changed the DataArray and EntryArray interfaces. Made the PagingPredicate work for primitives.
* Fix for setAnchor
* Update To map test and raw pointer examples
* Added example for builtin predicate queries.
* Added entry listener with different predicates tests.
  • Loading branch information
ihsandemir committed Apr 23, 2016
1 parent f9d375a commit ae83b4c
Show file tree
Hide file tree
Showing 85 changed files with 7,342 additions and 604 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ project (HazelcastClient)
INCLUDE(TestBigEndian)

SET(HZ_VERSION 3.6.2-SNAPSHOT)
add_definitions(-DHAZELCAST_VERSION="${HZ_VERSION}")

execute_process(COMMAND git show -s --format="%cd" --date=short OUTPUT_VARIABLE HAZELCAST_GIT_COMMIT_DATE)
string(STRIP "${HAZELCAST_GIT_COMMIT_DATE}" HAZELCAST_GIT_COMMIT_DATE)
if ("x${HAZELCAST_GIT_COMMIT_DATE}" MATCHES "x")
SET(HAZELCAST_GIT_COMMIT_DATE "NOT_FOUND")
endif()
message(STATUS "HAZELCAST_GIT_COMMIT_DATE = ${HAZELCAST_GIT_COMMIT_DATE}" )
add_definitions(-DHAZELCAST_GIT_COMMIT_DATE="${HAZELCAST_GIT_COMMIT_DATE}")

execute_process(COMMAND git show -s --format="%h" OUTPUT_VARIABLE HAZELCAST_GIT_COMMIT_ID)
string(STRIP "${HAZELCAST_GIT_COMMIT_ID}" HAZELCAST_GIT_COMMIT_ID)
if ("x${HAZELCAST_GIT_COMMIT_ID}" MATCHES "x")
SET(HAZELCAST_GIT_COMMIT_ID "NOT_FOUND")
endif()
message(STATUS "HAZELCAST_GIT_COMMIT_ID = ${HAZELCAST_GIT_COMMIT_ID}" )
add_definitions(-DHAZELCAST_GIT_COMMIT_ID="${HAZELCAST_GIT_COMMIT_ID}")


message(STATUS "Preparing hazelcast client ..... ")

Expand Down Expand Up @@ -132,8 +150,10 @@ IF(${HZ_BUILD_TESTS} MATCHES "ON")
SET(BUILD_GTEST "ON")
SET(BUILD_GMOCK "OFF")
ADD_SUBDIRECTORY(hazelcast/test)
message(STATUS "Configured to build the tests. BUILD_GTEST=${BUILD_GTEST} BUILD_GMOCK=${BUILD_GMOCK}")
ENDIF(${HZ_BUILD_TESTS} MATCHES "ON")

IF(${HZ_BUILD_EXAMPLES} MATCHES "ON")
ADD_SUBDIRECTORY(examples)
message(STATUS "Configured to build the examples.")
ENDIF(${HZ_BUILD_EXAMPLES} MATCHES "ON")
6 changes: 3 additions & 3 deletions examples/adaptor/RawList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ int main() {
std::auto_ptr<hazelcast::client::adaptor::DataArray<std::string> > vals = list.subList(0, 2);
std::cout << "Got sublist between indexes 0 and 2. Size is:" << vals->size() << std::endl;
for (size_t i = 0; i < vals->size(); ++i) {
std::auto_ptr<std::string> val = vals->get(i);
if (NULL == val.get()) {
const std::string *val = vals->get(i);
if (NULL == val) {
std::cout << "Value " << i << " is NULL" << std::endl;
} else {
std::cout << "Value: " << *val << std::endl;
Expand All @@ -60,7 +60,7 @@ int main() {
vals = list.toArray();

for (size_t i = 0; i < vals->size(); ++i) {
std::auto_ptr<std::string> val = vals->get(i);
std::auto_ptr<std::string> val = vals->release(i);
if (NULL == val.get()) {
std::cout << "Value " << i << " is NULL" << std::endl;
} else {
Expand Down
6 changes: 3 additions & 3 deletions examples/adaptor/RawMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ int main() {
std::cout << "There are " << entries->size() << " entries in the map" << std::endl;

for (size_t i = 0; i < entries->size(); ++i) {
std::auto_ptr<std::string> key = entries->getKey(i);
if ((std::string *) NULL == key.get()) {
const std::string * key = entries->getKey(i);
if ((std::string *) NULL == key) {
std::cout << "The key at index " << i << " is NULL" << std::endl;
} else {
std::auto_ptr<std::string> val = entries->getValue(i);
std::auto_ptr<std::string> val = entries->releaseValue(i);
std::cout << "(Key, Value) for index " << i << " is: (" << *key << ", " <<
(val.get() == NULL ? "NULL" : *val) << ")" << std::endl;
}
Expand Down
12 changes: 6 additions & 6 deletions examples/adaptor/RawMultiMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ int main() {
std::cout << "There are " << size << " entries in the multimap" << std::endl;

for (size_t i = 0; i < size; ++i) {
std::auto_ptr<std::string> key = entries->getKey(i);
if ((std::string *) NULL == key.get()) {
const std::string * key = entries->getKey(i);
if ((std::string *) NULL == key) {
std::cout << "The key at index " << i << " is NULL" << std::endl;
} else {
std::auto_ptr<std::string> val = entries->getValue(i);
const std::string *val = entries->getValue(i);
std::cout << "(Key, Value) for index " << i << " is: (" << *key << ", " <<
(val.get() == NULL ? "NULL" : *val) << ")" << std::endl;
(val == NULL ? "NULL" : *val) << ")" << std::endl;
}
}

Expand All @@ -55,8 +55,8 @@ int main() {
size = vals->size();
std::cout << "There are " << vals->size() << " values for key '1' in the multimap. These are:" << std::endl;
for (size_t j = 0; j < size; ++j) {
std::auto_ptr<std::string> val = vals->get(j);
if (NULL == val.get()) {
const std::string *val = vals->get(j);
if (NULL == val) {
std::cout << "NULL" << std::endl;
} else {
std::cout << *val << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions examples/adaptor/RawQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ int main() {
std::cout << "There are " << queue.size() << " values in the queue" << std::endl;

for (size_t i = 0; i < vals->size(); ++i) {
std::auto_ptr<std::string> val = vals->get(i);
if (NULL == val.get()) {
const std::string *val = vals->get(i);
if (NULL == val) {
std::cout << "Value " << i << " is NULL" << std::endl;
} else {
std::cout << "Value: " << *val << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions examples/adaptor/RawSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ int main() {
std::cout << "There are " << set.size() << " values in the set" << std::endl;

for (size_t i = 0; i < vals->size(); ++i) {
std::auto_ptr<std::string> val = (*vals)[i];
if (NULL == val.get()) {
const std::string *val = (*vals)[i];
if (NULL == val) {
std::cout << "Value " << i << " is NULL" << std::endl;
} else {
std::cout << "Value: " << *val << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion examples/distributed-map/criteria-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
add_executable(criteriaapi Predicate.cpp)
add_executable(criteriaapi Predicate.cpp Employee.h Employee.cpp)

119 changes: 119 additions & 0 deletions examples/distributed-map/criteria-api/Employee.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
//
// Created by ihsan demir on 18 Apr 2016.

#include "Employee.h"
#include "hazelcast/client/serialization/PortableWriter.h"
#include "hazelcast/client/serialization/PortableReader.h"

namespace hazelcast {
namespace client {
namespace examples {
namespace criteriaapi {
Employee::Employee():age(-1), name("") {

}

Employee::Employee(std::string name, int age)
:age(age)
, name(name) {

}

bool Employee::operator==(const Employee &rhs) const {
return age == rhs.getAge() && name == rhs.getName();
}

bool Employee::operator !=(const Employee &employee) const {
return !(*this == employee);
}

int Employee::getFactoryId() const {
return 666;
}

int Employee::getClassId() const {
return 2;
}

void Employee::writePortable(serialization::PortableWriter &writer) const {
writer.writeUTF("n", &name);
writer.writeInt("a", age);
}

void Employee::readPortable(serialization::PortableReader &reader) {
name = *reader.readUTF("n");
age = reader.readInt("a");
}

int Employee::getAge() const {
return age;
}

const std::string &Employee::getName() const {
return name;
}

bool Employee::operator<(const Employee &rhs) const {
return age < rhs.getAge();
}

int EmployeeEntryComparator::getFactoryId() const {
return 666;
}

int EmployeeEntryComparator::getClassId() const {
return 4;
}

void EmployeeEntryComparator::writeData(serialization::ObjectDataOutput &writer) const {
}

void EmployeeEntryComparator::readData(serialization::ObjectDataInput &reader) {
}

int EmployeeEntryComparator::compare(const std::pair<const int *, const Employee *> &lhs,
const std::pair<const int *, const Employee *> &rhs) const {
const Employee *lv = lhs.second;
const Employee *rv = rhs.second;

if (NULL == lv) {
return -1;
}

if (NULL == rv) {
return 1;
}

int la = lv->getAge();
int ra = rv->getAge();

if (la == ra) {
return 0;
}

if (la < ra) {
return -1;
}

return 1;
}
}
}
}
}

82 changes: 82 additions & 0 deletions examples/distributed-map/criteria-api/Employee.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
//
// Created by ihsan demir on 18 Apr 2016.

#ifndef HAZELCAST_Employee
#define HAZELCAST_Employee

#include <string>
#include "hazelcast/client/serialization/Portable.h"
#include "hazelcast/util/Comparator.h"
#include "hazelcast/client/serialization/IdentifiedDataSerializable.h"
#include "hazelcast/client/query/EntryComparator.h"

namespace hazelcast {
namespace client {
namespace examples {
namespace criteriaapi {
class Employee : public serialization::Portable {
public:
Employee();

Employee(std::string name, int age);

bool operator==(const Employee &employee) const;

bool operator!=(const Employee &employee) const;

int getFactoryId() const;

int getClassId() const;

void writePortable(serialization::PortableWriter &writer) const;

void readPortable(serialization::PortableReader &reader);

int getAge() const;

const std::string &getName() const;

bool operator<(const Employee &rhs) const;
private:
int age;
std::string name;
};

// Compares based on the employee age
class EmployeeEntryComparator
: public query::EntryComparator<int, Employee> {

public:
int getFactoryId() const;

int getClassId() const;

void writeData(serialization::ObjectDataOutput &writer) const;

void readData(serialization::ObjectDataInput &reader);

int compare(const std::pair<const int *, const Employee *> &lhs,
const std::pair<const int *, const Employee *> &rhs) const;
};
}
}
}
}

#endif //HAZELCAST_Employee

Loading

0 comments on commit ae83b4c

Please sign in to comment.