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.
'jdbacl' stands for 'Java DataBase ACcess Layer' and provides utilities for accessing JDBC databases from
Java programs, retrieving meta information in an object model and querying database data.
'rapiddweller jdbacl' is forked from Databene jdbacl by Volker Bergmann.
/*
* (c) Copyright 2010-2011 by Volker Bergmann. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted under the terms of the
* GNU General Public License (GPL).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
* REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
* HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.rapiddweller.jdbacl.sql;
import com.rapiddweller.common.ArrayBuilder;
import com.rapiddweller.common.exception.ExceptionFactory;
import com.rapiddweller.common.StringUtil;
import com.rapiddweller.jdbacl.DatabaseDialect;
import com.rapiddweller.jdbacl.model.DBColumn;
import com.rapiddweller.jdbacl.model.DBDataType;
import com.rapiddweller.jdbacl.model.DBPrimaryKeyConstraint;
import com.rapiddweller.jdbacl.model.DBTable;
import com.rapiddweller.jdbacl.sql.parser.SQLLexer;
import com.rapiddweller.jdbacl.sql.parser.SQLParser;
import com.rapiddweller.jdbacl.sql.parser.TextHolder;
import com.rapiddweller.common.Expression;
import com.rapiddweller.script.expression.ConcatExpression;
import com.rapiddweller.script.expression.ConditionalAndExpression;
import com.rapiddweller.script.expression.ConditionalOrExpression;
import com.rapiddweller.script.expression.DivisionExpression;
import com.rapiddweller.script.expression.EqualsExpression;
import com.rapiddweller.script.expression.ExclusiveOrExpression;
import com.rapiddweller.script.expression.ExpressionUtil;
import com.rapiddweller.script.expression.GreaterExpression;
import com.rapiddweller.script.expression.GreaterOrEqualsExpression;
import com.rapiddweller.script.expression.LessExpression;
import com.rapiddweller.script.expression.LessOrEqualsExpression;
import com.rapiddweller.script.expression.LogicalComplementExpression;
import com.rapiddweller.script.expression.ModuloExpression;
import com.rapiddweller.script.expression.MultiplicationExpression;
import com.rapiddweller.script.expression.NotEqualsExpression;
import com.rapiddweller.script.expression.NullExpression;
import com.rapiddweller.script.expression.SubtractionExpression;
import com.rapiddweller.script.expression.SumExpression;
import com.rapiddweller.script.expression.UnaryMinusExpression;
import com.rapiddweller.script.expression.ValueCollectionContainsExpression;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonToken;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.ParserRuleReturnScope;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Provides SQL parsing functionality.
* Created: 05.08.2010 10:19:38
* @author Volker Bergmann
* @since 0.1
*/
public class SQLParserUtil {
public static final String ERROR_PARSING_SQL = "Error parsing SQL";
private SQLParserUtil() {
// private constructor to prevent instantiation of this utility class
}
public static Object parse(CharStream in, DatabaseDialect dialect) {
String text = null;
if (in instanceof TextHolder) {
text = ((TextHolder) in).getText();
}
try {
SQLParser parser = parser(in);
SQLParser.commands_return r = parser.commands();
checkForSyntaxErrors(text, "weightedLiteralList", parser, r);
return convertNode((CommonTree) r.getTree(), dialect);
} catch (RuntimeException e) {
if (e.getCause() instanceof RecognitionException) {
RecognitionException cause = (RecognitionException) e.getCause();
throw ExceptionFactory.getInstance().syntaxErrorForText(ERROR_PARSING_SQL, cause, text,
cause.line, cause.charPositionInLine);
} else {
throw e;
}
} catch (RecognitionException e) {
throw ExceptionFactory.getInstance().syntaxErrorForText(ERROR_PARSING_SQL, e, text,
e.line, e.charPositionInLine);
}
}
public static Expression> parseExpression(CharStream in) {
String text = null;
if (in instanceof TextHolder) {
text = ((TextHolder) in).getText();
}
try {
SQLParser parser = parser(in);
SQLParser.expression_return r = parser.expression();
checkForSyntaxErrors(text, "expression", parser, r);
return convertExpressionNode((CommonTree) r.getTree());
} catch (RuntimeException e) {
if (e.getCause() instanceof RecognitionException) {
RecognitionException cause = (RecognitionException) e.getCause();
throw ExceptionFactory.getInstance().syntaxErrorForText(ERROR_PARSING_SQL, cause, text,
cause.line, cause.charPositionInLine);
} else {
throw e;
}
} catch (RecognitionException e) {
throw ExceptionFactory.getInstance().syntaxErrorForText(ERROR_PARSING_SQL, e, text,
e.line, e.charPositionInLine);
}
}
private static Object convertNode(CommonTree node, DatabaseDialect dialect) {
switch (node.getType()) {
case SQLLexer.CREATE_TABLE:
return convertCreateTable(node, dialect);
case SQLLexer.DROP_TABLE:
return convertDropTable(node);
case SQLLexer.ALTER_TABLE:
return convertAlterTable(node);
case SQLLexer.CREATE_SEQUENCE:
return convertCreateSequence(node);
case SQLLexer.DROP_SEQUENCE:
return convertDropSequence(node);
case SQLLexer.CREATE_INDEX:
return convertCreateIndex(node);
case SQLLexer.COMMENT_TABLE:
return convertTableComment(node);
case SQLLexer.COMMENT_COLUMN:
return convertColumnComment(node);
default:
if (node.isNil()) {
List