mirror of https://github.com/apache/openjpa.git
Do not execute testcases which require subselects if the dictionary doesn't provide that support
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@805141 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
129dc13af8
commit
11b1833028
|
@ -146,7 +146,9 @@ public class TestDiscriminatorTypes extends SingleEMFTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void testExistsQuery() {
|
public void testExistsQuery() {
|
||||||
|
if (getDBDictionary(emf).supportsSubselect) {
|
||||||
EntityManager em = emf.createEntityManager();
|
EntityManager em = emf.createEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
@ -166,8 +168,9 @@ public class TestDiscriminatorTypes extends SingleEMFTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
|
|
||||||
em = emf.createEntityManager();
|
em = emf.createEntityManager();
|
||||||
Query q = em.createQuery("select o from StringAbstractEntity o " +
|
Query q =
|
||||||
"where exists (select o2 from StringLeafEntity o2)");
|
em.createQuery("select o from StringAbstractEntity o "
|
||||||
|
+ "where exists (select o2 from StringLeafEntity o2)");
|
||||||
List<StringAbstractEntity> list = q.getResultList();
|
List<StringAbstractEntity> list = q.getResultList();
|
||||||
assertEquals(0, list.size());
|
assertEquals(0, list.size());
|
||||||
for (StringAbstractEntity entity : list)
|
for (StringAbstractEntity entity : list)
|
||||||
|
@ -175,3 +178,4 @@ public class TestDiscriminatorTypes extends SingleEMFTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,12 +18,23 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.models.company;
|
package org.apache.openjpa.persistence.models.company;
|
||||||
|
|
||||||
import java.beans.*;
|
import java.beans.ExceptionListener;
|
||||||
import java.io.*;
|
import java.beans.Introspector;
|
||||||
import java.util.*;
|
import java.beans.PropertyDescriptor;
|
||||||
import javax.persistence.*;
|
import java.beans.XMLDecoder;
|
||||||
import junit.framework.*;
|
import java.util.Collection;
|
||||||
import org.apache.openjpa.persistence.test.*;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import junit.framework.AssertionFailedError;
|
||||||
|
|
||||||
|
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
||||||
|
import org.apache.openjpa.persistence.test.SingleEMTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic test case that will be extended by a concrete company
|
* Generic test case that will be extended by a concrete company
|
||||||
|
@ -37,6 +48,8 @@ public abstract class CompanyModelTest
|
||||||
private static Map<Class,Class> factoryClasses;
|
private static Map<Class,Class> factoryClasses;
|
||||||
private Map<Class,Class> impls;
|
private Map<Class,Class> impls;
|
||||||
|
|
||||||
|
private static Boolean canExecute = null;
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
// make a map of the implementations based on the class names in
|
// make a map of the implementations based on the class names in
|
||||||
// the current package of the test subclass
|
// the current package of the test subclass
|
||||||
|
@ -53,8 +66,16 @@ public abstract class CompanyModelTest
|
||||||
impls.put(IProduct.class, localClass("Product"));
|
impls.put(IProduct.class, localClass("Product"));
|
||||||
|
|
||||||
setUp(impls.values().toArray(new Class[impls.size()]));
|
setUp(impls.values().toArray(new Class[impls.size()]));
|
||||||
|
|
||||||
|
if (canExecute == null) {
|
||||||
|
// This testcase requires subselects. Skip it if subselects will not
|
||||||
|
// work.
|
||||||
|
canExecute = getDBDictionary(emf).supportsSubselect;
|
||||||
|
}
|
||||||
|
if (canExecute) {
|
||||||
checkModel();
|
checkModel();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Class localClass(String name) {
|
private Class localClass(String name) {
|
||||||
String pkg = getClass().getPackage().getName();
|
String pkg = getClass().getPackage().getName();
|
||||||
|
@ -72,9 +93,10 @@ public abstract class CompanyModelTest
|
||||||
* should always return all known instances in the database.
|
* should always return all known instances in the database.
|
||||||
*/
|
*/
|
||||||
public void testBasicQueries() throws Exception {
|
public void testBasicQueries() throws Exception {
|
||||||
|
if (canExecute) {
|
||||||
for (Class c : impls.values()) {
|
for (Class c : impls.values()) {
|
||||||
for (PropertyDescriptor pd :
|
for (PropertyDescriptor pd : Introspector.getBeanInfo(c)
|
||||||
Introspector.getBeanInfo(c).getPropertyDescriptors()) {
|
.getPropertyDescriptors()) {
|
||||||
|
|
||||||
if (pd.getWriteMethod() == null) // ignore read-only
|
if (pd.getWriteMethod() == null) // ignore read-only
|
||||||
continue;
|
continue;
|
||||||
|
@ -87,7 +109,8 @@ public abstract class CompanyModelTest
|
||||||
// execute the individual queries
|
// execute the individual queries
|
||||||
for (String query : queries) {
|
for (String query : queries) {
|
||||||
find(c, "where " + query);
|
find(c, "where " + query);
|
||||||
str.append(str.length() > 0 ? " or " : "").append(query);
|
str.append(str.length() > 0 ? " or " : "")
|
||||||
|
.append(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now execute all the queries combined
|
// now execute all the queries combined
|
||||||
|
@ -95,6 +118,7 @@ public abstract class CompanyModelTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void getBasicQueries(Set<String> queries, PropertyDescriptor pd,
|
void getBasicQueries(Set<String> queries, PropertyDescriptor pd,
|
||||||
String prefix) throws Exception {
|
String prefix) throws Exception {
|
||||||
|
|
|
@ -87,6 +87,7 @@ public class TestSubquery
|
||||||
|
|
||||||
|
|
||||||
public void testSubquery() {
|
public void testSubquery() {
|
||||||
|
if(getDBDictionary(emf).supportsSubselect) {
|
||||||
EntityManager em = emf.createEntityManager();
|
EntityManager em = emf.createEntityManager();
|
||||||
for (int i = 0; i < querys.length; i++) {
|
for (int i = 0; i < querys.length; i++) {
|
||||||
String q = querys[i];
|
String q = querys[i];
|
||||||
|
@ -103,6 +104,7 @@ public class TestSubquery
|
||||||
em.getTransaction().rollback();
|
em.getTransaction().rollback();
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify a sub query can contain MAX and additional date comparisons
|
* Verify a sub query can contain MAX and additional date comparisons
|
||||||
|
@ -110,6 +112,7 @@ public class TestSubquery
|
||||||
* originally caused problems for DBDictionaries which used DATABASE syntax.
|
* originally caused problems for DBDictionaries which used DATABASE syntax.
|
||||||
*/
|
*/
|
||||||
public void testSubSelectMaxDateRange() {
|
public void testSubSelectMaxDateRange() {
|
||||||
|
if(getDBDictionary(emf).supportsSubselect) {
|
||||||
String query =
|
String query =
|
||||||
"SELECT e,d from Employee e, Dependent d "
|
"SELECT e,d from Employee e, Dependent d "
|
||||||
+ "WHERE e.empId = :empid "
|
+ "WHERE e.empId = :empid "
|
||||||
|
@ -125,3 +128,4 @@ public class TestSubquery
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,21 +20,25 @@ package org.apache.openjpa.persistence.test;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Persistence;
|
import javax.persistence.Persistence;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestResult;
|
import junit.framework.TestResult;
|
||||||
|
|
||||||
|
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
||||||
|
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
||||||
import org.apache.openjpa.kernel.AbstractBrokerFactory;
|
import org.apache.openjpa.kernel.AbstractBrokerFactory;
|
||||||
import org.apache.openjpa.kernel.Broker;
|
import org.apache.openjpa.kernel.Broker;
|
||||||
import org.apache.openjpa.meta.ClassMetaData;
|
import org.apache.openjpa.meta.ClassMetaData;
|
||||||
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
|
||||||
import org.apache.openjpa.persistence.JPAFacadeHelper;
|
import org.apache.openjpa.persistence.JPAFacadeHelper;
|
||||||
|
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base test class providing persistence utilities.
|
* Base test class providing persistence utilities.
|
||||||
|
@ -195,4 +199,9 @@ public abstract class PersistenceTestCase
|
||||||
ClassMetaData meta = JPAFacadeHelper.getMetaData(emf, c);
|
ClassMetaData meta = JPAFacadeHelper.getMetaData(emf, c);
|
||||||
return (meta == null) ? null : meta.getTypeAlias();
|
return (meta == null) ? null : meta.getTypeAlias();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected DBDictionary getDBDictionary(OpenJPAEntityManagerFactorySPI emf) {
|
||||||
|
return ((JDBCConfiguration) emf.getConfiguration())
|
||||||
|
.getDBDictionaryInstance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue