Search in sources :

Example 6 with SqlSequenceExpr

use of io.seata.sqlparser.struct.SqlSequenceExpr in project seata by seata.

the class OracleInsertRecognizer method getInsertRows.

@Override
public List<List<Object>> getInsertRows(Collection<Integer> primaryKeyIndex) {
    List<SQLInsertStatement.ValuesClause> valuesClauses = ast.getValuesList();
    List<List<Object>> rows = new ArrayList<>(valuesClauses.size());
    for (SQLInsertStatement.ValuesClause valuesClause : valuesClauses) {
        List<SQLExpr> exprs = valuesClause.getValues();
        List<Object> row = new ArrayList<>(exprs.size());
        rows.add(row);
        for (int i = 0, len = exprs.size(); i < len; i++) {
            SQLExpr expr = exprs.get(i);
            if (expr instanceof SQLNullExpr) {
                row.add(Null.get());
            } else if (expr instanceof SQLValuableExpr) {
                row.add(((SQLValuableExpr) expr).getValue());
            } else if (expr instanceof SQLVariantRefExpr) {
                row.add(((SQLVariantRefExpr) expr).getName());
            } else if (expr instanceof SQLMethodInvokeExpr) {
                row.add(SqlMethodExpr.get());
            } else if (expr instanceof SQLSequenceExpr) {
                SQLSequenceExpr sequenceExpr = (SQLSequenceExpr) expr;
                String sequence = sequenceExpr.getSequence().getSimpleName();
                String function = sequenceExpr.getFunction().name;
                row.add(new SqlSequenceExpr(sequence, function));
            } else {
                if (primaryKeyIndex.contains(i)) {
                    throw new SQLParsingException("Unknown SQLExpr: " + expr.getClass() + " " + expr);
                }
                row.add(NotPlaceholderExpr.get());
            }
        }
    }
    return rows;
}
Also used : SQLMethodInvokeExpr(com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr) ArrayList(java.util.ArrayList) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLValuableExpr(com.alibaba.druid.sql.ast.expr.SQLValuableExpr) SQLParsingException(io.seata.sqlparser.SQLParsingException) SQLInsertStatement(com.alibaba.druid.sql.ast.statement.SQLInsertStatement) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) ArrayList(java.util.ArrayList) List(java.util.List) SQLSequenceExpr(com.alibaba.druid.sql.ast.expr.SQLSequenceExpr) SqlSequenceExpr(io.seata.sqlparser.struct.SqlSequenceExpr)

Aggregations

SqlSequenceExpr (io.seata.sqlparser.struct.SqlSequenceExpr)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)2 SQLNullExpr (com.alibaba.druid.sql.ast.expr.SQLNullExpr)2 SQLSequenceExpr (com.alibaba.druid.sql.ast.expr.SQLSequenceExpr)2 SQLValuableExpr (com.alibaba.druid.sql.ast.expr.SQLValuableExpr)2 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)2 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)2 SQLParsingException (io.seata.sqlparser.SQLParsingException)2 Test (org.junit.jupiter.api.Test)2 SQLDefaultExpr (com.alibaba.druid.sql.ast.expr.SQLDefaultExpr)1 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)1 PreparedStatementProxy (io.seata.rm.datasource.PreparedStatementProxy)1 ColumnMeta (io.seata.rm.datasource.sql.struct.ColumnMeta)1 HashMap (java.util.HashMap)1