Java Code Examples for net.sf.jsqlparser.expression.Expression#accept()

The following examples show how to use net.sf.jsqlparser.expression.Expression#accept() . 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: CloudSpannerPreparedStatement.java    From spanner-jdbc with MIT License 6 votes vote down vote up
private void setWhereParameters(Expression where,
    com.google.cloud.spanner.Statement.Builder builder) {
  if (where != null) {
    where.accept(new ExpressionVisitorAdapter() {
      private String currentCol = null;

      @Override
      public void visit(Column col) {
        currentCol = unquoteIdentifier(col.getFullyQualifiedName());
      }

      @Override
      public void visit(JdbcParameter parameter) {
        parameter.accept(new ValueBinderExpressionVisitorAdapter<>(getParameterStore(),
            builder.bind("p" + parameter.getIndex()), currentCol));
        currentCol = null;
      }

      @Override
      public void visit(SubSelect subSelect) {
        setSelectParameters(subSelect.getSelectBody(), builder);
      }

    });
  }
}
 
Example 2
Source File: CloudSpannerPreparedStatement.java    From spanner-jdbc with MIT License 6 votes vote down vote up
private void visitDeleteWhereClause(Expression where, DeleteKeyBuilder keyBuilder,
    boolean generateParameterMetaData) throws SQLException {
  if (where != null) {
    DMLWhereClauseVisitor whereClauseVisitor = new DMLWhereClauseVisitor(getParameterStore()) {

      @Override
      protected void visitExpression(Column col, Expression expression) {
        String columnName = unquoteIdentifier(col.getFullyQualifiedName());
        keyBuilder.set(columnName);
        expression.accept(
            new KeyBuilderExpressionVisitorAdapter(getParameterStore(), columnName, keyBuilder));
      }

    };
    where.accept(whereClauseVisitor);
    if (!generateParameterMetaData && !whereClauseVisitor.isValid()) {
      throw new CloudSpannerSQLException(INVALID_WHERE_CLAUSE_DELETE_MESSAGE,
          Code.INVALID_ARGUMENT);
    }
  }
}
 
Example 3
Source File: CloudSpannerPreparedStatement.java    From spanner-jdbc with MIT License 6 votes vote down vote up
private boolean isSingleRowWhereClause(TableKeyMetaData table, Expression where) {
  if (where != null) {
    SingleRowWhereClauseValidator validator = new SingleRowWhereClauseValidator(table);
    DMLWhereClauseVisitor whereClauseVisitor = new DMLWhereClauseVisitor(getParameterStore()) {

      @Override
      protected void visitExpression(Column col, Expression expression) {
        String columnName = unquoteIdentifier(col.getFullyQualifiedName());
        validator.set(columnName);
        expression.accept(new SingleRowWhereClauseValidatorExpressionVisitorAdapter(
            getParameterStore(), validator));
      }

    };
    where.accept(whereClauseVisitor);
    return whereClauseVisitor.isValid() && validator.isValid();
  }
  return false;
}
 
Example 4
Source File: CloudSpannerPreparedStatement.java    From spanner-jdbc with MIT License 6 votes vote down vote up
private void visitUpdateWhereClause(Expression where, WriteBuilder builder,
    boolean generateParameterMetaData) throws SQLException {
  if (where != null) {
    DMLWhereClauseVisitor whereClauseVisitor = new DMLWhereClauseVisitor(getParameterStore()) {

      @Override
      protected void visitExpression(Column col, Expression expression) {
        String columnName = unquoteIdentifier(col.getFullyQualifiedName());
        expression.accept(new ValueBinderExpressionVisitorAdapter<>(getParameterStore(),
            builder.set(columnName), columnName));
      }

    };
    where.accept(whereClauseVisitor);
    if (!generateParameterMetaData && !whereClauseVisitor.isValid()) {
      throw new CloudSpannerSQLException(INVALID_WHERE_CLAUSE_UPDATE_MESSAGE,
          Code.INVALID_ARGUMENT);
    }
  } else {
    throw new SQLException(INVALID_WHERE_CLAUSE_UPDATE_MESSAGE);
  }
}
 
Example 5
Source File: SQLCommandInfoHolder.java    From sql-to-mongo-db-query-converter with Apache License 2.0 6 votes vote down vote up
private AliasHolder generateHashAliasFromSelectItems(List<SelectItem> selectItems) {
	HashMap<String,String> aliasFromFieldHash = new HashMap<String,String>();
	HashMap<String,String> fieldFromAliasHash = new HashMap<String,String>();
	for(SelectItem sitem: selectItems) {
		if(!(sitem instanceof AllColumns)) {
			if(sitem instanceof SelectExpressionItem) {
 			SelectExpressionItem seitem = (SelectExpressionItem) sitem;
 			if(seitem.getAlias() != null) {
  			Expression selectExp = seitem.getExpression();
  			selectExp.accept(new ExpVisitorEraseAliasTableBaseBuilder(this.from.getBaseAliasTable()));
  			String expStr = selectExp.toString();
  			String aliasStr = seitem.getAlias().getName();
 				aliasFromFieldHash.put( expStr, aliasStr);
 				fieldFromAliasHash.put( aliasStr, expStr);
 			}
			}
		}
	}
	return new AliasHolder(aliasFromFieldHash, fieldFromAliasHash);
}
 
Example 6
Source File: QueryConverter.java    From sql-to-mongo-db-query-converter with Apache License 2.0 6 votes vote down vote up
/**
  * Erase table base alias and get where part of main table when joins
  * @param exp
  * @param tholder
  * @return
  */
 private Expression preprocessWhere(Expression exp, FromHolder tholder){
 	if(sqlCommandInfoHolder.getJoins()!=null && !sqlCommandInfoHolder.getJoins().isEmpty()) {
 		ExpressionHolder partialWhereExpHolder = new ExpressionHolder(null);
 		MutableBoolean haveOrExpression = new MutableBoolean(false);
exp.accept(new WhereVisitorMatchAndLookupPipelineMatchBuilder(tholder.getBaseAliasTable(), partialWhereExpHolder, haveOrExpression));
if(haveOrExpression.booleanValue()) {
	return null;//with or exp we can't use match first step
}
exp = partialWhereExpHolder.getExpression();
     }
 	if(exp != null) {
 		exp.accept(new ExpVisitorEraseAliasTableBaseBuilder(tholder.getBaseAliasTable()));
 	}
 	return exp;
 }
 
Example 7
Source File: CTEToNestedQueryConverter.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void visit(Function function) {
	clear();
	boolean tmpLeftTableFound = false;
	boolean tmpRightTableFound = false;
	boolean tmpWhereOnlyExpFound = false;
	boolean prevIsTopVal = isTopLevel;
	isTopLevel = false;
	if (function.getParameters()!=null) {
		for (Expression e: function.getParameters().getExpressions()) {
			e.accept(this);
			tmpLeftTableFound |= leftTableFound;
			tmpRightTableFound |= rightTableFound;
			tmpWhereOnlyExpFound |= whereOnlyExpFound;
		}
	}
	leftTableFound = tmpLeftTableFound;
	rightTableFound = tmpRightTableFound;
	whereOnlyExpFound = tmpWhereOnlyExpFound;
	isTopLevel = prevIsTopVal;
	defaultTopLevelProcessing(function);
}
 
Example 8
Source File: ItemsListVisitorImpl.java    From DataPermissionHelper with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void visit(ExpressionList el) {
    List<Expression> list = el.getExpressions();
    if (list != null && list.size() > 0) {
        for (Expression expr : list) {
            expr.accept(new ExpressionVisitorImpl());
        }
    }
}
 
Example 9
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 10
Source File: ExpressionVisitorImpl.java    From DataPermissionHelper with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(RowConstructor rowConstructor) {
    for (Expression expr : rowConstructor.getExprList().getExpressions()) {
        expr.accept(this);
    }
}