Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/orientechnologies/orientdb
Browse files Browse the repository at this point in the history
… into develop
  • Loading branch information
lvca committed Aug 10, 2015
2 parents 36cc028 + ddb7734 commit 97ae539
Show file tree
Hide file tree
Showing 19 changed files with 4,359 additions and 4,534 deletions.
69 changes: 42 additions & 27 deletions core/src/main/grammar/OrientSQL.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ TOKEN:
< CLASS: ( "c" | "C" ) ( "l" | "L" ) ( "a" | "A" ) ( "s" | "S" ) ( "s" | "S" ) >
|
< CLASSES: ( "c" | "C" ) ( "l" | "L" ) ( "a" | "A" ) ( "s" | "S" ) ( "s" | "S" ) ( "e" | "E" ) ( "s" | "S" ) >
|
< EXCEPTION: ( "e" | "E" ) ( "x" | "X" ) ( "c" | "C" ) ( "e" | "E" ) ( "p" | "P" ) ( "t" | "T" ) ( "i" | "I" ) ( "o" | "O" ) ( "n" | "N" ) >
|
< THIS: "@" ( ( "t" | "T" ) ( "h" | "H" ) ( "i" | "I" ) ( "s" | "S" ) ) >
|
Expand Down Expand Up @@ -388,8 +390,8 @@ TOKEN :
TOKEN :
{
< IDENTIFIER: ( (<DOLLAR>)? <LETTER> (<PART_LETTER>)* ) >
//|
// < QUOTED_IDENTIFIER: ( "`" (~["`"]) (~["`"])* "`") >
|
< QUOTED_IDENTIFIER: ( "`" (~["`"]) (~["`"])* "`") >
|
< INDEX_IDENTIFIER: ( "I" | "i") ( "N" | "n") ( "D" | "d") ( "E" | "e") ( "X" | "x") ":" ( "__@recordmap@___" )? <IDENTIFIER> ( ( <DOT> | <MINUS> ) <IDENTIFIER> )* >
|
Expand Down Expand Up @@ -442,7 +444,7 @@ OStatement parse() :

OIdentifier Identifier():
{
//Token quotedToken = null;
Token quotedToken = null;
Token token = null;

}
Expand Down Expand Up @@ -490,6 +492,10 @@ OIdentifier Identifier():
|
token = <WITHIN>
|
token = <EXCEPTION>
|
quotedToken = <QUOTED_IDENTIFIER>
/*
(
//TODO REPLACE THIS WITH <QUOTED_IDENTIFIER>
<BACKTICK>
Expand Down Expand Up @@ -635,24 +641,27 @@ OIdentifier Identifier():
token = <INSTANCEOF>
|
token = <CLUSTER>
|
token = <EXCEPTION>
)
<BACKTICK>
)
*/
) {

//if(token!=null){
jjtThis.value = token.image;
/*
if(token!=null){
jjtThis.value = token.image;
}else{
jjtThis.quoted = true;
jjtThis.value = quotedToken.image;
jjtThis.value = jjtThis.value.substring(1, jjtThis.value.length() - 1);
try{
/*try{
jjtThis.value = java.net.URLEncoder.encode(jjtThis.value, null);
}catch(Exception e){

}
}*/
}
*/

return jjtThis;


Expand Down Expand Up @@ -1328,8 +1337,19 @@ OInsertStatement InsertStatement():
|
jjtThis.targetIndex = IndexIdentifier()
)
[ <RETURN> jjtThis.returnStatement = Projection() ]
jjtThis.insertBody = InsertBody()
[ LOOKAHEAD(InsertBody()) jjtThis.insertBody = InsertBody() ]
[ <RETURN> jjtThis.returnStatement = Projection() ]
[
[ <FROM> { jjtThis.selectWithFrom = true; } ]
(
jjtThis.selectStatement = SelectStatement()
|
LOOKAHEAD(2)
(
<LPAREN> jjtThis.selectStatement = SelectStatement() { jjtThis.selectInParentheses = true; } <RPAREN>
)
)
]
[ <UNSAFE> { jjtThis.unsafe = true; }]
) {return jjtThis;}
}
Expand Down Expand Up @@ -1406,21 +1426,9 @@ OInsertBody InsertBody():
)*
)
|
(
[ <FROM> ]
(
jjtThis.selectStatement = SelectStatement()
|
LOOKAHEAD(2)
(
<LPAREN> jjtThis.selectStatement = SelectStatement() { jjtThis.selectInParentheses = true; } <RPAREN>
)
)
)
|
( <CONTENT> jjtThis.content = Json() )
)
[ <RETURN> jjtThis.returnProjection = Projection() ]
//[ <RETURN> jjtThis.returnProjection = Projection() ]
)
{ return jjtThis; }
}
Expand Down Expand Up @@ -2776,13 +2784,20 @@ OBatch Batch():
{ return jjtThis; }
}

java.lang.Number Timeout():
OTimeout Timeout():
{ OInteger val; }
{
<TIMEOUT>

(
<TIMEOUT> val = Integer()
val = Integer() { jjtThis.val = val.getValue(); }
[
( <RETURN> { jjtThis.failureStrategy = OTimeout.RETURN;} )
|
( <EXCEPTION> { jjtThis.failureStrategy = OTimeout.EXCEPTION;} )
]
)
{ return val.getValue(); }
{ return jjtThis; }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ public static String getStringContent(final Object iValue) {
&& (s.charAt(0) == '\'' && s.charAt(s.length() - 1) == '\'' || s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"'))
return s.substring(1, s.length() - 1);

if (s.length() > 1
&& (s.charAt(0) == '`' && s.charAt(s.length() - 1) == '`'))
return s.substring(1, s.length() - 1);

return s;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ protected String parserRequiredWord(final boolean iUpperCase, final String iCust
parserNextWord(iUpperCase, iSeparators);
if (parserLastWord.length() == 0)
throwSyntaxErrorException(iCustomMessage);
if (parserLastWord.charAt(0) == '`' && parserLastWord.charAt(parserLastWord.length() - 1) == '`') {
return parserLastWord.substring(1, parserLastWord.length() - 1);
}
return parserLastWord.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ else if (c == BAG_END)
if (insideLinkPart > 0 && c != '-' && !Character.isDigit(c) && c != ORID.SEPARATOR && c != LINK)
insideLinkPart = 0;

if ((c == '"' || iStringSeparatorExtended && c == '\'') && !encodeMode) {
if ((c == '"' || c == '`' || iStringSeparatorExtended && c == '\'' ) && !encodeMode) {
// START STRING
stringBeginChar = c;
}
Expand All @@ -418,7 +418,7 @@ else if (c == BAG_END)
continue;
} else {
// INSIDE A STRING
if ((c == '"' || iStringSeparatorExtended && c == '\'') && !encodeMode) {
if ((c == '"' || c == '`' ||iStringSeparatorExtended && c == '\'') && !encodeMode) {
// CLOSE THE STRING ?
if (stringBeginChar == c) {
// SAME CHAR AS THE BEGIN OF THE STRING: CLOSE IT AND PUSH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.orientechnologies.orient.core.metadata.schema.OPropertyImpl;
import com.orientechnologies.orient.core.metadata.schema.OType;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

Expand Down Expand Up @@ -70,7 +72,7 @@ public OCommandExecutorSQLCreateProperty parse(final OCommandRequest iRequest) {
if (pos == -1)
throw new OCommandSQLParsingException("Expected <class>.<property>", parserText, oldPos);

String[] parts = word.toString().split("\\.");
String[] parts = split(word);
if (parts.length != 2)
throw new OCommandSQLParsingException("Expected <class>.<property>", parserText, oldPos);

Expand Down Expand Up @@ -108,6 +110,40 @@ public OCommandExecutorSQLCreateProperty parse(final OCommandRequest iRequest) {
return this;
}


private String[] split(StringBuilder word) {
List<String> result = new ArrayList<String>();
StringBuilder builder = new StringBuilder();
boolean quoted = false;
for (char c : word.toString().toCharArray()) {
if (!quoted) {
if (c == '`') {
quoted = true;
} else if (c == '.') {
String nextToken = builder.toString().trim();
if (nextToken.length() > 0) {
result.add(nextToken);
}
builder = new StringBuilder();
} else {
builder.append(c);
}
} else {
if (c == '`') {
quoted = false;
} else {
builder.append(c);
}
}
}
String nextToken = builder.toString().trim();
if (nextToken.length() > 0) {
result.add(nextToken);
}
return result.toArray(new String[] {});
// return word.toString().split("\\.");
}

@Override
public long getDistributedTimeout() {
return OGlobalConfiguration.DISTRIBUTED_COMMAND_TASK_SYNCH_TIMEOUT.getValueAsLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.serialization.serializer.OStringSerializerHelper;
import com.orientechnologies.orient.core.sql.method.misc.OSQLMethodField;
import com.orientechnologies.orient.core.sql.methods.OSQLMethodRuntime;

Expand Down Expand Up @@ -81,7 +82,7 @@ public boolean belongsTo(OSQLFilterItemField filterItemField) {
}

public OSQLFilterItemField(final String iName) {
this.name = iName;
this.name = OStringSerializerHelper.getStringContent(iName);
}

public OSQLFilterItemField(final OBaseParser iQueryToParse, final String iName) {
Expand Down Expand Up @@ -116,7 +117,7 @@ public String getRoot() {
}

public void setRoot(final OBaseParser iQueryToParse, final String iRoot) {
this.name = iRoot;
this.name = OStringSerializerHelper.getStringContent(iRoot);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class OIdentifier extends SimpleNode {

protected String value;
protected boolean quoted = false;

public OIdentifier(int id) {
super(id);
Expand All @@ -29,11 +30,17 @@ public void setValue(String value) {

@Override
public String toString(String prefix) {
if(quoted){
return '`'+value+'`';
}
return value;
}

@Override
public String toString() {
if(quoted){
return '`'+value+'`';
}
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ public class OInsertStatement extends OStatement {
OIdentifier targetClusterName;
OCluster targetCluster;
OIndexIdentifier targetIndex;
OProjection returnStatement;
OInsertBody insertBody;
boolean unsafe = false;
OProjection returnStatement;
OSelectStatement selectStatement;
boolean selectInParentheses = false;
boolean selectWithFrom = false;
boolean unsafe = false;

public OInsertStatement(int id) {
super(id);
Expand All @@ -39,13 +42,27 @@ public String toString() {
if (targetIndex != null) {
result.append(targetIndex.toString());
}
if (insertBody != null) {
result.append(" ");
result.append(insertBody.toString());
}
if (returnStatement != null) {
result.append(" RETURN ");
result.append(returnStatement.toString());
}
if (insertBody != null) {
if (selectStatement != null) {
result.append(" ");
result.append(insertBody.toString());
if (selectWithFrom) {
result.append("FROM ");
}
if (selectInParentheses) {
result.append("(");
}
result.append(selectStatement.toString());
if (selectInParentheses) {
result.append(")");
}

}
if (unsafe) {
result.append(" UNSAFE");
Expand All @@ -54,11 +71,14 @@ public String toString() {
}

public void replaceParameters(Map<Object, Object> params) {
if (insertBody != null) {
insertBody.replaceParameters(params);
}
if (returnStatement != null) {
returnStatement.replaceParameters(params);
}
if (insertBody != null) {
insertBody.replaceParameters(params);
if (selectStatement != null) {
selectStatement.replaceParameters(params);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class OSelectStatement extends OStatement {

protected OLetClause letClause;

protected Number timeout;
protected OTimeout timeout;

protected Boolean parallel;

Expand Down Expand Up @@ -198,7 +198,6 @@ public String toString() {
}

if (timeout != null) {
builder.append(" TIMEOUT ");
builder.append(timeout);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

public
class OTimeout extends SimpleNode {
public static final String RETURN = "RETURN";
public static final String EXCEPTION = "EXCEPTION";

protected Number val;
protected String failureStrategy;
public OTimeout(int id) {
super(id);
}
Expand All @@ -17,5 +22,14 @@ public OTimeout(OrientSql p, int id) {
public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
return visitor.visit(this, data);
}

@Override public String toString() {
StringBuilder builder = new StringBuilder(" TIMEOUT "+val);
if(failureStrategy!=null){
builder.append(" ");
builder.append(failureStrategy);
}
return builder.toString();
}
}
/* JavaCC - OriginalChecksum=fef7f5d488f7fca1b6ad0b70c6841931 (do not edit this line) */

0 comments on commit 97ae539

Please sign in to comment.