Skip to content

Commit

Permalink
Revise javadoc on extractors (#33763)
Browse files Browse the repository at this point in the history
* Revise javadoc on extractors

* Revise javadoc on extractors
  • Loading branch information
terrymanu authored Nov 21, 2024
1 parent 03f22b1 commit 2efaab8
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void check(final EncryptRule rule, final ShardingSphereSchema schema, fi

private boolean includesLike(final Collection<WhereSegment> whereSegments, final ColumnSegment targetColumnSegment) {
for (WhereSegment each : whereSegments) {
Collection<AndPredicate> andPredicates = ExpressionExtractor.getAndPredicates(each.getExpr());
Collection<AndPredicate> andPredicates = ExpressionExtractor.extractAndPredicates(each.getExpr());
for (AndPredicate andPredicate : andPredicates) {
if (isLikeColumnSegment(andPredicate, targetColumnSegment)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Collection<EncryptCondition> createEncryptConditions(final Collection<Whe
ShardingSphereSchema schema = ((TableAvailable) sqlStatementContext).getTablesContext().getSchemaName().map(schemas::get).orElseGet(() -> schemas.get(defaultSchema));
Map<String, String> expressionTableNames = ((TableAvailable) sqlStatementContext).getTablesContext().findTableNames(columnSegments, schema);
for (WhereSegment each : whereSegments) {
Collection<AndPredicate> andPredicates = ExpressionExtractor.getAndPredicates(each.getExpr());
Collection<AndPredicate> andPredicates = ExpressionExtractor.extractAndPredicates(each.getExpr());
for (AndPredicate predicate : andPredicates) {
addEncryptConditions(result, predicate.getPredicates(), expressionTableNames);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private SubstitutableColumnNameToken buildSubstitutableColumnNameToken(final Enc

private boolean includesLike(final Collection<WhereSegment> whereSegments, final ColumnSegment targetColumnSegment) {
for (WhereSegment each : whereSegments) {
Collection<AndPredicate> andPredicates = ExpressionExtractor.getAndPredicates(each.getExpr());
Collection<AndPredicate> andPredicates = ExpressionExtractor.extractAndPredicates(each.getExpr());
for (AndPredicate andPredicate : andPredicates) {
if (isLikeColumnSegment(andPredicate, targetColumnSegment)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected Collection<ShadowColumnCondition> getShadowColumnConditions(final Stri
private Collection<ExpressionSegment> getWhereSegment() {
Collection<ExpressionSegment> result = new LinkedList<>();
for (WhereSegment each : sqlStatementContext.getWhereSegments()) {
for (AndPredicate predicate : ExpressionExtractor.getAndPredicates(each.getExpr())) {
for (AndPredicate predicate : ExpressionExtractor.extractAndPredicates(each.getExpr())) {
result.addAll(predicate.getPredicates());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected Collection<ShadowColumnCondition> getShadowColumnConditions(final Stri
private Collection<ExpressionSegment> getWhereSegment() {
Collection<ExpressionSegment> result = new LinkedList<>();
for (WhereSegment each : sqlStatementContext.getWhereSegments()) {
for (AndPredicate predicate : ExpressionExtractor.getAndPredicates(each.getExpr())) {
for (AndPredicate predicate : ExpressionExtractor.extractAndPredicates(each.getExpr())) {
result.addAll(predicate.getPredicates());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected Collection<ShadowColumnCondition> getShadowColumnConditions(final Stri
private Collection<ExpressionSegment> getWhereSegment() {
Collection<ExpressionSegment> result = new LinkedList<>();
for (WhereSegment each : sqlStatementContext.getWhereSegments()) {
for (AndPredicate predicate : ExpressionExtractor.getAndPredicates(each.getExpr())) {
for (AndPredicate predicate : ExpressionExtractor.extractAndPredicates(each.getExpr())) {
result.addAll(predicate.getPredicates());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public List<ShardingCondition> createShardingConditions(final SQLStatementContex
}

private Collection<ShardingCondition> createShardingConditions(final ExpressionSegment expression, final List<Object> params, final Map<String, String> columnExpressionTableNames) {
Collection<AndPredicate> andPredicates = ExpressionExtractor.getAndPredicates(expression);
Collection<AndPredicate> andPredicates = ExpressionExtractor.extractAndPredicates(expression);
Collection<ShardingCondition> result = new LinkedList<>();
for (AndPredicate each : andPredicates) {
Map<Column, Collection<ShardingConditionValue>> shardingConditionValues = createShardingConditionValueMap(each.getPredicates(), params, columnExpressionTableNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ private boolean isJoinConditionContainsShardingColumns(final ShardingSphereSchem
Collection<String> databaseJoinConditionTables = new HashSet<>(tableNames.size(), 1F);
Collection<String> tableJoinConditionTables = new HashSet<>(tableNames.size(), 1F);
for (WhereSegment each : whereSegments) {
Collection<AndPredicate> andPredicates = ExpressionExtractor.getAndPredicates(each.getExpr());
Collection<AndPredicate> andPredicates = ExpressionExtractor.extractAndPredicates(each.getExpr());
if (andPredicates.size() > 1) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public PaginationContext createPaginationContext(final Collection<ExpressionSegm
if (!rowNumberAlias.isPresent()) {
return new PaginationContext(null, null, params);
}
Collection<AndPredicate> andPredicates = expressions.stream().flatMap(each -> ExpressionExtractor.getAndPredicates(each).stream()).collect(Collectors.toList());
Collection<AndPredicate> andPredicates = expressions.stream().flatMap(each -> ExpressionExtractor.extractAndPredicates(each).stream()).collect(Collectors.toList());
Collection<BinaryOperationExpression> rowNumberPredicates = getRowNumberPredicates(andPredicates, rowNumberAlias.get());
return rowNumberPredicates.isEmpty() ? new PaginationContext(null, null, params) : createPaginationWithRowNumber(rowNumberPredicates, params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class TopPaginationContextEngine {
* @return pagination context
*/
public PaginationContext createPaginationContext(final TopProjectionSegment topProjectionSegment, final Collection<ExpressionSegment> expressions, final List<Object> params) {
Collection<AndPredicate> andPredicates = expressions.stream().flatMap(each -> ExpressionExtractor.getAndPredicates(each).stream()).collect(Collectors.toList());
Collection<AndPredicate> andPredicates = expressions.stream().flatMap(each -> ExpressionExtractor.extractAndPredicates(each).stream()).collect(Collectors.toList());
Optional<ExpressionSegment> rowNumberPredicate = expressions.isEmpty() ? Optional.empty() : getRowNumberPredicate(andPredicates, topProjectionSegment.getAlias());
Optional<PaginationValueSegment> offset = rowNumberPredicate.isPresent() ? createOffsetWithRowNumber(rowNumberPredicate.get()) : Optional.empty();
PaginationValueSegment rowCount = topProjectionSegment.getTop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public SelectStatementContext(final ShardingSphereMetaData metaData, final List<

private void extractWhereSegments(final Collection<WhereSegment> whereSegments, final SelectStatement selectStatement) {
selectStatement.getWhere().ifPresent(whereSegments::add);
whereSegments.addAll(WhereExtractor.getSubqueryWhereSegments(selectStatement));
whereSegments.addAll(WhereExtractor.getJoinWhereSegments(selectStatement));
whereSegments.addAll(WhereExtractor.extractSubqueryWhereSegments(selectStatement));
whereSegments.addAll(WhereExtractor.extractJoinWhereSegments(selectStatement));
}

private Collection<TableSegment> getAllTableSegments(final Collection<TableSegment> inheritedTables) {
Expand Down Expand Up @@ -187,7 +187,7 @@ private Collection<TableMapperRuleAttribute> getTableMapperRuleAttributes(final

private Map<Integer, SelectStatementContext> createSubqueryContexts(final ShardingSphereMetaData metaData, final List<Object> params, final String currentDatabaseName,
final Collection<TableSegment> tableSegments) {
Collection<SubquerySegment> subquerySegments = SubqueryExtractor.getSubquerySegments(getSqlStatement(), false);
Collection<SubquerySegment> subquerySegments = SubqueryExtractor.extractSubquerySegments(getSqlStatement(), false);
Map<Integer, SelectStatementContext> result = new HashMap<>(subquerySegments.size(), 1F);
for (SubquerySegment each : subquerySegments) {
SelectStatementContext subqueryContext = new SelectStatementContext(metaData, params, each.getSelect(), currentDatabaseName, tableSegments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
public final class ColumnExtractor {

/**
* Extract column segment collection.
* Extract column segments from expression segment.
*
* @param expression expression segment
* @return column segment collection
* @param expression to be extracted expression segment
* @return column segments
*/
public static Collection<ColumnSegment> extract(final ExpressionSegment expression) {
Collection<ColumnSegment> result = new LinkedList<>();
Expand Down Expand Up @@ -95,7 +95,7 @@ public static Collection<ColumnSegment> extract(final ExpressionSegment expressi
*/
public static void extractColumnSegments(final Collection<ColumnSegment> columnSegments, final Collection<WhereSegment> whereSegments) {
for (WhereSegment each : whereSegments) {
for (AndPredicate andPredicate : ExpressionExtractor.getAndPredicates(each.getExpr())) {
for (AndPredicate andPredicate : ExpressionExtractor.extractAndPredicates(each.getExpr())) {
extractColumnSegments(columnSegments, andPredicate);
}
}
Expand All @@ -112,7 +112,7 @@ private static void extractColumnSegments(final Collection<ColumnSegment> column
*
* @param columnSegments column segments
* @param statement select statement
* @param containsSubQuery whether contains sub query
* @param containsSubQuery whether contains subquery
*/
public static void extractFromSelectStatement(final Collection<ColumnSegment> columnSegments, final SelectStatement statement, final boolean containsSubQuery) {
extractFromProjections(columnSegments, statement.getProjections().getProjections(), containsSubQuery);
Expand All @@ -124,7 +124,7 @@ public static void extractFromSelectStatement(final Collection<ColumnSegment> co
*
* @param columnSegments column segments
* @param statement select statement
* @param containsSubQuery whether contains sub query
* @param containsSubQuery whether contains subquery
*/
public static void extractFromSelectStatementWithoutProjection(final Collection<ColumnSegment> columnSegments, final SelectStatement statement, final boolean containsSubQuery) {
statement.getFrom().ifPresent(optional -> extractFromTable(columnSegments, optional, containsSubQuery));
Expand All @@ -141,7 +141,7 @@ public static void extractFromSelectStatementWithoutProjection(final Collection<
*
* @param columnSegments column segments
* @param projections projection segments
* @param containsSubQuery contains sub query
* @param containsSubQuery contains subquery
*/
public static void extractFromProjections(final Collection<ColumnSegment> columnSegments, final Collection<ProjectionSegment> projections, final boolean containsSubQuery) {
for (ProjectionSegment each : projections) {
Expand Down Expand Up @@ -195,7 +195,7 @@ private static void extractFromTable(final Collection<ColumnSegment> columnSegme
*
* @param columnSegments column segments
* @param whereSegment where segment
* @param containsSubQuery contains sub query
* @param containsSubQuery contains subquery
*/
public static void extractFromWhere(final Collection<ColumnSegment> columnSegments, final WhereSegment whereSegment, final boolean containsSubQuery) {
columnSegments.addAll(ExpressionExtractor.extractColumns(whereSegment.getExpr(), containsSubQuery));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@
public final class ExpressionExtractor {

/**
* Get and predicate collection.
* Extract and predicates.
*
* @param expression expression segment
* @return and predicate collection
* @param expression to be extracted expression segment
* @return and predicates
*/
public static Collection<AndPredicate> getAndPredicates(final ExpressionSegment expression) {
public static Collection<AndPredicate> extractAndPredicates(final ExpressionSegment expression) {
Collection<AndPredicate> result = new LinkedList<>();
extractAndPredicates(result, expression);
return result;
Expand All @@ -81,8 +81,8 @@ private static void extractAndPredicates(final Collection<AndPredicate> result,
extractAndPredicates(result, binaryExpression.getLeft());
extractAndPredicates(result, binaryExpression.getRight());
} else if (logicalOperator.isPresent() && LogicalOperator.AND == logicalOperator.get()) {
Collection<AndPredicate> predicates = getAndPredicates(binaryExpression.getRight());
for (AndPredicate each : getAndPredicates(binaryExpression.getLeft())) {
Collection<AndPredicate> predicates = extractAndPredicates(binaryExpression.getRight());
for (AndPredicate each : extractAndPredicates(binaryExpression.getLeft())) {
extractCombinedAndPredicates(result, each, predicates);
}
} else {
Expand All @@ -106,10 +106,10 @@ private static AndPredicate createAndPredicate(final ExpressionSegment expressio
}

/**
* Get parameter marker expression collection.
* Get parameter marker expressions.
*
* @param expressions expression collection
* @return parameter marker expression collection
* @param expressions expressions
* @return parameter marker expressions
*/
public static List<ParameterMarkerExpressionSegment> getParameterMarkerExpressions(final Collection<ExpressionSegment> expressions) {
List<ParameterMarkerExpressionSegment> result = new ArrayList<>();
Expand Down Expand Up @@ -155,11 +155,11 @@ public static void extractJoinConditions(final Collection<BinaryOperationExpress
}

/**
* Extract columns.
* Extract column segments.
*
* @param expression expression
* @param containsSubQuery contains sub query or not
* @return columns
* @param expression expression segment
* @param containsSubQuery contains subquery or not
* @return extracted column segments
*/
public static Collection<ColumnSegment> extractColumns(final ExpressionSegment expression, final boolean containsSubQuery) {
if (expression instanceof ColumnSegment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
public final class SubqueryExtractor {

/**
* Get subquery segment from SelectStatement.
* Extract subquery segment from select statement.
*
* @param selectStatement SelectStatement
* @param selectStatement select statement
* @param needRecursive need recursive
* @return subquery segment collection
* @return subquery segments
*/
public static Collection<SubquerySegment> getSubquerySegments(final SelectStatement selectStatement, final boolean needRecursive) {
public static Collection<SubquerySegment> extractSubquerySegments(final SelectStatement selectStatement, final boolean needRecursive) {
List<SubquerySegment> result = new LinkedList<>();
SubqueryType parentSubqueryType = selectStatement.getSubqueryType().orElse(null);
extractSubquerySegments(result, selectStatement, needRecursive, parentSubqueryType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@
public final class WhereExtractor {

/**
* Get join where segment from SelectStatement.
* Extract join where segment from select statement.
*
* @param selectStatement SelectStatement
* @return join where segment collection
* @param selectStatement to be extracted select statement
* @return extracted join where segments
*/
public static Collection<WhereSegment> getJoinWhereSegments(final SelectStatement selectStatement) {
return selectStatement.getFrom().map(WhereExtractor::getJoinWhereSegments).orElseGet(Collections::emptyList);
public static Collection<WhereSegment> extractJoinWhereSegments(final SelectStatement selectStatement) {
return selectStatement.getFrom().map(WhereExtractor::extractJoinWhereSegments).orElseGet(Collections::emptyList);
}

private static Collection<WhereSegment> getJoinWhereSegments(final TableSegment tableSegment) {
private static Collection<WhereSegment> extractJoinWhereSegments(final TableSegment tableSegment) {
if (!(tableSegment instanceof JoinTableSegment) || null == ((JoinTableSegment) tableSegment).getCondition()) {
return Collections.emptyList();
}
JoinTableSegment joinTableSegment = (JoinTableSegment) tableSegment;
Collection<WhereSegment> result = new LinkedList<>();
result.add(generateWhereSegment(joinTableSegment));
result.addAll(getJoinWhereSegments(joinTableSegment.getLeft()));
result.addAll(getJoinWhereSegments(joinTableSegment.getRight()));
result.addAll(extractJoinWhereSegments(joinTableSegment.getLeft()));
result.addAll(extractJoinWhereSegments(joinTableSegment.getRight()));
return result;
}

Expand All @@ -64,16 +64,16 @@ private static WhereSegment generateWhereSegment(final JoinTableSegment joinTabl
}

/**
* Get subquery where segment from SelectStatement.
* Extract subquery where segment from SelectStatement.
*
* @param selectStatement SelectStatement
* @return subquery where segment collection
* @param selectStatement to be extracted select statement
* @return extracted subquery where segments
*/
public static Collection<WhereSegment> getSubqueryWhereSegments(final SelectStatement selectStatement) {
public static Collection<WhereSegment> extractSubqueryWhereSegments(final SelectStatement selectStatement) {
Collection<WhereSegment> result = new LinkedList<>();
for (SubquerySegment each : SubqueryExtractor.getSubquerySegments(selectStatement, false)) {
for (SubquerySegment each : SubqueryExtractor.extractSubquerySegments(selectStatement, false)) {
each.getSelect().getWhere().ifPresent(result::add);
result.addAll(getJoinWhereSegments(each.getSelect()));
result.addAll(extractJoinWhereSegments(each.getSelect()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ public static String trimSemicolon(final String sql) {
/**
* Trim the comment of SQL.
*
* @param sql SQL to be trim
* @return remove comment from SQL
* @param sql to be trimmed SQL
* @return trimmed SQL
*/
public static String trimComment(final String sql) {
String result = sql;
Expand Down
Loading

0 comments on commit 2efaab8

Please sign in to comment.