All Downloads are FREE. Search and download functionalities are using the official Maven repository.

site.sorghum.anno._ddl.ColumnExpressionVisitor Maven / Gradle / Ivy

The newest version!
package site.sorghum.anno._ddl;

import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitorAdapter;
import net.sf.jsqlparser.expression.RowConstructor;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import site.sorghum.anno._common.util.JSqlParserUtil;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author songyinyin
 * @since 2023/7/8 17:44
 */
public class ColumnExpressionVisitor extends ExpressionVisitorAdapter {

    private final List> list;

    private final Map indexToColumn;

    public ColumnExpressionVisitor(List> list, Map indexToColumn) {
        this.list = list;
        this.indexToColumn = indexToColumn;
    }

    @Override
    public void visit(RowConstructor rowConstructor) {
        ExpressionList exprList = rowConstructor.getExprList();
        List expressions = exprList.getExpressions();
        Map columnToValue = new LinkedHashMap<>();
        for (int i = 0; i < expressions.size(); i++) {
            Expression expression = expressions.get(i);
            columnToValue.put(indexToColumn.get(i), JSqlParserUtil.getExpressionValue(expression));
        }
        list.add(columnToValue);

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy