Skip to content

Commit

Permalink
Add contains, startsWith, and endsWith to the operators supported in …
Browse files Browse the repository at this point in the history
…a relationship.
  • Loading branch information
motlin committed Oct 14, 2018
1 parent 2127e58 commit 60d14a3
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 105 deletions.
11 changes: 10 additions & 1 deletion reladomo/src/main/grammar/mithra.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This grammar files is used to generate the parser for Mithra relationship queries. The code generated is checked into
* cvs in package com.gs.fw.common.mithra.generator.queryparser. Care should be taken when regenerating code because we have
* custom code in SimpleNode, ASTLiteral, and ASTAttributeName
*
*
*/
options {
MULTI=true;
Expand Down Expand Up @@ -72,6 +72,9 @@ TOKEN: /* Separators and operators */
| < LESSER_THAN: "<" >
| < GREATER_THAN_EQUAL: ">=" >
| < LESSER_THAN_EQUAL: "<=" >
| < CONTAINS: "contains" >
| < STARTS_WITH: "startsWith" >
| < ENDS_WITH: "endsWith" >
| < OPEN_PAREN: "(" >
| < CLOSE_PAREN: ")" >
| < COMMA: "," >
Expand Down Expand Up @@ -168,6 +171,12 @@ void RelationalOperator() :
<GREATER_THAN_EQUAL> {jjtThis.setGreaterThanOrEqualTo(true); jjtThis.setString(">=");}
|
<LESSER_THAN_EQUAL> {jjtThis.setLesserThanOrEqualTo(true); jjtThis.setString("<=");}
|
<CONTAINS> {jjtThis.setContains(true); jjtThis.setString("contains");}
|
<STARTS_WITH> {jjtThis.setStartsWith(true); jjtThis.setString("startsWith");}
|
<ENDS_WITH> {jjtThis.setEndsWith(true); jjtThis.setString("endsWith");}
}

void InOperator() :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ public boolean isLesserThanOrEqualTo()
return false;
}

@Override
public boolean isContains()
{
return false;
}

@Override
public boolean isStartsWith()
{
return false;
}

@Override
public boolean isEndsWith()
{
return false;
}

public boolean isEqual()
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,25 @@ public boolean isLesserThanOrEqualTo()
return false;
}

public boolean isEqual()
@Override
public boolean isContains()
{
return false;
}

@Override
public boolean isStartsWith()
{
return false;
}

@Override
public boolean isEndsWith()
{
return false;
}

public boolean isEqual()
{
return false;
}
Expand Down Expand Up @@ -143,7 +161,7 @@ public boolean equalsOther(SimpleNode other)
{
return ((ASTIsNullClause)other).getMethodName().equals(this.getMethodName());
}
return false;
return false;
}

public boolean isUnary()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class ASTRelationalOperator extends SimpleNode implements Operator
private boolean lesserThan;
private boolean greaterThanOrEqualTo;
private boolean lesserThanOrEqualTo;
private boolean contains;
private boolean startsWith;
private boolean endsWith;
private String string;

public boolean isIsNullOrIsNotNull()
Expand Down Expand Up @@ -80,6 +83,36 @@ public void setLesserThanOrEqualTo(boolean lesserThanOrEqualTo)
this.lesserThanOrEqualTo = lesserThanOrEqualTo;
}

public boolean isContains()
{
return contains;
}

public void setContains(boolean contains)
{
this.contains = contains;
}

public boolean isStartsWith()
{
return startsWith;
}

public void setStartsWith(boolean startsWith)
{
this.startsWith = startsWith;
}

public boolean isEndsWith()
{
return endsWith;
}

public void setEndsWith(boolean endsWith)
{
this.endsWith = endsWith;
}

public ASTRelationalOperator(int id) {
super(id);
}
Expand Down Expand Up @@ -150,6 +183,18 @@ else if (this.isNotEqual())
{
return " != ";
}
else if (this.isContains())
{
return " contains ";
}
else if (this.isStartsWith())
{
return " startsWith ";
}
else if (this.isEndsWith())
{
return " endsWith ";
}
throw new RuntimeException("relational operator '" + this.toString() + "' not implemented");
}

Expand Down Expand Up @@ -179,6 +224,18 @@ else if (this.isNotEqual())
{
return "notEq";
}
else if (this.isContains())
{
return "contains";
}
else if (this.isStartsWith())
{
return "startsWith";
}
else if (this.isEndsWith())
{
return "endsWith";
}
throw new RuntimeException("relational operator '" + this.toString() + "' not implemented");
}
/**
Expand Down Expand Up @@ -239,6 +296,18 @@ else if (this.isNotEqual())
{
result += "!"+left+".equals("+right+")";
}
else if (this.isContains())
{
result += left+".contains("+right+")";
}
else if (this.isStartsWith())
{
result += left+".startsWith("+right+")";
}
else if (this.isEndsWith())
{
result += left+".endsWith("+right+")";
}
else
{
throw new RuntimeException("relational operator '" + this.toString() + "' not implemented");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ public boolean isLesserThanOrEqualTo()
return false;
}

@Override
public boolean isContains()
{
return false;
}

@Override
public boolean isStartsWith()
{
return false;
}

@Override
public boolean isEndsWith()
{
return false;
}

public boolean isEqual()
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ final public void RelationalOperator() throws ParseException {
jjtc000 = false;
jjtn000.setLesserThanOrEqualTo(true); jjtn000.setString("<=");
break;
case CONTAINS:
jj_consume_token(CONTAINS);
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
jjtn000.setContains(true); jjtn000.setString("contains");
break;
case STARTS_WITH:
jj_consume_token(STARTS_WITH);
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
jjtn000.setStartsWith(true); jjtn000.setString("startsWith");
break;
case ENDS_WITH:
jj_consume_token(ENDS_WITH);
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
jjtn000.setEndsWith(true); jjtn000.setString("endsWith");
break;
default:
jj_la1[1] = jj_gen;
jj_consume_token(-1);
Expand Down Expand Up @@ -288,6 +306,9 @@ final public void RelationalExpression() throws ParseException {
case LESSER_THAN:
case GREATER_THAN_EQUAL:
case LESSER_THAN_EQUAL:
case CONTAINS:
case STARTS_WITH:
case ENDS_WITH:
RelationalOperatorExpression();
break;
case IS:
Expand Down Expand Up @@ -564,10 +585,10 @@ final public void InLiteral() throws ParseException {
jj_la1_1();
}
private static void jj_la1_0() {
jj_la1_0 = new int[] {0x10000,0x7e0000,0x80,0xd8800000,0x40,0xd8800000,0x47e0c00,0xd8000000,0x100,0xd8000000,0x2000000,0x2000000,0x2000000,0xc8000000,0x800000,};
jj_la1_0 = new int[] {0x10000,0x3fe0000,0x80,0xc4000000,0x40,0xc4000000,0x23fe0c00,0xc0000000,0x100,0xc0000000,0x10000000,0x10000000,0x10000000,0x40000000,0x4000000,};
}
private static void jj_la1_1() {
jj_la1_1 = new int[] {0x0,0x0,0x0,0x7,0x0,0x7,0x0,0x7,0x0,0x3,0x0,0x0,0x0,0x0,0x2,};
jj_la1_1 = new int[] {0x0,0x0,0x0,0x3e,0x0,0x3e,0x0,0x3e,0x0,0x1e,0x0,0x0,0x0,0x6,0x10,};
}

public MithraQL(java.io.InputStream stream) {
Expand Down Expand Up @@ -669,8 +690,8 @@ final private int jj_ntk() {

public ParseException generateParseException() {
jj_expentries.removeAllElements();
boolean[] la1tokens = new boolean[37];
for (int i = 0; i < 37; i++) {
boolean[] la1tokens = new boolean[40];
for (int i = 0; i < 40; i++) {
la1tokens[i] = false;
}
if (jj_kind >= 0) {
Expand All @@ -689,7 +710,7 @@ public ParseException generateParseException() {
}
}
}
for (int i = 0; i < 37; i++) {
for (int i = 0; i < 40; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ public interface MithraQLConstants {
int LESSER_THAN = 20;
int GREATER_THAN_EQUAL = 21;
int LESSER_THAN_EQUAL = 22;
int OPEN_PAREN = 23;
int CLOSE_PAREN = 24;
int COMMA = 25;
int IN = 26;
int INTEGER_LITERAL = 27;
int FLOATING_POINT_LITERAL = 28;
int EXPONENT = 29;
int STRING_LITERAL = 30;
int CHARACTER_LITERAL = 31;
int BOOLEAN_LITERAL = 32;
int JAVA_LITERAL = 33;
int IDENTIFIER = 34;
int LETTER = 35;
int DIGIT = 36;
int CONTAINS = 23;
int STARTS_WITH = 24;
int ENDS_WITH = 25;
int OPEN_PAREN = 26;
int CLOSE_PAREN = 27;
int COMMA = 28;
int IN = 29;
int INTEGER_LITERAL = 30;
int FLOATING_POINT_LITERAL = 31;
int EXPONENT = 32;
int STRING_LITERAL = 33;
int CHARACTER_LITERAL = 34;
int BOOLEAN_LITERAL = 35;
int JAVA_LITERAL = 36;
int IDENTIFIER = 37;
int LETTER = 38;
int DIGIT = 39;

int DEFAULT = 0;

Expand Down Expand Up @@ -79,6 +82,9 @@ public interface MithraQLConstants {
"\"<\"",
"\">=\"",
"\"<=\"",
"\"contains\"",
"\"startsWith\"",
"\"endsWith\"",
"\"(\"",
"\")\"",
"\",\"",
Expand Down
Loading

0 comments on commit 60d14a3

Please sign in to comment.