olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chanda...@apache.org
Subject git commit: OLINGO-9 JPA Support for char type:
Date Fri, 13 Sep 2013 14:59:33 GMT
Updated Branches:
  refs/heads/master 336528180 -> b6fbd3be4


OLINGO-9 JPA Support for char type:


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

Branch: refs/heads/master
Commit: b6fbd3be4e5a46d1d1ea26ff39b216949b87446e
Parents: 3365281
Author: Chandan V A <chandan.v.a@sap.com>
Authored: Fri Sep 13 20:28:42 2013 +0530
Committer: Chandan V A <chandan.v.a@sap.com>
Committed: Fri Sep 13 20:28:42 2013 +0530

----------------------------------------------------------------------
 .../core/jpa/access/data/JPAEntity.java         | 14 +++-
 .../core/jpa/access/data/JPAEntityParser.java   | 78 ++++++++++++--------
 .../core/jpa/access/model/JPATypeConvertor.java |  3 +-
 3 files changed, 63 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b6fbd3be/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
index 31448c6..59b8313 100644
--- a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
+++ b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
@@ -246,7 +246,19 @@ public class JPAEntity {
   protected void setProperty(final Method method, final Object entity, final Object entityPropertyValue)
throws
       IllegalAccessException, IllegalArgumentException, InvocationTargetException {
     if (entityPropertyValue != null) {
-      method.invoke(entity, entityPropertyValue);
+      Class<?> parameterType = method.getParameterTypes()[0];
+      if (parameterType.equals(char[].class))
+      {
+        char[] characters = ((String) entityPropertyValue).toCharArray();
+        method.invoke(entity, characters);
+      }
+      else if (parameterType.equals(Character[].class))
+      {
+        Character[] characters = JPAEntityParser.toCharacterArray((String) entityPropertyValue);
+        method.invoke(entity, (Object)characters);
+      }
+      else
+        method.invoke(entity, entityPropertyValue);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b6fbd3be/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java
b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java
index ccc64ba..f22fd79 100644
--- a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java
+++ b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java
@@ -93,14 +93,14 @@ public final class JPAEntityParser {
             method = propertyVal.getClass().getMethod(
                 namePart, (Class<?>[]) null);
             method.setAccessible(true);
-            propertyVal = method.invoke(propertyVal);
+            propertyVal = getProperty(method, propertyVal);
           }
           edmEntity.put(property.getName(), propertyVal);
         } else {
           method = jpaEntity.getClass().getMethod(methodName,
               (Class<?>[]) null);
           method.setAccessible(true);
-          propertyValue = method.invoke(jpaEntity);
+          propertyValue = getProperty(method, jpaEntity);
           key = property.getName();
           if (property.getType().getKind()
               .equals(EdmTypeKind.COMPLEX)) {
@@ -130,14 +130,6 @@ public final class JPAEntityParser {
         throw ODataJPARuntimeException.throwException(
             ODataJPARuntimeException.GENERAL.addContent(e
                 .getMessage()), e);
-      } catch (IllegalAccessException e) {
-        throw ODataJPARuntimeException.throwException(
-            ODataJPARuntimeException.GENERAL.addContent(e
-                .getMessage()), e);
-      } catch (InvocationTargetException e) {
-        throw ODataJPARuntimeException.throwException(
-            ODataJPARuntimeException.GENERAL.addContent(e
-                .getMessage()), e);
       }
     }
 
@@ -187,9 +179,8 @@ public final class JPAEntityParser {
 
         if (method != null) {
           getters.get(key).setAccessible(true);
-          propertyValue = getters.get(key).invoke(jpaEntity);
+          propertyValue = getProperty(method, jpaEntity);
         }
-
         if (property.getType().getKind().equals(EdmTypeKind.COMPLEX)) {
           propertyValue = parse2EdmPropertyValueMap(propertyValue,
               (EdmStructuralType) property.getType());
@@ -209,7 +200,7 @@ public final class JPAEntityParser {
             method = propertyValue.getClass().getMethod(
                 namePart, (Class<?>[]) null);
             method.setAccessible(true);
-            propertyValue = method.invoke(propertyValue);
+            propertyValue = getProperty(method, jpaEntity);
           }
           edmEntity.put(key, propertyValue);
         }
@@ -230,14 +221,6 @@ public final class JPAEntityParser {
       throw ODataJPARuntimeException
           .throwException(ODataJPARuntimeException.GENERAL
               .addContent(e.getMessage()), e);
-    } catch (IllegalAccessException e) {
-      throw ODataJPARuntimeException
-          .throwException(ODataJPARuntimeException.GENERAL
-              .addContent(e.getMessage()), e);
-    } catch (InvocationTargetException e) {
-      throw ODataJPARuntimeException
-          .throwException(ODataJPARuntimeException.GENERAL
-              .addContent(e.getMessage()), e);
     }
     return edmEntity;
   }
@@ -260,21 +243,13 @@ public final class JPAEntityParser {
           Method getterMethod = jpaEntity.getClass()
               .getDeclaredMethod(methodName, (Class<?>[]) null);
           getterMethod.setAccessible(true);
-          result = getterMethod.invoke(jpaEntity);
+          result = getProperty(getterMethod, jpaEntity);
           navigationMap.put(navigationProperty.getName(), result);
         }
       } catch (IllegalArgumentException e) {
         throw ODataJPARuntimeException.throwException(
             ODataJPARuntimeException.GENERAL.addContent(e
                 .getMessage()), e);
-      } catch (IllegalAccessException e) {
-        throw ODataJPARuntimeException.throwException(
-            ODataJPARuntimeException.GENERAL.addContent(e
-                .getMessage()), e);
-      } catch (InvocationTargetException e) {
-        throw ODataJPARuntimeException.throwException(
-            ODataJPARuntimeException.GENERAL.addContent(e
-                .getMessage()), e);
       } catch (EdmException e) {
         throw ODataJPARuntimeException.throwException(
             ODataJPARuntimeException.GENERAL.addContent(e
@@ -365,6 +340,49 @@ public final class JPAEntityParser {
     return accessModifierMap;
   }
 
+  public static Object getProperty(Method method, Object entity) throws ODataJPARuntimeException
{
+    Object propertyValue = null;
+    try {
+      Class<?> returnType = method.getReturnType();
+
+      if (returnType.equals(char[].class))
+        propertyValue = (String) String.valueOf((char[]) method.invoke(entity));
+      else if (returnType.equals(Character[].class))
+        propertyValue = (String) toString((Character[]) method.invoke(entity));
+      else
+        propertyValue = method.invoke(entity);
+    } catch (IllegalAccessException e) {
+      throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
e);
+    } catch (IllegalArgumentException e) {
+      throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
e);
+    } catch (InvocationTargetException e) {
+      throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
e);
+    }
+    return propertyValue;
+  }
+
+  public static String toString(Character[] input) {
+    if (input == null) return null;
+
+    StringBuilder builder = new StringBuilder();
+    for (int i = 0; i < input.length; i++)
+      builder.append(input[i].charValue());
+
+    return builder.toString();
+
+  }
+
+  public static Character[] toCharacterArray(String input) {
+    if (input == null) return null;
+
+    Character[] characters = new Character[input.length()];
+    char[] chars = ((String) input).toCharArray();
+    for (int i = 0; i < input.length(); i++)
+      characters[i] = new Character(chars[i]);
+
+    return characters;
+  }
+
   public static String getAccessModifierName(final String propertyName, final EdmMapping
mapping, final String accessModifier)
       throws ODataJPARuntimeException {
     String name = null;

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b6fbd3be/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java
b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java
index 730c0f2..6bb69b5 100644
--- a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java
+++ b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java
@@ -52,7 +52,8 @@ public class JPATypeConvertor {
    * @see EdmSimpleTypeKind
    */
   public static EdmSimpleTypeKind convertToEdmSimpleType(final Class<?> jpaType, final
Attribute<?, ?> currentAttribute) throws ODataJPAModelException {
-    if (jpaType.equals(String.class)) {
+    if (jpaType.equals(String.class) || jpaType.equals(Character.class) || jpaType.equals(char.class)
|| jpaType.equals(char[].class) ||
+        jpaType.equals(Character[].class)) {
       return EdmSimpleTypeKind.String;
     } else if (jpaType.equals(Long.class) || jpaType.equals(long.class)) {
       return EdmSimpleTypeKind.Int64;


Mime
View raw message