Search in sources :

Example 26 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class StatementDeParserTest method shouldUseProvidedDeParserWhenDeParsingSetStatement.

@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeParserWhenDeParsingSetStatement() {
    String name = "name";
    Expression expression = mock(Expression.class);
    SetStatement setStatement = new SetStatement(name, expression);
    statementDeParser.visit(setStatement);
    then(expression).should().accept(expressionDeParser);
}
Also used : Expression(net.sf.jsqlparser.expression.Expression) SetStatement(net.sf.jsqlparser.statement.SetStatement) Test(org.junit.Test)

Example 27 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class StatementDeParserTest method shouldUseProvidedDeParserWhenDeParsingExecute.

@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeParserWhenDeParsingExecute() {
    Execute execute = new Execute();
    ExpressionList exprList = new ExpressionList();
    List<Expression> expressions = new ArrayList<Expression>();
    Expression expression1 = mock(Expression.class);
    Expression expression2 = mock(Expression.class);
    execute.setExprList(exprList);
    exprList.setExpressions(expressions);
    expressions.add(expression1);
    expressions.add(expression2);
    statementDeParser.visit(execute);
    then(expression1).should().accept(expressionDeParser);
    then(expression2).should().accept(expressionDeParser);
}
Also used : Execute(net.sf.jsqlparser.statement.execute.Execute) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) ExpressionList(net.sf.jsqlparser.expression.operators.relational.ExpressionList) Test(org.junit.Test)

Example 28 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class StatementDeParserTest method shouldUseProvidedDeparsersWhenDeParsingUpsertWithExpressionList.

@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeparsersWhenDeParsingUpsertWithExpressionList() throws JSQLParserException {
    Upsert upsert = new Upsert();
    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);
    upsert.setSelect(select);
    upsert.setTable(table);
    upsert.setUseDuplicate(true);
    upsert.setDuplicateUpdateColumns(duplicateUpdateColumns);
    upsert.setDuplicateUpdateExpressionList(duplicateUpdateExpressionList);
    duplicateUpdateColumns.add(duplicateUpdateColumn1);
    duplicateUpdateColumns.add(duplicateUpdateColumn2);
    duplicateUpdateExpressionList.add(duplicateUpdateExpression1);
    duplicateUpdateExpressionList.add(duplicateUpdateExpression2);
    upsert.setDuplicateUpdateExpressionList(duplicateUpdateExpressionList);
    select.setWithItemsList(withItemsList);
    select.setSelectBody(selectBody);
    withItemsList.add(withItem1);
    withItemsList.add(withItem2);
    withItem1.setSelectBody(withItem1SelectBody);
    withItem2.setSelectBody(withItem2SelectBody);
    statementDeParser.visit(upsert);
    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);
}
Also used : Upsert(net.sf.jsqlparser.statement.upsert.Upsert) Table(net.sf.jsqlparser.schema.Table) Column(net.sf.jsqlparser.schema.Column) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) Select(net.sf.jsqlparser.statement.select.Select) WithItem(net.sf.jsqlparser.statement.select.WithItem) SelectBody(net.sf.jsqlparser.statement.select.SelectBody) Test(org.junit.Test)

Example 29 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class ExpressionDeParser method visit.

@Override
public void visit(CaseExpression caseExpression) {
    buffer.append("CASE ");
    Expression switchExp = caseExpression.getSwitchExpression();
    if (switchExp != null) {
        switchExp.accept(this);
        buffer.append(" ");
    }
    for (Expression exp : caseExpression.getWhenClauses()) {
        exp.accept(this);
    }
    Expression elseExp = caseExpression.getElseExpression();
    if (elseExp != null) {
        buffer.append("ELSE ");
        elseExp.accept(this);
        buffer.append(" ");
    }
    buffer.append("END");
}
Also used : KeepExpression(net.sf.jsqlparser.expression.KeepExpression) CaseExpression(net.sf.jsqlparser.expression.CaseExpression) NotExpression(net.sf.jsqlparser.expression.NotExpression) ValueListExpression(net.sf.jsqlparser.expression.ValueListExpression) CastExpression(net.sf.jsqlparser.expression.CastExpression) OracleHierarchicalExpression(net.sf.jsqlparser.expression.OracleHierarchicalExpression) IsNullExpression(net.sf.jsqlparser.expression.operators.relational.IsNullExpression) Expression(net.sf.jsqlparser.expression.Expression) IntervalExpression(net.sf.jsqlparser.expression.IntervalExpression) OrExpression(net.sf.jsqlparser.expression.operators.conditional.OrExpression) TimeKeyExpression(net.sf.jsqlparser.expression.TimeKeyExpression) BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) JsonExpression(net.sf.jsqlparser.expression.JsonExpression) LikeExpression(net.sf.jsqlparser.expression.operators.relational.LikeExpression) ExistsExpression(net.sf.jsqlparser.expression.operators.relational.ExistsExpression) InExpression(net.sf.jsqlparser.expression.operators.relational.InExpression) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) AnalyticExpression(net.sf.jsqlparser.expression.AnalyticExpression) AllComparisonExpression(net.sf.jsqlparser.expression.AllComparisonExpression) ExtractExpression(net.sf.jsqlparser.expression.ExtractExpression) AnyComparisonExpression(net.sf.jsqlparser.expression.AnyComparisonExpression) SignedExpression(net.sf.jsqlparser.expression.SignedExpression) OldOracleJoinBinaryExpression(net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression) DateTimeLiteralExpression(net.sf.jsqlparser.expression.DateTimeLiteralExpression)

Example 30 with Expression

use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.

the class ExpressionDeParser method visit.

@Override
public void visit(RowConstructor rowConstructor) {
    if (rowConstructor.getName() != null) {
        buffer.append(rowConstructor.getName());
    }
    buffer.append("(");
    boolean first = true;
    for (Expression expr : rowConstructor.getExprList().getExpressions()) {
        if (first) {
            first = false;
        } else {
            buffer.append(", ");
        }
        expr.accept(this);
    }
    buffer.append(")");
}
Also used : KeepExpression(net.sf.jsqlparser.expression.KeepExpression) CaseExpression(net.sf.jsqlparser.expression.CaseExpression) NotExpression(net.sf.jsqlparser.expression.NotExpression) ValueListExpression(net.sf.jsqlparser.expression.ValueListExpression) CastExpression(net.sf.jsqlparser.expression.CastExpression) OracleHierarchicalExpression(net.sf.jsqlparser.expression.OracleHierarchicalExpression) IsNullExpression(net.sf.jsqlparser.expression.operators.relational.IsNullExpression) Expression(net.sf.jsqlparser.expression.Expression) IntervalExpression(net.sf.jsqlparser.expression.IntervalExpression) OrExpression(net.sf.jsqlparser.expression.operators.conditional.OrExpression) TimeKeyExpression(net.sf.jsqlparser.expression.TimeKeyExpression) BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) JsonExpression(net.sf.jsqlparser.expression.JsonExpression) LikeExpression(net.sf.jsqlparser.expression.operators.relational.LikeExpression) ExistsExpression(net.sf.jsqlparser.expression.operators.relational.ExistsExpression) InExpression(net.sf.jsqlparser.expression.operators.relational.InExpression) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) AnalyticExpression(net.sf.jsqlparser.expression.AnalyticExpression) AllComparisonExpression(net.sf.jsqlparser.expression.AllComparisonExpression) ExtractExpression(net.sf.jsqlparser.expression.ExtractExpression) AnyComparisonExpression(net.sf.jsqlparser.expression.AnyComparisonExpression) SignedExpression(net.sf.jsqlparser.expression.SignedExpression) OldOracleJoinBinaryExpression(net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression) DateTimeLiteralExpression(net.sf.jsqlparser.expression.DateTimeLiteralExpression)

Aggregations

Expression (net.sf.jsqlparser.expression.Expression)100 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)33 ArrayList (java.util.ArrayList)32 Test (org.junit.Test)30 BinaryExpression (net.sf.jsqlparser.expression.BinaryExpression)28 SignedExpression (net.sf.jsqlparser.expression.SignedExpression)26 ExpressionList (net.sf.jsqlparser.expression.operators.relational.ExpressionList)21 Column (net.sf.jsqlparser.schema.Column)19 CompiledSQLExpression (herddb.sql.expressions.CompiledSQLExpression)17 AlterExpression (net.sf.jsqlparser.statement.alter.AlterExpression)17 LikeExpression (net.sf.jsqlparser.expression.operators.relational.LikeExpression)15 StatementExecutionException (herddb.model.StatementExecutionException)14 NotExpression (net.sf.jsqlparser.expression.NotExpression)14 Table (net.sf.jsqlparser.schema.Table)14 CaseExpression (net.sf.jsqlparser.expression.CaseExpression)12 OrExpression (net.sf.jsqlparser.expression.operators.conditional.OrExpression)12 Column (herddb.model.Column)11 TimeKeyExpression (net.sf.jsqlparser.expression.TimeKeyExpression)11 InExpression (net.sf.jsqlparser.expression.operators.relational.InExpression)11 Function (net.sf.jsqlparser.expression.Function)10