@Test public void testparse2EdmPropertyListMapWithVirtualAccess() { JPAEntityParser resultParser = new JPAEntityParser(); Map<String, Object> edmEntity = new HashMap<String, Object>(); edmEntity.put("SoId", 1); DemoRelatedEntity relatedEntity = new DemoRelatedEntity("NewOrder"); demoItem jpaEntity = new demoItem("laptop", 1); jpaEntity.setRelatedEntity(relatedEntity); List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>(); EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class); JPAEdmMappingImpl edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class); try { EasyMock.expect(edmMapping.getInternalName()).andStubReturn("relatedEntity"); EasyMock.expect(((JPAEdmMappingImpl)edmMapping).isVirtualAccess()).andStubReturn(true); EasyMock.replay(edmMapping); EasyMock.expect(navigationProperty.getName()).andStubReturn("RelatedEntities"); EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping); EasyMock.replay(navigationProperty); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } navigationPropertyList.add(navigationProperty); try { HashMap<String, Object> result = resultParser.parse2EdmNavigationValueMap(jpaEntity, navigationPropertyList); assertEquals(relatedEntity, result.get("RelatedEntities")); } catch (ODataJPARuntimeException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } }
public final HashMap<String, Object> parse2EdmNavigationValueMap( final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList) throws ODataJPARuntimeException { Object result = null; String methodName = null; HashMap<String, Object> navigationMap = new HashMap<String, Object>(); if (jpaEntity == null) { return navigationMap; } if (navigationPropertyList != null && !navigationPropertyList.isEmpty()) { try { for (EdmNavigationProperty navigationProperty : navigationPropertyList) { methodName = getAccessModifierName(navigationProperty.getName(), navigationProperty.getMapping(), ACCESS_MODIFIER_GET); Method getterMethod = null; JPAEdmMapping jpaEdmMapping = (JPAEdmMapping)navigationProperty.getMapping(); if(jpaEdmMapping != null && jpaEdmMapping.isVirtualAccess()) { getterMethod = jpaEntity.getClass().getMethod(ACCESS_MODIFIER_GET, String.class); }else{ getterMethod = jpaEntity.getClass() .getMethod(methodName, (Class<?>[]) null); } getterMethod.setAccessible(true); result = getPropertyValue(getterMethod, jpaEntity, navigationProperty.getMapping().getInternalName()); navigationMap.put(navigationProperty.getName(), result); } } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (NoSuchMethodException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return navigationMap; }
JPAEntityParser { public final HashMap<String, Object> parse2EdmNavigationValueMap( final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList) throws ODataJPARuntimeException { Object result = null; String methodName = null; HashMap<String, Object> navigationMap = new HashMap<String, Object>(); if (jpaEntity == null) { return navigationMap; } if (navigationPropertyList != null && !navigationPropertyList.isEmpty()) { try { for (EdmNavigationProperty navigationProperty : navigationPropertyList) { methodName = getAccessModifierName(navigationProperty.getName(), navigationProperty.getMapping(), ACCESS_MODIFIER_GET); Method getterMethod = null; JPAEdmMapping jpaEdmMapping = (JPAEdmMapping)navigationProperty.getMapping(); if(jpaEdmMapping != null && jpaEdmMapping.isVirtualAccess()) { getterMethod = jpaEntity.getClass().getMethod(ACCESS_MODIFIER_GET, String.class); }else{ getterMethod = jpaEntity.getClass() .getMethod(methodName, (Class<?>[]) null); } getterMethod.setAccessible(true); result = getPropertyValue(getterMethod, jpaEntity, navigationProperty.getMapping().getInternalName()); navigationMap.put(navigationProperty.getName(), result); } } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (NoSuchMethodException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return navigationMap; } }
JPAEntityParser { public final HashMap<String, Object> parse2EdmNavigationValueMap( final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList) throws ODataJPARuntimeException { Object result = null; String methodName = null; HashMap<String, Object> navigationMap = new HashMap<String, Object>(); if (jpaEntity == null) { return navigationMap; } if (navigationPropertyList != null && !navigationPropertyList.isEmpty()) { try { for (EdmNavigationProperty navigationProperty : navigationPropertyList) { methodName = getAccessModifierName(navigationProperty.getName(), navigationProperty.getMapping(), ACCESS_MODIFIER_GET); Method getterMethod = null; JPAEdmMapping jpaEdmMapping = (JPAEdmMapping)navigationProperty.getMapping(); if(jpaEdmMapping != null && jpaEdmMapping.isVirtualAccess()) { getterMethod = jpaEntity.getClass().getMethod(ACCESS_MODIFIER_GET, String.class); }else{ getterMethod = jpaEntity.getClass() .getMethod(methodName, (Class<?>[]) null); } getterMethod.setAccessible(true); result = getPropertyValue(getterMethod, jpaEntity, navigationProperty.getMapping().getInternalName()); navigationMap.put(navigationProperty.getName(), result); } } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (NoSuchMethodException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return navigationMap; } JPAEntityParser(); }
JPAEntityParser { public final HashMap<String, Object> parse2EdmNavigationValueMap( final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList) throws ODataJPARuntimeException { Object result = null; String methodName = null; HashMap<String, Object> navigationMap = new HashMap<String, Object>(); if (jpaEntity == null) { return navigationMap; } if (navigationPropertyList != null && !navigationPropertyList.isEmpty()) { try { for (EdmNavigationProperty navigationProperty : navigationPropertyList) { methodName = getAccessModifierName(navigationProperty.getName(), navigationProperty.getMapping(), ACCESS_MODIFIER_GET); Method getterMethod = null; JPAEdmMapping jpaEdmMapping = (JPAEdmMapping)navigationProperty.getMapping(); if(jpaEdmMapping != null && jpaEdmMapping.isVirtualAccess()) { getterMethod = jpaEntity.getClass().getMethod(ACCESS_MODIFIER_GET, String.class); }else{ getterMethod = jpaEntity.getClass() .getMethod(methodName, (Class<?>[]) null); } getterMethod.setAccessible(true); result = getPropertyValue(getterMethod, jpaEntity, navigationProperty.getMapping().getInternalName()); navigationMap.put(navigationProperty.getName(), result); } } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (NoSuchMethodException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return navigationMap; } JPAEntityParser(); HashMap<String, Method> getJPAEntityAccessMap(final String jpaEntityName); HashMap<String, String> getJPAEmbeddableKeyMap(final String jpaEntityName); List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
      final List<EdmProperty> properties); final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
      final List<EdmProperty> selectPropertyList); final List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
      final EdmStructuralType structuralType); final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
      final EdmStructuralType structuralType); final HashMap<String, Object> parse2EdmNavigationValueMap(
      final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList); Method getAccessModifierSet(final Object jpaEntity, final String methodName); HashMap<String, Method> getAccessModifiers(final Object jpaEntity,
      final EdmStructuralType structuralType, final String accessModifier); static Object getPropertyValue(final Method method, final Object entity, String propertyName); static String getString(final Clob clob); static byte[] getBytes(final Blob blob); Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity, boolean isVirtualAccess); Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity); static String toString(final Character[] input); static Character[] toCharacterArray(final String input); static String getAccessModifierName(final String propertyName, final EdmMapping mapping,
      final String accessModifier); Method getAccessModifier(final Class<?> jpaEntityType, final EdmNavigationProperty navigationProperty,
      final String accessModifier); }
JPAEntityParser { public final HashMap<String, Object> parse2EdmNavigationValueMap( final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList) throws ODataJPARuntimeException { Object result = null; String methodName = null; HashMap<String, Object> navigationMap = new HashMap<String, Object>(); if (jpaEntity == null) { return navigationMap; } if (navigationPropertyList != null && !navigationPropertyList.isEmpty()) { try { for (EdmNavigationProperty navigationProperty : navigationPropertyList) { methodName = getAccessModifierName(navigationProperty.getName(), navigationProperty.getMapping(), ACCESS_MODIFIER_GET); Method getterMethod = null; JPAEdmMapping jpaEdmMapping = (JPAEdmMapping)navigationProperty.getMapping(); if(jpaEdmMapping != null && jpaEdmMapping.isVirtualAccess()) { getterMethod = jpaEntity.getClass().getMethod(ACCESS_MODIFIER_GET, String.class); }else{ getterMethod = jpaEntity.getClass() .getMethod(methodName, (Class<?>[]) null); } getterMethod.setAccessible(true); result = getPropertyValue(getterMethod, jpaEntity, navigationProperty.getMapping().getInternalName()); navigationMap.put(navigationProperty.getName(), result); } } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (NoSuchMethodException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return navigationMap; } JPAEntityParser(); HashMap<String, Method> getJPAEntityAccessMap(final String jpaEntityName); HashMap<String, String> getJPAEmbeddableKeyMap(final String jpaEntityName); List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
      final List<EdmProperty> properties); final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
      final List<EdmProperty> selectPropertyList); final List<Map<String, Object>> parse2EdmEntityList(final Collection<Object> jpaEntityList,
      final EdmStructuralType structuralType); final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity,
      final EdmStructuralType structuralType); final HashMap<String, Object> parse2EdmNavigationValueMap(
      final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList); Method getAccessModifierSet(final Object jpaEntity, final String methodName); HashMap<String, Method> getAccessModifiers(final Object jpaEntity,
      final EdmStructuralType structuralType, final String accessModifier); static Object getPropertyValue(final Method method, final Object entity, String propertyName); static String getString(final Clob clob); static byte[] getBytes(final Blob blob); Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity, boolean isVirtualAccess); Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity); static String toString(final Character[] input); static Character[] toCharacterArray(final String input); static String getAccessModifierName(final String propertyName, final EdmMapping mapping,
      final String accessModifier); Method getAccessModifier(final Class<?> jpaEntityType, final EdmNavigationProperty navigationProperty,
      final String accessModifier); static final String ACCESS_MODIFIER_GET; static final String ACCESS_MODIFIER_SET; }