use of org.eclipse.persistence.testing.models.jpa.advanced.Address in project eclipselink by eclipse-ee4j.
the class JUnitNativeQueryTestSuite method testNativeQueryWithMixedCaseFields.
/* Removed for 299926 when the default changed to false.
* force results to be returned in camel case - any case that is different from what is defined in the Entity's field definitions
*/
public void testNativeQueryWithMixedCaseFields() {
EntityManager em = createEntityManager(PUName);
try {
Address expectedAddress = (Address) em.createQuery("select a from Address a").getResultList().get(0);
Address returnedAddress = null;
ServerSession session = JUnitTestCase.getServerSession();
String delimiter = session.getPlatform().getStartDelimiter();
Query q = em.createNativeQuery("Select ADDRESS_ID as " + delimiter + "aDdReSs_iD" + delimiter + ", P_CODE as " + delimiter + "P_cOdE" + delimiter + ", STREET as " + delimiter + "StReeT" + delimiter + ", PROVINCE as " + delimiter + "PrOvInCe" + delimiter + ", TYPE as " + delimiter + "TyPe" + delimiter + ", CITY as " + delimiter + "CiTy" + delimiter + ", COUNTRY as " + delimiter + "CoUnTrY" + delimiter + ", VERSION as " + delimiter + "VeRsIoN" + delimiter + " from CMP3_ADDRESS where ADDRESS_ID = " + expectedAddress.getID(), Address.class);
returnedAddress = (Address) q.getSingleResult();
assertNotNull("no address returned", returnedAddress);
assertTrue("returned address does not match the expected address", session.compareObjects(returnedAddress, expectedAddress));
// this query uses a resultsetmapping that looks for columns as camel case.
q = em.createNativeQuery("Select ADDRESS_ID" + /* as " + delimiter + "aDrEsS_iD" +delimiter*/
", P_CODE" + /* as "+ delimiter + "P_cOdE" +delimiter*/
", STREET" + /* as "+ delimiter + "StReeT" +delimiter*/
", PROVINCE" + /* as "+ delimiter + "PrOvInCe" +delimiter*/
", TYPE" + /* as " + delimiter + "TyPe" +delimiter*/
", CITY" + /* as " + delimiter + "CiTy" +delimiter*/
", COUNTRY" + /* as " + delimiter + "CoUnTy" +delimiter*/
", VERSION" + /* as " + delimiter + "VeRsIoN" +delimiter*/
" from CMP3_ADDRESS where ADDRESS_ID = " + expectedAddress.getID(), "address-case-sensitive-map");
returnedAddress = (Address) q.getSingleResult();
assertNotNull("no address returned", returnedAddress);
assertTrue("returned address does not match the expected address", session.compareObjects(returnedAddress, expectedAddress));
} finally {
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Address in project eclipselink by eclipse-ee4j.
the class JUnitNativeQueryTestSuite method testNativeQueryCacheHit.
/**
* 334704 - native queries do not use the shared cache
*/
public void testNativeQueryCacheHit() {
Address result = null;
EntityManager em = createEntityManager(PUName);
Query query = em.createQuery("Select a from Address a");
Address a = (Address) query.getResultList().get(0);
closeEntityManager(em);
// test needs to use a new EM so that the object returned is from the shared cache.
em = createEntityManager(PUName);
try {
this.beginTransaction(em);
query = em.createNativeQuery("Select ADDRESS_ID from CMP3_ADDRESS where ADDRESS_ID=" + a.getID(), Address.class);
result = (Address) query.getSingleResult();
} finally {
rollbackTransaction(em);
clearCache(PUName);
closeEntityManager(em);
}
assertTrue("Street from Address read using native query did not match the cache version", result.getStreet() != null && result.getStreet().equals(a.getStreet()));
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Address in project eclipselink by eclipse-ee4j.
the class JUnitJPQLSimpleTestSuite method simpleEscapeUnderscoreTest.
public void simpleEscapeUnderscoreTest() {
EntityManager em = createEntityManager();
Address expectedResult = new Address();
expectedResult.setCity("Perth");
expectedResult.setCountry("Canada");
expectedResult.setProvince("ONT");
expectedResult.setPostalCode("Y3Q2N9");
expectedResult.setStreet("234 Wandering _Way");
Server serverSession = JUnitTestCase.getServerSession();
Session clientSession = serverSession.acquireClientSession();
UnitOfWork uow = clientSession.acquireUnitOfWork();
uow.registerObject(expectedResult);
uow.commit();
// test the apostrophe
String ejbqlString = "SELECT OBJECT(address) FROM Address address WHERE ";
// \ is always treated as escape in MySQL. Therefore ESCAPE '\' is considered a syntax error
if (getServerSession().getPlatform().isMySQL() || getServerSession().getPlatform().isPostgreSQL()) {
ejbqlString = ejbqlString + "address.street LIKE '234 Wandering $_Way' ESCAPE '$'";
} else {
ejbqlString = ejbqlString + "address.street LIKE '234 Wandering \\_Way' ESCAPE '\\'";
}
List result = em.createQuery(ejbqlString).getResultList();
Assert.assertTrue("Simple Escape Underscore test failed", comparer.compareObjects(result, expectedResult));
}
use of org.eclipse.persistence.testing.models.jpa.advanced.Address in project eclipselink by eclipse-ee4j.
the class JUnitJPQLSimpleTestSuite method simpleLikeEscapeTestWithParameter.
public void simpleLikeEscapeTestWithParameter() {
EntityManager em = createEntityManager();
Address expectedResult = new Address();
expectedResult.setCity("TAIYUAN");
expectedResult.setCountry("CHINA");
expectedResult.setProvince("SHANXI");
expectedResult.setPostalCode("030024");
expectedResult.setStreet("234 RUBY _Way");
Server serverSession = JUnitTestCase.getServerSession();
Session clientSession = serverSession.acquireClientSession();
UnitOfWork uow = clientSession.acquireUnitOfWork();
uow.registerObject(expectedResult);
uow.commit();
// test the apostrophe
String ejbqlString = "SELECT OBJECT(address) FROM Address address WHERE address.street LIKE :pattern ESCAPE :esc";
String patternString = null;
Character escChar = null;
// \ is always treated as escape in MySQL. Therefore ESCAPE '\' is considered a syntax error
if (getServerSession().getPlatform().isMySQL()) {
patternString = "234 RUBY $_Way";
escChar = '$';
} else {
patternString = "234 RUBY \\_Way";
escChar = '\\';
}
List result = em.createQuery(ejbqlString).setParameter("pattern", patternString).setParameter("esc", escChar).getResultList();
Assert.assertTrue("Simple Escape Underscore test failed", comparer.compareObjects(result, expectedResult));
}
Aggregations