Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
1. SQL Binder: Use Multimap and CaseInsensitiveString to replace CaseInsensitiveMap for supporting mysql multi table join with same table alias - [#33303](https://github.com/apache/shardingsphere/pull/33303)
1. SQL Binder: Fix the combine statement cannot find the outer table when bind - [#33357](https://github.com/apache/shardingsphere/pull/33357)
1. SQL Binder: Fix SQL performance issues caused by repeated subquery fetches - [#33361](https://github.com/apache/shardingsphere/pull/33361)
1. SQL Binder: Fix table does not exist exception when use HintManager#setDatabaseName to transparent - [#33370](https://github.com/apache/shardingsphere/pull/33370)

### Change Logs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContextFactory;
import org.apache.shardingsphere.infra.binder.engine.type.DDLStatementBindEngine;
import org.apache.shardingsphere.infra.binder.engine.type.DMLStatementBindEngine;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
Expand Down Expand Up @@ -55,7 +56,7 @@ public SQLStatementContext bind(final SQLStatement sqlStatement, final List<Obje
}

private boolean isNeedBind() {
return !hintValueContext.findHintDataSourceName().isPresent();
return !hintValueContext.findHintDataSourceName().isPresent() && !HintManager.getDataSourceName().isPresent();
}

private SQLStatement bindSQLStatement(final SQLStatement statement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.shardingsphere.driver;

import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
Expand Down Expand Up @@ -91,4 +92,27 @@ void assertVarbinaryColumnWorks() throws SQLException {
}
}
}

@Test
void assertDatabaseNameTransparentWithHintManager() throws SQLException {
try (
Connection connection = DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml");
Statement statement = connection.createStatement()) {
assertThat(connection, instanceOf(ShardingSphereConnection.class));
statement.execute("DROP TABLE IF EXISTS t_order");
statement.execute("CREATE TABLE t_order (order_id INT PRIMARY KEY, user_id INT)");
statement.execute("INSERT INTO t_order (order_id, user_id) VALUES (1, 101), (2, 102)");
try (HintManager hintManager = HintManager.getInstance()) {
executeQueryWithHintManager(hintManager, statement);
}
}
}

private void executeQueryWithHintManager(final HintManager hintManager, final Statement statement) throws SQLException {
hintManager.setDataSourceName("ds_0");
try (ResultSet resultSet = statement.executeQuery("SELECT COUNT(1) FROM t_order_0")) {
assertTrue(resultSet.next());
assertThat(resultSet.getInt(1), is(1));
}
}
}