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:
Michael Dick 2009-08-17 21:03:33 +00:00
parent 129dc13af8
commit 11b1833028
4 changed files with 110 additions and 69 deletions

View File

@ -146,7 +146,9 @@ public class TestDiscriminatorTypes extends SingleEMFTestCase {
em.close();
}
@SuppressWarnings("unchecked")
public void testExistsQuery() {
if (getDBDictionary(emf).supportsSubselect) {
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
@ -166,8 +168,9 @@ public class TestDiscriminatorTypes extends SingleEMFTestCase {
em.close();
em = emf.createEntityManager();
Query q = em.createQuery("select o from StringAbstractEntity o " +
"where exists (select o2 from StringLeafEntity o2)");
Query q =
em.createQuery("select o from StringAbstractEntity o "
+ "where exists (select o2 from StringLeafEntity o2)");
List<StringAbstractEntity> list = q.getResultList();
assertEquals(0, list.size());
for (StringAbstractEntity entity : list)
@ -175,3 +178,4 @@ public class TestDiscriminatorTypes extends SingleEMFTestCase {
em.close();
}
}
}

View File

@ -18,12 +18,23 @@
*/
package org.apache.openjpa.persistence.models.company;
import java.beans.*;
import java.io.*;
import java.util.*;
import javax.persistence.*;
import junit.framework.*;
import org.apache.openjpa.persistence.test.*;
import java.beans.ExceptionListener;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.beans.XMLDecoder;
import java.util.Collection;
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
@ -37,6 +48,8 @@ public abstract class CompanyModelTest
private static Map<Class,Class> factoryClasses;
private Map<Class,Class> impls;
private static Boolean canExecute = null;
public void setUp() {
// make a map of the implementations based on the class names in
// the current package of the test subclass
@ -53,8 +66,16 @@ public abstract class CompanyModelTest
impls.put(IProduct.class, localClass("Product"));
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();
}
}
private Class localClass(String name) {
String pkg = getClass().getPackage().getName();
@ -72,9 +93,10 @@ public abstract class CompanyModelTest
* should always return all known instances in the database.
*/
public void testBasicQueries() throws Exception {
if (canExecute) {
for (Class c : impls.values()) {
for (PropertyDescriptor pd :
Introspector.getBeanInfo(c).getPropertyDescriptors()) {
for (PropertyDescriptor pd : Introspector.getBeanInfo(c)
.getPropertyDescriptors()) {
if (pd.getWriteMethod() == null) // ignore read-only
continue;
@ -87,7 +109,8 @@ public abstract class CompanyModelTest
// execute the individual queries
for (String query : queries) {
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
@ -95,6 +118,7 @@ public abstract class CompanyModelTest
}
}
}
}
void getBasicQueries(Set<String> queries, PropertyDescriptor pd,
String prefix) throws Exception {

View File

@ -87,6 +87,7 @@ public class TestSubquery
public void testSubquery() {
if(getDBDictionary(emf).supportsSubselect) {
EntityManager em = emf.createEntityManager();
for (int i = 0; i < querys.length; i++) {
String q = querys[i];
@ -103,6 +104,7 @@ public class TestSubquery
em.getTransaction().rollback();
em.close();
}
}
/**
* 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.
*/
public void testSubSelectMaxDateRange() {
if(getDBDictionary(emf).supportsSubselect) {
String query =
"SELECT e,d from Employee e, Dependent d "
+ "WHERE e.empId = :empid "
@ -125,3 +128,4 @@ public class TestSubquery
em.close();
}
}
}

View File

@ -20,21 +20,25 @@ package org.apache.openjpa.persistence.test;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import junit.framework.TestCase;
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.Broker;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.JPAFacadeHelper;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
/**
* Base test class providing persistence utilities.
@ -195,4 +199,9 @@ public abstract class PersistenceTestCase
ClassMetaData meta = JPAFacadeHelper.getMetaData(emf, c);
return (meta == null) ? null : meta.getTypeAlias();
}
protected DBDictionary getDBDictionary(OpenJPAEntityManagerFactorySPI emf) {
return ((JDBCConfiguration) emf.getConfiguration())
.getDBDictionaryInstance();
}
}