Search in sources :

Example 16 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class SqlParser method parseEndBlockComment.

protected void parseEndBlockComment() {
    if (!isInBlockNode()) {
        throw new JdbcException(Message.DOMA2104, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    removeNodesTo(BlockNode.class);
    BlockNode blockNode = pop();
    EndNode node = new EndNode(token);
    blockNode.setEndNode(node);
    push(node);
}
Also used : IfBlockNode(org.seasar.doma.internal.jdbc.sql.node.IfBlockNode) ForBlockNode(org.seasar.doma.internal.jdbc.sql.node.ForBlockNode) BlockNode(org.seasar.doma.internal.jdbc.sql.node.BlockNode) EndNode(org.seasar.doma.internal.jdbc.sql.node.EndNode) JdbcException(org.seasar.doma.jdbc.JdbcException)

Example 17 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class SqlParser method appendNode.

protected void appendNode(SqlNode node) {
    if (isAfterValueNode()) {
        ValueNode valueNode = pop();
        if (node instanceof WordNode) {
            WordNode wordNode = (WordNode) node;
            String word = wordNode.getWord();
            Matcher matcher = LITERAL_PATTERN.matcher(word);
            if (matcher.lookingAt()) {
                valueNode.setWordNode(wordNode);
            } else {
                throw new JdbcException(Message.DOMA2142, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), valueNode.getText(), word);
            }
        } else if (node instanceof ParensNode) {
            ParensNode parensNode = (ParensNode) node;
            parensNode.setAttachedWithValue(true);
            valueNode.setParensNode(parensNode);
        } else {
            throw new JdbcException(Message.DOMA2110, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), valueNode.getText());
        }
    } else if (isAfterExpandNode()) {
        ExpandNode expandNode = pop();
        if (node instanceof OtherNode) {
            OtherNode otherNode = (OtherNode) node;
            if (!otherNode.getOther().equals("*")) {
                throw new JdbcException(Message.DOMA2143, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), expandNode.getText());
            }
        } else {
            throw new JdbcException(Message.DOMA2143, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), expandNode.getText());
        }
    } else {
        peek().appendNode(node);
    }
}
Also used : ParensNode(org.seasar.doma.internal.jdbc.sql.node.ParensNode) OtherNode(org.seasar.doma.internal.jdbc.sql.node.OtherNode) WordNode(org.seasar.doma.internal.jdbc.sql.node.WordNode) Matcher(java.util.regex.Matcher) ExpandNode(org.seasar.doma.internal.jdbc.sql.node.ExpandNode) ValueNode(org.seasar.doma.internal.jdbc.sql.node.ValueNode) JdbcException(org.seasar.doma.jdbc.JdbcException)

Example 18 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class SqlParser method parseElseifBlockComment.

protected void parseElseifBlockComment() {
    if (!isInIfBlockNode()) {
        throw new JdbcException(Message.DOMA2138, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    removeNodesTo(IfBlockNode.class);
    IfBlockNode ifBlockNode = peek();
    if (ifBlockNode.isElseNodeExistent()) {
        throw new JdbcException(Message.DOMA2139, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    String expression = tokenType.extract(token);
    ElseifNode node = new ElseifNode(getLocation(), expression, token);
    ifBlockNode.addElseifNode(node);
    push(node);
}
Also used : IfBlockNode(org.seasar.doma.internal.jdbc.sql.node.IfBlockNode) JdbcException(org.seasar.doma.jdbc.JdbcException) ElseifNode(org.seasar.doma.internal.jdbc.sql.node.ElseifNode)

Example 19 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class SqlParser method parseForBlockComment.

protected void parseForBlockComment() {
    ForBlockNode forBlockNode = new ForBlockNode();
    appendNode(forBlockNode);
    push(forBlockNode);
    String expr = tokenType.extract(token);
    int pos = expr.indexOf(":");
    if (pos == -1) {
        throw new JdbcException(Message.DOMA2124, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    String identifier = expr.substring(0, pos).trim();
    if (identifier.isEmpty()) {
        throw new JdbcException(Message.DOMA2125, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    String expression = expr.substring(pos + 1).trim();
    if (expression.isEmpty()) {
        throw new JdbcException(Message.DOMA2126, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    ForNode forNode = new ForNode(getLocation(), identifier, expression, token);
    forBlockNode.setForNode(forNode);
    push(forNode);
}
Also used : ForNode(org.seasar.doma.internal.jdbc.sql.node.ForNode) ForBlockNode(org.seasar.doma.internal.jdbc.sql.node.ForBlockNode) JdbcException(org.seasar.doma.jdbc.JdbcException)

Example 20 with JdbcException

use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.

the class SqlParser method validateParensClosed.

protected void validateParensClosed() {
    if (isInParensNode()) {
        removeNodesTo(ParensNode.class);
        ParensNode parensNode = pop();
        SqlLocation location = parensNode.getLocation();
        throw new JdbcException(Message.DOMA2135, sql, location.getLineNumber(), location.getPosition());
    }
}
Also used : ParensNode(org.seasar.doma.internal.jdbc.sql.node.ParensNode) SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation) JdbcException(org.seasar.doma.jdbc.JdbcException)

Aggregations

JdbcException (org.seasar.doma.jdbc.JdbcException)69 Test (org.junit.jupiter.api.Test)35 SqlNode (org.seasar.doma.jdbc.SqlNode)18 SQLException (java.sql.SQLException)15 BigDecimal (java.math.BigDecimal)9 Value (org.seasar.doma.internal.expr.Value)9 ExpressionEvaluator (org.seasar.doma.internal.expr.ExpressionEvaluator)8 SqlLocation (org.seasar.doma.internal.jdbc.sql.node.SqlLocation)7 SelectOptions (org.seasar.doma.jdbc.SelectOptions)7 SqlParser (org.seasar.doma.internal.jdbc.sql.SqlParser)6 Connection (java.sql.Connection)5 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)5 PreparedStatement (java.sql.PreparedStatement)4 Savepoint (java.sql.Savepoint)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 DomaNullPointerException (org.seasar.doma.DomaNullPointerException)4 MockConnection (org.seasar.doma.internal.jdbc.mock.MockConnection)4 MockDataSource (org.seasar.doma.internal.jdbc.mock.MockDataSource)4 IfBlockNode (org.seasar.doma.internal.jdbc.sql.node.IfBlockNode)4