Skip to content

Commit

Permalink
Check if used database is null or empty
Browse files Browse the repository at this point in the history
  • Loading branch information
MeteorSkyOne committed Jan 19, 2025
1 parent 50be70f commit 6a4e478
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException;
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException;
import org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
import org.apache.shardingsphere.infra.hint.HintValueContext;
Expand Down Expand Up @@ -90,6 +91,8 @@ private Collection<String> getCurrentDatabaseNames(final ConnectionContext conne
* @return used database
*/
public ShardingSphereDatabase getUsedDatabase() {
ShardingSpherePreconditions.checkNotNull(usedDatabaseNames, NoDatabaseSelectedException::new);
ShardingSpherePreconditions.checkNotEmpty(usedDatabaseNames, NoDatabaseSelectedException::new);
ShardingSpherePreconditions.checkState(usedDatabaseNames.size() <= 1,
() -> new UnsupportedSQLOperationException(String.format("Can not support multiple logic databases [%s]", Joiner.on(", ").join(usedDatabaseNames))));
String databaseName = usedDatabaseNames.iterator().next();
Expand Down

0 comments on commit 6a4e478

Please sign in to comment.