diff --git a/modules/platforms/cpp/examples/README.txt b/modules/platforms/cpp/examples/README.txt deleted file mode 100644 index 5406ea8..0000000 --- a/modules/platforms/cpp/examples/README.txt +++ /dev/null @@ -1,45 +0,0 @@ -Apache Ignite C++ Examples -================================== - -Common requirements ----------------------------------- - * Java Development Kit (JDK) must be installed: https://java.com/en/download/index.jsp - * JAVA_HOME environment variable must be set pointing to Java installation directory. - * IGNITE_HOME environment variable must be set to Ignite installation directory. - * Ignite must be build and packaged using Maven. You can use the followin Maven command: mvn clean package -DskipTests - * Apache Ignite C++ must be built according to instructions for your platform. - -Running examples on Linux ----------------------------------- - -Prerequisites: - * GCC, g++, autotools, automake, and libtool must be installed. - -To build any example execute the following commands one by one from example root directory. -(e.g. to build putget-example you should run these commands from the -$IGNITE_HOME/platforms/cpp/examples/putget-example directory): - * libtoolize - * aclocal - * autoheader - * automake --add-missing - * autoreconf - * ./configure - * make - -As a result executable will appear in example's directory. - -Before running examples ensure that: - * LD_LIBRARY_PATH environment variable is set and pointing to a directory with "libjvm.so" library. Typically this - library is located in $JAVA_HOME/jre/lib/amd64/server directory. - * For odbc-example additionaly ODBC Driver Manager must be present and installed on your platform and - Apache Ignite ODBC driver must be built and installed according to instructions for your platform. - -Running examples on Windows ----------------------------------- - -Prerequisites: - * Microsoft Visual Studio (tm) 2010 or higher must be installed. - * Windows SDK 7.1 must be installed. - -Open Visual Studio solution %IGNITE_HOME%\platforms\cpp\examples\project\vs\ignite-examples.sln and select proper -platform (x64 or x86). Run the solution. \ No newline at end of file diff --git a/modules/platforms/cpp/examples/include/ignite/examples/account.h b/modules/platforms/cpp/examples/include/ignite/examples/account.h new file mode 100644 index 0000000..2cb5679 --- /dev/null +++ b/modules/platforms/cpp/examples/include/ignite/examples/account.h @@ -0,0 +1,97 @@ +/* + * 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_EXAMPLES_ACCOUNT +#define _IGNITE_EXAMPLES_ACCOUNT + +#include + +#include "ignite/ignite.h" +#include "ignite/ignition.h" + +#include "ignite/examples/client.h" + +namespace ignite +{ + namespace examples + { + struct Account + { + Account() : accountId(0), clientId(0), balance(0.0) + { + // No-op. + } + + Account(int64_t accountId, int64_t clientId, double balance) : + accountId(accountId), + clientId(clientId), + balance(balance) + { + // No-op. + } + + Account(int64_t accountId, const Client& client, double balance) : + accountId(accountId), + clientId(client.clientId), + balance(balance) + { + // No-op. + } + + int64_t accountId; + int64_t clientId; + double balance; + }; + } +} + +namespace ignite +{ + namespace binary + { + IGNITE_BINARY_TYPE_START(ignite::examples::Account) + + typedef ignite::examples::Account Account; + + IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Account) + IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Account) + IGNITE_BINARY_GET_FIELD_ID_AS_HASH + IGNITE_BINARY_GET_HASH_CODE_ZERO(Account) + IGNITE_BINARY_IS_NULL_FALSE(Account) + IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Account) + + void Write(BinaryWriter& writer, Account obj) + { + writer.WriteInt64("accountId", obj.accountId); + writer.WriteInt64("clientId", obj.clientId); + writer.WriteDouble("balance", obj.balance); + } + + Account Read(BinaryReader& reader) + { + int64_t accountId = reader.ReadInt64("accountId"); + int64_t clientId = reader.ReadInt64("clientId"); + double balance = reader.ReadDouble("balance"); + + return Account(accountId, clientId, balance); + } + + IGNITE_BINARY_TYPE_END + } +}; + +#endif // _IGNITE_EXAMPLES_ACCOUNT \ No newline at end of file diff --git a/modules/platforms/cpp/examples/include/ignite/examples/city.h b/modules/platforms/cpp/examples/include/ignite/examples/city.h new file mode 100644 index 0000000..9652226 --- /dev/null +++ b/modules/platforms/cpp/examples/include/ignite/examples/city.h @@ -0,0 +1,87 @@ +/* + * 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_EXAMPLES_CITY +#define _IGNITE_EXAMPLES_CITY + +#include + +#include "ignite/ignite.h" +#include "ignite/ignition.h" + +namespace ignite +{ + namespace examples + { + struct City + { + City() : cityId(0), population(0) + { + // No-op. + } + + City(int64_t cityId, const std::string& cityName, int32_t population) : + cityId(cityId), + cityName(cityName), + population(population) + { + // No-op. + } + + int64_t cityId; + std::string cityName; + int32_t population; + }; + } +} + +namespace ignite +{ + namespace binary + { + IGNITE_BINARY_TYPE_START(ignite::examples::City) + + typedef ignite::examples::City City; + + IGNITE_BINARY_GET_TYPE_ID_AS_HASH(City) + IGNITE_BINARY_GET_TYPE_NAME_AS_IS(City) + IGNITE_BINARY_GET_FIELD_ID_AS_HASH + IGNITE_BINARY_GET_HASH_CODE_ZERO(City) + IGNITE_BINARY_IS_NULL_FALSE(City) + IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(City) + + void Write(BinaryWriter& writer, City obj) + { + writer.WriteInt64("cityId", obj.cityId); + writer.WriteString("cityName", obj.cityName); + writer.WriteInt32("population", obj.population); + } + + City Read(BinaryReader& reader) + { + int64_t cityId = reader.ReadInt64("cityId"); + std::string cityName = reader.ReadString("cityName"); + int32_t population = reader.ReadInt32("population"); + + return City(cityId, cityName, population); + } + + IGNITE_BINARY_TYPE_END + } +}; + +#endif // _IGNITE_EXAMPLES_CITY \ No newline at end of file diff --git a/modules/platforms/cpp/examples/include/ignite/examples/client.h b/modules/platforms/cpp/examples/include/ignite/examples/client.h new file mode 100644 index 0000000..8ffdd53 --- /dev/null +++ b/modules/platforms/cpp/examples/include/ignite/examples/client.h @@ -0,0 +1,104 @@ +/* + * 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_EXAMPLES_CLIENT +#define _IGNITE_EXAMPLES_CLIENT + +#include + +#include "ignite/ignite.h" +#include "ignite/ignition.h" + +#include "ignite/examples/city.h" + +namespace ignite +{ + namespace examples + { + struct Client + { + Client() : clientId(0), cityId(0) + { + // No-op. + } + + Client(int64_t clientId, int64_t cityId, const std::string& firstName, + const std::string& lastName) : + clientId(clientId), + cityId(cityId), + firstName(firstName), + lastName(lastName) + { + // No-op. + } + + Client(int64_t clientId, const City& city, const std::string& firstName, + const std::string& lastName) : + clientId(clientId), + cityId(city.cityId), + firstName(firstName), + lastName(lastName) + { + // No-op. + } + + int64_t clientId; + int64_t cityId; + std::string firstName; + std::string lastName; + }; + } +} + +namespace ignite +{ + namespace binary + { + IGNITE_BINARY_TYPE_START(ignite::examples::Client) + + typedef ignite::examples::Client Client; + + IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Client) + IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Client) + IGNITE_BINARY_GET_FIELD_ID_AS_HASH + IGNITE_BINARY_GET_HASH_CODE_ZERO(Client) + IGNITE_BINARY_IS_NULL_FALSE(Client) + IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Client) + + void Write(BinaryWriter& writer, Client obj) + { + writer.WriteInt64("clientId", obj.clientId); + writer.WriteInt64("cityId", obj.cityId); + writer.WriteString("firstName", obj.firstName); + writer.WriteString("lastName", obj.lastName); + } + + Client Read(BinaryReader& reader) + { + int64_t clientId = reader.ReadInt64("clientId"); + int64_t cityId = reader.ReadInt64("cityId"); + std::string firstName = reader.ReadString("firstName"); + std::string lastName = reader.ReadString("lastName"); + + return Client(clientId, cityId, firstName, lastName); + } + + IGNITE_BINARY_TYPE_END + } +}; + +#endif // _IGNITE_EXAMPLES_CLIENT \ No newline at end of file diff --git a/modules/platforms/cpp/examples/include/ignite/examples/client_product_relation.h b/modules/platforms/cpp/examples/include/ignite/examples/client_product_relation.h new file mode 100644 index 0000000..55ed346 --- /dev/null +++ b/modules/platforms/cpp/examples/include/ignite/examples/client_product_relation.h @@ -0,0 +1,88 @@ +/* + * 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_EXAMPLES_CLIENT_PRODUCT_RELATION +#define _IGNITE_EXAMPLES_CLIENT_PRODUCT_RELATION + +#include + +#include "ignite/ignite.h" +#include "ignite/ignition.h" + +namespace ignite +{ + namespace examples + { + struct ClientProductRelation + { + ClientProductRelation() : + clientProductId(0), clientId(0), productId(0) + { + // No-op. + } + + ClientProductRelation(int64_t clientProductId, int64_t clientId, int64_t productId) : + clientProductId(clientProductId), + clientId(clientId), + productId(productId) + { + // No-op. + } + + int64_t clientProductId; + int64_t clientId; + int64_t productId; + }; + } +} + +namespace ignite +{ + namespace binary + { + IGNITE_BINARY_TYPE_START(ignite::examples::ClientProductRelation) + + typedef ignite::examples::ClientProductRelation ClientProductRelation; + + IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ClientProductRelation) + IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ClientProductRelation) + IGNITE_BINARY_GET_FIELD_ID_AS_HASH + IGNITE_BINARY_GET_HASH_CODE_ZERO(ClientProductRelation) + IGNITE_BINARY_IS_NULL_FALSE(ClientProductRelation) + IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ClientProductRelation) + + void Write(BinaryWriter& writer, ClientProductRelation obj) + { + writer.WriteInt64("clientProductId", obj.clientProductId); + writer.WriteInt64("clientId", obj.clientId); + writer.WriteInt64("productId", obj.productId); + } + + ClientProductRelation Read(BinaryReader& reader) + { + int64_t clientProductId = reader.ReadInt64("clientProductId"); + int64_t clientId = reader.ReadInt64("clientId"); + int64_t productId = reader.ReadInt64("productId"); + + return ClientProductRelation(clientProductId, clientId, productId); + } + + IGNITE_BINARY_TYPE_END + } +}; + +#endif // _IGNITE_EXAMPLES_CLIENT_PRODUCT_RELATION \ No newline at end of file diff --git a/modules/platforms/cpp/examples/include/ignite/examples/product.h b/modules/platforms/cpp/examples/include/ignite/examples/product.h new file mode 100644 index 0000000..f0da6e3 --- /dev/null +++ b/modules/platforms/cpp/examples/include/ignite/examples/product.h @@ -0,0 +1,87 @@ +/* + * 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_EXAMPLES_PRODUCT +#define _IGNITE_EXAMPLES_PRODUCT + +#include + +#include "ignite/ignite.h" +#include "ignite/ignition.h" + +namespace ignite +{ + namespace examples + { + struct Product + { + Product() : productId(0), productPrice(0.0) + { + // No-op. + } + + Product(int64_t productId, const std::string& productName, double productPrice) : + productId(productId), + productName(productName), + productPrice(productPrice) + { + // No-op. + } + + int64_t productId; + std::string productName; + double productPrice; + }; + } +} + +namespace ignite +{ + namespace binary + { + IGNITE_BINARY_TYPE_START(ignite::examples::Product) + + typedef ignite::examples::Product Product; + + IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Product) + IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Product) + IGNITE_BINARY_GET_FIELD_ID_AS_HASH + IGNITE_BINARY_GET_HASH_CODE_ZERO(Product) + IGNITE_BINARY_IS_NULL_FALSE(Product) + IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Product) + + void Write(BinaryWriter& writer, Product obj) + { + writer.WriteInt64("productId", obj.productId); + writer.WriteString("productName", obj.productName); + writer.WriteDouble("productPrice", obj.productPrice); + } + + Product Read(BinaryReader& reader) + { + int64_t productId = reader.ReadInt64("productId"); + std::string productName = reader.ReadString("productName"); + double productPrice = reader.ReadDouble("productPrice"); + + return Product(productId, productName, productPrice); + } + + IGNITE_BINARY_TYPE_END + } +}; + +#endif // _IGNITE_EXAMPLES_CLIENT \ No newline at end of file diff --git a/modules/platforms/cpp/examples/odbc-example/README.txt b/modules/platforms/cpp/examples/odbc-example/README.txt new file mode 100644 index 0000000..479cb90 --- /dev/null +++ b/modules/platforms/cpp/examples/odbc-example/README.txt @@ -0,0 +1,34 @@ +Apache Ignite C++ ODBC Examples +================================== + +Common requirements +---------------------------------- + * ODBC Driver Manager must be present and installed on your platform. + * Apache Ignite ODBC driver must be built and installed according to instructions for your platform. + +Running examples on Linux +---------------------------------- + +Prerequisites: + * GCC, g++, autotools, automake, and libtool must be installed. + +To build examples execute the following commands one by one from $IGNITE_HOME/platforms/cpp/examples directory: + * libtoolize + * aclocal + * autoheader + * automake --add-missing + * autoreconf + * ./configure + * make + +As a result several executables will appear in example's directory. + +Running examples on Windows +---------------------------------- + +Prerequisites: + * Microsoft Visual Studio (tm) 2010 or higher must be installed. + * Windows SDK 7.1 must be installed. + +Open Visual Studio solution %IGNITE_HOME%\platforms\cpp\odbc\examples\project\vs\ignite-odbc-examples.sln and select proper +platform (x64 or x86). Run the solution. \ No newline at end of file diff --git a/modules/platforms/cpp/examples/odbc-example/config/example-cache.xml b/modules/platforms/cpp/examples/odbc-example/config/example-cache.xml new file mode 100644 index 0000000..51e67e0 --- /dev/null +++ b/modules/platforms/cpp/examples/odbc-example/config/example-cache.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 127.0.0.1:47500..47501 + + + + + + + + diff --git a/modules/platforms/cpp/examples/project/vs/ignite-examples.sln b/modules/platforms/cpp/examples/project/vs/ignite-examples.sln index e9da5e4..def4568 100644 --- a/modules/platforms/cpp/examples/project/vs/ignite-examples.sln +++ b/modules/platforms/cpp/examples/project/vs/ignite-examples.sln @@ -1,12 +1,12 @@  -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "putget-example", "..\..\putget-example\project\vs\putget-example.vcxproj", "{34935DEC-80FC-4168-AA52-3DBFF4F79B6B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "odbc-example", "..\..\odbc-example\project\vs\odbc-example.vcxproj", "{56839DFF-6C03-416B-BC5F-DDC6EBF8512D}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "visual-example", "..\..\visual-example\project\vs\visual-example.vcxproj", "{9651F10D-43A0-4841-90BC-A239791C4C63}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Release|x64 = Release|x64 @@ -21,6 +21,10 @@ Global {56839DFF-6C03-416B-BC5F-DDC6EBF8512D}.Release|x64.Build.0 = Release|x64 {56839DFF-6C03-416B-BC5F-DDC6EBF8512D}.Release|x86.ActiveCfg = Release|Win32 {56839DFF-6C03-416B-BC5F-DDC6EBF8512D}.Release|x86.Build.0 = Release|Win32 + {9651F10D-43A0-4841-90BC-A239791C4C63}.Release|x64.ActiveCfg = Release|x64 + {9651F10D-43A0-4841-90BC-A239791C4C63}.Release|x64.Build.0 = Release|x64 + {9651F10D-43A0-4841-90BC-A239791C4C63}.Release|x86.ActiveCfg = Release|Win32 + {9651F10D-43A0-4841-90BC-A239791C4C63}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/modules/platforms/cpp/examples/putget-example/README.txt b/modules/platforms/cpp/examples/putget-example/README.txt new file mode 100644 index 0000000..5406ea8 --- /dev/null +++ b/modules/platforms/cpp/examples/putget-example/README.txt @@ -0,0 +1,45 @@ +Apache Ignite C++ Examples +================================== + +Common requirements +---------------------------------- + * Java Development Kit (JDK) must be installed: https://java.com/en/download/index.jsp + * JAVA_HOME environment variable must be set pointing to Java installation directory. + * IGNITE_HOME environment variable must be set to Ignite installation directory. + * Ignite must be build and packaged using Maven. You can use the followin Maven command: mvn clean package -DskipTests + * Apache Ignite C++ must be built according to instructions for your platform. + +Running examples on Linux +---------------------------------- + +Prerequisites: + * GCC, g++, autotools, automake, and libtool must be installed. + +To build any example execute the following commands one by one from example root directory. +(e.g. to build putget-example you should run these commands from the +$IGNITE_HOME/platforms/cpp/examples/putget-example directory): + * libtoolize + * aclocal + * autoheader + * automake --add-missing + * autoreconf + * ./configure + * make + +As a result executable will appear in example's directory. + +Before running examples ensure that: + * LD_LIBRARY_PATH environment variable is set and pointing to a directory with "libjvm.so" library. Typically this + library is located in $JAVA_HOME/jre/lib/amd64/server directory. + * For odbc-example additionaly ODBC Driver Manager must be present and installed on your platform and + Apache Ignite ODBC driver must be built and installed according to instructions for your platform. + +Running examples on Windows +---------------------------------- + +Prerequisites: + * Microsoft Visual Studio (tm) 2010 or higher must be installed. + * Windows SDK 7.1 must be installed. + +Open Visual Studio solution %IGNITE_HOME%\platforms\cpp\examples\project\vs\ignite-examples.sln and select proper +platform (x64 or x86). Run the solution. \ No newline at end of file diff --git a/modules/platforms/cpp/examples/putget-example/project/vs/putget-example.vcxproj.filters b/modules/platforms/cpp/examples/putget-example/project/vs/putget-example.vcxproj.filters index 1bcaff5..de2d364 100644 --- a/modules/platforms/cpp/examples/putget-example/project/vs/putget-example.vcxproj.filters +++ b/modules/platforms/cpp/examples/putget-example/project/vs/putget-example.vcxproj.filters @@ -9,10 +9,6 @@ {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hh;hpp;hxx;hm;inl;inc;xsd - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - diff --git a/modules/platforms/cpp/examples/visual-example/Makefile.am b/modules/platforms/cpp/examples/visual-example/Makefile.am new file mode 100644 index 0000000..049bf46 --- /dev/null +++ b/modules/platforms/cpp/examples/visual-example/Makefile.am @@ -0,0 +1,39 @@ +## +## 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. +## + +ACLOCAL_AMFLAGS = "-Im4" + +SUBDIRS = . +DIST_SUBDIRS = . + +AM_CPPFLAGS = -I$(srcdir)/../include -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -DIGNITE_IMPL +AM_CXXFLAGS = -Wall -std=c++0x + +noinst_PROGRAMS = ignite-visualexample + +ignite_visualexample_SOURCES = src/visual_example.cpp + +ignite_visualexample_LDFLAGS = -static-libtool-libs -L/usr/local/lib -lignite + +run-check: check + ./ignite-visualexample -p + +clean-local: clean-check + $(RM) *.gcno *.gcda + +clean-check: + $(RM) $(ignite_visualexample_OBJECTS) diff --git a/modules/platforms/cpp/examples/visual-example/README.txt b/modules/platforms/cpp/examples/visual-example/README.txt new file mode 100644 index 0000000..dafe670 --- /dev/null +++ b/modules/platforms/cpp/examples/visual-example/README.txt @@ -0,0 +1,42 @@ +Apache Ignite C++ Examples +================================== + +Common requirements +---------------------------------- + * Java Development Kit (JDK) must be installed: https://java.com/en/download/index.jsp + * JAVA_HOME environment variable must be set pointing to Java installation directory. + * IGNITE_HOME environment variable must be set to Ignite installation directory. + * Ignite must be build and packaged using Maven. You can use the followin Maven command: mvn clean package -DskipTests + * Apache Ignite C++ must be built according to instructions for your platform. + +Running examples on Linux +---------------------------------- + +Prerequisites: + * GCC, g++, autotools, automake, and libtool must be installed. + +To build examples execute the following commands one by one from $IGNITE_HOME/platforms/cpp/examples directory: + * libtoolize + * aclocal + * autoheader + * automake --add-missing + * autoreconf + * ./configure + * make + +As a result several executables will appear in example's directory. + +Before running examples ensure that: + * LD_LIBRARY_PATH environment variable is set and pointing to a directory with "libjvm.so" library. Typically this + library is located in $JAVA_HOME/jre/lib/amd64/server directory. + + +Running examples on Windows +---------------------------------- + +Prerequisites: + * Microsoft Visual Studio (tm) 2010 or higher must be installed. + * Windows SDK 7.1 must be installed. + +Open Visual Studio solution %IGNITE_HOME%\platforms\cpp\examples\project\vs\ignite-examples.sln and select proper +platform (x64 or x86). Run the solution. \ No newline at end of file diff --git a/modules/platforms/cpp/examples/visual-example/config/example-cache.xml b/modules/platforms/cpp/examples/visual-example/config/example-cache.xml new file mode 100644 index 0000000..6b6cdaa --- /dev/null +++ b/modules/platforms/cpp/examples/visual-example/config/example-cache.xml @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 127.0.0.1:47500..47501 + + + + + + + + diff --git a/modules/platforms/cpp/examples/visual-example/configure.ac b/modules/platforms/cpp/examples/visual-example/configure.ac new file mode 100644 index 0000000..4062db3 --- /dev/null +++ b/modules/platforms/cpp/examples/visual-example/configure.ac @@ -0,0 +1,38 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.69]) +AC_INIT([Ignite C++ Visual example],[1.6.0.8653],[dec@ignite.apache.org],[ignite-examples],[ignite.apache.org]) +AC_CONFIG_SRCDIR(src) + +AC_CANONICAL_SYSTEM +AC_CONFIG_MACRO_DIR([m4]) +AC_LANG([C++]) + +# Initialize automake +AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) +AC_CONFIG_HEADER(config.h) + +AM_PROG_AR + +# Checks for programs. +GXX="-g -O2" + +AC_PROG_CXX + +# Initialize Libtool +LT_INIT + +AC_ARG_ENABLE([debug], + [AS_HELP_STRING([--enable-debug],[enable debug build [default=no]])], + [],[enable_debug=no]) + +if test "x$enable_debug" = xyes; then + CXXFLAGS="-g -O0" +else + CXXFLAGS="-g -O3" +fi + +AC_CONFIG_FILES(Makefile) + +AC_OUTPUT diff --git a/modules/platforms/cpp/examples/visual-example/project/vs/visual-example.vcxproj b/modules/platforms/cpp/examples/visual-example/project/vs/visual-example.vcxproj new file mode 100644 index 0000000..684b269 --- /dev/null +++ b/modules/platforms/cpp/examples/visual-example/project/vs/visual-example.vcxproj @@ -0,0 +1,111 @@ + + + + + Release + Win32 + + + Release + x64 + + + + {9651F10D-43A0-4841-90BC-A239791C4C63} + Win32Proj + igniteexamples + visual-example + + + + Application + false + v100 + true + Unicode + + + Application + false + v100 + true + Unicode + + + + + + + + + + + + + false + + + false + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;..\..\..\include;..\..\..\..\common\os\win\include;..\..\..\..\common\include;..\..\..\..\binary\include;..\..\..\..\core\os\win\include;..\..\..\..\core\include;$(BOOST_HOME);%(AdditionalIncludeDirectories) + + + Console + true + true + true + jvm.lib;ignite.common.lib;ignite.binary.lib;ignite.core.lib;%(AdditionalDependencies) + ..\..\..\..\project\vs\$(Platform)\$(Configuration)\;$(JAVA_HOME)\lib;%(AdditionalLibraryDirectories) + + + copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.common.dll" "$(OutDir)" +copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.core.dll" "$(OutDir)" + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + $(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;..\..\..\include;..\..\..\..\common\os\win\include;..\..\..\..\common\include;..\..\..\..\binary\include;..\..\..\..\core\os\win\include;..\..\..\..\core\include;$(BOOST_HOME);%(AdditionalIncludeDirectories) + + + Console + true + true + true + jvm.lib;ignite.common.lib;ignite.binary.lib;ignite.core.lib;%(AdditionalDependencies) + ..\..\..\..\project\vs\$(Platform)\$(Configuration)\;$(JAVA_HOME)\lib;%(AdditionalLibraryDirectories) + + + copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.common.dll" "$(OutDir)" +copy "$(ProjectDir)..\..\..\..\project\vs\$(Platform)\$(Configuration)\ignite.core.dll" "$(OutDir)" + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/platforms/cpp/examples/visual-example/project/vs/visual-example.vcxproj.filters b/modules/platforms/cpp/examples/visual-example/project/vs/visual-example.vcxproj.filters new file mode 100644 index 0000000..21fc548 --- /dev/null +++ b/modules/platforms/cpp/examples/visual-example/project/vs/visual-example.vcxproj.filters @@ -0,0 +1,35 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/modules/platforms/cpp/examples/visual-example/src/visual_example.cpp b/modules/platforms/cpp/examples/visual-example/src/visual_example.cpp new file mode 100644 index 0000000..b928093 --- /dev/null +++ b/modules/platforms/cpp/examples/visual-example/src/visual_example.cpp @@ -0,0 +1,400 @@ +/* + * 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. + */ +#include + +#include +#include + +#include + +#include "ignite/ignite.h" +#include "ignite/ignition.h" + +#include "ignite/examples/city.h" +#include "ignite/examples/client.h" +#include "ignite/examples/account.h" +#include "ignite/examples/product.h" +#include "ignite/examples/client_product_relation.h" + +using namespace ignite; +using namespace cache; + +using namespace examples; + +std::time_t now = std::time(0); +boost::random::mt19937 gen(static_cast(now)); + +/** + * Fill collection with test cities data. + * + * @param cities Collection to be filled. + */ +void GenerateCities(std::map& cities) +{ + cities.clear(); + + int64_t idCounter = 0; + + cities[idCounter] = City(++idCounter, "New York", 8491079); + cities[idCounter] = City(++idCounter, "Los Angeles", 3884307); + cities[idCounter] = City(++idCounter, "Chicago", 2722389); + cities[idCounter] = City(++idCounter, "Houston", 2239558); + cities[idCounter] = City(++idCounter, "Philadelphia", 1560297); + cities[idCounter] = City(++idCounter, "San Diego", 1381069); + cities[idCounter] = City(++idCounter, "San Francisco", 852469); + cities[idCounter] = City(++idCounter, "Charlotte", 809958); + cities[idCounter] = City(++idCounter, "Detroit", 680250); + cities[idCounter] = City(++idCounter, "El Paso", 679036); + cities[idCounter] = City(++idCounter, "Seattle", 668342); + cities[idCounter] = City(++idCounter, "Denver", 663862); + cities[idCounter] = City(++idCounter, "Boston", 655884); + cities[idCounter] = City(++idCounter, "Las Vegas", 613599); + cities[idCounter] = City(++idCounter, "Atlanta", 456002); + cities[idCounter] = City(++idCounter, "Omaha", 446599); + cities[idCounter] = City(++idCounter, "Miami", 430332); +} + +/** + * Fill collection with test client data. + * + * @param clients Clients collection to be filled. + * @param cities Filled cities collection to use. + * @param num Number of clients to generate. + */ +void GenerateClients(std::map& clients, + const std::map& cities, int64_t num) +{ + clients.clear(); + + std::vector firstNames; + + firstNames.push_back("Emily"); + firstNames.push_back("Amelia"); + firstNames.push_back("Olivia"); + firstNames.push_back("Jessica"); + firstNames.push_back("Lily"); + firstNames.push_back("Sophie"); + firstNames.push_back("Grace"); + firstNames.push_back("Mia"); + firstNames.push_back("Evie"); + firstNames.push_back("Ruby"); + firstNames.push_back("Chloe"); + firstNames.push_back("Scarlett"); + firstNames.push_back("Phoebe"); + firstNames.push_back("Charlotte"); + firstNames.push_back("Daisy"); + firstNames.push_back("Alice"); + firstNames.push_back("Sofia"); + firstNames.push_back("Florence"); + firstNames.push_back("Oliver"); + firstNames.push_back("Jack"); + firstNames.push_back("Harry"); + firstNames.push_back("Jacob"); + firstNames.push_back("Charlie"); + firstNames.push_back("Thomas"); + firstNames.push_back("George"); + firstNames.push_back("Oscar"); + firstNames.push_back("James"); + firstNames.push_back("William"); + firstNames.push_back("Henry"); + firstNames.push_back("Muhamma"); + firstNames.push_back("Joseph"); + firstNames.push_back("Daniel"); + firstNames.push_back("Edward"); + firstNames.push_back("Jake"); + firstNames.push_back("David"); + + std::vector lastNames; + + lastNames.push_back("Smith"); + lastNames.push_back("Jones"); + lastNames.push_back("Taylor"); + lastNames.push_back("Williams"); + lastNames.push_back("Brown"); + lastNames.push_back("Davies"); + lastNames.push_back("Evans"); + lastNames.push_back("Wilson"); + lastNames.push_back("Thomas"); + lastNames.push_back("Robert"); + lastNames.push_back("Johnson"); + lastNames.push_back("Lewis"); + lastNames.push_back("Walker"); + + int64_t allPopulation = 0; + + std::map::const_iterator it; + for (it = cities.begin(); it != cities.end(); ++it) + allPopulation += it->second.population; + + // Selecting random city considering its weight - population. + boost::random::uniform_int_distribution cityPopulationDistr(0, allPopulation - 1); + + // First name distribution. + boost::random::uniform_int_distribution firstNameDistr(0, firstNames.size() - 1); + + // Last name distribution. + boost::random::uniform_int_distribution lastNameDistr(0, lastNames.size() - 1); + + for (int64_t i = 1; i <= num; ++i) + { + int64_t cityId = 0; + + // Generating cityId depending on city weight - population. + int64_t populationPos = cityPopulationDistr(gen); + + for (it = cities.begin(); it != cities.end(); ++it) + { + populationPos -= it->second.population; + + if (populationPos < 0) + { + cityId = it->first; + + break; + } + } + + size_t firstNameIdx = firstNameDistr(gen); + size_t lastNameIdx = lastNameDistr(gen); + + clients[i] = Client(i, cityId, firstNames[firstNameIdx], lastNames[lastNameIdx]); + } +} + +/** + * Fill collection with test account data. + * + * @param accounts Accounts collection to be filled. + * @param clients Filled clients collection to use. + * @param avrgNum Average number of accounts per client. + */ +void GenerateAccounts(std::map& accounts, + const std::map& clients, double accountCntScale, double balanceScale) +{ + accounts.clear(); + + // Account number per client distributed by exponential law. + boost::random::exponential_distribution accountCntDistr; + + // Generating accounts for clients. + std::map::const_iterator itc; + for (itc = clients.begin(); itc != clients.end(); ++itc) + { + // Generating number of accounts for client using exponentional + // distribution. Minimum is 1. + int accountsCnt = 1 + static_cast(accountCntDistr(gen) * accountCntScale); + + // Generating acounts for the client. + for (int i = 0; i < accountsCnt; ++i) + { + int64_t accountId = static_cast(accounts.size() + 1); + + // Do not generate ballance just now. + accounts[accountId] = Account(accountId, itc->first, 0.0); + } + } + + // Using log-normal distribution for balance. + boost::random::lognormal_distribution balanceDistr; + + // Generating balance for accounts. + std::map::iterator ita; + for (ita = accounts.begin(); ita != accounts.end(); ++ita) + ita->second.balance = balanceDistr(gen) * balanceScale; +} + +/** + * Fill collection with test product data. + * + * @param products Product collection to be filled. + * @param num Number of products to generate. + */ +void GenerateProducts(std::map& products, int64_t num) +{ + products.clear(); + + // Using uniform distribution for price (hundreds of currency). + boost::random::uniform_int_distribution priceDistr(1, 100); + + // Generating products. + for (int64_t i = 1; i <= num; ++i) + { + std::stringstream ss("Product"); + ss << i; + + double price = priceDistr(gen) * 100.0; + + products[i] = Product(i, ss.str(), price); + } +} + + +/** + * Fill collection with test client-product relation data. + * + * @param clientProductRels ClientProductRelation collection to be filled. + * @param num Number of relations to generate. + */ +void GenerateClientProductRelations(std::map& clientProductRels, + const std::map& clients, const std::map& products, int64_t num) +{ + clientProductRels.clear(); + + // Starting with generating weights for the products - their popularity. + std::map productPopularity; + + // Using uniform distribution. + boost::random::uniform_int_distribution productPopularityDistr(5, 100); + + // We will need sum later. + int64_t popularitySum = 0; + + std::map::const_iterator it; + for (it = products.begin(); it != products.end(); ++it) + { + int8_t popularity = productPopularityDistr(gen); + + popularitySum += popularity; + + productPopularity[it->first] = popularity; + } + + // Distributing products between clients using uniform distribution + // in range [1..clientsNum]. + boost::random::uniform_int_distribution clientIdDistr(1, clients.size() + 1); + + // We are going to generate values in this range to select product + // considering its popularity. + boost::random::uniform_int_distribution popularityRangeDistr(1, popularitySum); + + // Generating relations. + for (int64_t i = 1; i <= num; ++i) + { + // Generating client id. + int64_t clientId = clientIdDistr(gen); + + // Shooting in popularity range. + int64_t popularity = popularityRangeDistr(gen); + + int64_t productId = 1; + + // Finding out product id. + std::map::const_iterator pit; + for (pit = productPopularity.begin(); pit != productPopularity.end(); ++pit) + { + popularity -= pit->second; + + if (popularity <= 0) + { + productId = pit->first; + + break; + } + } + + int64_t clientProductRelId = clientProductRels.size() + 1; + + clientProductRels[clientProductRelId] = ClientProductRelation(clientProductRelId, clientId, productId); + } +} + +/** + * Populate caches with generated data. + */ +void Populate(Ignite& grid) +{ + std::map cities; + std::map clients; + std::map accounts; + std::map products; + std::map clientProducts; + + // Generating test data. + GenerateCities(cities); + GenerateClients(clients, cities, 10000); + GenerateAccounts(accounts, clients, 1.0, 50000.0); + GenerateProducts(products, 24); + GenerateClientProductRelations(clientProducts, clients, products, 20000); + + // Getting cache instances. + Cache cityCache = grid.GetCache("City"); + Cache clientCache = grid.GetCache("Client"); + Cache accountCache = grid.GetCache("Account"); + Cache productCache = grid.GetCache("Product"); + Cache clientProductCache = grid.GetCache("ClientProductRelation"); + + // Clearing caches. + cityCache.Clear(); + clientCache.Clear(); + accountCache.Clear(); + productCache.Clear(); + clientProductCache.Clear(); + + // Loading entries into caches. + cityCache.PutAll(cities); + clientCache.PutAll(clients); + accountCache.PutAll(accounts); + productCache.PutAll(products); + clientProductCache.PutAll(clientProducts); +} + +/** + * Program entry point. + * + * @return Exit code. + */ +int main() +{ + IgniteConfiguration cfg; + + cfg.jvmInitMem = 512; + cfg.jvmMaxMem = 512; + + cfg.springCfgPath = "platforms/cpp/examples/visual-example/config/example-cache.xml"; + + try + { + // Start a node. + Ignite grid = Ignition::Start(cfg); + + std::cout << std::endl; + std::cout << ">>> Cache visual example started." << std::endl; + std::cout << std::endl; + + std::cout << ">>> Generating example data..." << std::endl; + + Populate(grid); + + std::cout << ">>> Data is generated and loaded to cache successfully." << std::endl; + + std::cout << ">>> Example is running, press any key to stop ..." << std::endl; + std::cin.get(); + + // Stop node. + Ignition::StopAll(false); + } + catch (IgniteError& err) + { + std::cout << "An error occurred: " << err.GetText() << std::endl; + } + + std::cout << std::endl; + std::cout << ">>> Example finished, exiting." << std::endl; + std::cout << std::endl; + + return 0; +}