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.ParseException;
import com.rapiddweller.common.StringUtil;
import com.rapiddweller.common.SyntaxError;
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.script.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 org.slf4j.LoggerFactory;
import org.slf4j.Logger;
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 {
/**
* The Logger.
*/
static final Logger LOGGER = LoggerFactory.getLogger(SQLParserUtil.class);
/**
* Parse object.
*
* @param in the in
* @param dialect the dialect
* @return the object
* @throws ParseException the parse exception
*/
public static Object parse(CharStream in, DatabaseDialect dialect) throws ParseException {
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);
if (r != null) {
return convertNode((CommonTree) r.getTree(), dialect);
} else {
return null;
}
} catch (RuntimeException e) {
if (e.getCause() instanceof RecognitionException) {
throw mapToParseException((RecognitionException) e.getCause(), text);
} else {
throw e;
}
} catch (RecognitionException e) {
throw mapToParseException(e, text);
}
}
/**
* Parse expression expression.
*
* @param in the in
* @return the expression
* @throws ParseException the parse exception
*/
public static Expression> parseExpression(CharStream in) throws ParseException {
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);
if (r != null) {
return convertExpressionNode((CommonTree) r.getTree());
} else {
return null;
}
} catch (RuntimeException e) {
if (e.getCause() instanceof RecognitionException) {
throw mapToParseException((RecognitionException) e.getCause(), text);
} else {
throw e;
}
} catch (RecognitionException e) {
throw mapToParseException(e, text);
}
}
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);
}
if (node.isNil()) {
List