added nullif tests

This commit is contained in:
Timo Westkämper 2012-11-28 16:39:17 +02:00
parent 67bc29f59a
commit 80e653a178
10 changed files with 39 additions and 2 deletions

View File

@ -64,6 +64,14 @@ public final class ColQueryFunctions {
}
return null;
}
public static <T> T nullif(T first, T second) {
if (first.equals(second)) {
return null;
} else {
return first;
}
}
public static int getDayOfMonth(Date date){
return getField(date, Calendar.DAY_OF_MONTH);

View File

@ -81,6 +81,8 @@ public class ColQueryTemplates extends JavaTemplates {
// coalesce
add(Ops.COALESCE, functions + ".coalesce({0})");
add(Ops.NULLIF, functions + ".nullif({0}, {1})");
}

View File

@ -327,7 +327,7 @@ public class FilterFactory {
}
// rv.add(expr.in(IntervalImpl.create("A", "Z")));
return rv;
}

View File

@ -219,6 +219,9 @@ public class ProjectionsFactory {
rv.add(expr.trim());
rv.add(expr.upper());
rv.add(expr.nullif("xxx"));
return rv;
}

View File

@ -390,6 +390,7 @@ public abstract class AbstractStandardTest {
}
@Test
@NoHibernate
public void Constant() {
//select cat.id, ?1 as const from Cat cat
query().from(cat).list(new QTuple(cat.id, Expressions.constantAs("abc", new StringPath("const"))));

View File

@ -44,6 +44,9 @@ import com.mysema.testutil.HibernateTestRunner;
@RunWith(HibernateTestRunner.class)
public class HibernateBase extends AbstractStandardTest {
@Rule
public static MethodRule jpaProviderRule = new JPAProviderRule();
@Rule
public static MethodRule targetRule = new TargetRule();

View File

@ -48,7 +48,7 @@ public class JPABase extends AbstractStandardTest {
public static MethodRule targetRule = new TargetRule();
@Rule
public static MethodRule hibernateOnly = new JPAProviderRule();
public static MethodRule jpaProviderRule = new JPAProviderRule();
private EntityManager entityManager;

View File

@ -19,6 +19,7 @@ public class JPAProviderRule implements MethodRule {
boolean noEclipseLink = hasAnnotation(method, NoEclipseLink.class);
boolean noOpenJPA = hasAnnotation(method, NoOpenJPA.class);
boolean noBatooJPA = hasAnnotation(method, NoBatooJPA.class);
boolean noHibernate = hasAnnotation(method, NoHibernate.class);
String mode = Mode.mode.get();
if (noEclipseLink && mode.contains("-eclipselink")) {
return EmptyStatement.DEFAULT;
@ -26,6 +27,8 @@ public class JPAProviderRule implements MethodRule {
return EmptyStatement.DEFAULT;
} else if (noBatooJPA && mode.contains("-batoo")) {
return EmptyStatement.DEFAULT;
} else if (noHibernate && !mode.contains("-")) {
return EmptyStatement.DEFAULT;
} else {
return base;
}

View File

@ -0,0 +1,14 @@
package com.mysema.query;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Inherited
public @interface NoHibernate {
}

View File

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