Created
January 19, 2018 04:56
-
-
Save KDamir/ec9f755219be312625973735c66b76d0 to your computer and use it in GitHub Desktop.
example query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ResultQuestion resultQuestion = new ResultQuestion(); | |
ScenarioSubject scenarioSubject = resultQuestion.questoin_id.innerQuestion().scenario_id_subject_id.innerScenarioSubject(); | |
resultQuestion.where(resultQuestion.event_record_id.eq(param(eventRecordId))); | |
Select select = Utils.createSelect(); | |
select.select(resultQuestion.questoin_id); | |
select.select(resultQuestion.question_text); | |
select.select(PostgresFunction.lag(resultQuestion.questoin_id).as("prev")); | |
select.select(PostgresFunction.lead(resultQuestion.questoin_id).as("next")); | |
select.select(when(scenarioSubject.question_show_count.gt(resultQuestion.show_count), value(true)).otherwise(value(false)).as("can_skip")); | |
select.orderBy(resultQuestion.questoin_id); | |
class MyView extends PostgresSelect { | |
private AliasColumn<MyView,Integer> question_id = new AliasColumn<MyView, Integer>(this, resultQuestion.questoin_id); | |
private AliasColumn<MyView,String> question_text = new AliasColumn<MyView,String>(this, resultQuestion.question_text); | |
private AliasColumn<MyView, Integer> prev = new AliasColumn<MyView, Integer>(this, PostgresFunction.lag(resultQuestion.questoin_id).as("prev")); | |
private AliasColumn<MyView, Integer> next = new AliasColumn<MyView, Integer>(this, PostgresFunction.lead(resultQuestion.questoin_id).as("next")); | |
@Override | |
public List<ParamExpression> getParamExpressions() { | |
List<ParamExpression> paramExpressions = new LinkedList<ParamExpression>(); | |
for (Expression<?> expression : selectExpressions) { | |
paramExpressions.addAll(expression.getParamExpressions()); | |
} | |
if (from != null) paramExpressions.addAll(from.getParamExpressions()); | |
if (havingCondition != null) paramExpressions.addAll(havingCondition.getParamExpressions()); | |
for (BaseSelect baseSelect : unions) { | |
paramExpressions.addAll(baseSelect.getParamExpressions()); | |
} | |
for (BaseSelect baseSelect : unionAllList) { | |
paramExpressions.addAll(baseSelect.getParamExpressions()); | |
} | |
paramExpressions.addAll(super.getParamExpressions()); | |
return paramExpressions; | |
} | |
} | |
MyView tbl = new MyView(); | |
tbl.where(tbl.question_id.eq(param(questionId))); | |
Select mainSelect = Utils.createSelect(); | |
mainSelect.select(tbl.question_id); | |
mainSelect.select(tbl.question_text); | |
mainSelect.select(tbl.prev); | |
mainSelect.select(tbl.next); | |
String sql = mainSelect.getSQL(); | |
Object[] values = mainSelect.getValues(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment