You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/05/22 13:22:26 UTC

[2/9] git commit: [OLINGO-260] Enhancement: non-static context

[OLINGO-260] Enhancement: non-static context


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/e897cf27
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/e897cf27
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/e897cf27

Branch: refs/heads/master
Commit: e897cf27f5b582124dc11fef4d9355b245ca3eea
Parents: 96c4551
Author: Francesco Chicchiriccò <--global>
Authored: Fri May 16 14:25:35 2014 +0200
Committer: Francesco Chicchiriccò <--global>
Committed: Fri May 16 14:25:35 2014 +0200

----------------------------------------------------------------------
 .../ext/proxy/EntityContainerFactory.java       |  39 ++---
 .../commons/AbstractInvocationHandler.java      |  36 ++--
 .../commons/AbstractTypeInvocationHandler.java  |  41 ++---
 .../ComplexFactoryInvocationHandler.java        |  17 +-
 .../commons/ComplexTypeInvocationHandler.java   |  40 +----
 .../olingo/ext/proxy/commons/ContainerImpl.java | 103 ++++++------
 .../EntityCollectionInvocationHandler.java      |   2 +-
 .../EntityContainerInvocationHandler.java       |  19 +--
 .../commons/EntitySetInvocationHandler.java     |  56 +++----
 .../commons/EntityTypeInvocationHandler.java    |  44 +----
 .../commons/OperationInvocationHandler.java     |  30 ++--
 .../commons/SingletonInvocationHandler.java     |   2 +-
 .../olingo/ext/proxy/utils/CoreUtils.java       |  31 ++--
 .../olingo/fit/proxy/v3/AbstractTestITCase.java |   5 +-
 .../proxy/v3/ActionOverloadingTestITCase.java   |   8 +-
 .../olingo/fit/proxy/v3/ContextTestITCase.java  | 165 ++++++++++---------
 .../fit/proxy/v3/EntityCreateTestITCase.java    |   8 +-
 .../olingo/fit/proxy/v3/OpenTypeTestITCase.java |   4 +-
 .../olingo/fit/proxy/v3/PropertyTestITCase.java |   7 +-
 .../olingo/fit/proxy/v4/AbstractTestITCase.java |   9 +-
 .../fit/proxy/v4/EntityCreateTestITCase.java    |   4 +-
 .../olingo/fit/proxy/v4/OpenTypeTestITCase.java |   4 +-
 .../olingo/fit/proxy/v4/PropertyTestITCase.java |   3 +-
 23 files changed, 302 insertions(+), 375 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
index c378a7a..83eb855 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
@@ -21,7 +21,6 @@ package org.apache.olingo.ext.proxy;
 import java.lang.reflect.Proxy;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.client.core.ODataClientFactory;
 import org.apache.olingo.commons.api.format.ODataPubFormat;
@@ -35,35 +34,17 @@ import org.apache.olingo.ext.proxy.context.Context;
  */
 public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<?>> {
 
-  private static final Object MONITOR = new Object();
-
-  private static Context context = null;
-
   private static final Map<String, EntityContainerFactory<?>> FACTORY_PER_SERVICEROOT =
           new ConcurrentHashMap<String, EntityContainerFactory<?>>();
 
   private static final Map<Class<?>, Object> ENTITY_CONTAINERS = new ConcurrentHashMap<Class<?>, Object>();
 
-  private final CommonEdmEnabledODataClient<?> client;
-
-  private final String serviceRoot;
-
-  public static Context getContext() {
-    synchronized (MONITOR) {
-      if (context == null) {
-        context = new Context();
-      }
-    }
-
-    return context;
-  }
-
   @SuppressWarnings("unchecked")
   private static <C extends CommonEdmEnabledODataClient<?>> EntityContainerFactory<C> getInstance(
           final C client, final String serviceRoot) {
 
     if (!FACTORY_PER_SERVICEROOT.containsKey(serviceRoot)) {
-      final EntityContainerFactory<C> instance = new EntityContainerFactory<C>(client, serviceRoot);
+      final EntityContainerFactory<C> instance = new EntityContainerFactory<C>(client);
       FACTORY_PER_SERVICEROOT.put(serviceRoot, instance);
     }
     client.getConfiguration().setDefaultPubFormat(ODataPubFormat.JSON_FULL_METADATA);
@@ -83,9 +64,13 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
     return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot), serviceRoot);
   }
 
-  private EntityContainerFactory(final CommonEdmEnabledODataClient<?> client, final String serviceRoot) {
+  private final CommonEdmEnabledODataClient<?> client;
+
+  private final Context context;
+
+  private EntityContainerFactory(final CommonEdmEnabledODataClient<?> client) {
     this.client = client;
-    this.serviceRoot = serviceRoot;
+    this.context = new Context();
   }
 
   @SuppressWarnings("unchecked")
@@ -93,8 +78,8 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
     return (C) client;
   }
 
-  public String getServiceRoot() {
-    return serviceRoot;
+  public Context getContext() {
+    return context;
   }
 
   /**
@@ -107,15 +92,11 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
    * @throws IllegalArgumentException if the passed reference is not an interface annotated as EntityContainer
    */
   public <T> T getEntityContainer(final Class<T> reference) throws IllegalStateException, IllegalArgumentException {
-    if (StringUtils.isBlank(serviceRoot)) {
-      throw new IllegalStateException("serviceRoot was not set");
-    }
-
     if (!ENTITY_CONTAINERS.containsKey(reference)) {
       final Object entityContainer = Proxy.newProxyInstance(
               Thread.currentThread().getContextClassLoader(),
               new Class<?>[] {reference},
-              EntityContainerInvocationHandler.getInstance(client, reference, this));
+              EntityContainerInvocationHandler.getInstance(reference, this));
       ENTITY_CONTAINERS.put(reference, entityContainer);
     }
     return reference.cast(ENTITY_CONTAINERS.get(reference));

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
index 5181b48..e16c96e 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
@@ -46,6 +46,7 @@ import org.apache.olingo.ext.proxy.EntityContainerFactory;
 import org.apache.olingo.ext.proxy.api.OperationType;
 import org.apache.olingo.ext.proxy.api.annotations.Operation;
 import org.apache.olingo.ext.proxy.api.annotations.Parameter;
+import org.apache.olingo.ext.proxy.context.Context;
 import org.apache.olingo.ext.proxy.utils.ClassUtils;
 import org.apache.olingo.ext.proxy.utils.CoreUtils;
 
@@ -53,19 +54,24 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
 
   private static final long serialVersionUID = 358520026931462958L;
 
-  protected final CommonEdmEnabledODataClient<?> client;
+  protected EntityContainerFactory<?> factory;
 
   protected EntityContainerInvocationHandler containerHandler;
 
-  protected AbstractInvocationHandler(
-          final CommonEdmEnabledODataClient<?> client, final EntityContainerInvocationHandler containerHandler) {
+  protected AbstractInvocationHandler(final EntityContainerFactory<?> factory) {
+    this.factory = factory;
+  }
 
-    this.client = client;
+  protected AbstractInvocationHandler(final EntityContainerInvocationHandler containerHandler) {
     this.containerHandler = containerHandler;
   }
 
   protected CommonEdmEnabledODataClient<?> getClient() {
-    return client;
+    return factory == null ? containerHandler.getClient() : factory.getClient();
+  }
+
+  protected Context getContext() {
+    return factory == null ? containerHandler.getContext() : factory.getContext();
   }
 
   protected boolean isSelfMethod(final Method method, final Object[] args) {
@@ -98,8 +104,7 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
     final List<Object> items = new ArrayList<Object>();
 
     for (CommonODataEntity entityFromSet : entitySet.getEntities()) {
-      items.add(getEntityProxy(
-              entityFromSet, entityContainerName, null, typeRef, checkInTheContext));
+      items.add(getEntityProxy(entityFromSet, entityContainerName, null, typeRef, checkInTheContext));
     }
 
     return Proxy.newProxyInstance(
@@ -135,8 +140,8 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
       handler.setETag(eTag);
     }
 
-    if (checkInTheContext && EntityContainerFactory.getContext().entityContext().isAttached(handler)) {
-      handler = EntityContainerFactory.getContext().entityContext().getEntity(handler.getUUID());
+    if (checkInTheContext && getContext().entityContext().isAttached(handler)) {
+      handler = getContext().entityContext().getEntity(handler.getUUID());
     }
 
     return (T) Proxy.newProxyInstance(
@@ -165,11 +170,11 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
         }
 
         final EdmTypeInfo type = new EdmTypeInfo.Builder().
-                setEdm(client.getCachedEdm()).setTypeExpression(parameter.getKey().type()).build();
+                setEdm(getClient().getCachedEdm()).setTypeExpression(parameter.getKey().type()).build();
 
         final ODataValue paramValue = parameter.getValue() == null
                 ? null
-                : CoreUtils.getODataValue(client, type, parameter.getValue());
+                : CoreUtils.getODataValue(getClient(), type, parameter.getValue());
 
         parameterValues.put(parameter.getKey().name(), paramValue);
       }
@@ -177,11 +182,11 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
 
     // 2. IMPORTANT: flush any pending change *before* invoke if this operation is side effecting
     if (annotation.type() == OperationType.ACTION) {
-      new ContainerImpl(client, containerHandler.getFactory()).flush();
+      new ContainerImpl(containerHandler.getFactory()).flush();
     }
 
     // 3. invoke
-    final ODataInvokeResult result = client.getInvokeRequestFactory().getInvokeRequest(
+    final ODataInvokeResult result = getClient().getInvokeRequestFactory().getInvokeRequest(
             target, edmOperation, parameterValues).execute().getBody();
 
     // 4. process invoke result
@@ -190,7 +195,7 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
     }
 
     final EdmTypeInfo edmType = new EdmTypeInfo.Builder().
-            setEdm(client.getCachedEdm()).setTypeExpression(annotation.returnType()).build();
+            setEdm(getClient().getCachedEdm()).setTypeExpression(annotation.returnType()).build();
 
     if (edmType.isEntityType()) {
       if (edmType.isCollection()) {
@@ -212,7 +217,8 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
                 false);
       }
     } else {
-      return CoreUtils.getValueFromProperty(client, (CommonODataProperty) result, method.getGenericReturnType(), null);
+      return CoreUtils.getValueFromProperty(
+              getClient(), (CommonODataProperty) result, method.getGenericReturnType(), null);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractTypeInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractTypeInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractTypeInvocationHandler.java
index 169ddfe..0923fbe 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractTypeInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractTypeInvocationHandler.java
@@ -24,10 +24,8 @@ import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
 import java.net.URI;
-import java.util.Collection;
 import java.util.Collections;
 import org.apache.commons.lang3.ArrayUtils;
-import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
 import org.apache.olingo.client.core.uri.URIUtils;
 import org.apache.olingo.commons.api.domain.CommonODataEntity;
@@ -35,13 +33,11 @@ import org.apache.olingo.commons.api.domain.ODataInlineEntity;
 import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
 import org.apache.olingo.commons.api.domain.ODataLink;
 import org.apache.olingo.commons.api.domain.ODataLinked;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
 import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
 import org.apache.olingo.ext.proxy.api.annotations.EntityType;
 import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty;
 import org.apache.olingo.ext.proxy.api.annotations.Property;
 import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
-import org.apache.olingo.ext.proxy.context.EntityContext;
 import org.apache.olingo.ext.proxy.utils.ClassUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,31 +53,27 @@ public abstract class AbstractTypeInvocationHandler extends AbstractInvocationHa
 
   protected final Class<?> typeRef;
 
-  protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
-
   protected EntityTypeInvocationHandler entityHandler;
 
   protected Object internal;
 
   protected AbstractTypeInvocationHandler(
-          final CommonEdmEnabledODataClient<?> client,
           final Class<?> typeRef,
           final Object internal,
           final EntityContainerInvocationHandler containerHandler) {
 
-    super(client, containerHandler);
+    super(containerHandler);
     this.internal = internal;
     this.typeRef = typeRef;
     this.entityHandler = EntityTypeInvocationHandler.class.cast(this);
   }
 
   protected AbstractTypeInvocationHandler(
-          final CommonEdmEnabledODataClient<?> client,
           final Class<?> typeRef,
           final Object internal,
           final EntityTypeInvocationHandler entityHandler) {
 
-    super(client, entityHandler == null ? null : entityHandler.containerHandler);
+    super(entityHandler == null ? null : entityHandler.containerHandler);
     this.internal = internal;
     this.typeRef = typeRef;
     this.entityHandler = entityHandler;
@@ -91,7 +83,7 @@ public abstract class AbstractTypeInvocationHandler extends AbstractInvocationHa
     return entityHandler;
   }
 
-  public void setEntityHandler(EntityTypeInvocationHandler entityHandler) {
+  public void setEntityHandler(final EntityTypeInvocationHandler entityHandler) {
     this.entityHandler = entityHandler;
   }
 
@@ -170,8 +162,8 @@ public abstract class AbstractTypeInvocationHandler extends AbstractInvocationHa
   }
 
   protected void attach() {
-    if (entityHandler != null && !entityContext.isAttached(entityHandler)) {
-      entityContext.attach(entityHandler, AttachedEntityStatus.ATTACHED);
+    if (entityHandler != null && !getContext().entityContext().isAttached(entityHandler)) {
+      getContext().entityContext().attach(entityHandler, AttachedEntityStatus.ATTACHED);
     }
   }
 
@@ -180,12 +172,12 @@ public abstract class AbstractTypeInvocationHandler extends AbstractInvocationHa
   }
 
   protected void attach(final AttachedEntityStatus status, final boolean override) {
-    if (entityContext.isAttached(entityHandler)) {
+    if (getContext().entityContext().isAttached(entityHandler)) {
       if (override) {
-        entityContext.setStatus(entityHandler, status);
+        getContext().entityContext().setStatus(entityHandler, status);
       }
     } else {
-      entityContext.attach(entityHandler, status);
+      getContext().entityContext().attach(entityHandler, status);
     }
   }
 
@@ -224,20 +216,19 @@ public abstract class AbstractTypeInvocationHandler extends AbstractInvocationHa
               false);
     } else {
       // navigate
-      final URI uri = URIUtils.getURI(
-              containerHandler.getFactory().getServiceRoot(), link.getLink().toASCIIString());
+      final URI uri = URIUtils.getURI(getClient().getServiceRoot(), link.getLink().toASCIIString());
 
       if (AbstractEntityCollection.class.isAssignableFrom(type)) {
         navPropValue = getEntityCollection(
                 collItemType,
                 type,
                 property.targetContainer(),
-                client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody(),
+                getClient().getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody(),
                 uri,
                 true);
       } else {
         final ODataRetrieveResponse<CommonODataEntity> res =
-                client.getRetrieveRequestFactory().getEntityRequest(uri).execute();
+                getClient().getRetrieveRequestFactory().getEntityRequest(uri).execute();
 
         navPropValue = getEntityProxy(
                 res.getBody(),
@@ -267,12 +258,10 @@ public abstract class AbstractTypeInvocationHandler extends AbstractInvocationHa
     return getPropertyValue(name, null);
   }
 
-  public abstract Collection<String> getAdditionalPropertyNames();
-
   private void setNavigationPropertyValue(final NavigationProperty property, final Object value) {
     // 1) attach source entity
-    if (!entityContext.isAttached(entityHandler)) {
-      entityContext.attach(entityHandler, AttachedEntityStatus.CHANGED);
+    if (!getContext().entityContext().isAttached(entityHandler)) {
+      getContext().entityContext().attach(entityHandler, AttachedEntityStatus.CHANGED);
     }
 
     // 2) attach the target entity handlers
@@ -289,8 +278,8 @@ public abstract class AbstractTypeInvocationHandler extends AbstractInvocationHa
         throw new IllegalArgumentException("Invalid argument type " + linkedHandler.getTypeRef().getSimpleName());
       }
 
-      if (!entityContext.isAttached(linkedHandler)) {
-        entityContext.attach(linkedHandler, AttachedEntityStatus.LINKED);
+      if (!getContext().entityContext().isAttached(linkedHandler)) {
+        getContext().entityContext().attach(linkedHandler, AttachedEntityStatus.LINKED);
       }
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
index 2f833c6..c20e476 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexFactoryInvocationHandler.java
@@ -20,7 +20,6 @@ package org.apache.olingo.ext.proxy.commons;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.ext.proxy.api.OperationExecutor;
 import org.apache.olingo.ext.proxy.api.annotations.Property;
 import org.apache.olingo.ext.proxy.utils.ClassUtils;
@@ -34,32 +33,33 @@ class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implemen
   private final AbstractTypeInvocationHandler invokerHandler;
 
   static ComplexFactoryInvocationHandler getInstance(
-          final CommonEdmEnabledODataClient<?> client,
           final EntityContainerInvocationHandler containerHandler,
           final EntityTypeInvocationHandler entityHandler,
           final AbstractTypeInvocationHandler targetHandler) {
 
-    return new ComplexFactoryInvocationHandler(client, containerHandler, entityHandler, targetHandler);
+    return new ComplexFactoryInvocationHandler(containerHandler, entityHandler, targetHandler);
   }
 
   static ComplexFactoryInvocationHandler getInstance(
           final EntityTypeInvocationHandler entityHandler,
           final AbstractTypeInvocationHandler targetHandler) {
+
     return new ComplexFactoryInvocationHandler(
-            entityHandler == null ? null : entityHandler.containerHandler.client,
             targetHandler == null
-            ? entityHandler == null ? null : entityHandler.containerHandler : targetHandler.containerHandler,
+            ? entityHandler == null
+            ? null
+            : entityHandler.containerHandler
+            : targetHandler.containerHandler,
             entityHandler,
             targetHandler);
   }
 
   private ComplexFactoryInvocationHandler(
-          final CommonEdmEnabledODataClient<?> client,
           final EntityContainerInvocationHandler containerHandler,
           final EntityTypeInvocationHandler entityHandler,
           final AbstractTypeInvocationHandler targetHandler) {
 
-    super(client, containerHandler);
+    super(containerHandler);
     this.invokerHandler = targetHandler;
     this.entityHandler = entityHandler;
   }
@@ -78,7 +78,8 @@ class ComplexFactoryInvocationHandler extends AbstractInvocationHandler implemen
       return Proxy.newProxyInstance(
               Thread.currentThread().getContextClassLoader(),
               new Class<?>[] {method.getReturnType()},
-              ComplexTypeInvocationHandler.getInstance(client, property.name(), method.getReturnType(), entityHandler));
+              ComplexTypeInvocationHandler.getInstance(
+                      getClient(), property.name(), method.getReturnType(), entityHandler));
     } else {
       throw new NoSuchMethodException(method.getName());
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java
index 2175e8c..2b5dcdd 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexTypeInvocationHandler.java
@@ -18,15 +18,11 @@
  */
 package org.apache.olingo.ext.proxy.commons;
 
-import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
 import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.commons.api.domain.CommonODataProperty;
 import org.apache.olingo.commons.api.domain.ODataComplexValue;
@@ -69,8 +65,7 @@ public class ComplexTypeInvocationHandler extends AbstractTypeInvocationHandler
     final ODataComplexValue<? extends CommonODataProperty> complex =
             client.getObjectFactory().newComplexValue(typeName.toString());
 
-    return (ComplexTypeInvocationHandler) ComplexTypeInvocationHandler.getInstance(
-            client, complex, complexTypeRef, handler);
+    return new ComplexTypeInvocationHandler(client, complex, complexTypeRef, handler);
   }
 
   public static ComplexTypeInvocationHandler getInstance(
@@ -82,13 +77,16 @@ public class ComplexTypeInvocationHandler extends AbstractTypeInvocationHandler
     return new ComplexTypeInvocationHandler(client, complex, typeRef, handler);
   }
 
-  public ComplexTypeInvocationHandler(
+  private final CommonEdmEnabledODataClient<?> client;
+
+  private ComplexTypeInvocationHandler(
           final CommonEdmEnabledODataClient<?> client,
           final ODataComplexValue<?> complex,
           final Class<?> typeRef,
           final EntityTypeInvocationHandler handler) {
 
-    super(client, typeRef, complex, handler);
+    super(typeRef, complex, handler);
+    this.client = client;
   }
 
   @SuppressWarnings("unchecked")
@@ -106,28 +104,6 @@ public class ComplexTypeInvocationHandler extends AbstractTypeInvocationHandler
   }
 
   @Override
-  public Collection<String> getAdditionalPropertyNames() {
-    final Set<String> res = new HashSet<String>();
-    final Set<String> propertyNames = new HashSet<String>();
-    for (Method method : typeRef.getMethods()) {
-      final Annotation ann = method.getAnnotation(Property.class);
-      if (ann != null) {
-        final String property = ((Property) ann).name();
-        propertyNames.add(property);
-      }
-    }
-
-    for (final Iterator<? extends CommonODataProperty> itor = getComplex().iterator(); itor.hasNext();) {
-      final CommonODataProperty property = itor.next();
-      if (!propertyNames.contains(property.getName())) {
-        res.add(property.getName());
-      }
-    }
-
-    return res;
-  }
-
-  @Override
   @SuppressWarnings("unchecked")
   protected void setPropertyValue(final Property property, final Object value) {
     final FullQualifiedName fqn =
@@ -155,8 +131,8 @@ public class ComplexTypeInvocationHandler extends AbstractTypeInvocationHandler
 
     client.getBinder().add(getComplex(), CoreUtils.getODataProperty(client, property.name(), type, toBeAdded));
 
-    if (entityHandler != null && !entityContext.isAttached(entityHandler)) {
-      entityContext.attach(entityHandler, AttachedEntityStatus.CHANGED);
+    if (entityHandler != null && !getContext().entityContext().isAttached(entityHandler)) {
+      getContext().entityContext().attach(entityHandler, AttachedEntityStatus.CHANGED);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
index ab824ec..2879f5f 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ContainerImpl.java
@@ -30,7 +30,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.client.api.communication.header.ODataPreferences;
 import org.apache.olingo.client.api.communication.request.ODataRequest;
 import org.apache.olingo.client.api.communication.request.ODataStreamedRequest;
@@ -73,12 +72,9 @@ class ContainerImpl implements Container {
    */
   private static final Logger LOG = LoggerFactory.getLogger(ContainerImpl.class);
 
-  private final CommonEdmEnabledODataClient<?> client;
+  private final EntityContainerFactory<?> factory;
 
-  private final EntityContainerFactory factory;
-
-  ContainerImpl(final CommonEdmEnabledODataClient<?> client, final EntityContainerFactory factory) {
-    this.client = client;
+  ContainerImpl(final EntityContainerFactory<?> factory) {
     this.factory = factory;
   }
 
@@ -87,8 +83,9 @@ class ContainerImpl implements Container {
    */
   @Override
   public void flush() {
-    final CommonODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(client.getServiceRoot());
-    ((ODataRequest)request).setAccept(client.getConfiguration().getDefaultBatchAcceptFormat());
+    final CommonODataBatchRequest request =
+            factory.getClient().getBatchRequestFactory().getBatchRequest(factory.getClient().getServiceRoot());
+    ((ODataRequest) request).setAccept(factory.getClient().getConfiguration().getDefaultBatchAcceptFormat());
 
     final BatchStreamManager streamManager = (BatchStreamManager) ((ODataStreamedRequest) request).execute();
 
@@ -99,7 +96,7 @@ class ContainerImpl implements Container {
 
     int pos = 0;
 
-    for (AttachedEntity attachedEntity : EntityContainerFactory.getContext().entityContext()) {
+    for (AttachedEntity attachedEntity : factory.getContext().entityContext()) {
       final AttachedEntityStatus status = attachedEntity.getStatus();
       if (((status != AttachedEntityStatus.ATTACHED
               && status != AttachedEntityStatus.LINKED) || attachedEntity.getEntity().isChanged())
@@ -113,8 +110,11 @@ class ContainerImpl implements Container {
 
     final ODataBatchResponse response = streamManager.getResponse();
 
-    if ((client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0 && response.getStatusCode() != 202)
-            || (client.getServiceVersion().compareTo(ODataServiceVersion.V30) > 0 && response.getStatusCode() != 200)) {
+    if ((factory.getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
+            && response.getStatusCode() != 202)
+            || (factory.getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) > 0
+            && response.getStatusCode() != 200)) {
+
       throw new IllegalStateException("Operation failed");
     }
 
@@ -152,7 +152,7 @@ class ContainerImpl implements Container {
       }
     }
 
-    EntityContainerFactory.getContext().detachAll();
+    factory.getContext().detachAll();
   }
 
   private void batch(
@@ -160,7 +160,7 @@ class ContainerImpl implements Container {
           final CommonODataEntity entity,
           final ODataChangeset changeset) {
 
-    switch (EntityContainerFactory.getContext().entityContext().getStatus(handler)) {
+    switch (factory.getContext().entityContext().getStatus(handler)) {
       case NEW:
         batchCreate(handler, entity, changeset);
         break;
@@ -187,9 +187,9 @@ class ContainerImpl implements Container {
 
     LOG.debug("Create '{}'", handler);
 
-    final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(factory.getServiceRoot()).
+    final CommonURIBuilder<?> uriBuilder = factory.getClient().getURIBuilder(factory.getClient().getServiceRoot()).
             appendEntitySetSegment(handler.getEntitySetName());
-    changeset.addRequest(client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), entity));
+    changeset.addRequest(factory.getClient().getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), entity));
   }
 
   private void batchUpdateMediaEntity(
@@ -201,7 +201,7 @@ class ContainerImpl implements Container {
     LOG.debug("Update media entity '{}'", uri);
 
     final ODataMediaEntityUpdateRequest<?> req =
-            client.getStreamedRequestFactory().getMediaEntityUpdateRequest(uri, input);
+            factory.getClient().getStreamedRequestFactory().getMediaEntityUpdateRequest(uri, input);
 
     req.setContentType(StringUtils.isBlank(handler.getEntity().getMediaContentType())
             ? ODataMediaFormat.WILDCARD.toString()
@@ -222,7 +222,8 @@ class ContainerImpl implements Container {
 
     LOG.debug("Update media entity '{}'", uri);
 
-    final ODataStreamUpdateRequest req = client.getStreamedRequestFactory().getStreamUpdateRequest(uri, input);
+    final ODataStreamUpdateRequest req = factory.getClient().
+            getStreamedRequestFactory().getStreamUpdateRequest(uri, input);
 
     if (StringUtils.isNotBlank(handler.getETag())) {
       req.setIfMatch(handler.getETag());
@@ -239,13 +240,13 @@ class ContainerImpl implements Container {
     LOG.debug("Update '{}'", changes.getEditLink());
 
     final ODataEntityUpdateRequest<CommonODataEntity> req =
-            client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
-            ? ((org.apache.olingo.client.api.v3.EdmEnabledODataClient) client).getCUDRequestFactory().
+            factory.getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
+            ? ((org.apache.olingo.client.api.v3.EdmEnabledODataClient) factory.getClient()).getCUDRequestFactory().
             getEntityUpdateRequest(org.apache.olingo.client.api.communication.request.cud.v3.UpdateType.PATCH, changes)
-            : ((org.apache.olingo.client.api.v4.EdmEnabledODataClient) client).getCUDRequestFactory().
+            : ((org.apache.olingo.client.api.v4.EdmEnabledODataClient) factory.getClient()).getCUDRequestFactory().
             getEntityUpdateRequest(org.apache.olingo.client.api.communication.request.cud.v4.UpdateType.PATCH, changes);
 
-    req.setPrefer(new ODataPreferences(client.getServiceVersion()).returnContent());
+    req.setPrefer(new ODataPreferences(factory.getClient().getServiceVersion()).returnContent());
 
     if (StringUtils.isNotBlank(handler.getETag())) {
       req.setIfMatch(handler.getETag());
@@ -263,15 +264,15 @@ class ContainerImpl implements Container {
     LOG.debug("Update '{}'", uri);
 
     final ODataEntityUpdateRequest<CommonODataEntity> req =
-            client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
-            ? ((org.apache.olingo.client.api.v3.EdmEnabledODataClient) client).getCUDRequestFactory().
+            factory.getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
+            ? ((org.apache.olingo.client.api.v3.EdmEnabledODataClient) factory.getClient()).getCUDRequestFactory().
             getEntityUpdateRequest(
-            uri, org.apache.olingo.client.api.communication.request.cud.v3.UpdateType.PATCH, changes)
-            : ((org.apache.olingo.client.api.v4.EdmEnabledODataClient) client).getCUDRequestFactory().
+                    uri, org.apache.olingo.client.api.communication.request.cud.v3.UpdateType.PATCH, changes)
+            : ((org.apache.olingo.client.api.v4.EdmEnabledODataClient) factory.getClient()).getCUDRequestFactory().
             getEntityUpdateRequest(
-            uri, org.apache.olingo.client.api.communication.request.cud.v4.UpdateType.PATCH, changes);
+                    uri, org.apache.olingo.client.api.communication.request.cud.v4.UpdateType.PATCH, changes);
 
-    req.setPrefer(new ODataPreferences(client.getServiceVersion()).returnContent());
+    req.setPrefer(new ODataPreferences(factory.getClient().getServiceVersion()).returnContent());
 
     if (StringUtils.isNotBlank(handler.getETag())) {
       req.setIfMatch(handler.getETag());
@@ -287,8 +288,8 @@ class ContainerImpl implements Container {
 
     LOG.debug("Delete '{}'", entity.getEditLink());
 
-    final ODataDeleteRequest req = client.getCUDRequestFactory().getDeleteRequest(URIUtils.getURI(
-            factory.getServiceRoot(), entity.getEditLink().toASCIIString()));
+    final ODataDeleteRequest req = factory.getClient().getCUDRequestFactory().getDeleteRequest(
+            URIUtils.getURI(factory.getClient().getServiceRoot(), entity.getEditLink().toASCIIString()));
 
     if (StringUtils.isNotBlank(handler.getETag())) {
       req.setIfMatch(handler.getETag());
@@ -311,11 +312,11 @@ class ContainerImpl implements Container {
     final CommonODataEntity entity = handler.getEntity();
     entity.getNavigationLinks().clear();
 
-    final AttachedEntityStatus currentStatus = EntityContainerFactory.getContext().entityContext().getStatus(handler);
+    final AttachedEntityStatus currentStatus = factory.getContext().entityContext().getStatus(handler);
 
     if (AttachedEntityStatus.DELETED != currentStatus) {
       entity.getProperties().clear();
-      CoreUtils.addProperties(client, handler.getPropertyChanges(), entity);
+      CoreUtils.addProperties(factory.getClient(), handler.getPropertyChanges(), entity);
     }
 
     for (Map.Entry<NavigationProperty, Object> property : handler.getLinkChanges().entrySet()) {
@@ -324,7 +325,7 @@ class ContainerImpl implements Container {
               : ODataLinkType.ENTITY_NAVIGATION;
 
       final Set<EntityTypeInvocationHandler> toBeLinked = new HashSet<EntityTypeInvocationHandler>();
-      final String serviceRoot = factory.getServiceRoot();
+      final String serviceRoot = factory.getClient().getServiceRoot();
 
       for (Object proxy : type == ODataLinkType.ENTITY_SET_NAVIGATION
               ? (Collection) property.getValue() : Collections.singleton(property.getValue())) {
@@ -332,8 +333,7 @@ class ContainerImpl implements Container {
         final EntityTypeInvocationHandler target =
                 (EntityTypeInvocationHandler) Proxy.getInvocationHandler(proxy);
 
-        final AttachedEntityStatus status =
-                EntityContainerFactory.getContext().entityContext().getStatus(target);
+        final AttachedEntityStatus status = factory.getContext().entityContext().getStatus(target);
 
         final URI editLink = target.getEntity().getEditLink();
 
@@ -385,7 +385,9 @@ class ContainerImpl implements Container {
       if (!handler.getPropertyChanges().isEmpty()) {
         final URI targetURI = currentStatus == AttachedEntityStatus.NEW
                 ? URI.create("$" + startingPos)
-                : URIUtils.getURI(factory.getServiceRoot(), handler.getEntity().getEditLink().toASCIIString());
+                : URIUtils.getURI(
+                        factory.getClient().getServiceRoot(),
+                        handler.getEntity().getEditLink().toASCIIString());
         batchUpdate(handler, targetURI, entity, changeset);
         pos++;
         items.put(handler, pos);
@@ -396,7 +398,8 @@ class ContainerImpl implements Container {
         final URI targetURI = currentStatus == AttachedEntityStatus.NEW
                 ? URI.create("$" + startingPos + "/$value")
                 : URIUtils.getURI(
-                factory.getServiceRoot(), handler.getEntity().getEditLink().toASCIIString() + "/$value");
+                        factory.getClient().getServiceRoot(),
+                        handler.getEntity().getEditLink().toASCIIString() + "/$value");
 
         batchUpdateMediaEntity(handler, targetURI, handler.getStreamChanges(), changeset);
 
@@ -408,9 +411,10 @@ class ContainerImpl implements Container {
 
     for (Map.Entry<String, InputStream> streamedChanges : handler.getStreamedPropertyChanges().entrySet()) {
       final URI targetURI = currentStatus == AttachedEntityStatus.NEW
-              ? URI.create("$" + startingPos) : URIUtils.getURI(
-              factory.getServiceRoot(),
-              CoreUtils.getMediaEditLink(streamedChanges.getKey(), entity).toASCIIString());
+              ? URI.create("$" + startingPos)
+              : URIUtils.getURI(
+                      factory.getClient().getServiceRoot(),
+                      CoreUtils.getMediaEditLink(streamedChanges.getKey(), entity).toASCIIString());
 
       batchUpdateMediaResource(handler, targetURI, streamedChanges.getValue(), changeset);
 
@@ -427,11 +431,11 @@ class ContainerImpl implements Container {
 
     switch (type) {
       case ENTITY_NAVIGATION:
-        result = client.getObjectFactory().newEntityNavigationLink(name, uri);
+        result = factory.getClient().getObjectFactory().newEntityNavigationLink(name, uri);
         break;
 
       case ENTITY_SET_NAVIGATION:
-        result = client.getObjectFactory().newEntitySetNavigationLink(name, uri);
+        result = factory.getClient().getObjectFactory().newEntitySetNavigationLink(name, uri);
         break;
 
       default:
@@ -452,15 +456,14 @@ class ContainerImpl implements Container {
       items.put(delayedUpdate.getSource(), pos);
 
       final CommonODataEntity changes =
-              client.getObjectFactory().newEntity(delayedUpdate.getSource().getEntity().getTypeName());
+              factory.getClient().getObjectFactory().newEntity(delayedUpdate.getSource().getEntity().getTypeName());
 
-      AttachedEntityStatus status =
-              EntityContainerFactory.getContext().entityContext().getStatus(delayedUpdate.getSource());
+      AttachedEntityStatus status = factory.getContext().entityContext().getStatus(delayedUpdate.getSource());
 
       final URI sourceURI;
       if (status == AttachedEntityStatus.CHANGED) {
         sourceURI = URIUtils.getURI(
-                factory.getServiceRoot(),
+                factory.getClient().getServiceRoot(),
                 delayedUpdate.getSource().getEntity().getEditLink().toASCIIString());
       } else {
         int sourcePos = items.get(delayedUpdate.getSource());
@@ -468,20 +471,22 @@ class ContainerImpl implements Container {
       }
 
       for (EntityTypeInvocationHandler target : delayedUpdate.getTargets()) {
-        status = EntityContainerFactory.getContext().entityContext().getStatus(target);
+        status = factory.getContext().entityContext().getStatus(target);
 
         final URI targetURI;
         if (status == AttachedEntityStatus.CHANGED) {
           targetURI = URIUtils.getURI(
-                  factory.getServiceRoot(), target.getEntity().getEditLink().toASCIIString());
+                  factory.getClient().getServiceRoot(), target.getEntity().getEditLink().toASCIIString());
         } else {
           int targetPos = items.get(target);
           targetURI = URI.create("$" + targetPos);
         }
 
         changes.addLink(delayedUpdate.getType() == ODataLinkType.ENTITY_NAVIGATION
-                ? client.getObjectFactory().newEntityNavigationLink(delayedUpdate.getSourceName(), targetURI)
-                : client.getObjectFactory().newEntitySetNavigationLink(delayedUpdate.getSourceName(), targetURI));
+                ? factory.getClient().getObjectFactory().
+                newEntityNavigationLink(delayedUpdate.getSourceName(), targetURI)
+                : factory.getClient().getObjectFactory().
+                newEntitySetNavigationLink(delayedUpdate.getSourceName(), targetURI));
 
         LOG.debug("'{}' from {} to {}", delayedUpdate.getType().name(), sourceURI, targetURI);
       }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java
index 06d03a2..ba3e449 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityCollectionInvocationHandler.java
@@ -47,7 +47,7 @@ public class EntityCollectionInvocationHandler<T extends Serializable>
   public EntityCollectionInvocationHandler(final EntityContainerInvocationHandler containerHandler,
           final Collection<T> items, final Class<?> itemRef, final URI uri) {
 
-    super(containerHandler.getClient(), containerHandler);
+    super(containerHandler);
 
     this.items = items;
     this.itemRef = itemRef;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
index 299a842..0289835 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
@@ -22,7 +22,6 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import org.apache.commons.lang3.ArrayUtils;
-import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.ext.proxy.EntityContainerFactory;
 import org.apache.olingo.ext.proxy.api.annotations.EntityContainer;
 import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
@@ -33,7 +32,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
 
   private static final long serialVersionUID = 7379006755693410764L;
 
-  private final EntityContainerFactory factory;
+  private final EntityContainerFactory<?> factory;
 
   protected final String namespace;
 
@@ -42,17 +41,15 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
   private final boolean defaultEC;
 
   public static EntityContainerInvocationHandler getInstance(
-          final CommonEdmEnabledODataClient<?> client, final Class<?> ref, final EntityContainerFactory factory) {
+          final Class<?> ref, final EntityContainerFactory<?> factory) {
 
-    final EntityContainerInvocationHandler instance = new EntityContainerInvocationHandler(client, ref, factory);
+    final EntityContainerInvocationHandler instance = new EntityContainerInvocationHandler(ref, factory);
     instance.containerHandler = instance;
     return instance;
   }
 
-  private EntityContainerInvocationHandler(
-          final CommonEdmEnabledODataClient<?> client, final Class<?> ref, final EntityContainerFactory factory) {
-
-    super(client, null);
+  private EntityContainerInvocationHandler(final Class<?> ref, final EntityContainerFactory<?> factory) {
+    super(factory);
 
     final Annotation annotation = ref.getAnnotation(EntityContainer.class);
     if (!(annotation instanceof EntityContainer)) {
@@ -66,7 +63,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
     this.namespace = ((EntityContainer) annotation).namespace();
   }
 
-  protected EntityContainerFactory getFactory() {
+  protected EntityContainerFactory<?> getFactory() {
     return factory;
   }
 
@@ -87,7 +84,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
     if (isSelfMethod(method, args)) {
       return invokeSelfMethod(method, args);
     } else if ("flush".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
-      new ContainerImpl(client, factory).flush();
+      new ContainerImpl(factory).flush();
       return ClassUtils.returnVoid();
     } else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
       final Class<?> returnType = method.getReturnType();
@@ -102,7 +99,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
       return Proxy.newProxyInstance(
               Thread.currentThread().getContextClassLoader(),
               new Class<?>[] {returnType},
-              ComplexFactoryInvocationHandler.getInstance(getClient(), this, null, null));
+              ComplexFactoryInvocationHandler.getInstance(this, null, null));
     } else {
       final Class<?> returnType = method.getReturnType();
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
index 18c2ce2..bcb0fb9 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
@@ -44,7 +44,6 @@ import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
 import org.apache.olingo.commons.api.format.ODataValueFormat;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
 import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
 import org.apache.olingo.ext.proxy.api.AbstractEntitySet;
 import org.apache.olingo.ext.proxy.api.AbstractSingleton;
@@ -96,7 +95,7 @@ class EntitySetInvocationHandler<
           final EntityContainerInvocationHandler containerHandler,
           final String entitySetName) {
 
-    super(containerHandler.getClient(), containerHandler);
+    super(containerHandler);
 
     this.entitySetName = entitySetName;
     this.isSingleton = AbstractSingleton.class.isAssignableFrom(ref);
@@ -106,7 +105,7 @@ class EntitySetInvocationHandler<
     this.typeRef = (Class<T>) entitySetParams[0];
     this.collTypeRef = (Class<EC>) entitySetParams[2];
 
-    final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(containerHandler.getFactory().getServiceRoot());
+    final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(getClient().getServiceRoot());
 
     final StringBuilder entitySetSegment = new StringBuilder();
     if (!containerHandler.isDefaultEntityContainer()) {
@@ -152,12 +151,12 @@ class EntitySetInvocationHandler<
 
   @SuppressWarnings("unchecked")
   private <NE> NE newEntity(final Class<NE> reference) {
-    final CommonODataEntity entity = client.getObjectFactory().newEntity(
+    final CommonODataEntity entity = getClient().getObjectFactory().newEntity(
             new FullQualifiedName(containerHandler.getSchemaName(), ClassUtils.getEntityTypeName(reference)));
 
     final EntityTypeInvocationHandler handler =
             EntityTypeInvocationHandler.getInstance(entity, entitySetName, reference, containerHandler);
-    EntityContainerFactory.getContext().entityContext().attachNew(handler);
+    getContext().entityContext().attachNew(handler);
 
     return (NE) Proxy.newProxyInstance(
             Thread.currentThread().getContextClassLoader(),
@@ -175,8 +174,8 @@ class EntitySetInvocationHandler<
 
   @Override
   public Long count() {
-    final ODataValueRequest req = client.getRetrieveRequestFactory().
-            getValueRequest(client.getURIBuilder(this.uri.toASCIIString()).count().build());
+    final ODataValueRequest req = getClient().getRetrieveRequestFactory().
+            getValueRequest(getClient().getURIBuilder(this.uri.toASCIIString()).count().build());
     req.setFormat(ODataValueFormat.TEXT);
     return Long.valueOf(req.execute().getBody().asPrimitive().toString());
   }
@@ -233,13 +232,13 @@ class EntitySetInvocationHandler<
     final EntityUUID uuid = new EntityUUID(containerHandler.getEntityContainerName(), entitySetName, typeRef, key);
     LOG.debug("Ask for '{}({})'", typeRef.getSimpleName(), key);
 
-    EntityTypeInvocationHandler handler = EntityContainerFactory.getContext().entityContext().getEntity(uuid);
+    EntityTypeInvocationHandler handler = getContext().entityContext().getEntity(uuid);
 
     if (handler == null) {
       // not yet attached: search against the service
       try {
         LOG.debug("Search for '{}({})' into the service", typeRef.getSimpleName(), key);
-        final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(this.uri.toASCIIString());
+        final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(this.uri.toASCIIString());
 
         if (key.getClass().getAnnotation(CompoundKey.class) == null) {
           LOG.debug("Append key segment '{}'", key);
@@ -252,17 +251,20 @@ class EntitySetInvocationHandler<
         LOG.debug("GET {}", uriBuilder.toString());
 
         final ODataRetrieveResponse<CommonODataEntity> res =
-                client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute();
+                getClient().getRetrieveRequestFactory().getEntityRequest(uriBuilder.build()).execute();
 
         final String etag = res.getETag();
         final CommonODataEntity entity = res.getBody();
-
-        if (entity == null || !key.equals(CoreUtils.getKey(client, typeRef, entity))) {
+        if (entity == null) {
           throw new IllegalArgumentException("Invalid " + typeRef.getSimpleName() + "(" + key + ")");
         }
 
         handler = EntityTypeInvocationHandler.getInstance(entity, this, typeRef);
         handler.setETag(etag);
+
+        if (!key.equals(CoreUtils.getKey(getClient(), handler, typeRef, entity))) {
+          throw new IllegalArgumentException("Invalid " + typeRef.getSimpleName() + "(" + key + ")");
+        }
       } catch (Exception e) {
         LOG.info("Entity '" + uuid + "' not found", e);
       }
@@ -285,13 +287,13 @@ class EntitySetInvocationHandler<
 
     if (isSingleton) {
       final ODataRetrieveResponse<org.apache.olingo.commons.api.domain.v4.Singleton> res =
-              ((ODataClient) client).getRetrieveRequestFactory().getSingletonRequest(uri).execute();
+              ((ODataClient) getClient()).getRetrieveRequestFactory().getSingletonRequest(uri).execute();
 
       entities.add(res.getBody());
       next = null;
     } else {
       final ODataRetrieveResponse<CommonODataEntitySet> res =
-              client.getRetrieveRequestFactory().getEntitySetRequest(uri).execute();
+              getClient().getRetrieveRequestFactory().getEntitySetRequest(uri).execute();
 
       final CommonODataEntitySet entitySet = res.getBody();
       entities.addAll(entitySet.getEntities());
@@ -303,8 +305,7 @@ class EntitySetInvocationHandler<
     for (CommonODataEntity entity : entities) {
       final EntityTypeInvocationHandler handler = EntityTypeInvocationHandler.getInstance(entity, this, typeRef);
 
-      final EntityTypeInvocationHandler handlerInTheContext =
-              EntityContainerFactory.getContext().entityContext().getEntity(handler.getUUID());
+      final EntityTypeInvocationHandler handlerInTheContext = getContext().entityContext().getEntity(handler.getUUID());
 
       items.add((S) Proxy.newProxyInstance(
               Thread.currentThread().getContextClassLoader(),
@@ -345,7 +346,7 @@ class EntitySetInvocationHandler<
     final Class<S> ref = (Class<S>) ClassUtils.extractTypeArg(collTypeRef);
     final Class<S> oref = (Class<S>) ClassUtils.extractTypeArg(this.collTypeRef);
 
-    final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(this.uri.toASCIIString());
+    final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(this.uri.toASCIIString());
 
     final URI entitySetURI;
     if (oref.equals(ref)) {
@@ -360,7 +361,7 @@ class EntitySetInvocationHandler<
 
   @Override
   public Filter<T, EC> createFilter() {
-    return new FilterImpl<T, EC>(this.client, this.collTypeRef, this.uri, this);
+    return new FilterImpl<T, EC>(getClient(), this.collTypeRef, this.uri, this);
   }
 
   @Override
@@ -368,16 +369,15 @@ class EntitySetInvocationHandler<
   public <S extends T, SEC extends AbstractEntityCollection<S>> Filter<S, SEC> createFilter(
           final Class<SEC> reference) {
 
-    return new FilterImpl<S, SEC>(
-            this.client, reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
+    return new FilterImpl<S, SEC>(getClient(), reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
   }
 
   @Override
   public Search<T, EC> createSearch() {
-    if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
+    if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
       throw new UnsupportedInV3Exception();
     }
-    return new SearchImpl<T, EC>((EdmEnabledODataClient) this.client, this.collTypeRef, this.uri, this);
+    return new SearchImpl<T, EC>((EdmEnabledODataClient) getClient(), this.collTypeRef, this.uri, this);
   }
 
   @Override
@@ -385,16 +385,16 @@ class EntitySetInvocationHandler<
   public <S extends T, SEC extends AbstractEntityCollection<S>> Search<S, SEC> createSearch(
           final Class<SEC> reference) {
 
-    if (client.getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
+    if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
       throw new UnsupportedInV3Exception();
     }
     return new SearchImpl<S, SEC>(
-            (EdmEnabledODataClient) this.client, reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
+            (EdmEnabledODataClient) getClient(), reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
   }
 
   @Override
   public void delete(final KEY key) throws IllegalArgumentException {
-    final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
+    final EntityContext entityContext = getContext().entityContext();
 
     EntityTypeInvocationHandler entity = entityContext.getEntity(new EntityUUID(
             containerHandler.getEntityContainerName(),
@@ -414,7 +414,7 @@ class EntitySetInvocationHandler<
 
   @Override
   public <S extends T> void delete(final Iterable<S> entities) {
-    final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
+    final EntityContext entityContext = getContext().entityContext();
 
     for (T en : entities) {
       final EntityTypeInvocationHandler entity = (EntityTypeInvocationHandler) Proxy.getInvocationHandler(en);
@@ -427,11 +427,11 @@ class EntitySetInvocationHandler<
   }
 
   private boolean isDeleted(final EntityTypeInvocationHandler handler) {
-    return EntityContainerFactory.getContext().entityContext().getStatus(handler) == AttachedEntityStatus.DELETED;
+    return getContext().entityContext().getStatus(handler) == AttachedEntityStatus.DELETED;
   }
 
   @Override
   public EntitySetIterator<T, KEY, EC> iterator() {
-    return new EntitySetIterator<T, KEY, EC>(client.getURIBuilder(this.uri.toASCIIString()).build(), this);
+    return new EntitySetIterator<T, KEY, EC>(getClient().getURIBuilder(this.uri.toASCIIString()).build(), this);
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java
index 57b73d0..5b2c30d 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityTypeInvocationHandler.java
@@ -19,7 +19,6 @@
 package org.apache.olingo.ext.proxy.commons;
 
 import java.io.InputStream;
-import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -28,9 +27,7 @@ import java.net.URI;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest;
@@ -92,7 +89,7 @@ public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
           final Class<?> typeRef,
           final EntityContainerInvocationHandler containerHandler) {
 
-    super(containerHandler.getClient(), typeRef, (ODataLinked) entity, containerHandler);
+    super(typeRef, (ODataLinked) entity, containerHandler);
 
     this.internal = entity;
     getEntity().setMediaEntity(typeRef.getAnnotation(EntityType.class).hasStream());
@@ -101,7 +98,7 @@ public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
             containerHandler.getEntityContainerName(),
             entitySetName,
             typeRef,
-            CoreUtils.getKey(client, typeRef, entity));
+            CoreUtils.getKey(getClient(), this, typeRef, entity));
   }
 
   public void setEntity(final CommonODataEntity entity) {
@@ -112,7 +109,7 @@ public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
             getUUID().getContainerName(),
             getUUID().getEntitySetName(),
             getUUID().getType(),
-            CoreUtils.getKey(client, typeRef, entity));
+            CoreUtils.getKey(getClient(), this, typeRef, entity));
 
     this.propertyChanges.clear();
     this.linkChanges.clear();
@@ -184,8 +181,7 @@ public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
       if (propertyChanges.containsKey(name)) {
         res = propertyChanges.get(name);
       } else {
-        res = CoreUtils.getValueFromProperty(client, property, type, this);
-
+        res = CoreUtils.getValueFromProperty(getClient(), property, type, this);
         if (res != null) {
           addPropertyChanges(name, res);
         }
@@ -198,30 +194,6 @@ public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
   }
 
   @Override
-  public Collection<String> getAdditionalPropertyNames() {
-    final Set<String> res = new HashSet<String>(propertyChanges.keySet());
-    final Set<String> propertyNames = new HashSet<String>();
-    for (Method method : typeRef.getMethods()) {
-      final Annotation ann = method.getAnnotation(Property.class);
-      if (ann != null) {
-        final String property = ((Property) ann).name();
-        propertyNames.add(property);
-
-        // maybe someone could add a normal attribute to the additional set
-        res.remove(property);
-      }
-    }
-
-    for (CommonODataProperty property : getEntity().getProperties()) {
-      if (!propertyNames.contains(property.getName())) {
-        res.add(property.getName());
-      }
-    }
-
-    return res;
-  }
-
-  @Override
   @SuppressWarnings("unchecked")
   protected void setPropertyValue(final Property property, final Object value) {
     if (property.type().equalsIgnoreCase(EdmPrimitiveTypeKind.Stream.toString())) {
@@ -230,7 +202,7 @@ public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
       addPropertyChanges(property.name(), value);
 
       if (value != null) {
-        final Collection<?> coll;
+        Collection<?> coll;
         if (Collection.class.isAssignableFrom(value.getClass())) {
           coll = Collection.class.cast(value);
         } else {
@@ -287,7 +259,7 @@ public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
       final String contentType =
               StringUtils.isBlank(getEntity().getMediaContentType()) ? "*/*" : getEntity().getMediaContentType();
 
-      final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(contentSource);
+      final ODataMediaRequest retrieveReq = getClient().getRetrieveRequestFactory().getMediaRequest(contentSource);
       retrieveReq.setFormat(ODataMediaFormat.fromFormat(contentType));
 
       this.stream = retrieveReq.execute().getBody();
@@ -303,10 +275,10 @@ public class EntityTypeInvocationHandler extends AbstractTypeInvocationHandler {
     try {
       if (res == null) {
         final URI link = URIUtils.getURI(
-                containerHandler.getFactory().getServiceRoot(),
+                getClient().getServiceRoot(),
                 CoreUtils.getMediaEditLink(property.name(), getEntity()).toASCIIString());
 
-        final ODataMediaRequest req = client.getRetrieveRequestFactory().getMediaRequest(link);
+        final ODataMediaRequest req = getClient().getRetrieveRequestFactory().getMediaRequest(link);
         res = req.execute().getBody();
 
       }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
index cdc0bfb..e2362eb 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/OperationInvocationHandler.java
@@ -49,8 +49,6 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
 
   private final FullQualifiedName targetFQN;
 
-  private final String serviceRoot;
-
   static OperationInvocationHandler getInstance(final EntityContainerInvocationHandler containerHandler) {
     return new OperationInvocationHandler(containerHandler);
   }
@@ -64,26 +62,21 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
   }
 
   private OperationInvocationHandler(final EntityContainerInvocationHandler containerHandler) {
-    super(containerHandler.getClient(), containerHandler);
+    super(containerHandler);
 
     this.target = containerHandler;
-
-    this.targetFQN =
-            new FullQualifiedName(containerHandler.getSchemaName(), containerHandler.getEntityContainerName());
-
-    this.serviceRoot = containerHandler.getFactory().getServiceRoot();
+    this.targetFQN = new FullQualifiedName(containerHandler.getSchemaName(), containerHandler.getEntityContainerName());
   }
 
   private OperationInvocationHandler(final EntityTypeInvocationHandler entityHandler) {
-    super(entityHandler.getClient(), entityHandler.containerHandler);
+    super(entityHandler.containerHandler);
 
     this.target = entityHandler;
     this.targetFQN = entityHandler.getEntity().getTypeName();
-    this.serviceRoot = containerHandler.getFactory().getServiceRoot();
   }
 
   private OperationInvocationHandler(final EntityCollectionInvocationHandler<?> collectionHandler) {
-    super(collectionHandler.getClient(), collectionHandler.containerHandler);
+    super(collectionHandler.containerHandler);
 
     this.target = collectionHandler;
 
@@ -91,7 +84,6 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
     final String typeNamespace = ClassUtils.getNamespace(collectionHandler.getEntityReference());
 
     this.targetFQN = new FullQualifiedName(typeNamespace, typeName);
-    this.serviceRoot = containerHandler.getFactory().getServiceRoot();
   }
 
   @Override
@@ -145,7 +137,7 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
 
   private Map.Entry<URI, EdmOperation> getUnboundOperation(
           final Operation operation, final List<String> parameterNames) {
-    final EdmEntityContainer container = client.getCachedEdm().getEntityContainer(targetFQN);
+    final EdmEntityContainer container = getClient().getCachedEdm().getEntityContainer(targetFQN);
     final EdmOperation edmOperation;
 
     if (operation.type() == OperationType.FUNCTION) {
@@ -154,7 +146,7 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
       edmOperation = container.getActionImport(operation.name()).getUnboundAction();
     }
 
-    final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(this.serviceRoot).
+    final CommonURIBuilder<?> uriBuilder = getClient().getURIBuilder(getClient().getServiceRoot()).
             appendOperationCallSegment(URIUtils.operationImportURISegment(container, edmOperation.getName()));
 
     return new AbstractMap.SimpleEntry<URI, EdmOperation>(uriBuilder.build(), edmOperation);
@@ -176,13 +168,13 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
             ? new FullQualifiedName(targetFQN.getNamespace(), boundOp.getTitle())
             : new FullQualifiedName(boundOp.getTitle());
 
-    EdmEntityType entityType = client.getCachedEdm().getEntityType(entity.getTypeName());
+    EdmEntityType entityType = getClient().getCachedEdm().getEntityType(entity.getTypeName());
     EdmOperation edmOperation = null;
     while (edmOperation == null && entityType != null) {
       edmOperation = operation.type() == OperationType.FUNCTION
-              ? client.getCachedEdm().getBoundFunction(
+              ? getClient().getCachedEdm().getBoundFunction(
                       operationFQN, entityType.getFullQualifiedName(), false, parameterNames)
-              : client.getCachedEdm().getBoundAction(
+              : getClient().getCachedEdm().getBoundAction(
                       operationFQN, entityType.getFullQualifiedName(), false);
       if (entityType.getBaseType() != null) {
         entityType = entityType.getBaseType();
@@ -202,10 +194,10 @@ class OperationInvocationHandler extends AbstractInvocationHandler implements Op
 
     EdmOperation edmOperation;
     if (operation.type() == OperationType.FUNCTION) {
-      edmOperation = client.getCachedEdm().getBoundFunction(
+      edmOperation = getClient().getCachedEdm().getBoundFunction(
               new FullQualifiedName(targetFQN.getNamespace(), operation.name()), targetFQN, true, parameterNames);
     } else {
-      edmOperation = client.getCachedEdm().getBoundAction(
+      edmOperation = getClient().getCachedEdm().getBoundAction(
               new FullQualifiedName(targetFQN.getNamespace(), operation.name()), targetFQN, true);
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
index 4ec75eb..664e894 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
@@ -42,7 +42,7 @@ public class SingletonInvocationHandler<
 
   @SuppressWarnings({"rawtypes", "unchecked"})
   private SingletonInvocationHandler(final Class<?> ref, final EntityContainerInvocationHandler containerHandler) {
-    super(containerHandler.getClient(), containerHandler);
+    super(containerHandler);
     this.entitySetHandler =
             new EntitySetInvocationHandler(ref, containerHandler, (ref.getAnnotation(Singleton.class)).name());
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
index cda964e..bd7a537 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/CoreUtils.java
@@ -349,7 +349,10 @@ public final class CoreUtils {
   }
 
   public static Object getKey(
-          final CommonEdmEnabledODataClient<?> client, final Class<?> entityTypeRef, final CommonODataEntity entity) {
+          final CommonEdmEnabledODataClient<?> client,
+          final EntityTypeInvocationHandler typeHandler,
+          final Class<?> entityTypeRef,
+          final CommonODataEntity entity) {
 
     Object res = null;
 
@@ -364,7 +367,7 @@ public final class CoreUtils {
       } else {
         try {
           res = keyRef.newInstance();
-          populate(client, res, CompoundKeyElement.class, entity.getProperties().iterator());
+          populate(client, typeHandler, res, CompoundKeyElement.class, entity.getProperties().iterator());
         } catch (Exception e) {
           LOG.error("Error population compound key {}", keyRef.getSimpleName(), e);
           throw new IllegalArgumentException("Cannot populate compound key");
@@ -375,8 +378,9 @@ public final class CoreUtils {
     return res;
   }
 
-  public static void populate(
+  private static void populate(
           final CommonEdmEnabledODataClient<?> client,
+          final EntityTypeInvocationHandler typeHandler,
           final Object bean,
           final Class<? extends Annotation> getterAnn,
           final Iterator<? extends CommonODataProperty> propItor) {
@@ -393,15 +397,16 @@ public final class CoreUtils {
       } else {
         typeRef = bean.getClass();
       }
-      populate(client, bean, typeRef, getterAnn, propItor);
+      populate(client, typeHandler, bean, typeRef, getterAnn, propItor);
     }
   }
 
   @SuppressWarnings({"unchecked"})
-  public static void populate(
+  private static void populate(
           final CommonEdmEnabledODataClient<?> client,
+          final EntityTypeInvocationHandler typeHandler,
           final Object bean,
-          final Class<?> reference,
+          final Class<?> typeRef,
           final Class<? extends Annotation> getterAnn,
           final Iterator<? extends CommonODataProperty> propItor) {
 
@@ -409,7 +414,7 @@ public final class CoreUtils {
       while (propItor.hasNext()) {
         final CommonODataProperty property = propItor.next();
 
-        final Method getter = ClassUtils.findGetterByAnnotatedName(reference, getterAnn, property.getName());
+        final Method getter = ClassUtils.findGetterByAnnotatedName(typeRef, getterAnn, property.getName());
 
         if (getter == null) {
           LOG.warn("Could not find any property annotated as {} in {}",
@@ -420,15 +425,15 @@ public final class CoreUtils {
               setPropertyValue(bean, getter, null);
             } else if (property.hasPrimitiveValue()) {
               setPropertyValue(bean, getter, primitiveValueToObject(
-                      property.getPrimitiveValue(), getPropertyClass(reference, property.getName())));
+                      property.getPrimitiveValue(), getPropertyClass(typeRef, property.getName())));
             } else if (property.hasComplexValue()) {
               final Object complex = Proxy.newProxyInstance(
                       Thread.currentThread().getContextClassLoader(),
                       new Class<?>[] {getter.getReturnType()},
                       ComplexTypeInvocationHandler.getInstance(
-                              client, property.getName(), getter.getReturnType(), null));
+                              client, property.getName(), getter.getReturnType(), typeHandler));
 
-              populate(client, complex, Property.class, property.getValue().asComplex().iterator());
+              populate(client, typeHandler, complex, Property.class, property.getValue().asComplex().iterator());
               setPropertyValue(bean, getter, complex);
             } else if (property.hasCollectionValue()) {
               final ParameterizedType collType = (ParameterizedType) getter.getGenericReturnType();
@@ -445,15 +450,15 @@ public final class CoreUtils {
                 final ODataValue value = collPropItor.next();
                 if (value.isPrimitive()) {
                   collection.add(primitiveValueToObject(
-                          value.asPrimitive(), getPropertyClass(reference, property.getName())));
+                          value.asPrimitive(), getPropertyClass(typeRef, property.getName())));
                 } else if (value.isComplex()) {
                   final Object collItem = Proxy.newProxyInstance(
                           Thread.currentThread().getContextClassLoader(),
                           new Class<?>[] {collItemClass},
                           ComplexTypeInvocationHandler.getInstance(
-                                  client, property.getName(), collItemClass, null));
+                                  client, property.getName(), collItemClass, typeHandler));
 
-                  populate(client, collItem, Property.class, value.asComplex().iterator());
+                  populate(client, typeHandler, collItem, Property.class, value.asComplex().iterator());
                   collection.add(collItem);
                 }
               }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
index de9cdc3..17bb65b 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
@@ -29,7 +29,6 @@ import java.util.Collections;
 import org.apache.olingo.client.api.v3.EdmEnabledODataClient;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.ext.proxy.EntityContainerFactory;
-import org.apache.olingo.ext.proxy.context.EntityContext;
 import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
         DefaultContainer;
 import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.
@@ -65,8 +64,6 @@ public abstract class AbstractTestITCase {
 
   protected static String testAuthServiceRootURL;
 
-  protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext();
-
   protected static EntityContainerFactory<EdmEnabledODataClient> containerFactory;
 
   protected static DefaultContainer container;
@@ -85,7 +82,7 @@ public abstract class AbstractTestITCase {
     containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
     container = containerFactory.getEntityContainer(DefaultContainer.class);
     assertNotNull(container);
-    EntityContainerFactory.getContext().detachAll();
+    containerFactory.getContext().detachAll();
   }
 
   protected Customer getSampleCustomerProfile(

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e897cf27/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java
index c0e65c9..5c8019b 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java
@@ -58,12 +58,12 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
     int res = aocontainer.operations().retrieveProduct();
     assertEquals(-10, res);
 
-    EntityContainerFactory.getContext().detachAll();
+    containerFactory.getContext().detachAll();
 
     res = aocontainer.getProduct().get(-10).operations().retrieveProduct();
     assertEquals(-10, res);
 
-    EntityContainerFactory.getContext().detachAll();
+    containerFactory.getContext().detachAll();
 
     final OrderLineKey key = new OrderLineKey();
     key.setOrderId(-10);
@@ -89,7 +89,7 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
     ecoll.operations().increaseSalaries(5);
 
     // the invoke above changed the local entities, re-read
-    EntityContainerFactory.getContext().detachAll();        
+    containerFactory.getContext().detachAll();        
     ecoll = aocontainer.getPerson().getAll(EmployeeCollection.class);
     empl = ecoll.iterator().next();
     
@@ -107,7 +107,7 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
     secoll.operations().increaseSalaries(5);
 
     // the invoke above changed the local entities, re-read
-    EntityContainerFactory.getContext().detachAll();        
+    containerFactory.getContext().detachAll();        
     secoll = aocontainer.getPerson().getAll(SpecialEmployeeCollection.class);
     sempl = secoll.toArray(new SpecialEmployee[secoll.size()])[1];