@Test public void testparse2EdmPropertyValueMapEdmExcep() { JPAEntityParser resultParser = new JPAEntityParser(); Object jpaEntity = new demoItem("abc", 10); EdmStructuralType structuralType = EasyMock .createMock(EdmStructuralType.class); EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class); EdmType edmType = EasyMock.createMock(EdmType.class); EdmProperty edmTyped01 = EasyMock.createMock(EdmProperty.class); EdmType edmType01 = EasyMock.createMock(EdmType.class); EdmMapping edmMapping = EasyMock.createMock(JPAEdmMappingImpl.class); EdmMapping edmMapping01 = EasyMock.createMock(JPAEdmMappingImpl.class); try { EasyMock.expect(edmType.getKind()) .andStubReturn(EdmTypeKind.SIMPLE); EasyMock.expect(edmType.getName()).andReturn("identifier"); EasyMock.replay(edmType); EasyMock.expect(edmMapping.getInternalName()).andStubReturn("id"); EasyMock.expect(((JPAEdmMappingImpl)edmMapping).isVirtualAccess()).andStubReturn(false); EasyMock.replay(edmMapping); EasyMock.expect(edmTyped.getType()).andStubThrow( new EdmException(null)); EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping); EasyMock.expect(edmTyped.getName()).andReturn("identifier").anyTimes(); EasyMock.replay(edmTyped); EasyMock.expect(structuralType.getProperty("identifier")) .andStubReturn(edmTyped); EasyMock.expect(edmType01.getKind()).andStubReturn( EdmTypeKind.SIMPLE); EasyMock.expect(edmType01.getName()).andStubReturn("value"); EasyMock.replay(edmType01); EasyMock.expect(edmMapping01.getInternalName()).andStubReturn( "value"); EasyMock.expect(((JPAEdmMappingImpl)edmMapping01).isVirtualAccess()) .andStubReturn(false); EasyMock.replay(edmMapping01); EasyMock.expect(edmTyped01.getName()).andReturn("value").anyTimes(); EasyMock.expect(edmTyped01.getType()).andStubReturn(edmType01); EasyMock.expect(edmTyped01.getMapping()) .andStubReturn(edmMapping01); EasyMock.replay(edmTyped01); EasyMock.expect(structuralType.getProperty("value")).andStubReturn( edmTyped01); List<String> propNames = new ArrayList<String>(); propNames.add("identifier"); propNames.add("value"); EasyMock.expect(structuralType.getPropertyNames()).andReturn( propNames); EasyMock.replay(structuralType); } catch (EdmException e) { fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2); } try { resultParser.parse2EdmPropertyValueMap(jpaEntity, structuralType); } catch (ODataJPARuntimeException e) { assertTrue(true); } }
public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } if (property.getType().getKind() .equals(EdmTypeKind.COMPLEX)) { propertyValue = parse2EdmPropertyValueMap(propertyValue, (EdmStructuralType) property.getType()); } edmEntity.put(propertyName, propertyValue); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; }
JPAEntityParser { public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } if (property.getType().getKind() .equals(EdmTypeKind.COMPLEX)) { propertyValue = parse2EdmPropertyValueMap(propertyValue, (EdmStructuralType) property.getType()); } edmEntity.put(propertyName, propertyValue); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; } }
JPAEntityParser { public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } if (property.getType().getKind() .equals(EdmTypeKind.COMPLEX)) { propertyValue = parse2EdmPropertyValueMap(propertyValue, (EdmStructuralType) property.getType()); } edmEntity.put(propertyName, propertyValue); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; } JPAEntityParser(); }
JPAEntityParser { public final HashMap<String, Object> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } if (property.getType().getKind() .equals(EdmTypeKind.COMPLEX)) { propertyValue = parse2EdmPropertyValueMap(propertyValue, (EdmStructuralType) property.getType()); } edmEntity.put(propertyName, propertyValue); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; } 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> parse2EdmPropertyValueMap(final Object jpaEntity, final List<EdmProperty> selectPropertyList) throws ODataJPARuntimeException { HashMap<String, Object> edmEntity = new HashMap<String, Object>(); HashMap<String, Method> accessModifierMap = null; Object propertyValue = null; String jpaEntityAccessKey = null; jpaEntityAccessKey = jpaEntity.getClass().getName(); if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) { accessModifierMap = getAccessModifiers((List<EdmProperty>) selectPropertyList, jpaEntity.getClass(), ACCESS_MODIFIER_GET); } else { accessModifierMap = jpaEntityAccessMap.get(jpaEntityAccessKey); } for (EdmProperty property : selectPropertyList) { propertyValue = jpaEntity; try { String propertyName = property.getName(); Method method = accessModifierMap.get(propertyName); if (method == null) { String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName); if (methodName != null) { boolean isVirtualAccess = false; if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) { isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess(); } if (isVirtualAccess) { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true); } else { propertyValue = getEmbeddablePropertyValue(methodName, propertyValue); } } } else { propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName); } if (property.getType().getKind() .equals(EdmTypeKind.COMPLEX)) { propertyValue = parse2EdmPropertyValueMap(propertyValue, (EdmStructuralType) property.getType()); } edmEntity.put(propertyName, propertyValue); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (SecurityException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } catch (IllegalArgumentException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } } return edmEntity; } 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; }