openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1339870 - in /openjpa/branches/1.0.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persis...
Date Thu, 17 May 2012 21:26:09 GMT
Author: hthomann
Date: Thu May 17 21:26:09 2012
New Revision: 1339870

URL: http://svn.apache.org/viewvc?rev=1339870&view=rev
Log:
OPENJPA-586: Applied Helen Xu's changes where she back ported Pinaki's changes from trunk.

Added:
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
  (with props)
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/
    openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
  (with props)
Modified:
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?rev=1339870&r1=1339869&r2=1339870&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Thu May 17 21:26:09 2012
@@ -1095,7 +1095,7 @@ public class JPQLExpressionBuilder
         if (fmd == null)
             return;
 
-        Class type = path.isXPath() ? path.getType() : fmd.getType();
+        Class type = path.isXPath() ? path.getType() : fmd.getDeclaredType();
         if (type == null)
             return;
 

Added: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java?rev=1339870&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
(added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
Thu May 17 21:26:09 2012
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.meta;
+
+
+import java.util.List;
+import java.util.UUID;
+
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.ArgumentException;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.meta.common.apps.ExternalValues;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * <p>Tests the {@link ExternalValuesFieldMapping}.</p>
+ *
+ * @author Abe White
+ * @author Pinaki Poddar (added binding query parameter tests) 
+ */
+public class TestExternalValues
+    extends SingleEMFTestCase {
+
+    public void setUp()
+        throws Exception {
+        super.setUp(CLEAR_TABLES, ExternalValues.class);
+    }
+    
+    public void testPositionalBindingQueryParameterEqualsDeclaredType() {
+        UUID uuid = new UUID(1,4);
+        createInstance(uuid);
+        
+        OpenJPAEntityManagerSPI em = emf.createEntityManager();
+        String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=?1";
+        List<ExternalValues> result = em.createQuery(jpql)
+                                        .setParameter(1, uuid)
+                                        .getResultList();
+        assertFalse(result.isEmpty());
+        for (ExternalValues x:result) {
+            assertEquals(uuid, x.getUuid());
+        }
+    }
+    
+    public void testNamedBindingQueryParameterEqualsDeclaredType() {
+        UUID uuid = new UUID(2,4);
+        createInstance(uuid);
+        
+        OpenJPAEntityManagerSPI em = emf.createEntityManager();
+        String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=:uuid";
+        List<ExternalValues> result = em.createQuery(jpql)
+                                        .setParameter("uuid", uuid)
+                                        .getResultList();
+        assertFalse(result.isEmpty());
+        for (ExternalValues pc:result) {
+            assertEquals(uuid, pc.getUuid());
+        }
+    }
+    
+    public void testPositionalBindingQueryParameterNotEqualsExternalizedType() {
+        UUID uuid = new UUID(1,4);
+        createInstance(uuid);
+        
+        OpenJPAEntityManagerSPI em = emf.createEntityManager();
+        String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=?1";
+        Query query = em.createQuery(jpql)
+                        .setParameter(1, uuid.toString());
+                                        
+        try {
+            query.getResultList();
+            fail("Expected ArgumentException");
+       } catch (ArgumentException ex) {
+           // expected
+       }
+    }
+
+    public void testNamedBindingQueryParameterNotEqualsExternalizedType() {
+        UUID uuid = new UUID(2,4);
+        createInstance(uuid);
+        
+        OpenJPAEntityManagerSPI em = emf.createEntityManager();
+        String jpql = "SELECT p FROM ExternalValues p WHERE p.uuid=:uuid";
+        Query query = em.createQuery(jpql)
+                        .setParameter("uuid", uuid.toString());
+        try {
+             query.getResultList();
+             fail("Expected ArgumentException");
+        } catch (ArgumentException ex) {
+            // expected
+        }
+    }
+    
+    private void createInstance(UUID uuid) {
+    	OpenJPAEntityManagerSPI em = emf.createEntityManager();
+        em.getTransaction().begin();
+        ExternalValues pc = new ExternalValues();
+        pc.setUuid(uuid);
+        em.persist(pc);
+        em.getTransaction().commit();
+        em.clear();
+    }
+}
+

Propchange: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestExternalValues.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java?rev=1339870&view=auto
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
(added)
+++ openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
Thu May 17 21:26:09 2012
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.meta.common.apps;
+
+
+import java.util.UUID;
+
+import javax.persistence.Entity;
+
+import org.apache.openjpa.persistence.Externalizer;
+import org.apache.openjpa.persistence.Factory;
+import org.apache.openjpa.persistence.Persistent;
+
+@Entity
+public class ExternalValues {
+
+    private boolean booleanToShort;
+    private byte byteToDouble;
+    private int intToFloat;
+    private long longToChar;
+    private short shortToString;
+    private float floatToBoolean;
+    private double doubleToByte;
+    private char charToInt;
+    private String stringToLong;
+    @Persistent
+    @Externalizer("toString")        
+    @Factory("UUID.fromString")
+    private UUID    uuid;
+
+    public boolean getBooleanToShort() {
+        return booleanToShort;
+    }
+
+    public void setBooleanToShort(boolean b) {
+        booleanToShort = b;
+    }
+
+    public byte getByteToDouble() {
+        return byteToDouble;
+    }
+
+    public void setByteToDouble(byte b) {
+        byteToDouble = b;
+    }
+
+    public int getIntToFloat() {
+        return intToFloat;
+    }
+
+    public void setIntToFloat(int i) {
+        intToFloat = i;
+    }
+
+    public long getLongToChar() {
+        return longToChar;
+    }
+
+    public void setLongToChar(long l) {
+        longToChar = l;
+    }
+
+    public short getShortToString() {
+        return shortToString;
+    }
+
+    public void setShortToString(short s) {
+        shortToString = s;
+    }
+
+    public double getDoubleToByte() {
+        return doubleToByte;
+    }
+
+    public void setDoubleToByte(double d) {
+        doubleToByte = d;
+    }
+
+    public float getFloatToBoolean() {
+        return floatToBoolean;
+    }
+
+    public void setFloatToBoolean(float f) {
+        floatToBoolean = f;
+    }
+
+    public char getCharToInt() {
+        return charToInt;
+    }
+
+    public void setCharToInt(char c) {
+        charToInt = c;
+    }
+
+    public String getStringToLong() {
+        return stringToLong;
+    }
+
+    public void setStringToLong(String s) {
+        stringToLong = s;
+    }
+
+    public UUID getUuid() {
+        return uuid;
+    }
+
+    public void setUuid(UUID uuid) {
+        this.uuid = uuid;
+    }
+}

Propchange: openjpa/branches/1.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/common/apps/ExternalValues.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message