use of net.sf.jsqlparser.statement.select.SelectBody in project JSqlParser by JSQLParser.
the class StatementDeParserTest method shouldUseProvidedDeparsersWhenDeParsingInsert.
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeparsersWhenDeParsingInsert() throws JSQLParserException {
Insert insert = new Insert();
Table table = new Table();
List<Column> duplicateUpdateColumns = new ArrayList<Column>();
List<Expression> duplicateUpdateExpressionList = new ArrayList<Expression>();
Column duplicateUpdateColumn1 = new Column();
Column duplicateUpdateColumn2 = new Column();
Expression duplicateUpdateExpression1 = mock(Expression.class);
Expression duplicateUpdateExpression2 = mock(Expression.class);
Select select = new Select();
List<WithItem> withItemsList = new ArrayList<WithItem>();
WithItem withItem1 = spy(new WithItem());
WithItem withItem2 = spy(new WithItem());
SelectBody withItem1SelectBody = mock(SelectBody.class);
SelectBody withItem2SelectBody = mock(SelectBody.class);
SelectBody selectBody = mock(SelectBody.class);
insert.setSelect(select);
insert.setTable(table);
insert.setUseDuplicate(true);
insert.setDuplicateUpdateColumns(duplicateUpdateColumns);
insert.setDuplicateUpdateExpressionList(duplicateUpdateExpressionList);
duplicateUpdateColumns.add(duplicateUpdateColumn1);
duplicateUpdateColumns.add(duplicateUpdateColumn2);
duplicateUpdateExpressionList.add(duplicateUpdateExpression1);
duplicateUpdateExpressionList.add(duplicateUpdateExpression2);
insert.setDuplicateUpdateExpressionList(duplicateUpdateExpressionList);
select.setWithItemsList(withItemsList);
select.setSelectBody(selectBody);
withItemsList.add(withItem1);
withItemsList.add(withItem2);
withItem1.setSelectBody(withItem1SelectBody);
withItem2.setSelectBody(withItem2SelectBody);
statementDeParser.visit(insert);
then(withItem1).should().accept(selectDeParser);
then(withItem2).should().accept(selectDeParser);
then(selectBody).should().accept(selectDeParser);
then(duplicateUpdateExpression1).should().accept(expressionDeParser);
then(duplicateUpdateExpression1).should().accept(expressionDeParser);
}
use of net.sf.jsqlparser.statement.select.SelectBody in project JSqlParser by JSQLParser.
the class StatementDeParserTest method shouldUseProvidedDeParsersWhenDeParsingSelect.
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeParsersWhenDeParsingSelect() {
Select select = new Select();
WithItem withItem1 = spy(new WithItem());
WithItem withItem2 = spy(new WithItem());
SelectBody selectBody = mock(SelectBody.class);
List<WithItem> withItemsList = new ArrayList<WithItem>();
select.setWithItemsList(withItemsList);
select.setSelectBody(selectBody);
withItemsList.add(withItem1);
withItemsList.add(withItem2);
statementDeParser.visit(select);
then(withItem1).should().accept(selectDeParser);
then(withItem2).should().accept(selectDeParser);
then(selectBody).should().accept(selectDeParser);
}
use of net.sf.jsqlparser.statement.select.SelectBody in project yyl_example by Relucent.
the class CountSqlParser method sqlToCount.
/**
* 将 SQL 转换为 COUNT 查询
*/
public void sqlToCount(Select select) {
SelectBody selectBody = select.getSelectBody();
List<SelectItem> countItem = new ArrayList<SelectItem>();
countItem.add(new SelectExpressionItem(new Column("count(*)")));
if (selectBody instanceof PlainSelect && isSimpleCount((PlainSelect) selectBody)) {
((PlainSelect) selectBody).setSelectItems(countItem);
} else {
SubSelect subSelect = new SubSelect();
subSelect.setSelectBody(selectBody);
subSelect.setAlias(TABLE_ALIAS);
PlainSelect plainSelect = new PlainSelect();
plainSelect.setFromItem(subSelect);
plainSelect.setSelectItems(countItem);
select.setSelectBody(plainSelect);
}
}
Aggregations