use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.
the class ReplaceDeParser method visit.
@Override
public void visit(MultiExpressionList multiExprList) {
buffer.append("VALUES ");
for (Iterator<ExpressionList> it = multiExprList.getExprList().iterator(); it.hasNext(); ) {
buffer.append("(");
for (Iterator<Expression> iter = it.next().getExpressions().iterator(); iter.hasNext(); ) {
Expression expression = iter.next();
expression.accept(expressionVisitor);
if (iter.hasNext()) {
buffer.append(", ");
}
}
buffer.append(")");
if (it.hasNext()) {
buffer.append(", ");
}
}
}
use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.
the class UpdateDeParser method deParse.
public void deParse(Update update) {
buffer.append("UPDATE ").append(PlainSelect.getStringList(update.getTables(), true, false)).append(" SET ");
if (!update.isUseSelect()) {
for (int i = 0; i < update.getColumns().size(); i++) {
Column column = update.getColumns().get(i);
column.accept(expressionVisitor);
buffer.append(" = ");
Expression expression = update.getExpressions().get(i);
expression.accept(expressionVisitor);
if (i < update.getColumns().size() - 1) {
buffer.append(", ");
}
}
} else {
if (update.isUseColumnsBrackets()) {
buffer.append("(");
}
for (int i = 0; i < update.getColumns().size(); i++) {
if (i != 0) {
buffer.append(", ");
}
Column column = update.getColumns().get(i);
column.accept(expressionVisitor);
}
if (update.isUseColumnsBrackets()) {
buffer.append(")");
}
buffer.append(" = ");
buffer.append("(");
Select select = update.getSelect();
select.getSelectBody().accept(selectVisitor);
buffer.append(")");
}
if (update.getFromItem() != null) {
buffer.append(" FROM ").append(update.getFromItem());
if (update.getJoins() != null) {
for (Join join : update.getJoins()) {
if (join.isSimple()) {
buffer.append(", ").append(join);
} else {
buffer.append(" ").append(join);
}
}
}
}
if (update.getWhere() != null) {
buffer.append(" WHERE ");
update.getWhere().accept(expressionVisitor);
}
if (update.getOrderByElements() != null) {
new OrderByDeParser(expressionVisitor, buffer).deParse(update.getOrderByElements());
}
if (update.getLimit() != null) {
new LimitDeparser(buffer).deParse(update.getLimit());
}
if (update.isReturningAllColumns()) {
buffer.append(" RETURNING *");
} else if (update.getReturningExpressionList() != null) {
buffer.append(" RETURNING ");
for (Iterator<SelectExpressionItem> iter = update.getReturningExpressionList().iterator(); iter.hasNext(); ) {
buffer.append(iter.next().toString());
if (iter.hasNext()) {
buffer.append(", ");
}
}
}
}
use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.
the class UpsertDeParser method visit.
@Override
public void visit(MultiExpressionList multiExprList) {
buffer.append(" VALUES ");
for (Iterator<ExpressionList> it = multiExprList.getExprList().iterator(); it.hasNext(); ) {
buffer.append("(");
for (Iterator<Expression> iter = it.next().getExpressions().iterator(); iter.hasNext(); ) {
Expression expression = iter.next();
expression.accept(expressionVisitor);
if (iter.hasNext()) {
buffer.append(", ");
}
}
buffer.append(")");
if (it.hasNext()) {
buffer.append(", ");
}
}
}
use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.
the class UpsertDeParser method visit.
@Override
public void visit(ExpressionList expressionList) {
buffer.append(" VALUES (");
for (Iterator<Expression> iter = expressionList.getExpressions().iterator(); iter.hasNext(); ) {
Expression expression = iter.next();
expression.accept(expressionVisitor);
if (iter.hasNext()) {
buffer.append(", ");
}
}
buffer.append(")");
}
use of net.sf.jsqlparser.expression.Expression in project JSqlParser by JSQLParser.
the class CNFConverter method handleNot.
/**
* This function mainly deals with pushing not operators down.
* check the child. If it is not a logic operator(and or or).
* stop at that point. Else use De Morgan law to push not downwards.
* @param index the index of the children appeared in parents array.
*/
private void handleNot(int index) {
child = ((NotExpression) temp1).getExpression();
// takes down the number of not operators.
int nums = 1;
while (child instanceof NotExpression) {
child = ((NotExpression) child).getExpression();
nums++;
}
/* if the number of not operators are even. we could get
* rid of all the not operators. set the child to the parent. */
if (nums % 2 == 0) {
((MultipleExpression) temp2).setChild(index, child);
temp1 = child;
pushNot(-1);
} else {
/* otherwise there will be one not left to push.
* if the child is not these two types of operators.
* that means we reach the leaves of the logical part.
* set a new not operator whose child is the current one
* and connect that operator with the parent and return. */
if (!(child instanceof MultiAndExpression) && !(child instanceof MultiOrExpression)) {
if (child instanceof LikeExpression) {
((LikeExpression) child).setNot(true);
} else if (child instanceof BinaryExpression) {
((BinaryExpression) child).setNot();
} else {
child = new NotExpression(child);
}
((MultipleExpression) temp2).setChild(index, child);
return;
} else if (child instanceof MultiAndExpression) {
MultiAndExpression and = (MultiAndExpression) child;
List<Expression> list = new ArrayList<Expression>();
for (int i = 0; i < and.size(); i++) {
/* push not to every element in the operator. */
NotExpression not = new NotExpression(and.getChild(i));
list.add(not);
}
/* the De Morgan law shows we need to change and to or. */
temp1 = new MultiOrExpression(list);
((MultipleExpression) temp2).setChild(index, temp1);
pushNot(-1);
} else if (child instanceof MultiOrExpression) {
MultiOrExpression or = (MultiOrExpression) child;
List<Expression> list = new ArrayList<Expression>();
for (int i = 0; i < or.size(); i++) {
/* push not to every element in the operator. */
NotExpression not = new NotExpression(or.getChild(i));
list.add(not);
}
/* the De Morgan law shows we need to change or to and. */
temp1 = new MultiAndExpression(list);
((MultipleExpression) temp2).setChild(index, temp1);
pushNot(-1);
}
}
}
Aggregations