net.sf.jsqlparser.expression.operators.conditional.AndExpression Java Examples

The following examples show how to use net.sf.jsqlparser.expression.operators.conditional.AndExpression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjPD.java    From openprodoc with GNU Affero General Public License v3.0 6 votes vote down vote up
private int EvalExprType(Expression where)
{
if (where instanceof AndExpression)
    return (EXPR_AND);
else if (where instanceof OrExpression)
    return (EXPR_OR);
else if (where instanceof BinaryExpression)
    return(EXPR_BASIC);
else if (where instanceof Function)
    return(EXPR_FUNCT);
else if (where instanceof Parenthesis)
    return (EXPR_PAR);
else if (where instanceof InExpression) 
    return (EXPR_IN);
else if (where instanceof NotExpression) 
    return (EXPR_NOT);
return(-1);
}
 
Example #2
Source File: QueryStripperVisitor.java    From evosql with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(AndExpression arg0) {
	Expression e = visitExpression(arg0.getLeftExpression());
	if (e != null) arg0.setLeftExpression(e);
	e = visitExpression(arg0.getRightExpression());
	if (e != null) arg0.setRightExpression(e);
}
 
Example #3
Source File: JSQLParserAdapter.java    From ddal with Apache License 2.0 5 votes vote down vote up
/**
 * To make ddal-jsqlparser work well, JSqlParser should include the feature of 'support getting jdbc parameter index'.
 * And this feature is provided on the version of {@link <a href="https://github.com/JSQLParser/JSqlParser/releases/tag/jsqlparser-0.9.7">0.9.7</a>}.
 * This method is designed to check the necessary feature.
 */
public static void checkJSqlParserFeature() throws JSQLParserException {
    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    String sql = "SELECT * FROM tab_1 WHERE tab_1.col_1 = ? AND col_2 IN (SELECT DISTINCT col_2 FROM tab_2 WHERE col_3 LIKE ? AND col_4 > ?) LIMIT ?, ?";
    Select select = (Select) parserManager.parse(new StringReader(sql));
    PlainSelect selectBody = (PlainSelect) select.getSelectBody();
    //
    AndExpression andExpression = (AndExpression) selectBody.getWhere();
    EqualsTo equalsTo = (EqualsTo) andExpression.getLeftExpression();
    JdbcParameter jdbcParameter = (JdbcParameter) equalsTo.getRightExpression();
    Integer index1 = jdbcParameter.getIndex();
    if (index1 != 1) {
        throw new IllegalStateException("Current version of JSQLParser doesn't support the feature of 'support "
                                        + "get jdbc parameter index'");
    }
    //
    InExpression inExpression = (InExpression) andExpression.getRightExpression();
    SubSelect subSelect = (SubSelect) inExpression.getRightItemsList();
    PlainSelect subSelectBody = (PlainSelect) subSelect.getSelectBody();
    AndExpression subAndExpression = (AndExpression) subSelectBody.getWhere();
    LikeExpression likeExpression = (LikeExpression) subAndExpression.getLeftExpression();
    if (((JdbcParameter) likeExpression.getRightExpression()).getIndex() != 2) {
        throw new IllegalStateException(
                                        "Current version of JSQLParser doesn't support the feature of 'support get jdbc parameter index'");
    }
    //
    GreaterThan greaterThan = (GreaterThan) subAndExpression.getRightExpression();
    if (((JdbcParameter) greaterThan.getRightExpression()).getIndex() != 3) {
        throw new IllegalStateException(
                                        "Current version of JSQLParser doesn't support the feature of 'support get jdbc parameter index'");
    }
    //
    Expression offset = selectBody.getLimit().getOffset();
    Expression rowCount = selectBody.getLimit().getRowCount();
    if (((JdbcParameter) offset).getIndex() != 4 || ((JdbcParameter) rowCount).getIndex() != 5) {
        throw new IllegalStateException(
                                        "Current version of JSQLParser doesn't support the feature of 'support get jdbc parameter index'");
    }
}
 
Example #4
Source File: JoinProcessor.java    From sql-to-mongo-db-query-converter with Apache License 2.0 5 votes vote down vote up
private static Document generateMatchJoin(FromHolder tholder, Expression onExp, Expression wherePartialExp, String joinTableAlias) throws ParseException {
	Document matchJoinStep = new Document();
	onExp.accept(new OnVisitorMatchLookupBuilder(joinTableAlias,tholder.getBaseAliasTable()));
	WhereCauseProcessor whereCauseProcessor = new WhereCauseProcessor(FieldType.UNKNOWN,
			Collections.<String, FieldType>emptyMap());
       
	matchJoinStep.put("$match", whereCauseProcessor
               .parseExpression(new Document(), wherePartialExp != null? new AndExpression(onExp,wherePartialExp):onExp, null));
	return matchJoinStep;
}
 
Example #5
Source File: WhereVisitorMatchAndLookupPipelineMatchBuilder.java    From sql-to-mongo-db-query-converter with Apache License 2.0 5 votes vote down vote up
protected void visitBinaryExpression(BinaryExpression expr) {
  	this.isBaseAliasOrValue = true;
  	expr.getLeftExpression().accept(this);
  	if(!this.isBaseAliasOrValue) {
  		expr.getRightExpression().accept(this);
}
  	else {
  		expr.getRightExpression().accept(this);
          if(this.isBaseAliasOrValue && !(expr instanceof AndExpression || expr instanceof OrExpression)) {
  			this.setOrAndExpression(outputMatch,expr);
  		}
  	}
  }
 
Example #6
Source File: QueryTranslator.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(AndExpression andExpression) {
    andExpression.getLeftExpression()
            .accept(this);
    andExpression.getRightExpression()
            .accept(this);
}
 
Example #7
Source File: CTEToNestedQueryConverter.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
protected List<Expression> flatten(AndExpression and) {
	List<Expression> ret = new LinkedList<Expression>();
	if (and.getLeftExpression() instanceof AndExpression)  {
		ret.addAll(flatten((AndExpression) and.getLeftExpression()));
	} else {
		ret.add(and.getLeftExpression());
	}
	if (and.getRightExpression() instanceof AndExpression) {
		ret.addAll(flatten((AndExpression) and.getRightExpression())); 
	} else {
		ret.add(and.getRightExpression());
	}
	return ret;
}
 
Example #8
Source File: CTEToNestedQueryConverter.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(AndExpression andExpression) {
	clear();
	boolean prevIsTopVal = isTopLevel;
	boolean tmpLeftTableFound = false;
	boolean tmpRightTableFound = false;
	boolean tmpWhereOnlyExpFound = false;
	isTopLevel = false;
	for (Expression exp: flatten(andExpression)) {
		exp.accept(this);
		if (prevIsTopVal) {
			if (whereOnlyExpFound) {
				whereExp = whereExp == null? exp: new AndExpression(whereExp, exp);
				
			} else {
				onExp = onExp==null? exp: new AndExpression(onExp, exp);
			}
		}
		// update tmp
		tmpLeftTableFound |= leftTableFound;
		tmpRightTableFound |= rightTableFound;
		tmpWhereOnlyExpFound |= whereOnlyExpFound;
		//
	}
	
	// update 
	leftTableFound = tmpLeftTableFound;
	rightTableFound = tmpRightTableFound;
	whereOnlyExpFound = tmpWhereOnlyExpFound;
	//
	
}
 
Example #9
Source File: ExpressionVisitorImpl.java    From DataPermissionHelper with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression andExpression) {
    visitBinaryExpression(andExpression);
}
 
Example #10
Source File: AllColumnRefsFinder.java    From jobson with Apache License 2.0 4 votes vote down vote up
public void visit(AndExpression andExpression) {
    andExpression.getLeftExpression().accept(this);
    andExpression.getRightExpression().accept(this);
}
 
Example #11
Source File: SeedVisitor.java    From evosql with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression arg0) {
	arg0.getLeftExpression().accept(this);
	arg0.getRightExpression().accept(this);
}
 
Example #12
Source File: UsedColumnExtractorVisitor.java    From evosql with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression arg0) {
	arg0.getLeftExpression().accept(this);
	arg0.getRightExpression().accept(this);
}
 
Example #13
Source File: TablesNamesFinder.java    From evosql with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression andExpression) {
    visitBinaryExpression(andExpression);
}
 
Example #14
Source File: ClassifierVisitor.java    From evosql with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression arg0) {
	arg0.getLeftExpression().accept(this);
	arg0.getRightExpression().accept(this);
}
 
Example #15
Source File: DetailedClassifierVisitor.java    From evosql with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression arg0) {
	arg0.getLeftExpression().accept(this);
	arg0.getRightExpression().accept(this);
}
 
Example #16
Source File: FunctionClassifierVisitor.java    From evosql with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression arg0) {
	arg0.getLeftExpression().accept(this);
	arg0.getRightExpression().accept(this);
}
 
Example #17
Source File: CryptoVisitor.java    From evosql with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression arg0) {
	arg0.getLeftExpression().accept(this);
	arg0.getRightExpression().accept(this);
}
 
Example #18
Source File: WhereCauseProcessor.java    From sql-to-mongo-db-query-converter with Apache License 2.0 4 votes vote down vote up
private boolean isOrAndExpression(Expression expression) {
    return OrExpression.class.isInstance(expression) || AndExpression.class.isInstance(expression);
}
 
Example #19
Source File: TableRenameVisitor.java    From compass with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression andExpression)
{
    visitBinaryExpression(andExpression);
}
 
Example #20
Source File: SqlToCqlTranslator.java    From cassandra-jdbc-driver with Apache License 2.0 4 votes vote down vote up
public void visit(AndExpression andExpression) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #21
Source File: ObjPD.java    From openprodoc with GNU Affero General Public License v3.0 4 votes vote down vote up
private Conditions EvalExpr(Expression ParentExpr ) throws PDException 
{
Conditions New = new Conditions();    
int ExprType= EvalExprType(ParentExpr);
//System.out.println("ParentExpr=["+ParentExpr+"]  Type="+ExprType);    
switch (ExprType)
    {
    case EXPR_BASIC:
        ComparisonOperator CO = (ComparisonOperator) ParentExpr;
        String Left=CO.getLeftExpression().toString();
        String Comp=CO.getStringExpression();
        String Right=CO.getRightExpression().toString();
        if (isField(Left) && isField(Right))
            New.addCondition(new Condition(Left,  Right));
        else  
            {
            String FieldName;
            Object Value;
            int TypeVal;
            if (isField(Left))
                {
                FieldName=Left;
                Value=CalcVal(Right);
                TypeVal=CalcTypeVal(Right);
                }
            else
                {
                FieldName=Right;
                Value=CalcVal(Left);
                TypeVal=CalcTypeVal(Left);
                }
//            System.out.println("Value="+Value+"  class="+Value.getClass().getName());
            New.addCondition(new Condition(FieldName,  getCompConv().get(Comp), Value, TypeVal));
            }
        break;    
    case EXPR_NOT:
        Conditions Cs=EvalExpr(((NotExpression) ParentExpr).getExpression());
        Cs.setInvert(true);
        New.addCondition(Cs);
        break;
    case EXPR_AND:
        New.addCondition(EvalExpr(((AndExpression) ParentExpr).getLeftExpression() ));
        New.addCondition(EvalExpr(((AndExpression) ParentExpr).getRightExpression() ));
        break;
    case EXPR_OR:
        New.addCondition(EvalExpr(((OrExpression) ParentExpr).getLeftExpression() ));
        New.addCondition(EvalExpr(((OrExpression) ParentExpr).getRightExpression() ));
        New.setOperatorAnd(false);
        break;
    case EXPR_PAR:
        New.addCondition(EvalExpr(((Parenthesis) ParentExpr).getExpression() ));
        break;
    case EXPR_IN:
        String FieldNameIn=((InExpression)ParentExpr).getLeftExpression().toString();
        HashSet<String> ListTerms = new HashSet<String>();
        List<Expression> LT =((ExpressionList)((InExpression)ParentExpr).getLeftItemsList()).getExpressions();
        for (Iterator<Expression> iterator = LT.iterator(); iterator.hasNext();)
            {
            StringValue NextTerm = (StringValue)iterator.next();
            ListTerms.add(NextTerm.getValue());
            }
        New.addCondition(new Condition(FieldNameIn,ListTerms));
        break;
    case EXPR_FUNCT:
        String Arg=((Function)ParentExpr).getParameters().getExpressions().get(0).toString();
        switch (((Function)ParentExpr).getName())
            {
            case Condition.CONTAINS:
                New.addCondition(Condition.genContainsCond(PDDocs.getTableName(),Arg, getDrv())); 
                break;
            case Condition.INTREE:
                New.addCondition(Condition.genInTreeCond( Arg, getDrv())); 
                break;
            case Condition.INFOLDER:
                New.addCondition(Condition.genInFolder(Arg, getDrv()));
                break;
                
            }
        break;    
        
    }
return(New);
}
 
Example #22
Source File: TableVisitor.java    From DDF with Apache License 2.0 4 votes vote down vote up
public void visit(AndExpression andExpression) throws Exception {
    visitBinaryExpression(andExpression);
}
 
Example #23
Source File: SqlElementVisitor.java    From foxtrot with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(AndExpression andExpression) {
    //supported construct
}