Skip to content

Commit

Permalink
Minor changes (apache#8707)
Browse files Browse the repository at this point in the history
* Move sequence of AgentPluginLoader.getInstance

* Adjust methods sequence of AgentPluginLoader

* Refactor TextProtocolBackendHandlerFactory

* For code format

* Refactor RemoveTokenGenerator

* Refactor SingleTableRoutingEngine
  • Loading branch information
terrymanu authored Dec 21, 2020
1 parent 3ee1590 commit bf74c0b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void route(final RouteContext routeContext, final ShardingRule shardingRu
routeContext.getRouteUnits().add(new RouteUnit(new RouteMapper(dataSourceName.get(), dataSourceName.get()), routingTables));
}

private Optional<String> getRandomDataSourceName(final Collection<String> dataSourceNames) {
String dataSourceName = Lists.newArrayList(dataSourceNames).get(ThreadLocalRandom.current().nextInt(dataSourceNames.size()));
return Optional.of(dataSourceName);
}

private Optional<String> findDataSourceNameOfSingleTable(final ShardingRule shardingRule) {
for (String each : logicTables) {
if (shardingRule.getSingleTableRules().containsKey(each)) {
Expand All @@ -62,9 +67,4 @@ private Optional<String> findDataSourceNameOfSingleTable(final ShardingRule shar
}
return Optional.empty();
}

private Optional<String> getRandomDataSourceName(final Collection<String> dataSourceNames) {
String dataSourceName = Lists.newArrayList(dataSourceNames).get(ThreadLocalRandom.current().nextInt(dataSourceNames.size()));
return Optional.of(dataSourceName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Remove token generator.
*/
public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator {
public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator<SQLStatementContext<?>> {

@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public static TextProtocolBackendHandler newInstance(final DatabaseType database
if (sqlStatement instanceof TCLStatement) {
return TransactionBackendHandlerFactory.newInstance((TCLStatement) sqlStatement, sql, backendConnection);
}
Optional<TextProtocolBackendHandler> distSQLBackendHandler = DistSQLBackendHandlerFactory.newInstance(databaseType, sqlStatement, backendConnection);
if (distSQLBackendHandler.isPresent()) {
return distSQLBackendHandler.get();
}
Optional<DatabaseAdminBackendHandlerFactory> adminBackendHandlerEngine = TypedSPIRegistry.findRegisteredService(
DatabaseAdminBackendHandlerFactory.class, databaseType.getName(), new Properties());
if (adminBackendHandlerEngine.isPresent()) {
Expand All @@ -80,10 +84,6 @@ public static TextProtocolBackendHandler newInstance(final DatabaseType database
return databaseAdminBackendHandler.get();
}
}
Optional<TextProtocolBackendHandler> distSQLBackendHandler = DistSQLBackendHandlerFactory.newInstance(databaseType, sqlStatement, backendConnection);
if (distSQLBackendHandler.isPresent()) {
return distSQLBackendHandler.get();
}
return DatabaseBackendHandlerFactory.newInstance(sqlStatement, sql, backendConnection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
@NoArgsConstructor
@Getter
public final class MySQLCallStatement extends CallStatement implements MySQLStatement {

private String procedureName;

private List<ExpressionSegment> parameters;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
@Setter
@ToString
public final class MySQLInsertStatement extends InsertStatement implements MySQLStatement {

private SetAssignmentSegment setAssignment;

private OnDuplicateKeyColumnsSegment onDuplicateKeyColumns;

/**
* Get set assignment segment.
*
Expand All @@ -45,7 +45,7 @@ public final class MySQLInsertStatement extends InsertStatement implements MySQL
public Optional<SetAssignmentSegment> getSetAssignment() {
return Optional.ofNullable(setAssignment);
}

/**
* Get on duplicate key columns segment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
@Setter
@ToString
public final class MySQLSelectStatement extends SelectStatement implements MySQLStatement {

private LimitSegment limit;

private LockSegment lock;

/**
Expand All @@ -45,7 +45,7 @@ public final class MySQLSelectStatement extends SelectStatement implements MySQL
public Optional<LimitSegment> getLimit() {
return Optional.ofNullable(limit);
}

/**
* Get lock segment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
public final class MySQLUpdateStatement extends UpdateStatement implements MySQLStatement {

private OrderBySegment orderBy;

private LimitSegment limit;

/**
* Get order by segment.
*
Expand All @@ -45,7 +45,7 @@ public final class MySQLUpdateStatement extends UpdateStatement implements MySQL
public Optional<OrderBySegment> getOrderBy() {
return Optional.ofNullable(orderBy);
}

/**
* Get order by segment.
*
Expand Down

0 comments on commit bf74c0b

Please sign in to comment.