mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-21 21:14:12 +08:00
Move RelationalFunctionCall factory methods to SQLExpressions
This commit is contained in:
parent
1a1845165c
commit
e447b99632
@ -35,23 +35,23 @@ public class TemplateExpressionImpl<T> extends ExpressionBase<T> implements Temp
|
||||
|
||||
private final Template template;
|
||||
|
||||
public static <C> Expression<C> create(Class<C> cl, String template) {
|
||||
public static <C> Expression<C> create(Class<? extends C> cl, String template) {
|
||||
return new TemplateExpressionImpl<C>(cl, TemplateFactory.DEFAULT.create(template), ImmutableList.of());
|
||||
}
|
||||
|
||||
public static <C> Expression<C> create(Class<C> cl, String template, Object one) {
|
||||
public static <C> Expression<C> create(Class<? extends C> cl, String template, Object one) {
|
||||
return new TemplateExpressionImpl<C>(cl, TemplateFactory.DEFAULT.create(template), ImmutableList.of(one));
|
||||
}
|
||||
|
||||
public static <C> Expression<C> create(Class<C> cl, String template, Object one, Object two) {
|
||||
public static <C> Expression<C> create(Class<? extends C> cl, String template, Object one, Object two) {
|
||||
return new TemplateExpressionImpl<C>(cl, TemplateFactory.DEFAULT.create(template), ImmutableList.of(one, two));
|
||||
}
|
||||
|
||||
public static <C> Expression<C> create(Class<C> cl, String template, Object... args) {
|
||||
public static <C> Expression<C> create(Class<? extends C> cl, String template, Object... args) {
|
||||
return new TemplateExpressionImpl<C>(cl, TemplateFactory.DEFAULT.create(template), args);
|
||||
}
|
||||
|
||||
public static <C> Expression<C> create(Class<C> cl, Template template, Object... args) {
|
||||
public static <C> Expression<C> create(Class<? extends C> cl, Template template, Object... args) {
|
||||
return new TemplateExpressionImpl<C>(cl, template, args);
|
||||
}
|
||||
|
||||
|
||||
@ -17,16 +17,11 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.querydsl.sql.Configuration;
|
||||
import com.querydsl.sql.RelationalFunctionCall;
|
||||
import com.querydsl.sql.RelationalPathBase;
|
||||
import com.querydsl.sql.SQLSerializer;
|
||||
import com.querydsl.sql.SQLServerTemplates;
|
||||
import com.querydsl.sql.SQLSubQuery;
|
||||
import com.querydsl.core.types.PathMetadataFactory;
|
||||
import com.querydsl.core.types.SubQueryExpression;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
import com.querydsl.core.types.dsl.StringPath;
|
||||
import com.querydsl.sql.*;
|
||||
|
||||
public class RelationalFunctionCallTest {
|
||||
|
||||
@ -49,7 +44,7 @@ public class RelationalFunctionCallTest {
|
||||
//select tab.col from Table tab join TableValuedFunction('parameter') func on tab.col not like func.col
|
||||
|
||||
QSurvey table = new QSurvey("SURVEY");
|
||||
RelationalFunctionCall<String> func = RelationalFunctionCall.create(String.class, "TableValuedFunction", "parameter");
|
||||
RelationalFunctionCall<String> func = SQLExpressions.relationalFunctionCall(String.class, "TableValuedFunction", "parameter");
|
||||
PathBuilder<String> funcAlias = new PathBuilder<String>(String.class, "tokFunc");
|
||||
SQLSubQuery sq = new SQLSubQuery();
|
||||
SubQueryExpression<?> expr = sq.from(table)
|
||||
|
||||
@ -49,20 +49,8 @@ public class RelationalFunctionCall<T> extends SimpleExpression<T> implements Te
|
||||
|
||||
private final TemplateExpression<T> templateMixin;
|
||||
|
||||
/**
|
||||
* Create a new RelationalFunctionCall for the given function and arguments
|
||||
*
|
||||
* @param type
|
||||
* @param function
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
public static <T> RelationalFunctionCall<T> create(Class<? extends T> type, String function, Object... args) {
|
||||
return new RelationalFunctionCall<T>(type, function, args);
|
||||
}
|
||||
|
||||
public RelationalFunctionCall(Class<? extends T> type, String function, Object... args) {
|
||||
super(TemplateExpressionImpl.create((Class)type, createTemplate(function, args.length), args));
|
||||
protected RelationalFunctionCall(Class<? extends T> type, String function, Object... args) {
|
||||
super(TemplateExpressionImpl.create(type, createTemplate(function, args.length), args));
|
||||
templateMixin = (TemplateExpression<T>)mixin;
|
||||
}
|
||||
|
||||
|
||||
@ -115,6 +115,19 @@ public final class SQLExpressions {
|
||||
return Expressions.booleanOperation(Ops.AggOps.BOOLEAN_ALL, expr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new RelationalFunctionCall for the given function and arguments
|
||||
*
|
||||
* @param type
|
||||
* @param function
|
||||
* @param args
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> RelationalFunctionCall<T> relationalFunctionCall(Class<? extends T> type, String function, Object... args) {
|
||||
return new RelationalFunctionCall<T>(type, function, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a nextval(sequence) expression
|
||||
*
|
||||
|
||||
@ -57,14 +57,14 @@ public class RelationalFunctionCallTest {
|
||||
|
||||
@Test
|
||||
public void NoArgs() {
|
||||
RelationalFunctionCall<String> functionCall = RelationalFunctionCall.create(String.class, "getElements");
|
||||
RelationalFunctionCall<String> functionCall = SQLExpressions.relationalFunctionCall(String.class, "getElements");
|
||||
assertEquals("getElements()", functionCall.getTemplate().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TwoArgs() {
|
||||
StringPath str = Expressions.stringPath("str");
|
||||
RelationalFunctionCall<String> functionCall = RelationalFunctionCall.create(String.class, "getElements", "a", str);
|
||||
RelationalFunctionCall<String> functionCall = SQLExpressions.relationalFunctionCall(String.class, "getElements", "a", str);
|
||||
assertEquals("getElements({0}, {1})", functionCall.getTemplate().toString());
|
||||
assertEquals("a", functionCall.getArg(0));
|
||||
assertEquals(str, functionCall.getArg(1));
|
||||
|
||||
@ -165,7 +165,7 @@ public class SQLSerializerTest {
|
||||
@Test
|
||||
public void Join_To_Function_With_Alias() {
|
||||
SQLQuery query = query();
|
||||
query.from(survey).join(RelationalFunctionCall.create(Survey.class, "functionCall"), Expressions.path(Survey.class, "fc"));
|
||||
query.from(survey).join(SQLExpressions.relationalFunctionCall(Survey.class, "functionCall"), Expressions.path(Survey.class, "fc"));
|
||||
query.where(survey.name.isNotNull());
|
||||
assertEquals("from SURVEY SURVEY\njoin functionCall() as fc\nwhere SURVEY.NAME is not null", query.toString());
|
||||
}
|
||||
@ -173,7 +173,7 @@ public class SQLSerializerTest {
|
||||
@Test
|
||||
public void Join_To_Function_In_Derby() {
|
||||
SQLQuery query = new SQLQuery(new DerbyTemplates());
|
||||
query.from(survey).join(RelationalFunctionCall.create(Survey.class, "functionCall"), Expressions.path(Survey.class, "fc"));
|
||||
query.from(survey).join(SQLExpressions.relationalFunctionCall(Survey.class, "functionCall"), Expressions.path(Survey.class, "fc"));
|
||||
query.where(survey.name.isNotNull());
|
||||
assertEquals("from SURVEY SURVEY\njoin table(functionCall()) as fc\nwhere SURVEY.NAME is not null", query.toString());
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public class SerializationTest {
|
||||
|
||||
@Test
|
||||
public void FunctionCall() {
|
||||
RelationalFunctionCall<String> func = RelationalFunctionCall.create(String.class, "TableValuedFunction", "parameter");
|
||||
RelationalFunctionCall<String> func = SQLExpressions.relationalFunctionCall(String.class, "TableValuedFunction", "parameter");
|
||||
PathBuilder<String> funcAlias = new PathBuilder<String>(String.class, "tokFunc");
|
||||
SQLSubQuery sq = new SQLSubQuery();
|
||||
SubQueryExpression<?> expr = sq.from(survey)
|
||||
@ -128,7 +128,7 @@ public class SerializationTest {
|
||||
|
||||
@Test
|
||||
public void FunctionCall2() {
|
||||
RelationalFunctionCall<String> func = RelationalFunctionCall.create(String.class, "TableValuedFunction", "parameter");
|
||||
RelationalFunctionCall<String> func = SQLExpressions.relationalFunctionCall(String.class, "TableValuedFunction", "parameter");
|
||||
PathBuilder<String> funcAlias = new PathBuilder<String>(String.class, "tokFunc");
|
||||
SQLQuery q = new SQLQuery(new SQLServerTemplates());
|
||||
q.from(survey)
|
||||
@ -141,7 +141,7 @@ public class SerializationTest {
|
||||
|
||||
@Test
|
||||
public void FunctionCall3() {
|
||||
RelationalFunctionCall<String> func = RelationalFunctionCall.create(String.class, "TableValuedFunction", "parameter");
|
||||
RelationalFunctionCall<String> func = SQLExpressions.relationalFunctionCall(String.class, "TableValuedFunction", "parameter");
|
||||
PathBuilder<String> funcAlias = new PathBuilder<String>(String.class, "tokFunc");
|
||||
SQLQuery q = new SQLQuery(new HSQLDBTemplates());
|
||||
q.from(survey)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user