Return-Path: X-Original-To: apmail-olingo-commits-archive@minotaur.apache.org Delivered-To: apmail-olingo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 469CE109F8 for ; Fri, 13 Sep 2013 16:12:34 +0000 (UTC) Received: (qmail 45613 invoked by uid 500); 13 Sep 2013 16:08:53 -0000 Delivered-To: apmail-olingo-commits-archive@olingo.apache.org Received: (qmail 45399 invoked by uid 500); 13 Sep 2013 16:08:53 -0000 Mailing-List: contact commits-help@olingo.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@olingo.incubator.apache.org Delivered-To: mailing list commits@olingo.incubator.apache.org Received: (qmail 45367 invoked by uid 99); 13 Sep 2013 16:08:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Sep 2013 16:08:53 +0000 X-ASF-Spam-Status: No, hits=-2000.7 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 13 Sep 2013 16:08:51 +0000 Received: (qmail 64573 invoked by uid 99); 13 Sep 2013 14:59:33 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Sep 2013 14:59:33 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 454B4822727; Fri, 13 Sep 2013 14:59:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chandanva@apache.org To: commits@olingo.incubator.apache.org Message-Id: <69e022828b12413190339ed28971b54f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: OLINGO-9 JPA Support for char type: Date: Fri, 13 Sep 2013 14:59:33 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Fri Sep 13 20:28:42 2013 +0530 Committer: Chandan V A 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;