Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package nl.topicus.jdbc.shaded.net.sf.jsqlparser.util.deparser;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.expression.*;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.schema.*;
import nl.topicus.jdbc.shaded.net.sf.jsqlparser.statement.select.*;
import java.util.*;
/**
* A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a
* {@link nl.topicus.jdbc.shaded.net.sf.jsqlparser.statement.select.Select}
*/
public class SelectDeParser implements SelectVisitor, SelectItemVisitor, FromItemVisitor, PivotVisitor {
private StringBuilder buffer = new StringBuilder();
private ExpressionVisitor expressionVisitor = new ExpressionVisitorAdapter();
public SelectDeParser() {
}
/**
* @param expressionVisitor a {@link ExpressionVisitor} to de-parse expressions. It has to share
* the same
* StringBuilder (buffer parameter) as this object in order to work
* @param buffer the buffer that will be filled with the select
*/
public SelectDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) {
this.buffer = buffer;
this.expressionVisitor = expressionVisitor;
}
@Override
public void visit(PlainSelect plainSelect) {
if (plainSelect.isUseBrackets()) {
buffer.append("(");
}
buffer.append("SELECT ");
OracleHint hint = plainSelect.getOracleHint();
if (hint != null) {
buffer.append(hint).append(" ");
}
Skip skip = plainSelect.getSkip();
if (skip != null) {
buffer.append(skip).append(" ");
}
First first = plainSelect.getFirst();
if (first != null) {
buffer.append(first).append(" ");
}
if (plainSelect.getDistinct() != null) {
if (plainSelect.getDistinct().isUseUnique()) {
buffer.append("UNIQUE ");
} else {
buffer.append("DISTINCT ");
}
if (plainSelect.getDistinct().getOnSelectItems() != null) {
buffer.append("ON (");
for (Iterator iter = plainSelect.getDistinct().getOnSelectItems().
iterator(); iter.hasNext();) {
SelectItem selectItem = iter.next();
selectItem.accept(this);
if (iter.hasNext()) {
buffer.append(", ");
}
}
buffer.append(") ");
}
}
Top top = plainSelect.getTop();
if (top != null) {
buffer.append(top).append(" ");
}
for (Iterator iter = plainSelect.getSelectItems().iterator(); iter.hasNext();) {
SelectItem selectItem = iter.next();
selectItem.accept(this);
if (iter.hasNext()) {
buffer.append(", ");
}
}
if (plainSelect.getIntoTables() != null) {
buffer.append(" INTO ");
for (Iterator