/*
 * 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.
 */

package org.apache.mnemonic.examples;

import org.apache.mnemonic.DurableType;
import org.apache.mnemonic.EntityFactoryProxy;
import org.apache.mnemonic.NonVolatileMemAllocator;
import org.apache.mnemonic.ParameterHolder;
import org.apache.mnemonic.RestorableAllocator;
import org.apache.mnemonic.Utils;

public class ShowOrder {

  public static void main(String[] argv) throws Exception {

    /* create a non-volatile memory pool from one of memory services */
    NonVolatileMemAllocator act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
        1024L * 1024 * 1024, "./example_order.dat", false);

    DurableType listgftypes[] = {DurableType.DURABLE};

    EntityFactoryProxy listefproxies[] = {
        new EntityFactoryProxy() {
          @Override
          public <A extends RestorableAllocator<A>> Product restore(
              A allocator, EntityFactoryProxy[] factoryproxys,
              DurableType[] gfields, long phandler, boolean autoreclaim) {
            return ProductFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
          }
          @Override
          public <A extends RestorableAllocator<A>> Product restore(ParameterHolder<A> ph) {
            return ProductFactory.restore(ph.getAllocator(),
                ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
          }
          @Override
          public <A extends RestorableAllocator<A>> Product create(
              A allocator, EntityFactoryProxy[] factoryproxys,
              DurableType[] gfields, boolean autoreclaim) {
            return ProductFactory.create(allocator, factoryproxys, gfields, autoreclaim);
          }
          @Override
          public <A extends RestorableAllocator<A>> Product create(ParameterHolder<A> ph) {
            return ProductFactory.create(ph.getAllocator(),
                ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
          }
        }
    };

    long hdl = 0L;
    for (long keyid = 1; keyid <= 3; keyid++) {
      hdl = act.getHandler(keyid);
      if (0L != hdl) {
        Order o = OrderFactory.restore(act, listefproxies, listgftypes, hdl, false);
        o.show();
      }
    }
  }
}

@@ -952,73 +952,30 @@
 nic.
-NonVolatileMemAllocator;%0Aimport org.apache.mnemonic.ParameterHold
+EntityFactoryProxyHelp
 er;%0A
@@ -1001,26 +1001,30 @@
 nemonic.
-Restorable
+NonVolatileMem
 Allocato
@@ -1496,25 +1496,16 @@
 es%5B%5D = %7B
-%0A        
 new Enti
@@ -1522,1246 +1522,38 @@
 roxy
-() %7B%0A          @Override%0A          public %3CA extends RestorableAllocator%3CA%3E%3E Product restore(%0A              A allocator, EntityFactoryProxy%5B%5D factoryproxys,%0A              DurableType%5B%5D gfields, long phandler, boolean autoreclaim) %7B%0A            return ProductFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);%0A          %7D%0A          @Override%0A          public %3CA extends RestorableAllocator%3CA%3E%3E Product restore(ParameterHolder%3CA%3E ph) %7B%0A            return ProductFactory.restore(ph.getAllocator(),%0A                ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());%0A          %7D%0A          @Override%0A          public %3CA extends RestorableAllocator%3CA%3E%3E Product create(%0A              A allocator, EntityFactoryProxy%5B%5D factoryproxys,%0A              DurableType%5B%5D gfields, boolean autoreclaim) %7B%0A            return ProductFactory.create(allocator, factoryproxys, gfields, autoreclaim);%0A          %7D%0A          @Override%0A          public %3CA extends RestorableAllocator%3CA%3E%3E Product create(ParameterHolder%3CA%3E ph) %7B%0A            return ProductFactory.create(ph.getAllocator(),%0A                ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());%0A          %7D%0A        %7D%0A   
+Helper%3CProduct%3E(Product.class)
  %7D;%0A

Simplify the example code of ShowOrder by using FactoryProxyHelper