com.alibaba.druid.sql.ast.statement.SQLTableElement Java Examples
The following examples show how to use
com.alibaba.druid.sql.ast.statement.SQLTableElement.
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: GlobalTableUtil.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
private static boolean hasGlobalColumn(SQLStatement statement){ for (SQLTableElement tableElement : ((SQLCreateTableStatement)statement).getTableElementList()) { SQLName sqlName = null; if (tableElement instanceof SQLColumnDefinition) { sqlName = ((SQLColumnDefinition)tableElement).getName(); } if (sqlName != null) { String simpleName = sqlName.getSimpleName(); simpleName = StringUtil.removeBackquote(simpleName); if (tableElement instanceof SQLColumnDefinition && GLOBAL_TABLE_MYCAT_COLUMN.equalsIgnoreCase(simpleName)) { return true; } } } return false; }
Example #2
Source File: DruidMysqlCreateTableTest.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
private static boolean hasColumn(SQLStatement statement){ for (SQLTableElement tableElement : ((SQLCreateTableStatement)statement).getTableElementList()) { SQLName sqlName = null; if (tableElement instanceof SQLColumnDefinition) { sqlName = ((SQLColumnDefinition)tableElement).getName(); } if (sqlName != null) { String simpleName = sqlName.getSimpleName(); simpleName = StringUtil.removeBackquote(simpleName); if (tableElement instanceof SQLColumnDefinition && "_slot".equalsIgnoreCase(simpleName)) { return true; } } } return false; }
Example #3
Source File: TableHandler.java From dble with GNU General Public License v2.0 | 6 votes |
/** * pre handle create table statement * * @param context * @param sqlStatement * @return whether statement is changed */ private boolean preHandleCreateTable(DumpFileContext context, SQLStatement sqlStatement) { TableConfig tableConfig = context.getTableConfig(); List<SQLTableElement> columns = ((MySqlCreateTableStatement) sqlStatement).getTableElementList(); boolean isChanged = false; if (tableConfig.isAutoIncrement() || tableConfig.getPartitionColumn() != null) { // check columns for sharing column index or increment column index isChanged = checkColumns(context, columns); // partition column check if (tableConfig.getPartitionColumn() != null && context.getPartitionColumnIndex() == -1) { throw new DumpException("can't find partition column in create."); } // increment column check if (tableConfig.isAutoIncrement() && context.getIncrementColumnIndex() == -1) { throw new DumpException("can't find increment column in create."); } } return isChanged; }
Example #4
Source File: DruidMysqlCreateTableTest.java From dble with GNU General Public License v2.0 | 6 votes |
private static boolean hasColumn(SQLStatement statement) { for (SQLTableElement tableElement : ((SQLCreateTableStatement) statement).getTableElementList()) { SQLName sqlName = null; if (tableElement instanceof SQLColumnDefinition) { sqlName = ((SQLColumnDefinition) tableElement).getName(); } if (sqlName != null) { String simpleName = sqlName.getSimpleName(); simpleName = StringUtil.removeBackQuote(simpleName); if (tableElement instanceof SQLColumnDefinition && "_slot".equalsIgnoreCase(simpleName)) { return true; } } } return false; }
Example #5
Source File: MetaHelper.java From dble with GNU General Public License v2.0 | 5 votes |
private static TableMeta initTableMeta(String table, SQLCreateTableStatement createStatement, long timeStamp) { TableMeta tableMeta = new TableMeta(); tableMeta.setTableName(table); tableMeta.setVersion(timeStamp); tableMeta.setCreateSql(createStatement.toString()); List<TableMeta.ColumnMeta> columns = new ArrayList<>(createStatement.getTableElementList().size()); for (SQLTableElement tableElement : createStatement.getTableElementList()) { if (tableElement instanceof SQLColumnDefinition) { columns.add(new TableMeta.ColumnMeta((SQLColumnDefinition) tableElement)); } } tableMeta.setColumns(columns); return tableMeta; }
Example #6
Source File: TableHandler.java From dble with GNU General Public License v2.0 | 5 votes |
/** * if there are create statement in dump file, we check increment column and sharding column index for insert statement. * * @param context * @param columns * @return whether column is changed */ private boolean checkColumns(DumpFileContext context, List<SQLTableElement> columns) { SQLTableElement column; TableConfig tableConfig = context.getTableConfig(); boolean isAutoIncrement = tableConfig.isAutoIncrement(); boolean isChanged = false; for (int j = 0; j < columns.size(); j++) { column = columns.get(j); if (!(columns.get(j) instanceof SQLColumnDefinition)) { continue; } String columnName = StringUtil.removeBackQuote(((SQLColumnDefinition) column).getNameAsString()); // find index of increment column if (isAutoIncrement && columnName.equalsIgnoreCase(tableConfig.getIncrementColumn())) { // check data type of increment column // if the column is increment column, data type must be bigint. SQLColumnDefinition columnDef = (SQLColumnDefinition) column; if (!columnDef.getDataType().getName().equals("bigint")) { context.addError("data type of increment column isn't bigint, dble replaced it by itself."); columnDef.setDataType(new SQLCharacterDataType("bigint")); isChanged = true; } context.setIncrementColumnIndex(j); } // find index of partition column if (columnName.equalsIgnoreCase(tableConfig.getPartitionColumn())) { context.setPartitionColumnIndex(j); } } return isChanged; }
Example #7
Source File: TableConfig.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
public List<SQLTableElement> getTableElementList() { return tableElementList; }
Example #8
Source File: TableConfig.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
public void setTableElementList(List<SQLTableElement> tableElementList) { this.tableElementList = tableElementList; }