make QueryPerformanceTest use different h2 database

This commit is contained in:
Timo Westkämper 2012-12-08 14:50:02 +02:00
parent e2b503d2b1
commit 787747b028
6 changed files with 29 additions and 23 deletions

View File

@ -45,16 +45,18 @@ import com.mysema.query.types.template.BooleanTemplate;
*/
public class ListAccessVisitor implements Visitor<Expression<?>,Context> {
private static final class UnderscoreTemplates extends Templates {
{
add(PathType.PROPERTY, "{0}_{1}");
add(PathType.LISTVALUE, "{0}_{1}");
add(PathType.LISTVALUE_CONSTANT, "{0}_{1}");
}
}
public static final ListAccessVisitor DEFAULT = new ListAccessVisitor();
public static final Templates TEMPLATE = new Templates() {
{
add(PathType.PROPERTY, "{0}_{1}");
add(PathType.LISTVALUE, "{0}_{1}");
add(PathType.LISTVALUE_CONSTANT, "{0}_{1}");
}};
public static final Templates TEMPLATE = new UnderscoreTemplates();
@SuppressWarnings("unchecked")
private static <T> Path<T> replaceParent(Path<T> path, Path<?> parent) {
PathMetadata<?> metadata = new PathMetadata(parent, path.getMetadata().getElement(),

View File

@ -35,7 +35,6 @@ public final class FactoryExpressionTransformer implements ResultTransformer {
this.constructor = constructor;
}
@SuppressWarnings("unchecked")
@Override
public List transformList(List collection) {
return collection;

View File

@ -58,12 +58,24 @@ public abstract class AbstractJPAQuery<Q extends AbstractJPAQuery<Q>> extends JP
private static Class<?> hibernateQueryClass;
private static Constructor<?> hibernateQueryTransformationConstructor;
static {
try {
hibernateQueryClass = Class.forName("org.hibernate.ejb.HibernateQuery");
} catch (ClassNotFoundException e) {
// do nothing
}
try {
Class<?> clazz = Class.forName("com.mysema.query.jpa.impl.HibernateQueryTransformation");
hibernateQueryTransformationConstructor = clazz.getConstructor(Query.class, FactoryExpression.class);
} catch (ClassNotFoundException e) {
// do nothing
} catch (SecurityException e) {
// do nothing
} catch (NoSuchMethodException e) {
// do nothing
}
}
protected final Map<String,Object> hints = new HashMap<String,Object>();
@ -163,21 +175,16 @@ public abstract class AbstractJPAQuery<Q extends AbstractJPAQuery<Q>> extends JP
if (!forCount && ((projection.size() == 1 && projection.get(0) instanceof FactoryExpression) || wrapped != null)) {
Expression<?> expr = wrapped != null ? wrapped : projection.get(0);
String transformation = null;
Constructor<?> transformation = null;
if (hibernateQueryClass != null && hibernateQueryClass.isInstance(query)) {
transformation = "com.mysema.query.jpa.impl.HibernateQueryTransformation";
transformation = hibernateQueryTransformationConstructor;
}
// else if (query.getClass().getName().startsWith("org.eclipse.persistence")) {
// transformation = "com.mysema.query.jpa.impl.EclipseLinkQueryTransformation";
// }
if (transformation != null) {
try {
Constructor<?> c = Class.forName(transformation).getConstructor(Query.class, FactoryExpression.class);
c.newInstance(query, expr);
} catch (NoSuchMethodException e) {
throw new QueryException(e);
} catch (ClassNotFoundException e) {
throw new QueryException(e);
transformation.newInstance(query, expr);
} catch (InstantiationException e) {
throw new QueryException(e);
} catch (IllegalAccessException e) {

View File

@ -23,7 +23,7 @@ public class QueryPerformanceTest {
@BeforeClass
public static void setUpClass() {
Mode.mode.set("h2-perf");
Mode.mode.set("h2perf");
Mode.target.set(Target.H2);
}

View File

@ -88,7 +88,7 @@ public class JPATestRunner extends BlockJUnit4ClassRunner {
private void start() throws Exception {
String mode = Mode.mode.get();
if (mode == null) {
mode = "h2";
mode = "h2perf";
}
System.out.println(mode);
isDerby = mode.contains("derby");

View File

@ -89,7 +89,7 @@
</properties>
</persistence-unit>
<persistence-unit name="h2-perf" transaction-type="RESOURCE_LOCAL">
<persistence-unit name="h2perf" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
@ -97,9 +97,7 @@
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.url" value="jdbc:h2:target/h2-perf" />
<property name="hibernate.connection.user" value="sa" />
<!--
<property name="hibernate.show_sql" value="true"/>
-->
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>