use of com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleDbLinkExpr in project druid by alibaba.
the class OracleExprParser method name.
public SQLName name() {
SQLName name = super.name();
if (lexer.token() == Token.MONKEYS_AT) {
lexer.nextToken();
if (lexer.token() != Token.IDENTIFIER) {
throw new ParserException("syntax error, expect identifier, but " + lexer.token());
}
OracleDbLinkExpr dbLink = new OracleDbLinkExpr();
dbLink.setExpr(name);
dbLink.setDbLink(lexer.stringVal());
lexer.nextToken();
return dbLink;
}
return name;
}
use of com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleDbLinkExpr in project druid by alibaba.
the class OracleExprParser method primaryRest.
public SQLExpr primaryRest(SQLExpr expr) {
if (expr.getClass() == SQLIdentifierExpr.class) {
String ident = ((SQLIdentifierExpr) expr).getName();
if ("TIMESTAMP".equalsIgnoreCase(ident)) {
if (lexer.token() != Token.LITERAL_ALIAS && lexer.token() != Token.LITERAL_CHARS) {
return new SQLIdentifierExpr("TIMESTAMP");
}
SQLTimestampExpr timestamp = new SQLTimestampExpr();
String literal = lexer.stringVal();
timestamp.setLiteral(literal);
accept(Token.LITERAL_CHARS);
if (identifierEquals("AT")) {
lexer.nextToken();
acceptIdentifier("TIME");
acceptIdentifier("ZONE");
String timezone = lexer.stringVal();
timestamp.setTimeZone(timezone);
accept(Token.LITERAL_CHARS);
}
return primaryRest(timestamp);
}
}
if (lexer.token() == Token.IDENTIFIER && expr instanceof SQLNumericLiteralExpr) {
String ident = lexer.stringVal();
if (ident.length() == 1) {
char unit = ident.charAt(0);
switch(unit) {
case 'K':
case 'M':
case 'G':
case 'T':
case 'P':
case 'E':
case 'k':
case 'm':
case 'g':
case 't':
case 'p':
case 'e':
expr = new OracleSizeExpr(expr, OracleSizeExpr.Unit.valueOf(ident.toUpperCase()));
lexer.nextToken();
break;
default:
break;
}
}
}
if (lexer.token() == Token.DOTDOT) {
lexer.nextToken();
SQLExpr upBound = expr();
return new OracleRangeExpr(expr, upBound);
}
if (lexer.token() == Token.MONKEYS_AT) {
lexer.nextToken();
OracleDbLinkExpr dblink = new OracleDbLinkExpr();
dblink.setExpr(expr);
if (lexer.token() == Token.BANG) {
dblink.setDbLink("!");
lexer.nextToken();
} else {
String link = lexer.stringVal();
accept(Token.IDENTIFIER);
dblink.setDbLink(link);
}
expr = dblink;
}
if (identifierEquals("DAY") || identifierEquals("YEAR")) {
lexer.mark();
String name = lexer.stringVal();
lexer.nextToken();
if (lexer.token() == Token.COMMA) {
lexer.reset();
return expr;
}
OracleIntervalExpr interval = new OracleIntervalExpr();
interval.setValue(expr);
OracleIntervalType type = OracleIntervalType.valueOf(name);
interval.setType(type);
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
if (lexer.token() != Token.LITERAL_INT) {
throw new ParserException("syntax error");
}
interval.setPrecision(lexer.integerValue().intValue());
lexer.nextToken();
accept(Token.RPAREN);
}
accept(Token.TO);
if (identifierEquals("SECOND")) {
lexer.nextToken();
interval.setToType(OracleIntervalType.SECOND);
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
if (lexer.token() != Token.LITERAL_INT) {
throw new ParserException("syntax error");
}
interval.setFactionalSecondsPrecision(lexer.integerValue().intValue());
lexer.nextToken();
accept(Token.RPAREN);
}
} else {
interval.setToType(OracleIntervalType.MONTH);
lexer.nextToken();
}
expr = interval;
}
if (identifierEquals("AT")) {
char markChar = lexer.current();
int markBp = lexer.bp();
lexer.nextToken();
if (identifierEquals("LOCAL")) {
lexer.nextToken();
expr = new OracleDatetimeExpr(expr, new SQLIdentifierExpr("LOCAL"));
} else {
if (identifierEquals("TIME")) {
lexer.nextToken();
} else {
lexer.reset(markBp, markChar, Token.IDENTIFIER);
return expr;
}
acceptIdentifier("ZONE");
SQLExpr timeZone = primary();
expr = new OracleDatetimeExpr(expr, timeZone);
}
}
SQLExpr restExpr = super.primaryRest(expr);
if (restExpr != expr && restExpr instanceof SQLMethodInvokeExpr) {
SQLMethodInvokeExpr methodInvoke = (SQLMethodInvokeExpr) restExpr;
if (methodInvoke.getParameters().size() == 1) {
SQLExpr paramExpr = methodInvoke.getParameters().get(0);
if (paramExpr instanceof SQLIdentifierExpr && "+".equals(((SQLIdentifierExpr) paramExpr).getName())) {
OracleOuterExpr outerExpr = new OracleOuterExpr();
if (methodInvoke.getOwner() == null) {
outerExpr.setExpr(new SQLIdentifierExpr(methodInvoke.getMethodName()));
} else {
outerExpr.setExpr(new SQLPropertyExpr(methodInvoke.getOwner(), methodInvoke.getMethodName()));
}
return outerExpr;
}
}
}
return restExpr;
}
use of com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleDbLinkExpr in project druid by alibaba.
the class EqualTest_dbLink method test_eq.
public void test_eq() throws Exception {
String sql = "a@b";
String sql_c = "a@c";
OracleDbLinkExpr exprA, exprB, exprC;
{
OracleExprParser parser = new OracleExprParser(sql);
exprA = (OracleDbLinkExpr) parser.expr();
}
{
OracleExprParser parser = new OracleExprParser(sql);
exprB = (OracleDbLinkExpr) parser.expr();
}
{
OracleExprParser parser = new OracleExprParser(sql_c);
exprC = (OracleDbLinkExpr) parser.expr();
}
Assert.assertEquals(exprA, exprB);
Assert.assertNotEquals(exprA, exprC);
Assert.assertTrue(exprA.equals(exprA));
Assert.assertFalse(exprA.equals(new Object()));
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
Assert.assertEquals(new OracleDbLinkExpr(), new OracleDbLinkExpr());
Assert.assertEquals(new OracleDbLinkExpr().hashCode(), new OracleDbLinkExpr().hashCode());
}
use of com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleDbLinkExpr in project druid by alibaba.
the class OracleASTVisitorAdapterTest method test_adapter.
public void test_adapter() throws Exception {
OracleASTVisitorAdapter adapter = new OracleASTVisitorAdapter();
new OraclePLSQLCommitStatement().accept(adapter);
new OracleAnalytic().accept(adapter);
new OracleAnalyticWindowing().accept(adapter);
new SQLDateExpr().accept(adapter);
new OracleDbLinkExpr().accept(adapter);
new OracleSelectForUpdate().accept(adapter);
new OracleSelectHierachicalQueryClause().accept(adapter);
new OracleSelectPivot.Item().accept(adapter);
new OracleSelectPivot().accept(adapter);
new CheckOption().accept(adapter);
new ReadOnly().accept(adapter);
new OracleSelectUnPivot().accept(adapter);
new SQLTimestampExpr().accept(adapter);
new PartitionExtensionClause().accept(adapter);
new VersionsFlashbackQueryClause().accept(adapter);
new VersionsFlashbackQueryClause().accept(adapter);
new AsOfFlashbackQueryClause().accept(adapter);
new SQLGroupingSetExpr().accept(adapter);
new OracleWithSubqueryEntry().accept(adapter);
new OracleFileSpecification().accept(adapter);
new OracleAlterTablespaceAddDataFile().accept(adapter);
new OracleAlterTablespaceStatement().accept(adapter);
new SQLCreateSequenceStatement().accept(adapter);
new SQLLoopStatement().accept(adapter);
new OracleIntervalExpr().accept(adapter);
new OracleDeleteStatement().accept(adapter);
new OracleUpdateStatement().accept(adapter);
new SampleClause().accept(adapter);
new OracleSelectTableReference().accept(adapter);
new SearchClause().accept(adapter);
new CycleClause().accept(adapter);
new OracleBinaryFloatExpr().accept(adapter);
new OracleBinaryDoubleExpr().accept(adapter);
new OracleCursorExpr().accept(adapter);
new OracleIsSetExpr().accept(adapter);
new ReturnRowsClause().accept(adapter);
new ModelClause().accept(adapter);
new MainModelClause().accept(adapter);
new ModelColumnClause().accept(adapter);
new QueryPartitionClause().accept(adapter);
new ModelColumn().accept(adapter);
new ModelRulesClause().accept(adapter);
new CellAssignmentItem().accept(adapter);
new CellAssignment().accept(adapter);
new SQLMergeStatement().accept(adapter);
new MergeUpdateClause().accept(adapter);
new MergeInsertClause().accept(adapter);
new SQLErrorLoggingClause().accept(adapter);
new OracleReturningClause().accept(adapter);
new OracleInsertStatement().accept(adapter);
new InsertIntoClause().accept(adapter);
new OracleMultiInsertStatement().accept(adapter);
new ConditionalInsertClause().accept(adapter);
new ConditionalInsertClauseItem().accept(adapter);
new OracleSelectQueryBlock().accept(adapter);
new SQLBlockStatement().accept(adapter);
new OracleLockTableStatement().accept(adapter);
new OracleAlterSessionStatement().accept(adapter);
new OracleExprStatement().accept(adapter);
new OracleDatetimeExpr().accept(adapter);
new OracleExceptionStatement().accept(adapter);
new OracleExceptionStatement.Item().accept(adapter);
new OracleArgumentExpr().accept(adapter);
new OracleSetTransactionStatement().accept(adapter);
new SQLDropSequenceStatement().accept(adapter);
new OracleDataTypeIntervalDay().accept(adapter);
new OracleDataTypeIntervalYear().accept(adapter);
new OracleDataTypeTimestamp().accept(adapter);
new OracleDropDbLinkStatement().accept(adapter);
new OracleCreateDatabaseDbLinkStatement().accept(adapter);
new SQLCreateProcedureStatement().accept(adapter);
new OracleSavePointStatement().accept(adapter);
new SQLFetchStatement().accept(adapter);
new OracleExitStatement().accept(adapter);
new OracleExplainStatement().accept(adapter);
new OracleAlterProcedureStatement().accept(adapter);
new OracleAlterTableDropPartition().accept(adapter);
new OracleAlterTableTruncatePartition().accept(adapter);
new OracleAlterTableSplitPartition.TableSpaceItem().accept(adapter);
new OracleAlterTableSplitPartition.UpdateIndexesClause().accept(adapter);
new OracleAlterTableSplitPartition.NestedTablePartitionSpec().accept(adapter);
new OracleAlterTableSplitPartition().accept(adapter);
new OracleAlterTableModify().accept(adapter);
new OracleCreateIndexStatement().accept(adapter);
new OracleAlterIndexStatement().accept(adapter);
new OracleForStatement().accept(adapter);
new OracleAlterIndexStatement().accept(adapter);
new OracleRangeExpr().accept(adapter);
new OraclePrimaryKey().accept(adapter);
new OracleCreateTableStatement().accept(adapter);
new SQLAlterTableRename().accept(adapter);
new OracleStorageClause().accept(adapter);
new OracleGotoStatement().accept(adapter);
new OracleLabelStatement().accept(adapter);
new SQLParameter().accept(adapter);
new OracleCommitStatement().accept(adapter);
new OracleAlterTriggerStatement().accept(adapter);
new OracleAlterSynonymStatement().accept(adapter);
new AsOfSnapshotClause().accept(adapter);
new OracleAlterViewStatement().accept(adapter);
new OracleAlterTableMoveTablespace().accept(adapter);
new OracleSizeExpr().accept(adapter);
}
Aggregations