This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new fc1d72f5815 Refactor PaginationContextEngineTest to use dynamic 
DatabaseType retrieval (#35288)
fc1d72f5815 is described below

commit fc1d72f5815e7bed79cd203663a7a8b7e16aad12
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Mon Apr 28 23:42:55 2025 +0800

    Refactor PaginationContextEngineTest to use dynamic DatabaseType retrieval 
(#35288)
---
 .../engine/PaginationContextEngineTest.java        | 24 ++++++++++++----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/engine/PaginationContextEngineTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/engine/PaginationContextEngineTest.java
index a83efc324db..a2930093152 100644
--- 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/engine/PaginationContextEngineTest.java
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/engine/PaginationContextEngineTest.java
@@ -19,10 +19,8 @@ package 
org.apache.shardingsphere.infra.binder.context.segment.select.pagination
 
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.pagination.PaginationContext;
 import 
org.apache.shardingsphere.infra.binder.context.segment.select.projection.ProjectionsContext;
-import org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType;
-import 
org.apache.shardingsphere.infra.database.postgresql.type.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.infra.database.sql92.type.SQL92DatabaseType;
-import 
org.apache.shardingsphere.infra.database.sqlserver.type.SQLServerDatabaseType;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.SubqueryProjectionSegment;
@@ -53,7 +51,7 @@ class PaginationContextEngineTest {
         MySQLSelectStatement selectStatement = new MySQLSelectStatement();
         selectStatement.setLimit(new LimitSegment(0, 10, new 
NumberLiteralLimitValueSegment(0, 10, 100L),
                 new NumberLiteralLimitValueSegment(0, 10, 100L)));
-        PaginationContext paginationContext = new PaginationContextEngine(new 
MySQLDatabaseType()).createPaginationContext(
+        PaginationContext paginationContext = new 
PaginationContextEngine(getDatabaseType("MySQL")).createPaginationContext(
                 selectStatement, mock(ProjectionsContext.class), 
Collections.emptyList(), Collections.emptyList());
         assertTrue(paginationContext.getOffsetSegment().isPresent());
         assertTrue(paginationContext.getRowCountSegment().isPresent());
@@ -64,7 +62,7 @@ class PaginationContextEngineTest {
         PostgreSQLSelectStatement selectStatement = new 
PostgreSQLSelectStatement();
         selectStatement.setLimit(new LimitSegment(0, 10, new 
NumberLiteralLimitValueSegment(0, 10, 100L),
                 new NumberLiteralLimitValueSegment(0, 10, 100L)));
-        PaginationContext paginationContext = new PaginationContextEngine(new 
PostgreSQLDatabaseType()).createPaginationContext(
+        PaginationContext paginationContext = new 
PaginationContextEngine(getDatabaseType("PostgreSQL")).createPaginationContext(
                 selectStatement, mock(ProjectionsContext.class), 
Collections.emptyList(), Collections.emptyList());
         assertTrue(paginationContext.getOffsetSegment().isPresent());
         assertTrue(paginationContext.getRowCountSegment().isPresent());
@@ -75,7 +73,7 @@ class PaginationContextEngineTest {
         SQL92SelectStatement selectStatement = new SQL92SelectStatement();
         selectStatement.setLimit(new LimitSegment(0, 10, new 
NumberLiteralLimitValueSegment(0, 10, 100L),
                 new NumberLiteralLimitValueSegment(0, 10, 100L)));
-        PaginationContext paginationContext = new PaginationContextEngine(new 
SQL92DatabaseType()).createPaginationContext(
+        PaginationContext paginationContext = new 
PaginationContextEngine(getDatabaseType("SQL92")).createPaginationContext(
                 selectStatement, mock(ProjectionsContext.class), 
Collections.emptyList(), Collections.emptyList());
         assertTrue(paginationContext.getOffsetSegment().isPresent());
         assertTrue(paginationContext.getRowCountSegment().isPresent());
@@ -86,7 +84,7 @@ class PaginationContextEngineTest {
         SQLServerSelectStatement selectStatement = new 
SQLServerSelectStatement();
         selectStatement.setLimit(new LimitSegment(0, 10, new 
NumberLiteralLimitValueSegment(0, 10, 100L),
                 new NumberLiteralLimitValueSegment(0, 10, 100L)));
-        PaginationContext paginationContext = new PaginationContextEngine(new 
SQLServerDatabaseType()).createPaginationContext(
+        PaginationContext paginationContext = new 
PaginationContextEngine(getDatabaseType("SQLServer")).createPaginationContext(
                 selectStatement, mock(ProjectionsContext.class), 
Collections.emptyList(), Collections.emptyList());
         assertTrue(paginationContext.getOffsetSegment().isPresent());
         assertTrue(paginationContext.getRowCountSegment().isPresent());
@@ -100,7 +98,7 @@ class PaginationContextEngineTest {
         SQLServerSelectStatement selectStatement = new 
SQLServerSelectStatement();
         selectStatement.setProjections(new ProjectionsSegment(0, 0));
         selectStatement.getProjections().getProjections().add(new 
SubqueryProjectionSegment(new SubquerySegment(0, 0, subquerySelectStatement, 
""), ""));
-        PaginationContext paginationContext = new PaginationContextEngine(new 
SQLServerDatabaseType()).createPaginationContext(
+        PaginationContext paginationContext = new 
PaginationContextEngine(getDatabaseType("SQLServer")).createPaginationContext(
                 selectStatement, mock(ProjectionsContext.class), 
Collections.emptyList(), Collections.emptyList());
         assertFalse(paginationContext.getOffsetSegment().isPresent());
         assertFalse(paginationContext.getRowCountSegment().isPresent());
@@ -113,7 +111,7 @@ class PaginationContextEngineTest {
         WhereSegment where = new WhereSegment(0, 10, null);
         selectStatement.setWhere(where);
         ProjectionsContext projectionsContext = new ProjectionsContext(0, 0, 
false, Collections.emptyList());
-        PaginationContext paginationContext = new PaginationContextEngine(new 
SQLServerDatabaseType()).createPaginationContext(
+        PaginationContext paginationContext = new 
PaginationContextEngine(getDatabaseType("SQLServer")).createPaginationContext(
                 selectStatement, projectionsContext, Collections.emptyList(), 
Collections.singletonList(where));
         assertFalse(paginationContext.getOffsetSegment().isPresent());
         assertFalse(paginationContext.getRowCountSegment().isPresent());
@@ -147,7 +145,11 @@ class PaginationContextEngineTest {
     private void 
assertCreatePaginationContextWhenResultIsPaginationContext(final 
SelectStatement selectStatement) {
         selectStatement.setProjections(new ProjectionsSegment(0, 0));
         ProjectionsContext projectionsContext = new ProjectionsContext(0, 0, 
false, Collections.emptyList());
-        assertThat(new PaginationContextEngine(new 
MySQLDatabaseType()).createPaginationContext(
+        assertThat(new 
PaginationContextEngine(getDatabaseType("MySQL")).createPaginationContext(
                 selectStatement, projectionsContext, Collections.emptyList(), 
Collections.emptyList()), instanceOf(PaginationContext.class));
     }
+    
+    private DatabaseType getDatabaseType(final String databaseType) {
+        return TypedSPILoader.getService(DatabaseType.class, databaseType);
+    }
 }

Reply via email to