mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-19 21:00:53 +08:00
added nullif tests
This commit is contained in:
parent
67bc29f59a
commit
80e653a178
@ -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);
|
||||
|
||||
@ -81,6 +81,8 @@ public class ColQueryTemplates extends JavaTemplates {
|
||||
|
||||
// coalesce
|
||||
add(Ops.COALESCE, functions + ".coalesce({0})");
|
||||
|
||||
add(Ops.NULLIF, functions + ".nullif({0}, {1})");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -327,7 +327,7 @@ public class FilterFactory {
|
||||
}
|
||||
|
||||
// rv.add(expr.in(IntervalImpl.create("A", "Z")));
|
||||
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -219,6 +219,9 @@ public class ProjectionsFactory {
|
||||
rv.add(expr.trim());
|
||||
|
||||
rv.add(expr.upper());
|
||||
|
||||
rv.add(expr.nullif("xxx"));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@ -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"))));
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
14
querydsl-jpa/src/test/java/com/mysema/query/NoHibernate.java
Normal file
14
querydsl-jpa/src/test/java/com/mysema/query/NoHibernate.java
Normal 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 {
|
||||
|
||||
}
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user