-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ShardingSphereMetaDataIdentifier and try to use in ShardingSphere…
…Table.columns (#33776) * Add ShardingSphereMetaDataIdentifier and try to use in ShardingSphereTable.columns * Add ShardingSphereMetaDataIdentifier and try to use in ShardingSphereTable.columns
- Loading branch information
Showing
6 changed files
with
128 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...he/shardingsphere/infra/metadata/identifier/DatabaseDialectMetaDataIdentifierHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.metadata.identifier; | ||
|
||
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI; | ||
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; | ||
|
||
/** | ||
* Database dialect meta data identifier handler. | ||
*/ | ||
@SingletonSPI | ||
public interface DatabaseDialectMetaDataIdentifierHandler extends DatabaseTypedSPI { | ||
|
||
/** | ||
* Whether identifier is case-sensitive. | ||
* | ||
* @return is case-sensitive or insensitive | ||
*/ | ||
boolean isCaseSensitive(); | ||
} |
78 changes: 78 additions & 0 deletions
78
...org/apache/shardingsphere/infra/metadata/identifier/ShardingSphereMetaDataIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.metadata.identifier; | ||
|
||
import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; | ||
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; | ||
import org.apache.shardingsphere.infra.database.core.type.DatabaseType; | ||
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; | ||
|
||
/** | ||
* ShardingSphere meta data identifier. | ||
*/ | ||
public final class ShardingSphereMetaDataIdentifier { | ||
|
||
private final boolean isCaseSensitive; | ||
|
||
private final CaseInsensitiveString value; | ||
|
||
public ShardingSphereMetaDataIdentifier(final String value) { | ||
isCaseSensitive = false; | ||
this.value = new CaseInsensitiveString(value); | ||
} | ||
|
||
public ShardingSphereMetaDataIdentifier(final String value, final DatabaseType databaseType) { | ||
isCaseSensitive = DatabaseTypedSPILoader.findService(DatabaseDialectMetaDataIdentifierHandler.class, databaseType) | ||
.map(DatabaseDialectMetaDataIdentifierHandler::isCaseSensitive).orElse(false); | ||
this.value = new CaseInsensitiveString(value); | ||
} | ||
|
||
public ShardingSphereMetaDataIdentifier(final IdentifierValue value) { | ||
isCaseSensitive = QuoteCharacter.NONE != value.getQuoteCharacter(); | ||
this.value = new CaseInsensitiveString(value.getValue()); | ||
} | ||
|
||
public ShardingSphereMetaDataIdentifier(final IdentifierValue value, final DatabaseType databaseType) { | ||
isCaseSensitive = QuoteCharacter.NONE != value.getQuoteCharacter() | ||
&& DatabaseTypedSPILoader.findService(DatabaseDialectMetaDataIdentifierHandler.class, databaseType).map(DatabaseDialectMetaDataIdentifierHandler::isCaseSensitive).orElse(false); | ||
this.value = new CaseInsensitiveString(value.getValue()); | ||
} | ||
|
||
/** | ||
* Get identifier value. | ||
* | ||
* @return identifier value | ||
*/ | ||
public String getValue() { | ||
return value.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (!(obj instanceof ShardingSphereMetaDataIdentifier)) { | ||
return false; | ||
} | ||
return isCaseSensitive ? value.toString().equals(((ShardingSphereMetaDataIdentifier) obj).value.toString()) : value.equals(((ShardingSphereMetaDataIdentifier) obj).value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return isCaseSensitive ? value.toString().hashCode() : value.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters