Monday, January 11, 2016

Coherence backed by JPA with C++ Client

In my previous post, I showed how you can access JPA based POJO's using Java Client. This example shows how you can access these POJOs using C++.

The procedure of using c++ client is the same. But you need to have corresponding c++ classes.

1. Create C++ Project
2. Create C++ Classes for corresponding classes
3. Create C++ coherence Config
4. Create C++ Client
5. Run the Client


1. Create C++ Project

2. Create C++ Classes for corresponding classes

ORDER.HPP

#ifndef ORDER_HPP_
#define ORDER_HPP_

#include "coherence/lang.ns"
#include "coherence/util/List.hpp"
#include "coherence/io/pof/SystemPofContext.hpp"

using coherence::util::List;

using namespace coherence::lang;
using coherence::io::pof::SystemPofContext;

class Order: public class_spec<Order> // extends<Object> is implied
{
friend class factory<Order> ;

public:
Order(const long sOrderId, long sCustomerId, std::string& sOrderMode,
float sOrderStatus, float sOrderTotal, long sPromotionId,
long sSalesRepId, List::Handle& sOrderItemList) {
setOrderId(sOrderId);
setCustomerId(sCustomerId);
setOrderMode(sOrderMode);
setOrderStatus(sOrderStatus);
setOrderTotal(sOrderTotal);
setPromotionId(sPromotionId);
setSalesRepId(sSalesRepId);
setOrderItemList(sOrderItemList);
}

Order(Order& that) {
setOrderId(that.getOrderId());
setCustomerId(that.getCustomerId());
setOrderMode(that.getOrderMode());
setOrderStatus(that.getOrderStatus());
setOrderTotal(that.getOrderTotal());
setOrderItemList(that.getOrderItemList());
setPromotionId(that.getPromotionId());
setSalesRepId(that.getSalesRepId());
}

Order() {
setOrderId(0);
setCustomerId(0);
setOrderStatus(0);
setOrderTotal(0);
}

public:
virtual bool equals(Object::View that) const {
if (instanceof<Order::View>(that)) {
Order::View vThat = cast<Order::View>(that);

return getOrderId() == vThat->getOrderId();
}

return false;
}

virtual size32_t hashCode() const {
return (size32_t) orderId;
}

virtual void toStream(std::ostream& out) const {
out << getOrderId() << ", " << getCustomerId() << "  "
<< getOrderMode();
}

public:
long getCustomerId() const {
return customerId;
}

void setCustomerId(long customerId) {
this->customerId = customerId;
}

long getOrderId() const {
return orderId;
}

void setOrderId(long orderId) {
this->orderId = orderId;
//SystemPofContext::Handle hCtx = SystemPofContext::getInstance();
//hCtx->setReferenceEnabled(true);
}

const List::Handle& getOrderItemList() const {
return orderItemList;
}

void setOrderItemList(const List::Handle& orderItemList) {
this->orderItemList = orderItemList;
}

void setOrderList(List::Handle& orderItemList) {
this->orderItemList = orderItemList;
}

List::Handle& getOrderList() {
return orderItemList;
}

const std::string& getOrderMode() const {
return orderMode;
}

void setOrderMode(const std::string& orderMode) {
this->orderMode = orderMode;
}

void setOMode(std::string& orderMode) {
this->orderMode = orderMode;
}


float getOrderStatus() const {
return orderStatus;
}

void setOrderStatus(float orderStatus) {
this->orderStatus = orderStatus;
}

float getOrderTotal() const {
return orderTotal;
}

void setOrderTotal(float orderTotal) {
this->orderTotal = orderTotal;
}

long getPromotionId() const {
return promotionId;
}

void setPromotionId(long promotionId) {
this->promotionId = promotionId;
}

long getSalesRepId() const {
return salesRepId;
}

void setSalesRepId(long salesRepId) {
this->salesRepId = salesRepId;
}

private:
long orderId;

long customerId;

float orderStatus;

float orderTotal;

std::string orderMode;

List::Handle orderItemList;

long promotionId;

long salesRepId;

//const MemberView<String> m_vsCity;
//const MemberView<String> m_vsState;
//const int32_t      m_nZip;
};

#endif /* ORDER_HPP_ */

ORDERITEM.HPP


#ifndef ORDERITEM_HPP_
#define ORDERITEM_HPP_

#include "coherence/lang.ns"
#include "coherence/util/List.hpp"
#include "Order.hpp"
#include "ProductInformation.hpp"
#include "OrderItemPK.hpp"

using coherence::util::List;

using namespace coherence::lang;

class OrderItem: public class_spec<OrderItem> // extends<Object> is implied
{
friend class factory<OrderItem> ;

public:
OrderItem(long sQuantity, long sUnitPrice,
ProductInformation::View sInformation,
OrderItemPK::View sOrderItemPK) {
setQuantity(sQuantity);
setUnitPrice(sUnitPrice);
setInformation(sInformation);
setOrderItemPk(sOrderItemPK);
}

OrderItem(long sQuantity, long sUnitPrice,
ProductInformation::View sInformation,
OrderItemPK::View sOrderItemPK, Order::View sOrder) {
setQuantity(sQuantity);
setUnitPrice(sUnitPrice);
setInformation(sInformation);
setOrderItemPk(sOrderItemPK);
setOrder(sOrder);
}

OrderItem(const OrderItem& that) {
setQuantity(that.getQuantity());
setUnitPrice(that.getUnitPrice());
setInformation(that.getInformation());
//setOrder(that.getOrder());
}

public:
virtual bool equals(Object::View that) const {
if (instanceof<OrderItem::View>(that)) {
OrderItem::View vThat = cast<OrderItem::View>(that);
return getQuantity() == vThat->getQuantity();
}

return false;
}

virtual size32_t hashCode() const {
return (size32_t) quantity;
}

virtual void toStream(std::ostream& out) const {
out << "[Unit Price:" << getUnitPrice() << ", Quantity " << getQuantity() << ", Total Price: " << this->quantity*this->unitPrice << "]";
}

long getQuantity() const {
return quantity;
}

void setQuantity(long quantity) {
this->quantity = quantity;
}

long getUnitPrice() const {
return unitPrice;
}

void setUnitPrice(long unitPrice) {
this->unitPrice = unitPrice;
}

const ProductInformation::View& getInformation() const {
return pInformation;
}

void setInformation(const ProductInformation::View& information) {
pInformation = information;
}

const OrderItemPK::View& getOrderItemPk() const {
return pOrderItemPK;
}

void setOrderItemPk(const OrderItemPK::View& orderItemPk) {
pOrderItemPK = orderItemPk;
}

const Order::View& getOrder() const {
return pOrder;
}

void setOrder(const Order::View& order) {
pOrder = order;
}

public:

private:
long quantity;
long unitPrice;
ProductInformation::View pInformation;
OrderItemPK::View pOrderItemPK;
Order::View pOrder;

//const MemberView<String> m_vsCity;
//const MemberView<String> m_vsState;
//const int32_t      m_nZip;
};

#endif /* ORDERITEM_HPP_ */

PRODUCTINFORMATION.HPP

#ifndef PRODUCTINFORMATION_HPP_
#define PRODUCTINFORMATION_HPP_

#include "coherence/lang.ns"
#include "coherence/util/List.hpp"

using coherence::util::List;

using namespace coherence::lang;

class ProductInformation: public class_spec<ProductInformation> // extends<Object> is implied
{
friend class factory<ProductInformation>;

public:
ProductInformation(long sProductId, std::string sCatalogUrl,
int sCategoryId, float sListPrice, float sMinPrice,
std::string sProductDescription, std::string sProductName,
std::string sProductStatus, long sSupplierId, long sWeightClass) {
setProductId(sProductId);
setCatalogUrl(sCatalogUrl);
setProductDescription(sProductDescription);
setProductName(sProductName);
setCategoryId(sCategoryId);
setListPrice(sListPrice);
setMinPrice(sMinPrice);
setProductStatus(sProductStatus);
setSupplierId(sSupplierId);
setWeightClass(sWeightClass);

}

ProductInformation(const ProductInformation& that) {
setProductId(that.getProductId());
setCatalogUrl(that.getCatalogUrl());
setProductDescription(that.getProductDescription());
setProductName(that.getProductName());
setCategoryId(that.getCategoryId());
setListPrice(that.getListPrice());
setMinPrice(that.getMinPrice());
setProductStatus(that.getProductStatus());
setSupplierId(that.getSupplierId());
setWeightClass(that.getWeightClass());
}

ProductInformation() {
setProductId(0);
setCatalogUrl("");
setProductDescription("");
setProductName("");
setCategoryId(0);
setListPrice(0);
setMinPrice(0);
setProductStatus(0);
setSupplierId(0);
setWeightClass(0);
}

public:
virtual bool equals(Object::View that) const {
if (instanceof<ProductInformation::View>(that)) {
ProductInformation::View vThat = cast<ProductInformation::View>(
that);

return getProductId() == vThat->getProductId();
}

return false;
}

virtual size32_t hashCode() const {
return (size32_t) productId;
}

virtual void toStream(std::ostream& out) const {
out << getProductId() << ", " << getProductName();
}

const std::string& getCatalogUrl() const {
return catalogUrl;
}

void setCatalogUrl(const std::string& catalogUrl) {
this->catalogUrl = catalogUrl;
}

int getCategoryId() const {
return categoryId;
}

void setCategoryId(int categoryId) {
this->categoryId = categoryId;
}

float getListPrice() const {
return listPrice;
}

void setListPrice(float listPrice) {
this->listPrice = listPrice;
}

float getMinPrice() const {
return minPrice;
}

void setMinPrice(float minPrice) {
this->minPrice = minPrice;
}

const std::string& getProductDescription() const {
return productDescription;
}

void setProductDescription(const std::string& productDescription) {
this->productDescription = productDescription;
}

long getProductId() const {
return productId;
}

void setProductId(long productId) {
this->productId = productId;
}

const std::string& getProductName() const {
return productName;
}

void setProductName(const std::string& productName) {
this->productName = productName;
}

const std::string& getProductStatus() const {
return productStatus;
}

void setProductStatus(const std::string& productStatus) {
this->productStatus = productStatus;
}

long getSupplierId() const {
return supplierId;
}

void setSupplierId(long supplierId) {
this->supplierId = supplierId;
}

long getWeightClass() const {
return weightClass;
}

void setWeightClass(long weightClass) {
this->weightClass = weightClass;
}

public:

private:
long productId;

std::string catalogUrl;

int categoryId;

float listPrice;

float minPrice;

std::string productDescription;

std::string productName;

std::string productStatus;

long supplierId;

long weightClass;
};

#endif /* PRODUCTINFORMATION_HPP_ */

ORDERITEMPK.hpp


#ifndef ORDERITEMPK_HPP_

#define ORDERITEMPK_HPP_

#include "coherence/lang.ns"
#include "coherence/util/List.hpp"
#include "coherence/lang/Comparable.hpp"

using coherence::util::List;

using namespace coherence::lang;

class OrderItemPK: public class_spec<OrderItemPK>  // extends<Object> is implied
{
friend class factory<OrderItemPK> ;

public:
OrderItemPK(long sOrderId, long sLineItemId) {
setOrderId (sOrderId);
setLineItemId (sLineItemId);
}

OrderItemPK(long sOrderId) {
setOrderId (sOrderId);
}

OrderItemPK() {
}

OrderItemPK(const OrderItemPK& that) {
setOrderId(that.getOrderId());
setLineItemId(that.getLineItemId());
}

public:

virtual bool equals(Object::View that) const {
if (instanceof<OrderItemPK::View>(that)) {
OrderItemPK::View vThat = cast<OrderItemPK::View>(that);

return getOrderId() == vThat->getOrderId();
}

return false;
}

virtual size32_t hashCode() const {
return (size32_t) orderId;
}

virtual void toStream(std::ostream& out) const {
out << getOrderId() << ", " << getLineItemId();
}

long getLineItemId() const {
return lineItemId;
}

void setLineItemId(long lineItemId) {
this->lineItemId = lineItemId;
}

long getOrderId() const {
return orderId;
}

void setOrderId(long orderId) {
this->orderId = orderId;
}

private:
long lineItemId;

long orderId;
};

#endif /* ORDERITEMPK_HPP_ */


ORDERITEMPKSerializer.cpp

#include "coherence/lang.ns"

#include "coherence/io/pof/PofReader.hpp"
#include "coherence/io/pof/PofWriter.hpp"
#include "coherence/io/pof/PortableObject.hpp"
#include "coherence/io/pof/PofSerializer.hpp"
#include "coherence/lang/lang_spec.hpp"
#include "coherence/io/pof/SystemPofContext.hpp"

#include "OrderItemPK.hpp"

using coherence::util::List;

using namespace coherence::lang;

using coherence::io::pof::PofReader;
using coherence::io::pof::PofWriter;
using coherence::io::pof::PofSerializer;

class OrderItemPKSerializer: public class_spec<OrderItemPKSerializer,
extends<Object>, implements<PofSerializer> > {
friend class factory<OrderItemPKSerializer> ;

public:
OrderItemPKSerializer() {
}

public:
// PofSerializer interface
virtual void serialize(PofWriter::Handle hOut, Object::View v) const {
//std::cout << "Starting serialize OrderItemPK" << std::endl;
OrderItemPK::View vOrderItemPK = cast<OrderItemPK::View>(v);
hOut->writeInt64(0, vOrderItemPK->getOrderId());
hOut->writeInt64(1, vOrderItemPK->getLineItemId());
hOut->writeRemainder(NULL);
//std::cout << "Ending serialize OrderItemPK" << std::endl;
}

virtual Object::Holder deserialize(PofReader::Handle hIn) const {
//std::cout << "Starting deserialize OrderItemPK" << std::endl;
long sOrderId = hIn->readInt64(0);
long sLineItemId = hIn->readInt64(1);
hIn->readRemainder();
//std::cout << "Ending deserialize OrderItemPK" << std::endl;
return OrderItemPK::create(sOrderId, sLineItemId);
}
};
COH_REGISTER_POF_SERIALIZER(1003, TypedBarrenClass<OrderItemPK>::create(),
OrderItemPKSerializer::create()); // This must appear in the .cpp not the .hpp

ProductInformationSerializer.hpp


/*

 * ProductInformationSerializer.cpp
 *
 *  Created on: Jan 2, 2016
 *      Author: oracle
 */

#include "coherence/lang.ns"

#include "coherence/io/pof/PofReader.hpp"
#include "coherence/io/pof/PofWriter.hpp"
#include "coherence/io/pof/PortableObject.hpp"
#include "coherence/io/pof/PofSerializer.hpp"
#include "coherence/lang/lang_spec.hpp"
#include "coherence/io/pof/SystemPofContext.hpp"

#include "ProductInformation.hpp"
#include "coherence/util/List.hpp"

using coherence::util::List;

using namespace coherence::lang;

using coherence::io::pof::PofReader;
using coherence::io::pof::PofWriter;
using coherence::io::pof::PofSerializer;
using coherence::io::pof::SystemPofContext;

class ProductInformationSerializer: public class_spec<
ProductInformationSerializer, extends<Object>, implements<PofSerializer> > {
friend class factory<ProductInformationSerializer> ;

public:
ProductInformationSerializer() {

}

public:
// PofSerializer interface
virtual void serialize(PofWriter::Handle hOut, Object::View v) const {
//std::cout << "Starting serialize ProductInformation" << std::endl;
ProductInformation::View info = cast<ProductInformation::View>(v);
hOut->writeInt64(0, info->getProductId());
hOut->writeString(1, info->getCatalogUrl());
hOut->writeInt32(2, info->getCategoryId());
hOut->writeFloat64(3, info->getListPrice());
hOut->writeFloat64(4, info->getMinPrice());
hOut->writeString(5, info->getProductDescription());
hOut->writeString(6, info->getProductName());
hOut->writeString(7, info->getProductStatus());
hOut->writeInt64(8, info->getSupplierId());
hOut->writeInt32(9, info->getWeightClass());
hOut->writeRemainder(NULL);
//std::cout << "Ending serialize ProductInformation" << std::endl;
}

virtual Object::Holder deserialize(PofReader::Handle hIn) const {

//std::cout << "Starting deserialize ProductInformation" << std::endl;
long sProductId = hIn->readInt64(0);
std::string sCatalogUrl = hIn->readString(1);
int sCategoryId = hIn->readInt32(2);
long sListPrice = hIn->readInt64(3);
long sMinPrice = hIn->readInt64(4);
std::string sProductDescription = hIn->readString(5);
std::string sProductName = hIn->readString(6);
std::string sProductStatus = hIn->readString(7);
long sSupplierId = hIn->readInt64(8);
long sWeightClass = hIn->readInt64(9);
hIn->readRemainder();
//std::cout << "Ending Deserializing ProductInformation" << std::endl;
return ProductInformation::create(sProductId, sCatalogUrl, sCategoryId,
sListPrice, sMinPrice, sProductDescription, sProductName,
sProductStatus, sSupplierId, sWeightClass);
}
};
COH_REGISTER_POF_SERIALIZER(1004,
TypedBarrenClass<ProductInformation>::create(),
ProductInformationSerializer::create()); // This must appear in the .cpp not the .hpp

ORDERITEMSERIALIZER.cpp

#include "coherence/lang.ns"

#include "coherence/io/pof/PofReader.hpp"
#include "coherence/io/pof/PofWriter.hpp"
#include "coherence/io/pof/PortableObject.hpp"
#include "coherence/io/pof/PofSerializer.hpp"
#include "coherence/lang/lang_spec.hpp"
#include "coherence/io/pof/SystemPofContext.hpp"

#include "OrderItem.hpp"
#include "coherence/util/List.hpp"

using coherence::util::List;

using namespace coherence::lang;

using coherence::io::pof::PofReader;
using coherence::io::pof::PofWriter;
using coherence::io::pof::PofSerializer;

class OrderItemSerializer: public class_spec<OrderItemSerializer,
extends<Object>, implements<PofSerializer> > {
friend class factory<OrderItemSerializer> ;

public:
OrderItemSerializer() {
}

public:
// PofSerializer interface
virtual void serialize(PofWriter::Handle hOut, Object::View v) const {
//std::cout << "Starting serialize Order Item" << std::endl;
OrderItem::View vOrderItem = cast<OrderItem::View>(v);
hOut->writeInt64(0, vOrderItem->getQuantity());
hOut->writeInt64(1, vOrderItem->getUnitPrice());
hOut->writeObject(2, vOrderItem->getInformation());
//hOut->writeObject(3, vOrderItem->getOrderItemPk());
hOut->writeRemainder(NULL);
//std::cout << "Ending serialize Order Item" << std::endl;
}

virtual Object::Holder deserialize(PofReader::Handle hIn) const {
//std::cout << "Starting deserialize Order Item" << std::endl;
long sQuantity = hIn->readInt64(0);
long sUnitPrice = hIn->readInt64(1);
ProductInformation::View vProductInformation = cast<ProductInformation::View>(hIn->readObject(2));
OrderItemPK::View vOrderItemPK = cast<OrderItemPK::View>(hIn->readObject(3));
OrderItem::Handle ohOrderItem = OrderItem::create(sQuantity, sUnitPrice, vProductInformation, vOrderItemPK);
hIn->registerIdentity(ohOrderItem);
Order::View vOrder = cast<Order::View>(hIn->readObject(4));
ohOrderItem->setOrder(vOrder);
hIn->readRemainder();
return ohOrderItem;
//return OrderItem::create(sQuantity, sUnitPrice, vProductInformation, vOrderItemPK);
}
};
COH_REGISTER_POF_SERIALIZER(1002, TypedBarrenClass<OrderItem>::create(),
OrderItemSerializer::create()); // This must appear in the .cpp not the .hpp

ORDERSERIALIZER.cpp

#include "coherence/lang.ns"

#include "coherence/io/pof/PofReader.hpp"
#include "coherence/io/pof/PofWriter.hpp"
#include "coherence/io/pof/PortableObject.hpp"
#include "coherence/io/pof/PofSerializer.hpp"
#include "coherence/lang/lang_spec.hpp"
#include "coherence/io/pof/SystemPofContext.hpp"

#include "Order.hpp"
#include "coherence/util/List.hpp"

using coherence::util::List;

using namespace coherence::lang;

using coherence::io::pof::PofReader;
using coherence::io::pof::PofWriter;
using coherence::io::pof::PofSerializer;
using coherence::io::pof::SystemPofContext;

class OrderSerializer: public class_spec<OrderSerializer, extends<Object>,
implements<PofSerializer> > {
friend class factory<OrderSerializer> ;

public:
OrderSerializer() {
}

public:
// PofSerializer interface
virtual void serialize(PofWriter::Handle hOut, Object::View v) const {
//std::cout << "Starting serialize Order" << std::endl;
Order::View info = cast<Order::View>(v);
hOut->writeInt64(0, info->getOrderId());
hOut->writeInt64(1, info->getCustomerId());
hOut->writeString(2, info->getOrderMode());
hOut->writeFloat64(3, info->getOrderStatus());
hOut->writeFloat64(4, info->getOrderTotal());
hOut->writeInt64(5, info->getPromotionId());
hOut->writeInt64(6, info->getSalesRepId());
Object::Handle ho = info->getOrderItemList();
List::Handle hs = cast<List::Handle>(ho);
hOut->writeCollection(7, hs);
hOut->writeRemainder(NULL);
//std::cout << "Ending serialize Order" << std::endl;
}

virtual Object::Holder deserialize(PofReader::Handle hIn) const {
//std::cout << "Starting deserialize Order" << std::endl;
List::Handle orderItemList;
long orderId = hIn->readInt64(0);
long customerId = hIn->readInt64(1);
std::string orderMode = hIn->readString(2);
float orderStatus = hIn->readFloat64(3);
float orderTotal = hIn->readFloat64(4);
long promotionId = hIn->readInt64(5);
long salesRepId = hIn->readInt64(6);
Order::Handle ohOrder = Order::create(orderId, customerId, orderMode, orderStatus, orderTotal, promotionId, salesRepId, orderItemList);
hIn->registerIdentity(ohOrder);
orderItemList = cast<List::Handle>(hIn->readCollection(7));
ohOrder->setOrderList(orderItemList);

hIn->readRemainder();
return ohOrder;
//std::cout << "Ending deserialize Order" << std::endl;

}
};
COH_REGISTER_POF_SERIALIZER(1001, TypedBarrenClass<Order>::create(),
OrderSerializer::create()); // This must appear in the .cpp not the .hpp



3. Create C++ coherence Config

<?xml version="1.0"?>

<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
   xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config
   coherence-cache-config.xsd">
  <caching-scheme-mapping>
     <cache-mapping>
      <!-- Set the name of the cache to be the entity name.  -->
      <cache-name>Order</cache-name>
      <!-- Configure this cache to use the following defined scheme. -->
      <scheme-name>jpa-distributed</scheme-name>
    </cache-mapping>
     <cache-mapping>
      <!-- Set the name of the cache to be the entity name.  -->
      <cache-name>OrderItem</cache-name>
      <!-- Configure this cache to use the following defined scheme. -->
      <scheme-name>jpa-distributed</scheme-name>
    </cache-mapping>
  </caching-scheme-mapping>
  
  <caching-schemes>
    <remote-cache-scheme>
      <scheme-name>jpa-distributed</scheme-name>
      <service-name>ExtendTcpCacheService</service-name>
      <initiator-config>
        <tcp-initiator>
          <remote-addresses>
            <socket-address>
              <address>localhost</address>
              <port>9099</port>
            </socket-address>
          </remote-addresses>
          <connect-timeout>30s</connect-timeout>
        </tcp-initiator>
        <outgoing-message-handler>
          <request-timeout>20s</request-timeout>
        </outgoing-message-handler>
      </initiator-config>
    </remote-cache-scheme>

    <remote-invocation-scheme>
      <scheme-name>extend-invocation</scheme-name>
      <service-name>ExtendTcpInvocationService</service-name>
      <initiator-config>
        <tcp-initiator>
          <remote-addresses>
            <socket-address>
              <address>localhost</address>
              <port>9099</port>
            </socket-address>
          </remote-addresses>
          <connect-timeout>30s</connect-timeout>
        </tcp-initiator>
        <outgoing-message-handler>
          <request-timeout>25s</request-timeout>
        </outgoing-message-handler>
      </initiator-config>
    </remote-invocation-scheme>
  </caching-schemes>
</cache-config>


4. Create C++ Client

#include "Order.hpp"
#include "OrderItem.hpp"
#include "OrderItemPK.hpp"

#include "coherence/lang.ns"
#include "coherence/net/CacheFactory.hpp"
#include "coherence/net/NamedCache.hpp"
#include "coherence/util/HashSet.hpp"
#include "coherence/util/aggregator/Integer64Sum.hpp"
#include "coherence/util/filter/EqualsFilter.hpp"
#include "coherence/util/filter/GreaterEqualsFilter.hpp"
#include "coherence/util/Filter.hpp"
#include "coherence/util/Hashtable.hpp"
#include "coherence/util/ValueExtractor.hpp"
#include "coherence/util/extractor/PofExtractor.hpp"
#include "coherence/util/extractor/ReflectionExtractor.hpp"
#include "coherence/io/pof/SystemPofContext.hpp"

#include <iostream>
#include <sstream>
#include <ostream>
#include <string>

#include <iostream>
#include <sstream>
#include <ctime>
using namespace std;

using namespace coherence::lang;

using coherence::net::CacheFactory;
using coherence::net::NamedCache;
using coherence::util::aggregator::Integer64Sum;
using coherence::util::ValueExtractor;
using coherence::util::ValueExtractor;
using coherence::util::extractor::PofExtractor;
using coherence::util::extractor::ReflectionExtractor;
using coherence::util::filter::EqualsFilter;
using coherence::util::filter::GreaterEqualsFilter;
using coherence::util::Filter;
using coherence::util::Iterator;
using coherence::util::Hashtable;
using coherence::io::pof::SystemPofContext;

#include <stdlib.h>

int RunCompleteCppClient(int argc, char** argv) {
OrderItem::View vOrderItem;
NamedCache::Handle hCache = CacheFactory::getCache("Order");
long orderId = 2445;
cout << "Fetching Details for Order ID: " << orderId << endl;
Integer64::Handle hViewKey = Integer64::create(orderId);
Order::View vOrder = cast<Order::View>(hCache->get(hViewKey));
std::cout << "[Order ID: " << vOrder->getOrderId() << ", Order Mode: "
<< vOrder->getOrderMode() << ", Order Total: $"
<< vOrder->getOrderTotal() << ", Products Ordered = {" << std::endl;
int max = vOrder->getOrderItemList()->size();
for (int var = 0; var < max; var++) {
vOrderItem = cast<OrderItem::View>(
vOrder->getOrderItemList()->get(var));
std::cout << "ItemID: " << vOrderItem->getOrderItemPk()->getLineItemId() << ", Qty: "<< vOrderItem->getQuantity() << ", Product Name: " << vOrderItem->getInformation()->getProductName() << "#"
<< std::endl;
}
std::cout << "}" << std::endl;
hCache->release();
return 0;
}

int main(int argc, char** argv) {
RunCompleteCppClient(argc, argv);
return 0;
}

5. Run the Client

No comments: