Skip to content

Commit

Permalink
Refactor SelectStatementBinder (#32048)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Jul 9, 2024
1 parent beb0443 commit 1afc200
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public static CombineSegment bind(final CombineSegment segment, final SQLStateme
ShardingSphereMetaData metaData = statementBinderContext.getMetaData();
String currentDatabaseName = statementBinderContext.getCurrentDatabaseName();
Map<String, TableSegmentBinderContext> externalTableBinderContexts = statementBinderContext.getExternalTableBinderContexts();
SelectStatement boundedLeftSelect = new SelectStatementBinder().bindWithExternalTableContexts(segment.getLeft().getSelect(), metaData, currentDatabaseName, externalTableBinderContexts);
SelectStatement boundedRightSelect = new SelectStatementBinder().bindWithExternalTableContexts(segment.getRight().getSelect(), metaData, currentDatabaseName, externalTableBinderContexts);
SelectStatement boundedLeftSelect = new SelectStatementBinder().bind(segment.getLeft().getSelect(), metaData, currentDatabaseName, externalTableBinderContexts);
SelectStatement boundedRightSelect = new SelectStatementBinder().bind(segment.getRight().getSelect(), metaData, currentDatabaseName, externalTableBinderContexts);
SubquerySegment boundedLeft = new SubquerySegment(segment.getLeft().getStartIndex(), segment.getLeft().getStopIndex(), segment.getLeft().getText());
boundedLeft.setSelect(boundedLeftSelect);
boundedLeft.setSubqueryType(segment.getLeft().getSubqueryType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
public interface SQLStatementBinder<T extends SQLStatement> {

/**
* Bind SQL statement with metadata.
* Bind SQL statement.
*
* @param sqlStatement SQL statement
* @param metaData meta data
* @param currentDatabaseName current database name
* @return bounded SQL statement
* @return bound SQL statement
*/
T bind(T sqlStatement, ShardingSphereMetaData metaData, String currentDatabaseName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@
*/
public final class SelectStatementBinder implements SQLStatementBinder<SelectStatement> {

/**
* Bind correlate subquery select statement.
*
* @param sqlStatement subquery select statement
* @param metaData meta data
* @param currentDatabaseName current database name
* @param outerTableBinderContexts outer select statement table binder contexts
* @param externalTableBinderContexts external table binder contexts
* @return bounded correlate subquery select statement
*/
public SelectStatement bindCorrelateSubquery(final SelectStatement sqlStatement, final ShardingSphereMetaData metaData, final String currentDatabaseName,
final Map<String, TableSegmentBinderContext> outerTableBinderContexts, final Map<String, TableSegmentBinderContext> externalTableBinderContexts) {
return bind(sqlStatement, metaData, currentDatabaseName, outerTableBinderContexts, externalTableBinderContexts);
}

/**
* Bind with external table contexts.
*
* @param statement select statement
* @param metaData meta data
* @param currentDatabaseName current database name
* @param externalTableContexts external table contexts
* @return select statement
*/
public SelectStatement bind(final SelectStatement statement, final ShardingSphereMetaData metaData, final String currentDatabaseName,
final Map<String, TableSegmentBinderContext> externalTableContexts) {
return bind(statement, metaData, currentDatabaseName, Collections.emptyMap(), externalTableContexts);
}

@Override
public SelectStatement bind(final SelectStatement sqlStatement, final ShardingSphereMetaData metaData, final String currentDatabaseName) {
return bind(sqlStatement, metaData, currentDatabaseName, Collections.emptyMap(), Collections.emptyMap());
Expand Down Expand Up @@ -77,33 +106,4 @@ private SelectStatement copy(final SelectStatement sqlStatement) {
result.getCommentSegments().addAll(sqlStatement.getCommentSegments());
return result;
}

/**
* Bind correlate subquery select statement.
*
* @param sqlStatement subquery select statement
* @param metaData meta data
* @param currentDatabaseName current database name
* @param outerTableBinderContexts outer select statement table binder contexts
* @param externalTableBinderContexts external table binder contexts
* @return bounded correlate subquery select statement
*/
public SelectStatement bindCorrelateSubquery(final SelectStatement sqlStatement, final ShardingSphereMetaData metaData, final String currentDatabaseName,
final Map<String, TableSegmentBinderContext> outerTableBinderContexts, final Map<String, TableSegmentBinderContext> externalTableBinderContexts) {
return bind(sqlStatement, metaData, currentDatabaseName, outerTableBinderContexts, externalTableBinderContexts);
}

/**
* Bind with external table contexts.
*
* @param statement select statement
* @param metaData meta data
* @param currentDatabaseName current database name
* @param externalTableContexts external table contexts
* @return select statement
*/
public SelectStatement bindWithExternalTableContexts(final SelectStatement statement, final ShardingSphereMetaData metaData, final String currentDatabaseName,
final Map<String, TableSegmentBinderContext> externalTableContexts) {
return bind(statement, metaData, currentDatabaseName, Collections.emptyMap(), externalTableContexts);
}
}

0 comments on commit 1afc200

Please sign in to comment.