Skip to content

Commit

Permalink
Merge pull request #41 from sharding-sphere/dev
Browse files Browse the repository at this point in the history
update from origin
  • Loading branch information
beckhampu authored Oct 18, 2018
2 parents 966c221 + e442863 commit da6e0aa
Show file tree
Hide file tree
Showing 131 changed files with 331 additions and 7,162 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<javax.transaction.version>1.1</javax.transaction.version>
<atomikos.version>4.0.4</atomikos.version>

<zookeeper.version>3.4.6</zookeeper.version>
<curator.version>2.10.0</curator.version>
<grpc.version>1.7.0</grpc.version>
<protobuf.version>3.4.0</protobuf.version>
Expand Down Expand Up @@ -156,11 +155,6 @@
<version>${atomikos.version}</version>
</dependency>

<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private DALStatement parseShowTables(final LexerEngine lexerEngine) {
DALStatement result = new ShowTablesStatement();
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
}
return result;
}
Expand All @@ -172,7 +172,7 @@ private DALStatement parseShowColumnsFields(final LexerEngine lexerEngine) {
parseSingleTableWithSchema(lexerEngine, result);
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
}
return result;
}
Expand All @@ -182,7 +182,7 @@ private void parseSingleTableWithSchema(final LexerEngine lexerEngine, final SQL
String literals = lexerEngine.getCurrentToken().getLiterals();
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(Symbol.DOT)) {
sqlStatement.getSqlTokens().add(new SchemaToken(beginPosition, literals, null));
sqlStatement.addSQLToken(new SchemaToken(beginPosition, literals, null));
lexerEngine.nextToken();
}
}
Expand All @@ -193,7 +193,7 @@ private DALStatement parseShowIndex(final LexerEngine lexerEngine) {
parseSingleTableWithSchema(lexerEngine, result);
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
}
return result;
}
Expand All @@ -203,7 +203,7 @@ private DALStatement parseShowTableStatus(final LexerEngine lexerEngine) {
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private Collection<Column> parseWithoutColumn(
final InsertStatement insertStatement, final ShardingTableMetaData shardingTableMetaData, final String tableName, final Optional<Column> generateKeyColumn) {
int count = 0;
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length() - 1;
insertStatement.getSqlTokens().add(new InsertColumnToken(beginPosition, "("));
insertStatement.addSQLToken(new InsertColumnToken(beginPosition, "("));
ItemsToken columnsToken = new ItemsToken(beginPosition);
columnsToken.setFirstOfItemsSpecial(true);
Collection<Column> result = new LinkedList<>();
Expand All @@ -119,8 +119,8 @@ private Collection<Column> parseWithoutColumn(
count++;
}
}
insertStatement.getSqlTokens().add(columnsToken);
insertStatement.getSqlTokens().add(new InsertColumnToken(beginPosition, ")"));
insertStatement.addSQLToken(columnsToken);
insertStatement.addSQLToken(new InsertColumnToken(beginPosition, ")"));
insertStatement.setColumnsListLastPosition(beginPosition);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void parse(final InsertStatement insertStatement) {
removeUnnecessaryToken(insertStatement);
insertStatement.setGenerateKeyColumnIndex(-1);
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
insertStatement.getSqlTokens().add(new InsertValuesToken(beginPosition, insertStatement.getTables().getSingleTableName()));
insertStatement.addSQLToken(new InsertValuesToken(beginPosition, insertStatement.getTables().getSingleTableName()));
String tableName = insertStatement.getTables().getSingleTableName();
Optional<Column> generateKeyColumn = shardingRule.getGenerateKeyColumn(tableName);
int count = 0;
Expand Down Expand Up @@ -111,7 +111,7 @@ public void parse(final InsertStatement insertStatement) {
}

private void removeUnnecessaryToken(final InsertStatement insertStatement) {
Iterator<SQLToken> sqlTokens = insertStatement.getSqlTokens().iterator();
Iterator<SQLToken> sqlTokens = insertStatement.getSQLTokens().iterator();
while (sqlTokens.hasNext()) {
SQLToken sqlToken = sqlTokens.next();
if (sqlToken instanceof InsertColumnToken || sqlToken instanceof ItemsToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void parseValues(final InsertStatement insertStatement) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
int endPosition;
int startParametersIndex;
insertStatement.getSqlTokens().add(new InsertValuesToken(beginPosition, insertStatement.getTables().getSingleTableName()));
insertStatement.addSQLToken(new InsertValuesToken(beginPosition, insertStatement.getTables().getSingleTableName()));
do {
beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
startParametersIndex = insertStatement.getParametersIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private SelectItem parseCommonOrStarSelectItem(final SelectStatement selectState
} else if (lexerEngine.equalAny(Symbol.DOT)) {
String tableName = SQLUtil.getExactlyValue(literals);
if (shardingRule.tryFindTableRuleByLogicTable(tableName).isPresent() || shardingRule.findBindingTableRule(tableName).isPresent()) {
selectStatement.getSqlTokens().add(new TableToken(position, 0, literals));
selectStatement.addSQLToken(new TableToken(position, 0, literals));
}
result.append(lexerEngine.getCurrentToken().getLiterals());
lexerEngine.nextToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected final void parseTableFactor(final SQLStatement sqlStatement, final boo
}
if (isSingleTableOnly || shardingRule.tryFindTableRuleByLogicTable(tableName).isPresent() || shardingRule.findBindingTableRule(tableName).isPresent()
|| shardingRule.getShardingDataSourceNames().getDataSourceNames().contains(shardingRule.getShardingDataSourceNames().getDefaultDataSourceName())) {
sqlStatement.getSqlTokens().add(new TableToken(beginPosition, skippedSchemaNameLength, literals));
sqlStatement.addSQLToken(new TableToken(beginPosition, skippedSchemaNameLength, literals));
sqlStatement.getTables().add(new Table(tableName, aliasExpressionParser.parseTableAlias(sqlStatement, true, tableName)));
} else {
aliasExpressionParser.parseTableAlias();
Expand All @@ -125,7 +125,7 @@ private void parseForceIndex(final String tableName, final SQLStatement sqlState
Preconditions.checkState(!Symbol.RIGHT_PAREN.getLiterals().equals(literals), "There is an error in the vicinity of the force index syntax.");
if (shardingRule.isLogicIndex(literals, tableName)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - literals.length();
sqlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, tableName));
sqlStatement.addSQLToken(new IndexToken(beginPosition, literals, tableName));
}
lexerEngine.nextToken();
} while (lexerEngine.skipIfEqual(Symbol.COMMA));
Expand Down Expand Up @@ -192,7 +192,7 @@ public final void parseSingleTableWithoutAlias(final SQLStatement sqlStatement)
literals = lexerEngine.getCurrentToken().getLiterals();
lexerEngine.nextToken();
}
sqlStatement.getSqlTokens().add(new TableToken(beginPosition, skippedSchemaNameLength, literals));
sqlStatement.addSQLToken(new TableToken(beginPosition, skippedSchemaNameLength, literals));
sqlStatement.getTables().add(new Table(SQLUtil.getExactlyValue(literals), Optional.<String>absent()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void parseSetColumn(final DMLStatement updateStatement) {
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(Symbol.DOT)) {
if (updateStatement.getTables().getSingleTableName().equalsIgnoreCase(SQLUtil.getExactlyValue(literals))) {
updateStatement.getSqlTokens().add(new TableToken(beginPosition - literals.length(), 0, literals));
updateStatement.addSQLToken(new TableToken(beginPosition - literals.length(), 0, literals));
}
lexerEngine.nextToken();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private void parseRowCountCondition(final SelectStatement selectStatement, final
if (sqlExpression instanceof SQLNumberExpression) {
int rowCount = ((SQLNumberExpression) sqlExpression).getNumber().intValue();
selectStatement.getLimit().setRowCount(new LimitValue(rowCount, -1, includeRowCount));
selectStatement.getSqlTokens().add(new RowCountToken(endPosition - String.valueOf(rowCount).length(), rowCount));
selectStatement.addSQLToken(new RowCountToken(endPosition - String.valueOf(rowCount).length(), rowCount));
} else if (sqlExpression instanceof SQLPlaceholderExpression) {
selectStatement.getLimit().setRowCount(new LimitValue(-1, ((SQLPlaceholderExpression) sqlExpression).getIndex(), includeRowCount));
}
Expand All @@ -308,7 +308,7 @@ private void parseOffsetCondition(final SelectStatement selectStatement, final b
if (sqlExpression instanceof SQLNumberExpression) {
int offset = ((SQLNumberExpression) sqlExpression).getNumber().intValue();
selectStatement.getLimit().setOffset(new LimitValue(offset, -1, includeOffset));
selectStatement.getSqlTokens().add(new OffsetToken(
selectStatement.addSQLToken(new OffsetToken(
lexerEngine.getCurrentToken().getEndPosition() - String.valueOf(offset).length() - lexerEngine.getCurrentToken().getLiterals().length(), offset));
} else if (sqlExpression instanceof SQLPlaceholderExpression) {
selectStatement.getLimit().setOffset(new LimitValue(-1, ((SQLPlaceholderExpression) sqlExpression).getIndex(), includeOffset));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private Optional<String> parseAlias(final SQLStatement sqlStatement, final boole
String literals = lexerEngine.getCurrentToken().getLiterals();
String alias = SQLUtil.getExactlyValue(literals);
if (setTableToken && alias.equals(tableName)) {
sqlStatement.getSqlTokens().add(new TableToken(beginPosition, 0, literals));
sqlStatement.addSQLToken(new TableToken(beginPosition, 0, literals));
}
lexerEngine.nextToken();
return Optional.of(SQLUtil.getExactlyValue(literals));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void skipRestCompositeExpression(final SQLStatement sqlStatement) {
private void setTableToken(final SQLStatement sqlStatement, final int beginPosition, final SQLPropertyExpression propertyExpr) {
String owner = propertyExpr.getOwner().getName();
if (sqlStatement.getTables().getTableNames().contains(SQLUtil.getExactlyValue(propertyExpr.getOwner().getName()))) {
sqlStatement.getSqlTokens().add(new TableToken(beginPosition - owner.length(), 0, owner));
sqlStatement.addSQLToken(new TableToken(beginPosition - owner.length(), 0, owner));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void parse(final SelectStatement selectStatement) {
if (isParameterForValue) {
selectStatement.increaseParametersIndex();
} else {
selectStatement.getSqlTokens().add(new RowCountToken(valueBeginPosition, value));
selectStatement.addSQLToken(new RowCountToken(valueBeginPosition, value));
}
Limit limit = new Limit(DatabaseType.MySQL);
limit.setRowCount(new LimitValue(value, valueIndex, false));
Expand All @@ -104,12 +104,12 @@ private Limit getLimitWithComma(final int index, final int valueBeginPosition, f
if (isParameterForValue) {
selectStatement.increaseParametersIndex();
} else {
selectStatement.getSqlTokens().add(new OffsetToken(valueBeginPosition, value));
selectStatement.addSQLToken(new OffsetToken(valueBeginPosition, value));
}
if (isParameterForRowCount) {
selectStatement.increaseParametersIndex();
} else {
selectStatement.getSqlTokens().add(new RowCountToken(rowCountBeginPosition, rowCountValue));
selectStatement.addSQLToken(new RowCountToken(rowCountBeginPosition, rowCountValue));
}
Limit result = new Limit(DatabaseType.MySQL);
result.setRowCount(new LimitValue(rowCountValue, rowCountIndex, false));
Expand All @@ -136,12 +136,12 @@ private Limit getLimitWithOffset(final int index, final int valueBeginPosition,
if (isParameterForOffset) {
selectStatement.increaseParametersIndex();
} else {
selectStatement.getSqlTokens().add(new OffsetToken(offsetBeginPosition, offsetValue));
selectStatement.addSQLToken(new OffsetToken(offsetBeginPosition, offsetValue));
}
if (isParameterForValue) {
selectStatement.increaseParametersIndex();
} else {
selectStatement.getSqlTokens().add(new RowCountToken(valueBeginPosition, value));
selectStatement.addSQLToken(new RowCountToken(valueBeginPosition, value));
}
Limit result = new Limit(DatabaseType.MySQL);
result.setRowCount(new LimitValue(value, index, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ private DALStatement parseShowTableStatus() {
if (lexerEngine.equalAny(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
lexerEngine.nextToken();
result.getSqlTokens().add(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
result.addSQLToken(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
}
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(DefaultKeyword.LIKE)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length() - 1;
String literals = lexerEngine.getCurrentToken().getLiterals();
result.getSqlTokens().add(new TableToken(beginPosition, 0, literals));
result.addSQLToken(new TableToken(beginPosition, 0, literals));
result.getTables().add(new Table(SQLUtil.getExactlyValue(literals), Optional.<String>absent()));
}
return result;
Expand All @@ -108,7 +108,7 @@ private DALStatement parseShowTables() {
if (lexerEngine.equalAny(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
lexerEngine.nextToken();
result.getSqlTokens().add(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
result.addSQLToken(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
}
return result;
}
Expand All @@ -119,7 +119,7 @@ private DALStatement parseShowColumnsFields() {
tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
}
return result;
}
Expand All @@ -136,7 +136,7 @@ private DALStatement parseShowIndex() {
tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private Optional<LimitValue> buildRowCount(final SelectStatement selectStatement
if (lexerEngine.equalAny(Literals.INT, Literals.FLOAT)) {
rowCountValue = NumberUtil.roundHalfUp(lexerEngine.getCurrentToken().getLiterals());
valueBeginPosition = valueBeginPosition - (rowCountValue + "").length();
selectStatement.getSqlTokens().add(new RowCountToken(valueBeginPosition, rowCountValue));
selectStatement.addSQLToken(new RowCountToken(valueBeginPosition, rowCountValue));
} else if (lexerEngine.equalAny(Symbol.QUESTION)) {
rowCountIndex = parameterIndex++;
selectStatement.setParametersIndex(parameterIndex);
Expand All @@ -98,7 +98,7 @@ private Optional<LimitValue> buildOffset(final SelectStatement selectStatement)
if (lexerEngine.equalAny(Literals.INT, Literals.FLOAT)) {
offsetValue = NumberUtil.roundHalfUp(lexerEngine.getCurrentToken().getLiterals());
offsetBeginPosition = offsetBeginPosition - (offsetValue + "").length();
selectStatement.getSqlTokens().add(new OffsetToken(offsetBeginPosition, offsetValue));
selectStatement.addSQLToken(new OffsetToken(offsetBeginPosition, offsetValue));
} else if (lexerEngine.equalAny(Symbol.QUESTION)) {
offsetIndex = parameterIndex++;
selectStatement.setParametersIndex(parameterIndex);
Expand Down
Loading

0 comments on commit da6e0aa

Please sign in to comment.