OPENJPA-586: Applied Helen Xu's changes where she back ported Pinaki's changes from trunk.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@1339870 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2012-05-17 21:26:09 +00:00
parent 8349d51e6f
commit 6862a736d3
3 changed files with 246 additions and 1 deletions

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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;
}
}