mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
Move NullExpression creation to Expressions
This commit is contained in:
parent
cfa11f5095
commit
1227c60d66
@ -86,7 +86,7 @@ public class DetachableMixin implements Detachable {
|
||||
} else if (arg != null) {
|
||||
return ConstantImpl.create(arg);
|
||||
} else {
|
||||
return NullExpression.DEFAULT;
|
||||
return Expressions.nullExpression();
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ public class DetachableMixin implements Detachable {
|
||||
}
|
||||
|
||||
private Expression<?> nullAsTemplate(@Nullable Expression<?> expr) {
|
||||
return expr != null ? expr : NullExpression.DEFAULT;
|
||||
return expr != null ? expr : Expressions.nullExpression();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@ -77,7 +77,7 @@ public final class Expressions {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <D> SimpleExpression<D> as(Expression<D> source, Path<D> alias) {
|
||||
if (source == null) {
|
||||
return as((Expression)NullExpression.DEFAULT, alias);
|
||||
return as((Expression)nullExpression(), alias);
|
||||
} else {
|
||||
return SimpleOperation.create((Class<D>)alias.getType(), Ops.ALIAS, source, alias);
|
||||
}
|
||||
@ -163,7 +163,7 @@ public final class Expressions {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static <D> SimpleExpression<D> constantAs(D source, Path<D> alias) {
|
||||
if (source == null) {
|
||||
return as((Expression)NullExpression.DEFAULT, alias);
|
||||
return as((Expression)nullExpression(), alias);
|
||||
} else {
|
||||
return as(ConstantImpl.create(source), alias);
|
||||
}
|
||||
@ -632,6 +632,37 @@ public final class Expressions {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default null expression
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static NullExpression<Object> nullExpression() {
|
||||
return NullExpression.DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a null expression for the given type
|
||||
*
|
||||
* @param type
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> NullExpression<T> nullExpression(Class<T> type) {
|
||||
return new NullExpression<T>(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a null expression for the given path
|
||||
*
|
||||
* @param path
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> NullExpression<T> nullExpression(Path<T> path) {
|
||||
return new NullExpression<T>(path.getType());
|
||||
}
|
||||
|
||||
private Expressions() {}
|
||||
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class DetachableMixinTest {
|
||||
SubQueryExpression<?> subQuery = detachable.unique(new PathImpl(Object.class, "x"), null);
|
||||
List<? extends Expression<?>> exprs = ((FactoryExpression)subQuery.getMetadata().getProjection()).getArgs();
|
||||
assertEquals(new PathImpl(Object.class, "x"), exprs.get(0));
|
||||
assertEquals(NullExpression.DEFAULT, exprs.get(1));
|
||||
assertEquals(Expressions.nullExpression(), exprs.get(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ import com.querydsl.core.QueryMetadata;
|
||||
import com.querydsl.core.dml.UpdateClause;
|
||||
import com.querydsl.core.support.Expressions;
|
||||
import com.querydsl.core.types.Expression;
|
||||
import com.querydsl.core.types.NullExpression;
|
||||
import com.querydsl.core.types.Path;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
@ -51,7 +50,7 @@ public class JDOUpdateClause implements UpdateClause<JDOUpdateClause> {
|
||||
if (values.get(i) != null) {
|
||||
updates.put(paths.get(i), Expressions.constant(values.get(i)));
|
||||
} else {
|
||||
updates.put(paths.get(i), new NullExpression(paths.get(i).getType()));
|
||||
updates.put(paths.get(i), Expressions.nullExpression(paths.get(i)));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
@ -62,7 +61,7 @@ public class JDOUpdateClause implements UpdateClause<JDOUpdateClause> {
|
||||
if (value != null) {
|
||||
updates.put(path, Expressions.constant(value));
|
||||
} else {
|
||||
updates.put(path, new NullExpression<T>(path.getType()));
|
||||
updates.put(path, Expressions.nullExpression(path));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -76,7 +75,7 @@ public class JDOUpdateClause implements UpdateClause<JDOUpdateClause> {
|
||||
|
||||
@Override
|
||||
public <T> JDOUpdateClause setNull(Path<T> path) {
|
||||
updates.put(path, new NullExpression<T>(path.getType()));
|
||||
updates.put(path, Expressions.nullExpression(path));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@ public class HibernateUpdateClause implements
|
||||
|
||||
@Override
|
||||
public <T> HibernateUpdateClause setNull(Path<T> path) {
|
||||
updates.put(path, new NullExpression<T>(path.getType()));
|
||||
updates.put(path, Expressions.nullExpression(path));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ public class HibernateUpdateClause implements
|
||||
if (values.get(i) != null) {
|
||||
updates.put(paths.get(i), Expressions.constant(values.get(i)));
|
||||
} else {
|
||||
updates.put(paths.get(i), new NullExpression(paths.get(i).getType()));
|
||||
updates.put(paths.get(i), Expressions.nullExpression(paths.get(i)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ public class JPAUpdateClause implements UpdateClause<JPAUpdateClause> {
|
||||
|
||||
@Override
|
||||
public <T> JPAUpdateClause setNull(Path<T> path) {
|
||||
updates.put(path, new NullExpression<T>(path.getType()));
|
||||
updates.put(path, Expressions.nullExpression(path));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ public class JPAUpdateClause implements UpdateClause<JPAUpdateClause> {
|
||||
if (values.get(i) != null) {
|
||||
updates.put(paths.get(i), Expressions.constant(values.get(i)));
|
||||
} else {
|
||||
updates.put(paths.get(i), new NullExpression(paths.get(i).getType()));
|
||||
updates.put(paths.get(i), Expressions.nullExpression(paths.get(i)));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user