Java Code Examples for net.sf.jsqlparser.schema.Table#getName()

The following examples show how to use net.sf.jsqlparser.schema.Table#getName() . 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: FromItemVisitorImpl.java    From DataPermissionHelper with Apache License 2.0 7 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 File: JSQLParserAdapter.java    From ddal with Apache License 2.0 6 votes vote down vote up
private void routeTable(TableWrapper tab, Column column, Object sdValue) {
    if (tab == null) {//
        return;
    }
    if (tab == AMBIGUOUS_TABLE) {
        throw new RuntimeException("Shard value '" + column.toString() + "' in where clause is ambiguous. Sql is ["
                                   + sql + "]");
    }
    ShardRouteInfo routeInfo = getRouteInfo(tab, sdValue);
    // 当没有设置别名,但分表字段使用了表前缀时,别前缀需要根据路由结果进行重写;
    // 这里之所有没有采用将table取名的方式是因为update/delete/insert不全支持别名;
    // 由于select都是支持别名的,所有都会被添加别名,因此不会执行下面的操作;
    Table columnTable = column.getTable();
    if (tab.getAlias() == null && columnTable != null && columnTable.getName() != null
        && columnTable.getName().length() > 0) {
        if (columnTable.getSchemaName() != null) {
            columnTable.setSchemaName(routeInfo.getScName());
        }
        columnTable.setName(routeInfo.getTbName());
    }
    route0(tab, routeInfo);
}
 
Example 3
Source File: JSQLParserAdapter.java    From ddal with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(Table table) {
    String tbName = table.getName();

    ShardRouteConfig routeConfig = shardRouter.getRouteConfig(table.getSchemaName(), tbName);
    if (routeConfig != null) {
        TableWrapper tab = new TableWrapper(table, routeConfig);
        FrameContext frameContext = this.getStack().peek();
        StatementType statementType = frameContext.getStatementType();
        if (statementType == StatementType.SELECT) {
            addRoutedTableIntoContext(tab, routeConfig, true);
        } else {
            addRoutedTableIntoContext(tab, routeConfig, false);
        }
    }
}
 
Example 4
Source File: UsedColumnExtractorVisitor.java    From evosql with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(Table arg0) {
	// This can only happen in a FROM, source the table
	String tableName = arg0.getName();
	String tableAlias = tableName;
	
	// Handle alias
	if (arg0.getAlias() != null) {
		tableAlias = arg0.getAlias().getName();
	}
	
	sourceTable(tableName, tableAlias);
}
 
Example 5
Source File: SqlSecurerVisitor.java    From evosql with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(Table arg0) {
	if (arg0.getName() == null) return;
	
	arg0.setName(secureName(arg0.getName()));
	
	// Handle alias
	if (arg0.getAlias() != null) {
		arg0.getAlias().setName(secureName(arg0.getAlias().getName()));
	}
}
 
Example 6
Source File: CryptoVisitor.java    From evosql with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(Table arg0) {
	if (arg0.getName() == null) return;
	
	arg0.setName(transform(arg0.getName()));
	
	// Handle alias
	if (arg0.getAlias() != null) {
		arg0.getAlias().setName(transform(arg0.getAlias().getName()));
	}
}
 
Example 7
Source File: TableRef.java    From herddb with Apache License 2.0 5 votes vote down vote up
static TableRef buildFrom(Table fromTable, String defaultTableSpace) {
    String tableSpace = fromTable.getSchemaName();
    String tableName = fromTable.getName();
    String tableAlias = tableName;
    if (fromTable.getAlias() != null && fromTable.getAlias().getName() != null) {
        tableAlias = fromTable.getAlias().getName();
    }
    if (tableSpace == null) {
        tableSpace = defaultTableSpace;
    }
    return new TableRef(tableSpace, tableName, tableAlias);
}
 
Example 8
Source File: TableRenameVisitor.java    From compass with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(Table table) 
{
    String fullyQualifiedName = table.getFullyQualifiedName();
    if (!otherItemNames.contains(fullyQualifiedName.toLowerCase()))
    {
        String oldTableName=table.getName();
        String newTableName=this.tableRenamer.rename(oldTableName);
        table.setName(newTableName);
    }
}
 
Example 9
Source File: SelectSqlConverter.java    From mybatis-shard with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void visit(Table tableName) {
    String tableNameName = tableName.getName();

    if (includePattern.matcher(tableNameName).find()) {

        String newName = convertTableName(tableNameName, suffix);
        tableName.setName(newName);
    }
}
 
Example 10
Source File: QueryStripperVisitor.java    From evosql with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(Table arg0) {
	if (arg0.getName() == null) return;
}