You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2026/01/19 13:13:53 UTC
(shardingsphere) branch master updated: Refactor ShardingSphereIdentifier (#37774)
This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 8ebdd20af78 Refactor ShardingSphereIdentifier (#37774)
8ebdd20af78 is described below
commit 8ebdd20af78df750539d6a33350d2956b0a5951b
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Mon Jan 19 21:13:47 2026 +0800
Refactor ShardingSphereIdentifier (#37774)
---
.../identifier/ShardingSphereIdentifier.java | 8 +-
.../identifier/ShardingSphereIdentifierTest.java | 207 +++++++++------------
2 files changed, 90 insertions(+), 125 deletions(-)
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereIdentifier.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereIdentifier.java
index ccd638b6c9d..bc2cc6a94d8 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereIdentifier.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereIdentifier.java
@@ -22,6 +22,8 @@ import lombok.Getter;
import org.apache.shardingsphere.database.connector.core.metadata.database.enums.QuoteCharacter;
import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.DialectDatabaseMetaData;
import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.IdentifierPatternType;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
/**
@@ -42,14 +44,16 @@ public final class ShardingSphereIdentifier {
caseSensitive = false;
}
- public ShardingSphereIdentifier(final String value, final DialectDatabaseMetaData dialectDatabaseMetaData) {
+ public ShardingSphereIdentifier(final String value, final DatabaseType databaseType) {
this.value = new CaseInsensitiveString(value);
+ DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData();
standardizeValue = standardizeValue(value, dialectDatabaseMetaData, false);
caseSensitive = dialectDatabaseMetaData.isCaseSensitive();
}
- public ShardingSphereIdentifier(final IdentifierValue identifierValue, final DialectDatabaseMetaData dialectDatabaseMetaData) {
+ public ShardingSphereIdentifier(final IdentifierValue identifierValue, final DatabaseType databaseType) {
value = new CaseInsensitiveString(identifierValue.getValue());
+ DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData();
standardizeValue = standardizeValue(identifierValue.getValue(), dialectDatabaseMetaData, QuoteCharacter.NONE != identifierValue.getQuoteCharacter());
caseSensitive = dialectDatabaseMetaData.isCaseSensitive();
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereIdentifierTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereIdentifierTest.java
index 1c1492f3c6a..5cd6ab4459f 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereIdentifierTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereIdentifierTest.java
@@ -17,9 +17,8 @@
package org.apache.shardingsphere.infra.metadata.identifier;
-import org.apache.shardingsphere.database.connector.core.metadata.database.enums.QuoteCharacter;
-import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.DialectDatabaseMetaData;
-import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.IdentifierPatternType;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.junit.jupiter.api.Test;
@@ -30,8 +29,6 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
class ShardingSphereIdentifierTest {
@@ -42,20 +39,20 @@ class ShardingSphereIdentifierTest {
}
@Test
- void assertConstructorWithValueAndMetaData() {
- DialectDatabaseMetaData mockMetaData = mockPostgreSQLMetaData();
- assertThat(new ShardingSphereIdentifier("foo", mockMetaData).getValue(), is("foo"));
- assertThat(new ShardingSphereIdentifier("foo", mockMetaData).getStandardizeValue(), is("foo"));
- assertThat(new ShardingSphereIdentifier("FOO", mockMetaData).getStandardizeValue(), is("foo"));
+ void assertConstructorWithValueAndDatabaseType() {
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
+ assertThat(new ShardingSphereIdentifier("foo", postgresql).getValue(), is("foo"));
+ assertThat(new ShardingSphereIdentifier("foo", postgresql).getStandardizeValue(), is("foo"));
+ assertThat(new ShardingSphereIdentifier("FOO", postgresql).getStandardizeValue(), is("foo"));
}
@Test
- void assertConstructorWithIdentifierValue() {
- DialectDatabaseMetaData mockMetaData = mockPostgreSQLMetaData();
- assertThat(new ShardingSphereIdentifier(new IdentifierValue("foo"), mockMetaData).getValue(), is("foo"));
- assertThat(new ShardingSphereIdentifier(new IdentifierValue("FOO"), mockMetaData).getStandardizeValue(), is("foo"));
- assertThat(new ShardingSphereIdentifier(new IdentifierValue("foo", QuoteCharacter.QUOTE), mockMetaData).getStandardizeValue(), is("foo"));
- assertThat(new ShardingSphereIdentifier(new IdentifierValue("FOO", QuoteCharacter.QUOTE), mockMetaData).getStandardizeValue(), is("FOO"));
+ void assertConstructorWithIdentifierValueAndDatabaseType() {
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
+ assertThat(new ShardingSphereIdentifier(new IdentifierValue("foo"), postgresql).getValue(), is("foo"));
+ assertThat(new ShardingSphereIdentifier(new IdentifierValue("FOO"), postgresql).getStandardizeValue(), is("foo"));
+ assertThat(new ShardingSphereIdentifier(new IdentifierValue("\"foo\""), postgresql).getStandardizeValue(), is("foo"));
+ assertThat(new ShardingSphereIdentifier(new IdentifierValue("\"FOO\""), postgresql).getStandardizeValue(), is("FOO"));
}
@Test
@@ -71,58 +68,58 @@ class ShardingSphereIdentifierTest {
}
@Test
- void assertEqualsWithNoDialectMetadata() {
+ void assertEqualsWithNoDatabaseType() {
assertThat(new ShardingSphereIdentifier("foo"), is(new ShardingSphereIdentifier("foo")));
assertThat(new ShardingSphereIdentifier("foo"), is(new ShardingSphereIdentifier("FOO")));
}
@Test
- void assertHashCodeWithNoDialectMetadata() {
+ void assertHashCodeWithNoDatabaseType() {
assertThat(new ShardingSphereIdentifier("foo").hashCode(), is(new ShardingSphereIdentifier("foo").hashCode()));
assertThat(new ShardingSphereIdentifier("foo").hashCode(), is(new ShardingSphereIdentifier("FOO").hashCode()));
}
@Test
void assertToString() {
- DialectDatabaseMetaData mockMetaData = mockPostgreSQLMetaData();
- assertThat(new ShardingSphereIdentifier("foo", mockMetaData).toString(), is("foo"));
- assertThat(new ShardingSphereIdentifier("FOO", mockMetaData).toString(), is("FOO"));
- assertThat(new ShardingSphereIdentifier(new IdentifierValue("foo"), mockMetaData).toString(), is("foo"));
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
+ assertThat(new ShardingSphereIdentifier("foo", postgresql).toString(), is("foo"));
+ assertThat(new ShardingSphereIdentifier("FOO", postgresql).toString(), is("FOO"));
+ assertThat(new ShardingSphereIdentifier(new IdentifierValue("foo"), postgresql).toString(), is("foo"));
}
@Test
- void assertPostgreSQLLowerCaseUnquoted() {
- DialectDatabaseMetaData postgres = mockPostgreSQLMetaData();
+ void assertPostgresSQLLowerCaseUnquoted() {
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
- map.put(new ShardingSphereIdentifier("mytable", postgres), "value1");
- assertThat(map.get(new ShardingSphereIdentifier("MYTABLE", postgres)), is("value1"));
- assertThat(map.get(new ShardingSphereIdentifier("mytable", postgres)), is("value1"));
+ map.put(new ShardingSphereIdentifier("mytable", postgresql), "value1");
+ assertThat(map.get(new ShardingSphereIdentifier("MYTABLE", postgresql)), is("value1"));
+ assertThat(map.get(new ShardingSphereIdentifier("mytable", postgresql)), is("value1"));
}
@Test
- void assertPostgreSQLQuotedCaseSensitive() {
- DialectDatabaseMetaData postgres = mockPostgreSQLMetaData();
+ void assertPostgresSQLQuotedCaseSensitive() {
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
- map.put(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), postgres), "value1");
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), postgres)), is("value1"));
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.NONE), postgres)), is(nullValue()));
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("mytable", QuoteCharacter.NONE), postgres)), is(nullValue()));
+ map.put(new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), postgresql), "value1");
+ assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), postgresql)), is("value1"));
+ assertThat(map.get(new ShardingSphereIdentifier("MyTable", postgresql)), is(nullValue()));
+ assertThat(map.get(new ShardingSphereIdentifier("mytable", postgresql)), is(nullValue()));
}
@Test
- void assertPostgreSQLStandardizeValue() {
- DialectDatabaseMetaData postgres = mockPostgreSQLMetaData();
- ShardingSphereIdentifier unquoted = new ShardingSphereIdentifier("MyTable", postgres);
+ void assertPostgresSQLStandardizeValue() {
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
+ ShardingSphereIdentifier unquoted = new ShardingSphereIdentifier("MyTable", postgresql);
assertThat(unquoted.getValue(), is("MyTable"));
assertThat(unquoted.getStandardizeValue(), is("mytable"));
- ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), postgres);
+ ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), postgresql);
assertThat(quoted.getValue(), is("MyTable"));
assertThat(quoted.getStandardizeValue(), is("MyTable"));
}
@Test
void assertOracleUpperCaseUnquoted() {
- DialectDatabaseMetaData oracle = mockOracleMetaData();
+ DatabaseType oracle = getDatabaseType("Oracle");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
map.put(new ShardingSphereIdentifier("MYTABLE", oracle), "value1");
assertThat(map.get(new ShardingSphereIdentifier("mytable", oracle)), is("value1"));
@@ -130,103 +127,103 @@ class ShardingSphereIdentifierTest {
}
@Test
- void assertOracleQuotedCaseSensitive() {
- DialectDatabaseMetaData oracle = mockOracleMetaData();
+ void assertOracleQuotedCaseInsensitive() {
+ DatabaseType oracle = getDatabaseType("Oracle");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
- map.put(new ShardingSphereIdentifier(new IdentifierValue("MYTABLE", QuoteCharacter.QUOTE), oracle), "value1");
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("MYTABLE", QuoteCharacter.QUOTE), oracle)), is("value1"));
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("mytable", QuoteCharacter.QUOTE), oracle)), is(nullValue()));
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("mytable", QuoteCharacter.NONE), oracle)), is("value1"));
+ map.put(new ShardingSphereIdentifier(new IdentifierValue("\"MYTABLE\""), oracle), "value1");
+ assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("\"MYTABLE\""), oracle)), is("value1"));
+ assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("\"mytable\""), oracle)), is("value1"));
+ assertThat(map.get(new ShardingSphereIdentifier("mytable", oracle)), is("value1"));
}
@Test
void assertOracleStandardizeValue() {
- DialectDatabaseMetaData oracle = mockOracleMetaData();
+ DatabaseType oracle = getDatabaseType("Oracle");
ShardingSphereIdentifier unquoted = new ShardingSphereIdentifier("mytable", oracle);
assertThat(unquoted.getValue(), is("mytable"));
- assertThat(unquoted.getStandardizeValue(), is("MYTABLE"));
- ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("mytable", QuoteCharacter.QUOTE), oracle);
+ assertThat(unquoted.getStandardizeValue(), is("mytable"));
+ ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("\"mytable\""), oracle);
assertThat(quoted.getValue(), is("mytable"));
assertThat(quoted.getStandardizeValue(), is("mytable"));
}
@Test
void assertClickHouseKeepOriginUnquoted() {
- DialectDatabaseMetaData clickhouse = mockClickHouseMetaData();
+ DatabaseType clickhouse = getDatabaseType("ClickHouse");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
map.put(new ShardingSphereIdentifier("MyTable", clickhouse), "value1");
assertThat(map.get(new ShardingSphereIdentifier("MyTable", clickhouse)), is("value1"));
- assertThat(map.get(new ShardingSphereIdentifier("mytable", clickhouse)), is(nullValue()));
+ assertThat(map.get(new ShardingSphereIdentifier("mytable", clickhouse)), is("value1"));
}
@Test
void assertClickHouseQuotedCaseSensitive() {
- DialectDatabaseMetaData clickhouse = mockClickHouseMetaData();
+ DatabaseType clickhouse = getDatabaseType("ClickHouse");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
- map.put(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), clickhouse), "value1");
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), clickhouse)), is("value1"));
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("mytable", QuoteCharacter.QUOTE), clickhouse)), is(nullValue()));
+ map.put(new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), clickhouse), "value1");
+ assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), clickhouse)), is("value1"));
+ assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("\"mytable\""), clickhouse)), is("value1"));
}
@Test
void assertClickHouseStandardizeValue() {
- DialectDatabaseMetaData clickhouse = mockClickHouseMetaData();
+ DatabaseType clickhouse = getDatabaseType("ClickHouse");
ShardingSphereIdentifier unquoted = new ShardingSphereIdentifier("MyTable", clickhouse);
assertThat(unquoted.getValue(), is("MyTable"));
assertThat(unquoted.getStandardizeValue(), is("MyTable"));
- ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), clickhouse);
+ ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), clickhouse);
assertThat(quoted.getValue(), is("MyTable"));
assertThat(quoted.getStandardizeValue(), is("MyTable"));
}
@Test
void assertHashCodeWithCaseSensitive() {
- DialectDatabaseMetaData postgres = mockPostgreSQLMetaData();
- ShardingSphereIdentifier quoted1 = new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), postgres);
- ShardingSphereIdentifier quoted2 = new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), postgres);
- ShardingSphereIdentifier quoted3 = new ShardingSphereIdentifier(new IdentifierValue("mytable", QuoteCharacter.QUOTE), postgres);
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
+ ShardingSphereIdentifier quoted1 = new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), postgresql);
+ ShardingSphereIdentifier quoted2 = new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), postgresql);
+ ShardingSphereIdentifier quoted3 = new ShardingSphereIdentifier(new IdentifierValue("\"mytable\""), postgresql);
assertThat(quoted1.hashCode(), is(quoted2.hashCode()));
assertThat(quoted1.hashCode(), not(quoted3.hashCode()));
}
@Test
void assertNullValue() {
- DialectDatabaseMetaData postgres = mockPostgreSQLMetaData();
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
ShardingSphereIdentifier nullIdentifier = new ShardingSphereIdentifier((String) null);
assertThat(nullIdentifier.getValue(), is(nullValue()));
assertThat(nullIdentifier.getStandardizeValue(), is(nullValue()));
- ShardingSphereIdentifier nullIdentifierWithMetaData = new ShardingSphereIdentifier(new IdentifierValue((String) null), postgres);
- assertThat(nullIdentifierWithMetaData.getValue(), is(nullValue()));
- assertThat(nullIdentifierWithMetaData.getStandardizeValue(), is(nullValue()));
+ ShardingSphereIdentifier nullIdentifierWithDatabaseType = new ShardingSphereIdentifier(new IdentifierValue((String) null), postgresql);
+ assertThat(nullIdentifierWithDatabaseType.getValue(), is(nullValue()));
+ assertThat(nullIdentifierWithDatabaseType.getStandardizeValue(), is(nullValue()));
}
@Test
void assertEqualsWithNullValues() {
- DialectDatabaseMetaData postgres = mockPostgreSQLMetaData();
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
ShardingSphereIdentifier null1 = new ShardingSphereIdentifier((String) null);
ShardingSphereIdentifier null2 = new ShardingSphereIdentifier((String) null);
assertThat(null1, is(null2));
assertThat(null1.hashCode(), is(null2.hashCode()));
- ShardingSphereIdentifier null3 = new ShardingSphereIdentifier(new IdentifierValue((String) null), postgres);
- ShardingSphereIdentifier null4 = new ShardingSphereIdentifier(new IdentifierValue((String) null), postgres);
+ ShardingSphereIdentifier null3 = new ShardingSphereIdentifier(new IdentifierValue((String) null), postgresql);
+ ShardingSphereIdentifier null4 = new ShardingSphereIdentifier(new IdentifierValue((String) null), postgresql);
assertThat(null3, is(null4));
assertThat(null3.hashCode(), is(null4.hashCode()));
}
@Test
void assertNotEqualsWithOneNullValue() {
- DialectDatabaseMetaData postgres = mockPostgreSQLMetaData();
+ DatabaseType postgresql = getDatabaseType("PostgreSQL");
ShardingSphereIdentifier nullIdentifier = new ShardingSphereIdentifier((String) null);
ShardingSphereIdentifier nonNullIdentifier = new ShardingSphereIdentifier("foo");
assertThat(nullIdentifier, not(nonNullIdentifier));
- ShardingSphereIdentifier nullIdentifierWithMeta = new ShardingSphereIdentifier(new IdentifierValue((String) null), postgres);
- ShardingSphereIdentifier nonNullIdentifierWithMeta = new ShardingSphereIdentifier("foo", postgres);
- assertThat(nullIdentifierWithMeta, not(nonNullIdentifierWithMeta));
+ ShardingSphereIdentifier nullIdentifierWithDatabaseType = new ShardingSphereIdentifier(new IdentifierValue((String) null), postgresql);
+ ShardingSphereIdentifier nonNullIdentifierWithDatabaseType = new ShardingSphereIdentifier("foo", postgresql);
+ assertThat(nullIdentifierWithDatabaseType, not(nonNullIdentifierWithDatabaseType));
}
@Test
void assertMySQLKeepOriginUnquoted() {
- DialectDatabaseMetaData mysql = mockMySQLMetaData();
+ DatabaseType mysql = getDatabaseType("MySQL");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
map.put(new ShardingSphereIdentifier("MyTable", mysql), "value1");
assertThat(map.get(new ShardingSphereIdentifier("MyTable", mysql)), is("value1"));
@@ -235,27 +232,27 @@ class ShardingSphereIdentifierTest {
@Test
void assertMySQLQuotedCaseSensitive() {
- DialectDatabaseMetaData mysql = mockMySQLMetaData();
+ DatabaseType mysql = getDatabaseType("MySQL");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
- map.put(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.BACK_QUOTE), mysql), "value1");
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.BACK_QUOTE), mysql)), is("value1"));
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("mytable", QuoteCharacter.BACK_QUOTE), mysql)), is("value1"));
+ map.put(new ShardingSphereIdentifier(new IdentifierValue("`MyTable`"), mysql), "value1");
+ assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("`MyTable`"), mysql)), is("value1"));
+ assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("`mytable`"), mysql)), is("value1"));
}
@Test
void assertMySQLStandardizeValue() {
- DialectDatabaseMetaData mysql = mockMySQLMetaData();
+ DatabaseType mysql = getDatabaseType("MySQL");
ShardingSphereIdentifier unquoted = new ShardingSphereIdentifier("MyTable", mysql);
assertThat(unquoted.getValue(), is("MyTable"));
assertThat(unquoted.getStandardizeValue(), is("MyTable"));
- ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.BACK_QUOTE), mysql);
+ ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("`MyTable`"), mysql);
assertThat(quoted.getValue(), is("MyTable"));
assertThat(quoted.getStandardizeValue(), is("MyTable"));
}
@Test
void assertOpenGaussLowerCaseUnquoted() {
- DialectDatabaseMetaData opengauss = mockOpenGaussMetaData();
+ DatabaseType opengauss = getDatabaseType("openGauss");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
map.put(new ShardingSphereIdentifier("mytable", opengauss), "value1");
assertThat(map.get(new ShardingSphereIdentifier("MYTABLE", opengauss)), is("value1"));
@@ -264,62 +261,26 @@ class ShardingSphereIdentifierTest {
@Test
void assertOpenGaussQuotedCaseSensitive() {
- DialectDatabaseMetaData opengauss = mockOpenGaussMetaData();
+ DatabaseType opengauss = getDatabaseType("openGauss");
Map<ShardingSphereIdentifier, String> map = new HashMap<>();
- map.put(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), opengauss), "value1");
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), opengauss)), is("value1"));
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.NONE), opengauss)), is(nullValue()));
- assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("mytable", QuoteCharacter.NONE), opengauss)), is(nullValue()));
+ map.put(new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), opengauss), "value1");
+ assertThat(map.get(new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), opengauss)), is("value1"));
+ assertThat(map.get(new ShardingSphereIdentifier("MyTable", opengauss)), is(nullValue()));
+ assertThat(map.get(new ShardingSphereIdentifier("mytable", opengauss)), is(nullValue()));
}
@Test
void assertOpenGaussStandardizeValue() {
- DialectDatabaseMetaData opengauss = mockOpenGaussMetaData();
+ DatabaseType opengauss = getDatabaseType("openGauss");
ShardingSphereIdentifier unquoted = new ShardingSphereIdentifier("MyTable", opengauss);
assertThat(unquoted.getValue(), is("MyTable"));
assertThat(unquoted.getStandardizeValue(), is("mytable"));
- ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("MyTable", QuoteCharacter.QUOTE), opengauss);
+ ShardingSphereIdentifier quoted = new ShardingSphereIdentifier(new IdentifierValue("\"MyTable\""), opengauss);
assertThat(quoted.getValue(), is("MyTable"));
assertThat(quoted.getStandardizeValue(), is("MyTable"));
}
- private DialectDatabaseMetaData mockPostgreSQLMetaData() {
- DialectDatabaseMetaData result = mock(DialectDatabaseMetaData.class);
- when(result.getQuoteCharacter()).thenReturn(QuoteCharacter.QUOTE);
- when(result.getIdentifierPatternType()).thenReturn(IdentifierPatternType.LOWER_CASE);
- when(result.isCaseSensitive()).thenReturn(true);
- return result;
- }
-
- private DialectDatabaseMetaData mockOracleMetaData() {
- DialectDatabaseMetaData result = mock(DialectDatabaseMetaData.class);
- when(result.getQuoteCharacter()).thenReturn(QuoteCharacter.QUOTE);
- when(result.getIdentifierPatternType()).thenReturn(IdentifierPatternType.UPPER_CASE);
- when(result.isCaseSensitive()).thenReturn(true);
- return result;
- }
-
- private DialectDatabaseMetaData mockClickHouseMetaData() {
- DialectDatabaseMetaData result = mock(DialectDatabaseMetaData.class);
- when(result.getQuoteCharacter()).thenReturn(QuoteCharacter.QUOTE);
- when(result.getIdentifierPatternType()).thenReturn(IdentifierPatternType.KEEP_ORIGIN);
- when(result.isCaseSensitive()).thenReturn(true);
- return result;
- }
-
- private DialectDatabaseMetaData mockMySQLMetaData() {
- DialectDatabaseMetaData result = mock(DialectDatabaseMetaData.class);
- when(result.getQuoteCharacter()).thenReturn(QuoteCharacter.BACK_QUOTE);
- when(result.getIdentifierPatternType()).thenReturn(IdentifierPatternType.KEEP_ORIGIN);
- when(result.isCaseSensitive()).thenReturn(false);
- return result;
- }
-
- private DialectDatabaseMetaData mockOpenGaussMetaData() {
- DialectDatabaseMetaData result = mock(DialectDatabaseMetaData.class);
- when(result.getQuoteCharacter()).thenReturn(QuoteCharacter.QUOTE);
- when(result.getIdentifierPatternType()).thenReturn(IdentifierPatternType.LOWER_CASE);
- when(result.isCaseSensitive()).thenReturn(true);
- return result;
+ private DatabaseType getDatabaseType(final String databaseTypeName) {
+ return TypedSPILoader.getService(DatabaseType.class, databaseTypeName);
}
}