Sunday, October 9, 2016

OWSM Log Policy

During development/debugging you are required to view the input/output SOAP messages within your SOA environment.

One of the ways to do this is viewing the message in the EM console. Another way is to enable oracle/log_policy. Enabling the policy will write all the input/output messages to diagnostic logs which is very helpful at time. The following are the steps to enable log policy

1. Attaching Log Policy to Service
2. Increasing the log level associated with the log policy.


1) Attaching Log Policy.

a. Click on the composite which contains the service against which you want to enable the logs.

 b. Click on Policy Configuration. Click on Attach/Detach Policy.

c. Select oracle/log_policy and attach it. Click on Validate and then Ok to save it.
















2) The next step is to increasing the log level associated with the log policy.

a. For this go to SOA Infrastructure->Logs->Logs configuration



b. Select View as "Loggers with Persistent log level State" & change the log level of oracle.owsm.msg.logging to Trace:32 (Finest)

































c. On saving it you would be getting confirmation of the changes.






















d. Click on the log file tab in the lab configuration screen. Here you can check to which location the log file is getting created.















Test the log policy by executing a test request. You should be able to see the SOAP Request/Response of the service against which you have associated the log policy.

Monday, June 6, 2016

Consuming Protected Rest Service in Process Cloud Service Form Rules.

Recently, I was working on a customer requirement where in I had to invoke protected REST service that returns JSON and pre-populates the Web Form. 

The below shows the steps on achieving the same.

1.     In Process Cloud (BPM) Workspace, Select Administration and Credentials
2.     In Credentials, create a new Credential for Forms Rules. The credentials should be of type "Web Form Rest Services Credential". Give the necessary details like base url, user name & password & Click Save & Log out of the work space





3.     Login to the composer and go to your web form.

  1. Click on new/existing form rules & use the below code



if(buttonClickedr.clicked) //On Click on Button
{
try {
      var uri = "https://www.protectedrestservice.com:80/PCS/previousOrder?supplierId=6666&storeId=2";
var data = http.get(uri);

      }  catch (e) {
        Desc.value = 'got exception' + e ;
   }

Desc.value = data;

Make sure the url matches the key that you had created in the workspace.

Test the form rule. You should be able to see the response from the REST invocation into the description field.


Wednesday, June 1, 2016

12 Factor Apps - What is it?

It’s a  methodology for developers to follow when building modern web-based applications. These rules are typically applied to SaaS/Cloud based/Multi-tenant application

12 Factor Apps

Code Base: One Code base for all our applications. It could be Git, SVN, etc.\
    • Can there be multiple code bases? No. If it has, this  means it’s a distributed system. So each system in distributed system should be considered as an application and then each app should follow 12 factor app rules
    • Can multiple app share the same code? Yes. But only as a library which is then managed by dependency manager
Dependencies: 12FA should be explicit about dependencies. For example having manifest that gives details of dependencies. For example if you application uses a database connection within java, never assume that server you would be deploying will have the required libraries. So you give all the required details like lib, version, etc and when you build it, the app downloads all the respective libraries

Configuration:  Different deployment may have different configuration. As a best practice, it is often said that config and code must be separate .i.e. apps that store configurations in code as constants is not acceptable.

The twelve-factor app stores these configurations in environment variables  These vars are easy to change between deploys without changing any code and unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard.


Backing Services:  It’s a service that your application may use. It could be external db connection or email connection. The code adhering to twelve-factor makes no distinction between local and third party services. To the app, both are attached resources, accessed via an URL with credentials being stored in the configuration file. For example, if the app’s database is misbehaving due to a hardware issue, the app’s administrator might spin up a new database server restored from a recent backup. The current production database could be detached, and the new database attached – all without any code changes.

Build/Release/Run: The 12FA follows strict separation of Build, Release & Run.

a.       Build Stage: Application Code is compiled. This could also fetch vendor dependencies.
b.      Release Stage: Build Stage + Configuration (specific to deploy environment)
c.       Run Stage: Actual execution of the app.

By strict separation I mean For example, it is impossible to make changes to the code at run time, since there is no way to propagate those changes back to the build stage.

Processes: 12FA processes should be stateless and share nothing. If any data needs to be shared between restarts or releases, it should be stored in the database.

Port Binding: 12FA should be totally self contained. This means any application that relies on web server is not 12FA. Instead these apps bind to port and listens to request directly.

Concurrency:  Scale out via the process model

Disposability: The twelve-factor app’s processes are disposable, meaning they can be started or stopped at a moment’s notice. This facilitates fast elastic scaling, rapid deployment of code or config changes, and robustness of production deploys.  This mean applications should have little startup time as possible and apps should be robus against sudden death.

Dev/Pro Parity: Keep Dev/QA/Production environment as close as possible. Usually there are substantial  gaps due to time any other release. The twelve-factor app is designed for continuous deployment by keeping the gap between development and production small. So in 12FA, code is moved between deployment sooner that earlier, developers are more involved with deployment process and tools used in various environments are similar.

Logs: Logs provide visibility into the behavior of a running app. In server-based environments they are commonly written to a file on disk.  A 12FA is never worried about storage of its output stream. It should not attempt to write to or manage log files. Instead, each running process writes its event stream, unbuffered, to stdout. During local development, the developer will view this stream in the foreground of their terminal to observe the app’s behavior. In production, these logs can be captured by the execution environment, collaged and routed to final destination like Splunk

Admin Processes: Run admin/management tasks as one-off processes .i.e. having scripts compared to running individual commands.

For more information, refer to the below link
http://12factor.net/


Tuesday, May 24, 2016

OEP: specified predicate requires full scan of external source which is not supported Error

Recently, I was working on a POC, which involved coherence as one of the components in building OEP application.

There was a stream of events coming up from CSV and  I had to query coherence cache for correlation.  While building the application, I receved the below error

Invalid statement: "alter query >>GroupingQuery<< start"
Description: specified predicate requires full scan of external source which is not supported
Cause: specified predicate requires full scan of external source which is not supported
Action: please modify the join predicate

As per the documentation, the above error comes up if cache key is not used in the query, but in our case, it is one of the parameters within the query.

My CQL query was

<query id="GroupingQuery"><![CDATA[
select c.posid, c.tid as totalCount, c.tvalue as totalAmount, p.posname as POSNAME, p.poscity as POSCITY
from CSVIntoProcessor [now] as c, Pos as p
where p.posid<!-- java.lang.Integer -> = c.posid<!-- int ->]]></query>

Pos is my coherence & Posid was my coherence key.

After spending hrs in fixing this, I was able to fix this which was nothing but a data type issue.

To debug I first enable the cache logs

1. Go to ORACLE_CEP_HOME/user_projects/domains/DOMAIN_DIR/servername/config & edit config.xml & change the default values from Notice to Debug

<entry>
        <key>Cache</key>
        <value> Debug </value>
</entry>
<entry>
        <key>CQLProcessor</key>
        <value> Debug </value>
</entry>
<entry>
        <key>CQLEngine</key>
        <value> Debug </value>
</entry>
<entry>
        <key>CQLEngineTrace</key>
        <value>Debug</value>
</entry>


2. Restart the server and check the logs after deploying your app and look for the below lines

####<May 23, 2015 8:29:52 PM PDT> <Info> <CQLProcessor> <> <defaultserver> <SpringOsgiExtenderThread-154> <> <> <> <1464060592137> <BEA-000000> <execute DDL [register external relation Pos(posid java.lang.Integer, posname char(2147483647), poscity char(2147483647), _this oracle.coherence.Pos)]> 

####<May 23, 2016 8:29:52 PM PDT> <Info> <CQLProcessor> <> <defaultserver> <SpringOsgiExtenderThread-154> <> <> <> <1464060592168> <BEA-000000> <execute DDL [register stream channel(posId int, tDate java.util.Date, tValue float, tId int, cId int, _this com.oracle.oep.Transactions) is system timestamped]> 



3. Carefully observe the key data types. The external relation pos  key is java.lang.Integer, where as the key in my stream channel is posId which is int. (Shown this in red in the error message)

4. Change the data type of the external schema from java.lang.Integer to int and redeply the app, the issue should be fixed. Ideally , that shouldn't have been the problem since java offers auto-boxing but never the less, I am glad that this worked.

Happy Learning!!



OEP - Hello World

This blog will walk you thru building a very basic OEP application. components. So this application reads a csv file. The csv file contains list of transactions and contains data like TransactionID, CustomerID, TrasactionValue. In this blog, we will be reading the CSV file and output it to the console.

1. Create new OEP Jdeveloper Project

2. Create supporting java classes

i. Right click on the OEP Project and select "Create New Java Class"



ii. Create a Class named "Transaction" & create private members within it (trasactionID:int, customerId:int, transactionValue:float). Create the setters/getters with it.

package demoprj;

public class Transaction {
    
    int transactionId;
    
    float transactionValue;
    
    int customerId;
    
    public Transaction() {
        super();
    }

    public void setTransactionId(int transactionId) {
        this.transactionId = transactionId;
    }

    public int getTransactionId() {
        return transactionId;
    }

    public void setTransactionValue(float transactionValue) {
        this.transactionValue = transactionValue;
    }

    public float getTransactionValue() {
        return transactionValue;
    }

    public void setCustomerId(int customerId) {
        this.customerId = customerId;
    }


    @Override
    public String toString() {
        // TODO Implement this method
        return new Integer(transactionId).toString();

    }

    public int getCustomerId() {
        return customerId;
    }
}

iii. Create another class named "TransactionListener". This class implements com.bea.wlevs.ede.api.StreamSink. 

package demoprj;

import com.bea.wlevs.ede.api.EventRejectedException;
import com.bea.wlevs.ede.api.StreamSink;

public class TransactionListener implements StreamSink {
    public TransactionListner() {
        super();
    }

    @Override
    public void onInsertEvent(Object object) throws EventRejectedException {
        if (object instanceof Transaction) {
        Transaction transactionEvent = (Transaction) object;
        System.out.println("Event: " + transactionEvent);
        }
    }
}


2. Create supporting Event Types

i. Click on the EPN Diagram from the left navigation and click on Event Type Tab & Click on the + icon to create new event Type




ii. Create a new event type named "Transaction" and associated the recently created Transaction java class. Save the project.



3. Drag CSVInbound from the advanced adapter to the EPN Diagram







i. This opens up the CSVInbound configuration screen. Leave the default as its .i.e. Adapter ID: csv-inbound-adapter and configuration location as: processes.xml & Click Next



ii. Select the event type as "Transaction", Source URL as "file:///demo/transaction.csv (this would change depending upon your environment), Event Interval as 1 & Initial Delay as 2 & Click Finish


iii. You should see the csv-inbound-adapter in your EPN diagram as shown in the diagram.


4. Configure: Channels is away by which you can transfer events from one stage to another in the EPN. 



i. Drag Channel from EPN components to EPN Page

ii. Select eventType as Transaction and leave default values to channelID


iii. Re Do the above to steps and name the channel ID as output channel & event type to Transaction.

5. Configure Beans: Beans are listener events, that receive events from the channel and works on those events. In my blog ,I am going to print the information to the console.

i. Drag Bean to EPN diagram




ii. Select bean class to "demoprj.TransactionListner" & leave the bean ID to default



6. The final step is to add a Processor. The process would be added between the channel & output channel. The Oracle CQL code queries the events sent to the processor from Channel. In a real-world scenario, this component typically executes additional and possibly much more processing of the events from the stream, such as selecting a subset of events based on a property value, grouping events, and so on using Oracle CQL.

i. Drag Processor component on the EPN Diagram.




ii. Without changing the default values click Ok (Processor ID: processor & FileName: Processor.xml)



iii. Right click on the dropped component and click on "Go to Configuration Source"


iv. Make sure channel name is correct. The correct query should be

<rules>
      <query id="ExampleQuery"><![CDATA[ 
 select * from channel [now] ]]></query>
    </rules>

7. Connect CSV Inbound adapter to channel,channel to processor, processor to outputchannel and output channel to bean.,  & refresh it. The EPN diagram should look like the below


8. Right-click the OEP project and select Deploy > New Deployment Profile.

Monitor the Server Console, you should be able to see the output as shown below





Sample Content of CSV file being used in this blog

transactionId,transactionValue,customerId
1,10.5,5001
2,10.5,5001
3,10.5,5001
4,10.5,5002
5,10.5,5004

OEP - Creating New OEP Project in Jdeveloper

In this blog, you will learn how to create new OEP application using J Developer

1. Open Jdeveloper

2. Click File->New->Application and Select OEP application & Click Ok


3. Give the application details like application name, prefix, directory structure etc. & Click Next


4. Give Project details like project name & directory. Note the project features that has been added to the application. You should see Java, XML & OEP Suite in the project feature section


5. Configure Java Settings. The default packaged mentioned here will used to store all OEP related java classes.




6. In the next window, select Empty OEP Project & Click on + icon to create OEP Server Connection. Give your OEP server details which could be either remote or local.






7. Click Ok->Finish. This will create new OEP Project




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