com.github.changemonitor.sql.JsqlParserHelper Maven / Gradle / Ivy
package com.github.changemonitor.sql;
import java.util.ArrayList;
import java.util.List;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitorAdapter;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.util.SelectUtils;
public class JsqlParserHelper {
public static List getWhereColumn(Expression whereExpression){
final List result = new ArrayList<>();
whereExpression.accept(new ExpressionVisitorAdapter() {
@Override
public void visit(Column expr) {
if(!result.contains(expr.getColumnName())){
result.add(expr.getColumnName().toLowerCase());
}
}
});
return result;
}
public static Select getSelect(Table table, List column, Expression whereExpression){
Column[] selectColumns = (Column[]) column.toArray(new Column[column.size()]);
Select select = SelectUtils.buildSelectFromTableAndExpressions(table, selectColumns);
PlainSelect selectPlain = (PlainSelect) select.getSelectBody();
selectPlain.setWhere(whereExpression);
return select;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy