Java Code Examples for net.sf.jsqlparser.statement.select.SubSelect

The following examples show how to use net.sf.jsqlparser.statement.select.SubSelect. These examples are extracted from open source projects. 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 Project: DataPermissionHelper   Source File: FromItemVisitorImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void visit(Table table) {
    String tableName = table.getName();
    //关键点:解析到需要进行数据权限控制的表时进行拼装,可以从当前线程获取表数据
    //需要进行的数据权限控制的表数据
    Map<String, IdsAndColumn> tables = DPHelper.getLocalDataPermissions().getTables();
    if (tables.containsKey(tableName)) {
        IdsAndColumn idsAndColumn = tables.get(tableName);
        List<String> ids = idsAndColumn.getIds();
        List<String> columns = idsAndColumn.getColumns();

        SubSelect subSelect = new SubSelect();
        String subSql = SqlSpliceUtils.spliceIdAndColumn(tableName, ids, columns);
        try {
            subSelect.setSelectBody(((Select) (CCJSqlParserUtil.parse(subSql))).getSelectBody());
        } catch (JSQLParserException e) {
            logger.error("数据权限sql解析异常");
        }
        //TODO:采用随机别名不能避免重名
        subSelect.setAlias(table.getAlias() != null ? table.getAlias() : new Alias("DP" + UUID.randomUUID()
                .toString().replace("-", "")));
        this.subSelect = subSelect;
    }
}
 
Example 2
Source Project: spanner-jdbc   Source File: CloudSpannerPreparedStatement.java    License: 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 3
private void addToSQLHolderMap(FromItem from) throws com.github.vincentrussell.query.mongodb.sql.converter.ParseException, ParseException {
	if (from instanceof Table) {
		Table table = (Table)from;
		fromToSQLHolder.put(table, new SQLTableInfoHolder(table.getName()));
   	}
   	else if(from instanceof SubSelect){
   		SubSelect subselect = (SubSelect) from; 
   		fromToSQLHolder.put(from, SQLCommandInfoHolder.Builder
                   .create(defaultFieldType, fieldNameToFieldTypeMapping)
                   .setPlainSelect((PlainSelect)subselect.getSelectBody())
                   .build());
   	}
   	else {//Not happen SubJoin, not supported previously
   		return;
   	}
}
 
Example 4
@Override
public void visit(SubSelect subSelect) {
    if (subSelect.getWithItemsList() != null) {
        for (WithItem withItem : subSelect.getWithItemsList()) {
            withItem.accept(new SelectVisitorImpl());
        }
    }
    subSelect.getSelectBody().accept(new SelectVisitorImpl());
}
 
Example 5
Source Project: quetzal   Source File: CTEToNestedQueryConverter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(LateralSubSelect lateralSubSelect) {
	if (lateralSubSelect.getSubSelect()!=null) {
		lateralSubSelect.getSubSelect().accept(this);
		lateralSubSelect.setSubSelect((SubSelect) result);
	}
	result = lateralSubSelect;
}
 
Example 6
Source Project: quetzal   Source File: CTEToNestedQueryConverter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(SubSelect subSelect) {
	if (subSelect.getSelectBody()!=null) {
		replace(subSelect.getSelectBody(), cteName2Def, placeHolderTables);
	}
	result = subSelect;
}
 
Example 7
Source Project: DataPermissionHelper   Source File: FromItemVisitorImpl.java    License: Apache License 2.0 4 votes vote down vote up
public SubSelect getSubSelect() {
    return this.subSelect;
}
 
Example 8
Source Project: DataPermissionHelper   Source File: FromItemVisitorImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void visit(SubSelect subSelect) {
    // 如果是子查询的话返回到select接口实现类
    subSelect.getSelectBody().accept(new SelectVisitorImpl());
}
 
Example 9
Source Project: DataPermissionHelper   Source File: ItemsListVisitorImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void visit(SubSelect ss) {
    ss.getSelectBody().accept(new SelectVisitorImpl());
}
 
Example 10
Source Project: spanner-jdbc   Source File: DMLWhereClauseVisitorAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public void visit(SubSelect subSelect) {
  invalid = true;
  super.visit(subSelect);
}
 
Example 11
public static List<Document> toPipelineSteps(QueryConverter queryConverter, FromHolder tholder, List<Join> ljoins, Expression whereExpression) throws ParseException, net.sf.jsqlparser.parser.ParseException {
	List<Document> ldoc = new LinkedList<Document>();
	MutableBoolean haveOrExpression = new MutableBoolean();
	for(Join j : ljoins) {
		if(j.isInner() || j.isLeft()) {
			
			if(j.getRightItem() instanceof Table || j.getRightItem() instanceof SubSelect) {
				ExpressionHolder whereExpHolder;
				String joinTableAlias = j.getRightItem().getAlias().getName();
				String joinTableName = tholder.getSQLHolder(j.getRightItem()).getBaseTableName();
				
				whereExpHolder = new ExpressionHolder(null);
				
				if(whereExpression != null) {
					haveOrExpression.setValue(false);
					whereExpression.accept(new WhereVisitorMatchAndLookupPipelineMatchBuilder(joinTableAlias, whereExpHolder, haveOrExpression));
					if(!haveOrExpression.booleanValue() && whereExpHolder.getExpression() != null) {
						whereExpHolder.getExpression().accept(new ExpVisitorEraseAliasTableBaseBuilder(joinTableAlias));
					}
					else {
						whereExpHolder.setExpression(null);
					}
				}
				
				List<Document> subqueryDocs = new LinkedList<>();
				
				if(j.getRightItem() instanceof SubSelect) {
					subqueryDocs = queryConverter.fromSQLCommandInfoHolderToAggregateSteps((SQLCommandInfoHolder)tholder.getSQLHolder(j.getRightItem()));
				}
				
				ldoc.add(generateLookupStep(tholder,joinTableName,joinTableAlias,j.getOnExpression(),whereExpHolder.getExpression(),subqueryDocs));
				ldoc.add(generateUnwindStep(tholder,joinTableAlias,j.isLeft()));
			}
			else {
				throw new ParseException("From join not supported");
			}
		}
		else {
			throw new ParseException("Only inner join and left supported");
		}
		
	}
	if(haveOrExpression.booleanValue()) {//if there is some "or" we use this step for support this logic and no other match steps
		ldoc.add(generateMatchAfterJoin(tholder,whereExpression));
	}
	return ldoc;
}
 
Example 12
Source Project: quetzal   Source File: CTEToNestedQueryConverter.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void visit(SubSelect subSelect) {
	defaultVisit(subSelect);
}
 
Example 13
Source Project: tx-lcn   Source File: PrimaryKeyListVisitor.java    License: Apache License 2.0 2 votes vote down vote up
@Override
public void visit(SubSelect subSelect) {

}