0001: /* Generated By:JavaCC: Do not edit this line. SQLConditionParser.java */
0002: package org.netbeans.modules.sql.framework.parser.conditionparser;
0003:
0004: import java.io.ByteArrayInputStream;
0005: import java.io.StringReader;
0006: import java.math.BigDecimal;
0007: import java.sql.Types;
0008: import java.util.ArrayList;
0009: import java.util.List;
0010:
0011: import org.netbeans.modules.sql.framework.common.jdbc.SQLUtils;
0012: import org.netbeans.modules.sql.framework.model.SQLConstants;
0013: import org.netbeans.modules.sql.framework.model.SQLGenericOperator;
0014: import org.netbeans.modules.sql.framework.model.SQLLiteral;
0015: import org.netbeans.modules.sql.framework.model.SQLModelObjectFactory;
0016: import org.netbeans.modules.sql.framework.model.SQLObject;
0017: import org.netbeans.modules.sql.framework.model.SQLObjectFactory;
0018: import org.netbeans.modules.sql.framework.model.SQLOperator;
0019: import org.netbeans.modules.sql.framework.model.VisibleSQLPredicate;
0020: import org.netbeans.modules.sql.framework.model.utils.SQLParserUtil;
0021:
0022: import com.sun.sql.framework.exception.BaseException;
0023:
0024: /**
0025: * JavaCC generated SQL parser.
0026: * Generated from SQLConditionParser.jj
0027: * Do not edit this (.java) file directly, it is programmaticly generated.
0028: *
0029: * @author Ahimanikya Satapathy
0030: * @author Ritesh Adval
0031: * @author Jonathan Giron
0032: */
0033: public class SQLConditionParser implements SQLConditionParserConstants {
0034: private SQLParserUtil sqlHelper;
0035:
0036: public void setSQLParserUtil(SQLParserUtil helper) {
0037: this .sqlHelper = helper;
0038: }
0039:
0040: public SQLConditionParser() {
0041: this (new ByteArrayInputStream(new byte[0]));
0042: }
0043:
0044: public SQLObject parse(String sql) throws BaseException {
0045: try {
0046: StringReader rReader = new StringReader(sql);
0047: this .ReInit(rReader);
0048: return this .SqlRootPredicate();
0049: } catch (TokenMgrError e) {
0050: throw new SQLConditionException(e);
0051: } catch (ParseException ex) {
0052: throw new SQLConditionException(ex);
0053: }
0054: }
0055:
0056: public SQLObject createPredicate(SQLObject left, String opName,
0057: SQLObject right) throws BaseException {
0058: ArrayList args = new ArrayList();
0059:
0060: if (left != null) {
0061: args.add(left);
0062: }
0063:
0064: if (right != null) {
0065: args.add(right);
0066: }
0067: SQLObject predicate = createOperator(opName, args);
0068:
0069: return predicate;
0070: }
0071:
0072: private SQLObject createOperator(String opName, List args)
0073: throws BaseException {
0074: SQLOperator fun = SQLObjectFactory
0075: .createOperatorFromParsedList(opName, args);
0076: //since by default some operatoras have bracket but for condition we want
0077: //to put brackets only if user typed it
0078: fun.setShowParenthesis(false);
0079: return fun;
0080: }
0081:
0082: public static void main(String[] args) throws ParseException,
0083: TokenMgrError {
0084: SQLParserUtil helper = new SQLParserUtil();
0085: SQLConditionParser parser = new SQLConditionParser(System.in);
0086: parser.setSQLParserUtil(helper);
0087:
0088: try {
0089: SQLObject obj = parser.SqlCompareExpr();
0090: System.out.println(" the sql is " + obj.toString());
0091: } catch (BaseException ex) {
0092: ex.printStackTrace();
0093: }
0094: }
0095:
0096: /**
0097: * Replaces all occurances of <i>old</i> in <i>src</i> with <i>nu</i>.
0098: *
0099: * @param src the source String
0100: * @param old the character to replace
0101: * @param nu the String to replace <i>old</i> with
0102: * @return a copy of <i>src</i> with all instances of <i>old</i>
0103: * replaced by <i>nu</i>
0104: * @throws java.lang.NullPointerException if any argument is null.
0105: */
0106: private final static String replace(String src, String old,
0107: String nu) {
0108: int srclen = src.length();
0109: int cur = 0;
0110: int loc = 0;
0111: int oldlen = old.length();
0112: StringBuffer buf = new StringBuffer(srclen + nu.length());
0113: do {
0114: loc = src.indexOf(old, cur);
0115: if (loc != -1) {
0116: buf.append(src.substring(cur, loc));
0117: buf.append(nu);
0118: cur = loc + oldlen;
0119: }
0120: } while (loc != -1);
0121: if (cur < srclen) {
0122: buf.append(src.substring(cur));
0123: }
0124: return buf.toString();
0125: }
0126:
0127: //TOKEN : //end of line
0128: //{
0129: // <EOL: "\n" | "\r" | "\r\n">
0130: //}
0131: final public String SqlLValueTerm() throws ParseException {
0132: StringBuffer buffer = new StringBuffer();
0133: Token t = null;
0134: t = jj_consume_token(ID);
0135: buffer.append(t.image);
0136: label_1: while (true) {
0137: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0138: case DOT:
0139: ;
0140: break;
0141: default:
0142: jj_la1[0] = jj_gen;
0143: break label_1;
0144: }
0145: t = jj_consume_token(DOT);
0146: buffer.append(t.image);
0147: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0148: case ID:
0149: t = jj_consume_token(ID);
0150: buffer.append(t.image);
0151: break;
0152: case ASTERISK:
0153: jj_consume_token(ASTERISK);
0154: buffer.append("*");
0155: break;
0156: default:
0157: jj_la1[1] = jj_gen;
0158: jj_consume_token(-1);
0159: throw new ParseException();
0160: }
0161: }
0162: {
0163: if (true)
0164: return buffer.toString();
0165: }
0166: throw new Error("Missing return statement in function");
0167: }
0168:
0169: final public SQLObject SqlColumn() throws ParseException,
0170: BaseException {
0171: Token t = null;
0172: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0173: case COLUMN1:
0174: t = jj_consume_token(COLUMN1);
0175: {
0176: if (true)
0177: return sqlHelper
0178: .getColumnForFullyQualifiedName(t.image);
0179: }
0180: break;
0181: case COLUMN2:
0182: t = jj_consume_token(COLUMN2);
0183: {
0184: if (true)
0185: return sqlHelper
0186: .getColumnForFullyQualifiedName(t.image);
0187: }
0188: break;
0189: case COLUMN3:
0190: t = jj_consume_token(COLUMN3);
0191: {
0192: if (true)
0193: return sqlHelper.getColumn(t.image);
0194: }
0195: break;
0196: default:
0197: jj_la1[2] = jj_gen;
0198: jj_consume_token(-1);
0199: throw new ParseException();
0200: }
0201: throw new Error("Missing return statement in function");
0202: }
0203:
0204: final public SQLObject SqlColumnRef() throws ParseException,
0205: BaseException {
0206: String column = null;
0207: column = SqlLValueTerm();
0208: {
0209: if (true)
0210: return sqlHelper.getColumn(column);
0211: }
0212: throw new Error("Missing return statement in function");
0213: }
0214:
0215: final public SQLObject SQLCurrentDate() throws ParseException,
0216: BaseException {
0217: Token t = null;
0218: SQLObject dateOp = null;
0219: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0220: case CURRENT_TIMESTAMP:
0221: t = jj_consume_token(CURRENT_TIMESTAMP);
0222: dateOp = createOperator(t.image, new ArrayList());
0223: {
0224: if (true)
0225: return dateOp;
0226: }
0227: break;
0228: case CURRENT_DATE:
0229: t = jj_consume_token(CURRENT_DATE);
0230: dateOp = createOperator("CURRENT_TIMESTAMP",
0231: new ArrayList());
0232: {
0233: if (true)
0234: return dateOp;
0235: }
0236: break;
0237: default:
0238: jj_la1[3] = jj_gen;
0239: jj_consume_token(-1);
0240: throw new ParseException();
0241: }
0242: throw new Error("Missing return statement in function");
0243: }
0244:
0245: final public SQLObject SqlSelectableElements()
0246: throws ParseException, BaseException {
0247: SQLObject sel = null;
0248: boolean openP = false;
0249: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0250: case OPENPAREN:
0251: jj_consume_token(OPENPAREN);
0252: openP = true;
0253: sel = SqlWhereOr();
0254: jj_consume_token(CLOSEPAREN);
0255: if (sel instanceof VisibleSQLPredicate && openP) {
0256: ((VisibleSQLPredicate) sel).setShowParenthesis(true);
0257: } else if (sel instanceof SQLGenericOperator && openP) {
0258: ((SQLGenericOperator) sel).setShowParenthesis(true);
0259: }
0260:
0261: {
0262: if (true)
0263: return sel;
0264: }
0265: break;
0266: case FALSE:
0267: case NULL:
0268: case TRUE:
0269: case CAST:
0270: case CURRENT_DATE:
0271: case CURRENT_TIMESTAMP:
0272: case RUNTIME_INPUT:
0273: case COLUMN1:
0274: case COLUMN2:
0275: case COLUMN3:
0276: case INTEGER_LITERAL:
0277: case FLOATING_POINT_LITERAL:
0278: case STRING_LITERAL:
0279: case ID:
0280: case ASTERISK:
0281: case MINUS:
0282: if (jj_2_1(2)) {
0283: sel = SqlFunction();
0284: } else {
0285: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0286: case CURRENT_DATE:
0287: case CURRENT_TIMESTAMP:
0288: sel = SQLCurrentDate();
0289: break;
0290: case CAST:
0291: sel = SqlCastAs();
0292: break;
0293: case COLUMN1:
0294: case COLUMN2:
0295: case COLUMN3:
0296: sel = SqlColumn();
0297: break;
0298: case FALSE:
0299: case NULL:
0300: case TRUE:
0301: case INTEGER_LITERAL:
0302: case FLOATING_POINT_LITERAL:
0303: case STRING_LITERAL:
0304: case ID:
0305: case ASTERISK:
0306: case MINUS:
0307: sel = SqlLiteral();
0308: break;
0309: case RUNTIME_INPUT:
0310: sel = SqlRuntimeInput();
0311: break;
0312: default:
0313: jj_la1[4] = jj_gen;
0314: jj_consume_token(-1);
0315: throw new ParseException();
0316: }
0317: }
0318: {
0319: if (true)
0320: return sel;
0321: }
0322: break;
0323: default:
0324: jj_la1[5] = jj_gen;
0325: jj_consume_token(-1);
0326: throw new ParseException();
0327: }
0328: throw new Error("Missing return statement in function");
0329: }
0330:
0331: final public SQLObject SqlProductExprSelectable()
0332: throws ParseException, BaseException {
0333: SQLObject parent = null;
0334: SQLObject left = null;
0335: SQLObject right = null;
0336: String function = null;
0337: SQLObject result = null;
0338: left = SqlSelectableElements();
0339: result = left;
0340: label_2: while (true) {
0341: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0342: case ASTERISK:
0343: case SLASH:
0344: ;
0345: break;
0346: default:
0347: jj_la1[6] = jj_gen;
0348: break label_2;
0349: }
0350: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0351: case ASTERISK:
0352: jj_consume_token(ASTERISK);
0353: function = "*";
0354: break;
0355: case SLASH:
0356: jj_consume_token(SLASH);
0357: function = "/";
0358: break;
0359: default:
0360: jj_la1[7] = jj_gen;
0361: jj_consume_token(-1);
0362: throw new ParseException();
0363: }
0364: right = SqlSelectableElements();
0365: ArrayList args = new ArrayList();
0366: args.add(left);
0367: args.add(right);
0368:
0369: parent = createOperator(function, args);
0370: left = parent;
0371: result = parent;
0372: }
0373: {
0374: if (true)
0375: return result;
0376: }
0377: throw new Error("Missing return statement in function");
0378: }
0379:
0380: final public SQLObject SqlSumExprSelectable()
0381: throws ParseException, BaseException {
0382: SQLObject parent = null;
0383: SQLObject left = null;
0384: SQLObject right = null;
0385: String function = null;
0386: SQLObject result = null;
0387: left = SqlProductExprSelectable();
0388: result = left;
0389: label_3: while (true) {
0390: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0391: case CONCAT:
0392: case PLUS:
0393: case MINUS:
0394: ;
0395: break;
0396: default:
0397: jj_la1[8] = jj_gen;
0398: break label_3;
0399: }
0400: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0401: case PLUS:
0402: jj_consume_token(PLUS);
0403: function = "+";
0404: break;
0405: case MINUS:
0406: jj_consume_token(MINUS);
0407: function = "-";
0408: break;
0409: case CONCAT:
0410: jj_consume_token(CONCAT);
0411: function = "||";
0412: break;
0413: default:
0414: jj_la1[9] = jj_gen;
0415: jj_consume_token(-1);
0416: throw new ParseException();
0417: }
0418: right = SqlProductExprSelectable();
0419: ArrayList args = new ArrayList();
0420: args.add(left);
0421: args.add(right);
0422:
0423: parent = createOperator(function, args);
0424: left = parent;
0425: result = parent;
0426: }
0427: {
0428: if (true)
0429: return result;
0430: }
0431: throw new Error("Missing return statement in function");
0432: }
0433:
0434: final public SQLObject SqlCompareExpr() throws ParseException,
0435: BaseException {
0436: SQLObject left = null;
0437: SQLObject right = null;
0438: String symbol = null;
0439: SQLObject result = null;
0440: Token t = null;
0441: left = SqlSumExprSelectable();
0442: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0443: case IS:
0444: case LIKE:
0445: case LESS:
0446: case LESSEQUAL:
0447: case GREATER:
0448: case GREATEREQUAL:
0449: case EQUAL:
0450: case NOTEQUAL:
0451: case NOTEQUAL2:
0452: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0453: case IS:
0454: symbol = SqlIsNullClause();
0455: result = createPredicate(left, symbol, null);
0456: break;
0457: case LESS:
0458: case LESSEQUAL:
0459: case GREATER:
0460: case GREATEREQUAL:
0461: case EQUAL:
0462: case NOTEQUAL:
0463: case NOTEQUAL2:
0464: symbol = SqlCompareOp();
0465: right = SqlSumExprSelectable();
0466: result = createPredicate(left, symbol, right);
0467: break;
0468: case LIKE:
0469: t = jj_consume_token(LIKE);
0470: symbol = t.image;
0471: right = SqlSumExprSelectable();
0472: result = createPredicate(left, "like", right);
0473: break;
0474: default:
0475: jj_la1[10] = jj_gen;
0476: jj_consume_token(-1);
0477: throw new ParseException();
0478: }
0479: break;
0480: default:
0481: jj_la1[11] = jj_gen;
0482: ;
0483: }
0484: if (result == null) {
0485: result = left;
0486: }
0487: {
0488: if (true)
0489: return (result);
0490: }
0491: throw new Error("Missing return statement in function");
0492: }
0493:
0494: final public SQLObject SqlRootPredicate() throws ParseException,
0495: BaseException {
0496: SQLObject result = null;
0497: // [<OPENPAREN>]
0498: // result = SqlFunction()
0499: // [<CLOSEPAREN>]
0500: // |
0501: result = SqlWhereOr();
0502: {
0503: if (true)
0504: return result;
0505: }
0506: throw new Error("Missing return statement in function");
0507: }
0508:
0509: final public SQLObject SqlWhereOr() throws ParseException,
0510: BaseException {
0511: SQLObject parent = null;
0512: SQLObject left = null;
0513: SQLObject right = null;
0514: SQLObject result = null;
0515: left = SqlWhereAnd();
0516: result = left;
0517: label_4: while (true) {
0518: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0519: case OR:
0520: ;
0521: break;
0522: default:
0523: jj_la1[12] = jj_gen;
0524: break label_4;
0525: }
0526: jj_consume_token(OR);
0527: right = SqlWhereAnd();
0528: parent = createPredicate(left, "or", right);
0529: left = parent;
0530: result = parent;
0531: }
0532: {
0533: if (true)
0534: return result;
0535: }
0536: throw new Error("Missing return statement in function");
0537: }
0538:
0539: final public SQLObject SqlWhereAnd() throws ParseException,
0540: BaseException {
0541: SQLObject parent = null;
0542: SQLObject left = null;
0543: SQLObject right = null;
0544: SQLObject result = null;
0545: left = SqlWhereNot();
0546: result = left;
0547: label_5: while (true) {
0548: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0549: case AND:
0550: ;
0551: break;
0552: default:
0553: jj_la1[13] = jj_gen;
0554: break label_5;
0555: }
0556: jj_consume_token(AND);
0557: right = SqlWhereNot();
0558: parent = createPredicate(left, "and", right);
0559: left = parent;
0560: result = parent;
0561: }
0562: {
0563: if (true)
0564: return result;
0565: }
0566: throw new Error("Missing return statement in function");
0567: }
0568:
0569: final public SQLObject SqlWhereNot() throws ParseException,
0570: BaseException {
0571: SQLObject child = null;
0572: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0573: case NOT:
0574: jj_consume_token(NOT);
0575: child = SqlWhereElt();
0576: child = createPredicate(null, "not", child);
0577: {
0578: if (true)
0579: return child;
0580: }
0581: break;
0582: case FALSE:
0583: case NULL:
0584: case TRUE:
0585: case CAST:
0586: case CURRENT_DATE:
0587: case CURRENT_TIMESTAMP:
0588: case RUNTIME_INPUT:
0589: case COLUMN1:
0590: case COLUMN2:
0591: case COLUMN3:
0592: case INTEGER_LITERAL:
0593: case FLOATING_POINT_LITERAL:
0594: case STRING_LITERAL:
0595: case ID:
0596: case OPENPAREN:
0597: case ASTERISK:
0598: case MINUS:
0599: child = SqlWhereElt();
0600: {
0601: if (true)
0602: return child;
0603: }
0604: break;
0605: default:
0606: jj_la1[14] = jj_gen;
0607: jj_consume_token(-1);
0608: throw new ParseException();
0609: }
0610: throw new Error("Missing return statement in function");
0611: }
0612:
0613: final public SQLObject SqlWhereElt() throws ParseException,
0614: BaseException {
0615: SQLObject result = null;
0616: result = SqlCompareExpr();
0617: {
0618: if (true)
0619: return result;
0620: }
0621: throw new Error("Missing return statement in function");
0622: }
0623:
0624: final public SQLObject SqlCastAs() throws ParseException,
0625: BaseException {
0626: SQLObject column = null;
0627: Object[] tuple;
0628: jj_consume_token(CAST);
0629: jj_consume_token(OPENPAREN);
0630: column = SqlSumExprSelectable();
0631: jj_consume_token(AS);
0632: tuple = SqlCastAsType();
0633: jj_consume_token(CLOSEPAREN);
0634: ArrayList argList = new ArrayList();
0635: argList.add(column);
0636: String castTo = (String) tuple[0];
0637: SQLLiteral literal = SQLModelObjectFactory.getInstance()
0638: .createSQLLiteral(castTo, castTo,
0639: SQLLiteral.VARCHAR_UNQUOTED);
0640: argList.add(literal);
0641:
0642: String precision = (String) tuple[1];
0643: if (precision != null) {
0644: argList.add(precision);
0645: String scale = (String) tuple[2];
0646: if (scale != null) {
0647: argList.add(scale);
0648: }
0649: }
0650: {
0651: if (true)
0652: return createOperator("castas", argList);
0653: }
0654: throw new Error("Missing return statement in function");
0655: }
0656:
0657: final public Object[] SqlCastAsType() throws ParseException,
0658: BaseException {
0659: Object[] tuple = new Object[3];
0660: Token type = null;
0661: Token scale = null;
0662: Token precision = null;
0663:
0664: int jdbcType = SQLConstants.JDBCSQL_TYPE_UNDEFINED;
0665: tuple[1] = null;
0666: tuple[2] = null;
0667: type = jj_consume_token(ID);
0668: tuple[0] = type.image;
0669: jdbcType = SQLUtils.getStdJdbcType(type.image);
0670: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0671: case OPENPAREN:
0672: jj_consume_token(OPENPAREN);
0673: precision = jj_consume_token(INTEGER_LITERAL);
0674: if (SQLUtils.isPrecisionRequired(jdbcType)) {
0675: if (precision != null) {
0676: tuple[1] = precision.image;
0677: } else {
0678: {
0679: if (true)
0680: throw new BaseException(
0681: "Precision argument required for type "
0682: + type.image);
0683: }
0684: }
0685: }
0686: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0687: case CLOSEPAREN:
0688: jj_consume_token(CLOSEPAREN);
0689: break;
0690: case COMMA:
0691: jj_consume_token(COMMA);
0692: scale = jj_consume_token(INTEGER_LITERAL);
0693: if (scale != null) {
0694: if (SQLUtils.isScaleRequired(jdbcType)) {
0695: tuple[2] = scale.image;
0696: } else {
0697: {
0698: if (true)
0699: throw new BaseException(
0700: "Scale argument is invalid for type "
0701: + type.image);
0702: }
0703: }
0704: }
0705: jj_consume_token(CLOSEPAREN);
0706: break;
0707: default:
0708: jj_la1[15] = jj_gen;
0709: jj_consume_token(-1);
0710: throw new ParseException();
0711: }
0712: break;
0713: default:
0714: jj_la1[16] = jj_gen;
0715: ;
0716: }
0717: {
0718: if (true)
0719: return tuple;
0720: }
0721: throw new Error("Missing return statement in function");
0722: }
0723:
0724: final public String SqlIsNullClause() throws ParseException {
0725: boolean foundnot = false;
0726: Token isToken = null;
0727: Token notToken = null;
0728: Token nullToken = null;
0729: isToken = jj_consume_token(IS);
0730: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0731: case NOT:
0732: notToken = jj_consume_token(NOT);
0733: foundnot = true;
0734: break;
0735: default:
0736: jj_la1[17] = jj_gen;
0737: ;
0738: }
0739: nullToken = jj_consume_token(NULL);
0740: String result = (foundnot ? isToken.image + " "
0741: + notToken.image : isToken.image)
0742: + " " + nullToken;
0743: {
0744: if (true)
0745: return (result.trim().toUpperCase());
0746: }
0747: throw new Error("Missing return statement in function");
0748: }
0749:
0750: final public SQLObject SqlLiteral() throws ParseException,
0751: BaseException {
0752: SQLObject literal = null;
0753: Token t = null;
0754: boolean minus = false;
0755: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0756: case STRING_LITERAL:
0757: t = jj_consume_token(STRING_LITERAL);
0758: // trim off the open and close quotes
0759: String trimmed = t.image.substring(1, t.image.length() - 1);
0760: // replace all '' with '
0761: String result = replace(trimmed, "''", "'");
0762: literal = SQLModelObjectFactory.getInstance()
0763: .createVisibleSQLLiteral(result, result,
0764: Types.VARCHAR);
0765: break;
0766: case INTEGER_LITERAL:
0767: case FLOATING_POINT_LITERAL:
0768: case MINUS:
0769: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0770: case MINUS:
0771: jj_consume_token(MINUS);
0772: minus = true;
0773: break;
0774: default:
0775: jj_la1[18] = jj_gen;
0776: ;
0777: }
0778: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0779: case INTEGER_LITERAL:
0780: t = jj_consume_token(INTEGER_LITERAL);
0781: literal = SQLModelObjectFactory.getInstance()
0782: .createVisibleSQLLiteral(
0783: t.image,
0784: new Integer((minus ? "-" : "")
0785: + t.image).toString(),
0786: Types.INTEGER);
0787: break;
0788: case FLOATING_POINT_LITERAL:
0789: t = jj_consume_token(FLOATING_POINT_LITERAL);
0790: literal = SQLModelObjectFactory.getInstance()
0791: .createVisibleSQLLiteral(
0792: t.image,
0793: new BigDecimal((minus ? "-" : "")
0794: + t.image).toString(),
0795: Types.NUMERIC);
0796: break;
0797: default:
0798: jj_la1[19] = jj_gen;
0799: jj_consume_token(-1);
0800: throw new ParseException();
0801: }
0802: break;
0803: case NULL:
0804: jj_consume_token(NULL);
0805: literal = SQLModelObjectFactory.getInstance()
0806: .createVisibleSQLLiteral("null", "null",
0807: Types.VARCHAR);
0808: break;
0809: case TRUE:
0810: jj_consume_token(TRUE);
0811: literal = SQLModelObjectFactory.getInstance()
0812: .createVisibleSQLLiteral("true",
0813: Boolean.TRUE.toString(), Types.BOOLEAN);
0814: break;
0815: case FALSE:
0816: jj_consume_token(FALSE);
0817: literal = SQLModelObjectFactory.getInstance()
0818: .createVisibleSQLLiteral("false",
0819: Boolean.FALSE.toString(), Types.BOOLEAN);
0820: break;
0821: case ASTERISK:
0822: jj_consume_token(ASTERISK);
0823:
0824: break;
0825: case ID:
0826: t = jj_consume_token(ID);
0827: result = t.image;
0828: literal = SQLModelObjectFactory.getInstance()
0829: .createSQLLiteral(result, result,
0830: SQLLiteral.VARCHAR_UNQUOTED);
0831: break;
0832: default:
0833: jj_la1[20] = jj_gen;
0834: jj_consume_token(-1);
0835: throw new ParseException();
0836: }
0837: {
0838: if (true)
0839: return literal;
0840: }
0841: throw new Error("Missing return statement in function");
0842: }
0843:
0844: final public SQLObject SqlSelectable() throws ParseException,
0845: BaseException {
0846: SQLObject sel = null;
0847: sel = SqlWhereOr();
0848: {
0849: if (true)
0850: return sel;
0851: }
0852: throw new Error("Missing return statement in function");
0853: }
0854:
0855: final public List SqlSelectList() throws ParseException,
0856: BaseException {
0857: List list = new ArrayList();
0858: SQLObject curCol = null;
0859: curCol = SqlSelectable();
0860: list.add(curCol);
0861: label_6: while (true) {
0862: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0863: case COMMA:
0864: ;
0865: break;
0866: default:
0867: jj_la1[21] = jj_gen;
0868: break label_6;
0869: }
0870: jj_consume_token(COMMA);
0871:
0872: curCol = SqlSelectable();
0873: list.add(curCol);
0874: }
0875: {
0876: if (true)
0877: return list;
0878: }
0879: throw new Error("Missing return statement in function");
0880: }
0881:
0882: final public List SqlSelectCols() throws ParseException,
0883: BaseException {
0884: List list = new ArrayList();
0885: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0886: case FALSE:
0887: case NOT:
0888: case NULL:
0889: case TRUE:
0890: case CAST:
0891: case CURRENT_DATE:
0892: case CURRENT_TIMESTAMP:
0893: case RUNTIME_INPUT:
0894: case COLUMN1:
0895: case COLUMN2:
0896: case COLUMN3:
0897: case INTEGER_LITERAL:
0898: case FLOATING_POINT_LITERAL:
0899: case STRING_LITERAL:
0900: case ID:
0901: case OPENPAREN:
0902: case ASTERISK:
0903: case MINUS:
0904: // <ASTERISK>
0905: // {
0906: // list.add(new ColumnIdentifier("*"));
0907: // }
0908: // |
0909: list = SqlSelectList();
0910: break;
0911: default:
0912: jj_la1[22] = jj_gen;
0913: ;
0914: }
0915: {
0916: if (true)
0917: return list;
0918: }
0919: throw new Error("Missing return statement in function");
0920: }
0921:
0922: final public List SqlFunctionArgs() throws ParseException,
0923: BaseException {
0924: List args = new ArrayList();
0925: jj_consume_token(OPENPAREN);
0926: args = SqlSelectCols();
0927: jj_consume_token(CLOSEPAREN);
0928: {
0929: if (true)
0930: return args;
0931: }
0932: throw new Error("Missing return statement in function");
0933: }
0934:
0935: final public SQLObject SqlFunction() throws ParseException,
0936: BaseException {
0937: String name = null;
0938: List fnargs = null;
0939: jj_consume_token(ID);
0940: name = token.image;
0941: fnargs = SqlFunctionArgs();
0942: {
0943: if (true)
0944: return createOperator(name, fnargs);
0945: }
0946: throw new Error("Missing return statement in function");
0947: }
0948:
0949: final public String SqlCompareOp() throws ParseException {
0950: String result = null;
0951: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
0952: case EQUAL:
0953: jj_consume_token(EQUAL);
0954: result = "=";
0955: break;
0956: case NOTEQUAL:
0957: jj_consume_token(NOTEQUAL);
0958: result = "!=";
0959: break;
0960: case NOTEQUAL2:
0961: jj_consume_token(NOTEQUAL2);
0962: result = "!=";
0963: break;
0964: case GREATER:
0965: jj_consume_token(GREATER);
0966: result = ">";
0967: break;
0968: case GREATEREQUAL:
0969: jj_consume_token(GREATEREQUAL);
0970: result = ">=";
0971: break;
0972: case LESS:
0973: jj_consume_token(LESS);
0974: result = "<";
0975: break;
0976: case LESSEQUAL:
0977: jj_consume_token(LESSEQUAL);
0978: result = "<=";
0979: break;
0980: default:
0981: jj_la1[23] = jj_gen;
0982: jj_consume_token(-1);
0983: throw new ParseException();
0984: }
0985: {
0986: if (true)
0987: return result;
0988: }
0989: throw new Error("Missing return statement in function");
0990: }
0991:
0992: final public SQLObject SqlRuntimeInput() throws ParseException,
0993: BaseException {
0994: Token t = null;
0995: t = jj_consume_token(RUNTIME_INPUT);
0996: {
0997: if (true)
0998: return this .sqlHelper.getRuntimeInput(t.image);
0999: }
1000: throw new Error("Missing return statement in function");
1001: }
1002:
1003: final private boolean jj_2_1(int xla) {
1004: jj_la = xla;
1005: jj_lastpos = jj_scanpos = token;
1006: boolean retval = !jj_3_1();
1007: jj_save(0, xla);
1008: return retval;
1009: }
1010:
1011: final private boolean jj_3_1() {
1012: if (jj_3R_7())
1013: return true;
1014: if (jj_la == 0 && jj_scanpos == jj_lastpos)
1015: return false;
1016: return false;
1017: }
1018:
1019: final private boolean jj_3R_8() {
1020: if (jj_scan_token(OPENPAREN))
1021: return true;
1022: if (jj_la == 0 && jj_scanpos == jj_lastpos)
1023: return false;
1024: return false;
1025: }
1026:
1027: final private boolean jj_3R_7() {
1028: if (jj_scan_token(ID))
1029: return true;
1030: if (jj_la == 0 && jj_scanpos == jj_lastpos)
1031: return false;
1032: if (jj_3R_8())
1033: return true;
1034: if (jj_la == 0 && jj_scanpos == jj_lastpos)
1035: return false;
1036: return false;
1037: }
1038:
1039: public SQLConditionParserTokenManager token_source;
1040: SimpleCharStream jj_input_stream;
1041: public Token token, jj_nt;
1042: private int jj_ntk;
1043: private Token jj_scanpos, jj_lastpos;
1044: private int jj_la;
1045: public boolean lookingAhead = false;
1046: //private boolean jj_semLA;
1047: private int jj_gen;
1048: final private int[] jj_la1 = new int[24];
1049: static private int[] jj_la1_0;
1050: static private int[] jj_la1_1;
1051: static private int[] jj_la1_2;
1052: static private int[] jj_la1_3;
1053: static {
1054: jj_la1_0();
1055: jj_la1_1();
1056: jj_la1_2();
1057: jj_la1_3();
1058: }
1059:
1060: private static void jj_la1_0() {
1061: jj_la1_0 = new int[] { 0x0, 0x0, 0x0, 0x0, 0x20000000,
1062: 0x20000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x400,
1063: 0x20000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20000000, 0x0,
1064: 0x20000000, 0x0, };
1065: }
1066:
1067: private static void jj_la1_1() {
1068: jj_la1_1 = new int[] { 0x0, 0x0, 0x0, 0x0, 0x10000, 0x10000,
1069: 0x0, 0x0, 0x0, 0x0, 0x2200, 0x2200, 0x80000, 0x0,
1070: 0x18000, 0x0, 0x0, 0x8000, 0x0, 0x0, 0x10000, 0x0,
1071: 0x18000, 0x0, };
1072: }
1073:
1074: private static void jj_la1_2() {
1075: jj_la1_2 = new int[] { 0x10000000, 0x100000, 0xe000, 0xc00,
1076: 0x1bfd01, 0x1bfd01, 0x0, 0x0, 0x4000000, 0x4000000,
1077: 0xe0000000, 0xe0000000, 0x0, 0x0, 0x1bfd01, 0x2000000,
1078: 0x0, 0x0, 0x0, 0x30000, 0x1b0001, 0x2000000, 0x1bfd01,
1079: 0xe0000000, };
1080: }
1081:
1082: private static void jj_la1_3() {
1083: jj_la1_3 = new int[] { 0x0, 0x80, 0x0, 0x0, 0x480, 0x4a0,
1084: 0x180, 0x180, 0x600, 0x600, 0xf, 0xf, 0x0, 0x0, 0x4a0,
1085: 0x40, 0x20, 0x0, 0x400, 0x0, 0x480, 0x0, 0x4a0, 0xf, };
1086: }
1087:
1088: final private JJCalls[] jj_2_rtns = new JJCalls[1];
1089: private boolean jj_rescan = false;
1090: private int jj_gc = 0;
1091:
1092: public SQLConditionParser(java.io.InputStream stream) {
1093: jj_input_stream = new SimpleCharStream(stream, 1, 1);
1094: token_source = new SQLConditionParserTokenManager(
1095: jj_input_stream);
1096: token = new Token();
1097: jj_ntk = -1;
1098: jj_gen = 0;
1099: for (int i = 0; i < 24; i++)
1100: jj_la1[i] = -1;
1101: for (int i = 0; i < jj_2_rtns.length; i++)
1102: jj_2_rtns[i] = new JJCalls();
1103: }
1104:
1105: public void ReInit(java.io.InputStream stream) {
1106: jj_input_stream.ReInit(stream, 1, 1);
1107: token_source.ReInit(jj_input_stream);
1108: token = new Token();
1109: jj_ntk = -1;
1110: jj_gen = 0;
1111: for (int i = 0; i < 24; i++)
1112: jj_la1[i] = -1;
1113: for (int i = 0; i < jj_2_rtns.length; i++)
1114: jj_2_rtns[i] = new JJCalls();
1115: }
1116:
1117: public SQLConditionParser(java.io.Reader stream) {
1118: jj_input_stream = new SimpleCharStream(stream, 1, 1);
1119: token_source = new SQLConditionParserTokenManager(
1120: jj_input_stream);
1121: token = new Token();
1122: jj_ntk = -1;
1123: jj_gen = 0;
1124: for (int i = 0; i < 24; i++)
1125: jj_la1[i] = -1;
1126: for (int i = 0; i < jj_2_rtns.length; i++)
1127: jj_2_rtns[i] = new JJCalls();
1128: }
1129:
1130: public void ReInit(java.io.Reader stream) {
1131: jj_input_stream.ReInit(stream, 1, 1);
1132: token_source.ReInit(jj_input_stream);
1133: token = new Token();
1134: jj_ntk = -1;
1135: jj_gen = 0;
1136: for (int i = 0; i < 24; i++)
1137: jj_la1[i] = -1;
1138: for (int i = 0; i < jj_2_rtns.length; i++)
1139: jj_2_rtns[i] = new JJCalls();
1140: }
1141:
1142: public SQLConditionParser(SQLConditionParserTokenManager tm) {
1143: token_source = tm;
1144: token = new Token();
1145: jj_ntk = -1;
1146: jj_gen = 0;
1147: for (int i = 0; i < 24; i++)
1148: jj_la1[i] = -1;
1149: for (int i = 0; i < jj_2_rtns.length; i++)
1150: jj_2_rtns[i] = new JJCalls();
1151: }
1152:
1153: public void ReInit(SQLConditionParserTokenManager tm) {
1154: token_source = tm;
1155: token = new Token();
1156: jj_ntk = -1;
1157: jj_gen = 0;
1158: for (int i = 0; i < 24; i++)
1159: jj_la1[i] = -1;
1160: for (int i = 0; i < jj_2_rtns.length; i++)
1161: jj_2_rtns[i] = new JJCalls();
1162: }
1163:
1164: final private Token jj_consume_token(int kind)
1165: throws ParseException {
1166: Token oldToken;
1167: if ((oldToken = token).next != null)
1168: token = token.next;
1169: else
1170: token = token.next = token_source.getNextToken();
1171: jj_ntk = -1;
1172: if (token.kind == kind) {
1173: jj_gen++;
1174: if (++jj_gc > 100) {
1175: jj_gc = 0;
1176: for (int i = 0; i < jj_2_rtns.length; i++) {
1177: JJCalls c = jj_2_rtns[i];
1178: while (c != null) {
1179: if (c.gen < jj_gen)
1180: c.first = null;
1181: c = c.next;
1182: }
1183: }
1184: }
1185: return token;
1186: }
1187: token = oldToken;
1188: jj_kind = kind;
1189: throw generateParseException();
1190: }
1191:
1192: final private boolean jj_scan_token(int kind) {
1193: if (jj_scanpos == jj_lastpos) {
1194: jj_la--;
1195: if (jj_scanpos.next == null) {
1196: jj_lastpos = jj_scanpos = jj_scanpos.next = token_source
1197: .getNextToken();
1198: } else {
1199: jj_lastpos = jj_scanpos = jj_scanpos.next;
1200: }
1201: } else {
1202: jj_scanpos = jj_scanpos.next;
1203: }
1204: if (jj_rescan) {
1205: int i = 0;
1206: Token tok = token;
1207: while (tok != null && tok != jj_scanpos) {
1208: i++;
1209: tok = tok.next;
1210: }
1211: if (tok != null)
1212: jj_add_error_token(kind, i);
1213: }
1214: return (jj_scanpos.kind != kind);
1215: }
1216:
1217: final public Token getNextToken() {
1218: if (token.next != null)
1219: token = token.next;
1220: else
1221: token = token.next = token_source.getNextToken();
1222: jj_ntk = -1;
1223: jj_gen++;
1224: return token;
1225: }
1226:
1227: final public Token getToken(int index) {
1228: Token t = lookingAhead ? jj_scanpos : token;
1229: for (int i = 0; i < index; i++) {
1230: if (t.next != null)
1231: t = t.next;
1232: else
1233: t = t.next = token_source.getNextToken();
1234: }
1235: return t;
1236: }
1237:
1238: final private int jj_ntk() {
1239: if ((jj_nt = token.next) == null)
1240: return (jj_ntk = (token.next = token_source.getNextToken()).kind);
1241: else
1242: return (jj_ntk = jj_nt.kind);
1243: }
1244:
1245: private java.util.Vector jj_expentries = new java.util.Vector();
1246: private int[] jj_expentry;
1247: private int jj_kind = -1;
1248: private int[] jj_lasttokens = new int[100];
1249: private int jj_endpos;
1250:
1251: private void jj_add_error_token(int kind, int pos) {
1252: if (pos >= 100)
1253: return;
1254: if (pos == jj_endpos + 1) {
1255: jj_lasttokens[jj_endpos++] = kind;
1256: } else if (jj_endpos != 0) {
1257: jj_expentry = new int[jj_endpos];
1258: for (int i = 0; i < jj_endpos; i++) {
1259: jj_expentry[i] = jj_lasttokens[i];
1260: }
1261: boolean exists = false;
1262: for (java.util.Enumeration e = jj_expentries.elements(); e
1263: .hasMoreElements();) {
1264: int[] oldentry = (int[]) (e.nextElement());
1265: if (oldentry.length == jj_expentry.length) {
1266: exists = true;
1267: for (int i = 0; i < jj_expentry.length; i++) {
1268: if (oldentry[i] != jj_expentry[i]) {
1269: exists = false;
1270: break;
1271: }
1272: }
1273: if (exists)
1274: break;
1275: }
1276: }
1277: if (!exists)
1278: jj_expentries.addElement(jj_expentry);
1279: if (pos != 0)
1280: jj_lasttokens[(jj_endpos = pos) - 1] = kind;
1281: }
1282: }
1283:
1284: public ParseException generateParseException() {
1285: jj_expentries.removeAllElements();
1286: boolean[] la1tokens = new boolean[108];
1287: for (int i = 0; i < 108; i++) {
1288: la1tokens[i] = false;
1289: }
1290: if (jj_kind >= 0) {
1291: la1tokens[jj_kind] = true;
1292: jj_kind = -1;
1293: }
1294: for (int i = 0; i < 24; i++) {
1295: if (jj_la1[i] == jj_gen) {
1296: for (int j = 0; j < 32; j++) {
1297: if ((jj_la1_0[i] & (1 << j)) != 0) {
1298: la1tokens[j] = true;
1299: }
1300: if ((jj_la1_1[i] & (1 << j)) != 0) {
1301: la1tokens[32 + j] = true;
1302: }
1303: if ((jj_la1_2[i] & (1 << j)) != 0) {
1304: la1tokens[64 + j] = true;
1305: }
1306: if ((jj_la1_3[i] & (1 << j)) != 0) {
1307: la1tokens[96 + j] = true;
1308: }
1309: }
1310: }
1311: }
1312: for (int i = 0; i < 108; i++) {
1313: if (la1tokens[i]) {
1314: jj_expentry = new int[1];
1315: jj_expentry[0] = i;
1316: jj_expentries.addElement(jj_expentry);
1317: }
1318: }
1319: jj_endpos = 0;
1320: jj_rescan_token();
1321: jj_add_error_token(0, 0);
1322: int[][] exptokseq = new int[jj_expentries.size()][];
1323: for (int i = 0; i < jj_expentries.size(); i++) {
1324: exptokseq[i] = (int[]) jj_expentries.elementAt(i);
1325: }
1326: return new ParseException(token, exptokseq, tokenImage);
1327: }
1328:
1329: final public void enable_tracing() {
1330: }
1331:
1332: final public void disable_tracing() {
1333: }
1334:
1335: final private void jj_rescan_token() {
1336: jj_rescan = true;
1337: for (int i = 0; i < 1; i++) {
1338: JJCalls p = jj_2_rtns[i];
1339: do {
1340: if (p.gen > jj_gen) {
1341: jj_la = p.arg;
1342: jj_lastpos = jj_scanpos = p.first;
1343: switch (i) {
1344: case 0:
1345: jj_3_1();
1346: break;
1347: }
1348: }
1349: p = p.next;
1350: } while (p != null);
1351: }
1352: jj_rescan = false;
1353: }
1354:
1355: final private void jj_save(int index, int xla) {
1356: JJCalls p = jj_2_rtns[index];
1357: while (p.gen > jj_gen) {
1358: if (p.next == null) {
1359: p = p.next = new JJCalls();
1360: break;
1361: }
1362: p = p.next;
1363: }
1364: p.gen = jj_gen + xla - jj_la;
1365: p.first = token;
1366: p.arg = xla;
1367: }
1368:
1369: static final class JJCalls {
1370: int gen;
1371: Token first;
1372: int arg;
1373: JJCalls next;
1374: }
1375:
1376: }
|