Search in sources :

Example 21 with OrderId

use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.

the class PRTransactionDUnitTest method moveBucket.

@SuppressWarnings("unchecked")
private void moveBucket(Op op, DistributedMember dm1, DistributedMember dm2) {
    PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + CustomerPartitionedRegionName);
    CustId cust1 = new CustId(1);
    OrderId order1 = new OrderId(11, cust1);
    boolean isCust1Local = isCust1LocalSingleBucket(pr, cust1);
    DistributedMember source = isCust1Local ? dm1 : dm2;
    DistributedMember destination = isCust1Local ? dm2 : dm1;
    PartitionedRegion prOrder = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
    LogService.getLogger().info("source ={}, destination ={}", source, destination);
    switch(op) {
        case GET:
            moveBucketForGet(order1, isCust1Local, source, destination, prOrder);
            break;
        case CONTAINSVALUEFORKEY:
        case CONTAINSKEY:
        case CREATE:
        case PUT:
        case INVALIDATE:
        case DESTROY:
        case GETENTRY:
            PartitionRegionHelper.moveBucketByKey(prOrder, source, destination, order1);
            break;
        default:
            throw new AssertionError("Unknown operations " + op);
    }
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DistributedMember(org.apache.geode.distributed.DistributedMember) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 22 with OrderId

use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.

the class PerfFunction method execute.

public void execute(FunctionContext context) {
    RegionFunctionContext ctx = (RegionFunctionContext) context;
    Region customerPR = ctx.getDataSet();
    Region orderPR = customerPR.getCache().getRegion(PRColocationDUnitTest.OrderPartitionedRegionName);
    Region shipmentPR = customerPR.getCache().getRegion(PRColocationDUnitTest.ShipmentPartitionedRegionName);
    ArrayList args = (ArrayList) ctx.getArguments();
    for (int i = 0; i < args.size() / 4; i++) {
        OrderId orderId = (OrderId) args.get(i * 4);
        Order order = (Order) args.get(i * 4 + 1);
        ShipmentId shipmentId = (ShipmentId) args.get(i * 4 + 2);
        Shipment shipment = (Shipment) args.get(i * 4 + 3);
        orderPR.put(orderId, order);
        shipmentPR.put(shipmentId, shipment);
    }
    context.getResultSender().lastResult(null);
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 23 with OrderId

use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.

the class PerfTxFunction method execute.

public void execute(FunctionContext context) {
    RegionFunctionContext ctx = (RegionFunctionContext) context;
    Region customerPR = ctx.getDataSet();
    Region orderPR = customerPR.getCache().getRegion(PRColocationDUnitTest.OrderPartitionedRegionName);
    Region shipmentPR = customerPR.getCache().getRegion(PRColocationDUnitTest.ShipmentPartitionedRegionName);
    ArrayList args = (ArrayList) ctx.getArguments();
    // put the entries
    CacheTransactionManager mgr = customerPR.getCache().getCacheTransactionManager();
    mgr.begin();
    for (int i = 0; i < args.size() / 4; i++) {
        OrderId orderId = (OrderId) args.get(i * 4);
        Order order = (Order) args.get(i * 4 + 1);
        ShipmentId shipmentId = (ShipmentId) args.get(i * 4 + 2);
        Shipment shipment = (Shipment) args.get(i * 4 + 3);
        orderPR.put(orderId, order);
        shipmentPR.put(shipmentId, shipment);
    }
    mgr.commit();
    context.getResultSender().lastResult(null);
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager)

Example 24 with OrderId

use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.

the class CustomerFixedPartitionResolver method getPartitionName.

public String getPartitionName(EntryOperation opDetails, Set allAvailablePartitions) {
    int customerID = -1;
    if (opDetails.getKey() instanceof ShipmentId) {
        ShipmentId shipmentId = (ShipmentId) opDetails.getKey();
        customerID = shipmentId.getOrderId().getCustId().getCustId();
    }
    if (opDetails.getKey() instanceof OrderId) {
        OrderId orderId = (OrderId) opDetails.getKey();
        customerID = orderId.getCustId().getCustId();
    } else if (opDetails.getKey() instanceof CustId) {
        CustId custId = (CustId) opDetails.getKey();
        customerID = custId.getCustId();
    }
    if (customerID >= 1 && customerID <= 10) {
        return "10";
    } else if (customerID > 10 && customerID <= 20) {
        return "20";
    } else if (customerID > 20 && customerID <= 30) {
        return "30";
    } else if (customerID > 30 && customerID <= 40) {
        return "40";
    } else {
        return "Invalid";
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) CustId(org.apache.geode.internal.cache.execute.data.CustId) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 25 with OrderId

use of org.apache.geode.internal.cache.execute.data.OrderId in project geode by apache.

the class CustomerFixedPartitionResolver method getRoutingObject.

public Serializable getRoutingObject(EntryOperation opDetails) {
    Serializable routingbject = null;
    if (opDetails.getKey() instanceof ShipmentId) {
        ShipmentId shipmentId = (ShipmentId) opDetails.getKey();
        routingbject = shipmentId.getOrderId().getCustId();
    }
    if (opDetails.getKey() instanceof OrderId) {
        OrderId orderId = (OrderId) opDetails.getKey();
        routingbject = orderId.getCustId();
    } else if (opDetails.getKey() instanceof CustId) {
        CustId custId = (CustId) opDetails.getKey();
        routingbject = custId.getCustId();
    }
    return routingbject;
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) DataSerializable(org.apache.geode.DataSerializable) Serializable(java.io.Serializable) CustId(org.apache.geode.internal.cache.execute.data.CustId) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Aggregations

OrderId (org.apache.geode.internal.cache.execute.data.OrderId)80 CustId (org.apache.geode.internal.cache.execute.data.CustId)73 Order (org.apache.geode.internal.cache.execute.data.Order)53 Region (org.apache.geode.cache.Region)44 Customer (org.apache.geode.internal.cache.execute.data.Customer)35 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)31 ShipmentId (org.apache.geode.internal.cache.execute.data.ShipmentId)25 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)20 Test (org.junit.Test)20 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)19 IOException (java.io.IOException)17 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)16 Host (org.apache.geode.test.dunit.Host)15 IgnoredException (org.apache.geode.test.dunit.IgnoredException)15 VM (org.apache.geode.test.dunit.VM)15 ArrayList (java.util.ArrayList)13 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)12 CacheWriterException (org.apache.geode.cache.CacheWriterException)12 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)12 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)12