fix(oceanbase): support manual transaction control in oracle mode
This commit is contained in:
15 files changed
+391
-52
No files matched your search
@@ -255,13 +255,19 @@ public abstract class AbstractJdbcAgent extends BaseDatabaseAgent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryResult executeTransaction(List<String> statements, String schema) {
|
public QueryResult executeTransaction(List<String> statements, String schema) {
|
||||||
return TransactionExecutor.executeUpdateStatements(
|
Connection conn = requireConnected();
|
||||||
requireConnected(),
|
return unchecked(() -> {
|
||||||
statements,
|
if (!conn.getAutoCommit()) {
|
||||||
schema,
|
throw new IllegalStateException("Cannot start a one-shot transaction while a manual transaction is open");
|
||||||
this::setSchemaSQL,
|
}
|
||||||
this::resetSchemaSQL
|
return TransactionExecutor.executeUpdateStatements(
|
||||||
);
|
conn,
|
||||||
|
statements,
|
||||||
|
schema,
|
||||||
|
this::setSchemaSQL,
|
||||||
|
this::resetSchemaSQL
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -377,7 +383,9 @@ public abstract class AbstractJdbcAgent extends BaseDatabaseAgent {
|
|||||||
JdbcExecutor executor,
|
JdbcExecutor executor,
|
||||||
boolean succeeded,
|
boolean succeeded,
|
||||||
boolean requiresSessionAffinity,
|
boolean requiresSessionAffinity,
|
||||||
boolean evictAfterRequest
|
boolean evictAfterRequest,
|
||||||
|
boolean endsSessionAffinity,
|
||||||
|
boolean preservesSchemaContext
|
||||||
) {
|
) {
|
||||||
if (poolRegistry == null) {
|
if (poolRegistry == null) {
|
||||||
return;
|
return;
|
||||||
@@ -389,7 +397,12 @@ public abstract class AbstractJdbcAgent extends BaseDatabaseAgent {
|
|||||||
}
|
}
|
||||||
if (succeeded && requiresSessionAffinity) {
|
if (succeeded && requiresSessionAffinity) {
|
||||||
sessionAffinity = true;
|
sessionAffinity = true;
|
||||||
JdbcSchemaSwitcher.forget(connection);
|
if (!preservesSchemaContext) {
|
||||||
|
JdbcSchemaSwitcher.forget(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (succeeded && endsSessionAffinity) {
|
||||||
|
sessionAffinity = false;
|
||||||
}
|
}
|
||||||
if (pooledLease == null) {
|
if (pooledLease == null) {
|
||||||
connection = null;
|
connection = null;
|
||||||
|
|||||||
@@ -224,13 +224,71 @@ public interface DatabaseAgent {
|
|||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
throw new IllegalStateException("Not connected");
|
throw new IllegalStateException("Not connected");
|
||||||
}
|
}
|
||||||
return TransactionExecutor.executeUpdateStatements(
|
return unchecked(() -> {
|
||||||
conn,
|
if (!conn.getAutoCommit()) {
|
||||||
statements,
|
throw new IllegalStateException("Cannot start a one-shot transaction while a manual transaction is open");
|
||||||
schema,
|
}
|
||||||
this::setSchemaSQL,
|
return TransactionExecutor.executeUpdateStatements(
|
||||||
this::resetSchemaSQL
|
conn,
|
||||||
);
|
statements,
|
||||||
|
schema,
|
||||||
|
this::setSchemaSQL,
|
||||||
|
this::resetSchemaSQL
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Starts an interactive transaction on the current JDBC connection. */
|
||||||
|
default Map<String, Object> beginManualTransaction(String schema) {
|
||||||
|
Connection conn = getConnection();
|
||||||
|
if (conn == null) {
|
||||||
|
throw new IllegalStateException("Not connected");
|
||||||
|
}
|
||||||
|
return unchecked(() -> {
|
||||||
|
if (!conn.getAutoCommit()) {
|
||||||
|
throw new IllegalStateException("Manual transaction already open");
|
||||||
|
}
|
||||||
|
if (schema != null && !schema.trim().isEmpty()) {
|
||||||
|
JdbcSchemaSwitcher.apply(conn, schema, this::setSchemaSQL, this::resetSchemaSQL);
|
||||||
|
}
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
JdbcSchemaSwitcher.preserve(conn);
|
||||||
|
return Collections.singletonMap("ok", (Object) true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Commits an interactive transaction on the current JDBC connection. */
|
||||||
|
default Map<String, Object> commitManualTransaction() {
|
||||||
|
Connection conn = getConnection();
|
||||||
|
if (conn == null) {
|
||||||
|
throw new IllegalStateException("Not connected");
|
||||||
|
}
|
||||||
|
return unchecked(() -> {
|
||||||
|
if (conn.getAutoCommit()) {
|
||||||
|
throw new IllegalStateException("No manual transaction open");
|
||||||
|
}
|
||||||
|
conn.commit();
|
||||||
|
conn.setAutoCommit(true);
|
||||||
|
JdbcSchemaSwitcher.releasePreserved(conn);
|
||||||
|
return Collections.singletonMap("ok", (Object) true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Rolls back an interactive transaction on the current JDBC connection. */
|
||||||
|
default Map<String, Object> rollbackManualTransaction() {
|
||||||
|
Connection conn = getConnection();
|
||||||
|
if (conn == null) {
|
||||||
|
throw new IllegalStateException("Not connected");
|
||||||
|
}
|
||||||
|
return unchecked(() -> {
|
||||||
|
if (conn.getAutoCommit()) {
|
||||||
|
throw new IllegalStateException("No manual transaction open");
|
||||||
|
}
|
||||||
|
conn.rollback();
|
||||||
|
conn.setAutoCommit(true);
|
||||||
|
JdbcSchemaSwitcher.releasePreserved(conn);
|
||||||
|
return Collections.singletonMap("ok", (Object) true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
default QueryResult executeBatch(List<String> statements, String schema) {
|
default QueryResult executeBatch(List<String> statements, String schema) {
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import java.util.function.Supplier;
|
|||||||
final class JdbcSchemaSwitcher {
|
final class JdbcSchemaSwitcher {
|
||||||
private static final Map<Connection, ResetState> RESET_STATE_BY_CONNECTION =
|
private static final Map<Connection, ResetState> RESET_STATE_BY_CONNECTION =
|
||||||
Collections.synchronizedMap(new WeakHashMap<>());
|
Collections.synchronizedMap(new WeakHashMap<>());
|
||||||
|
private static final Map<Connection, Boolean> PRESERVED_BY_CONNECTION =
|
||||||
|
Collections.synchronizedMap(new WeakHashMap<>());
|
||||||
|
|
||||||
private JdbcSchemaSwitcher() {
|
private JdbcSchemaSwitcher() {
|
||||||
}
|
}
|
||||||
@@ -27,6 +29,9 @@ final class JdbcSchemaSwitcher {
|
|||||||
Supplier<String> resetSchemaSql
|
Supplier<String> resetSchemaSql
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
if (schema == null || schema.trim().isEmpty()) {
|
if (schema == null || schema.trim().isEmpty()) {
|
||||||
|
if (isPreserved(conn)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!restore(conn, true)) {
|
if (!restore(conn, true)) {
|
||||||
throw new SQLException("Failed to restore the original JDBC schema context");
|
throw new SQLException("Failed to restore the original JDBC schema context");
|
||||||
}
|
}
|
||||||
@@ -70,7 +75,20 @@ final class JdbcSchemaSwitcher {
|
|||||||
RESET_STATE_BY_CONNECTION.remove(conn);
|
RESET_STATE_BY_CONNECTION.remove(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void preserve(Connection conn) {
|
||||||
|
PRESERVED_BY_CONNECTION.put(conn, Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void releasePreserved(Connection conn) {
|
||||||
|
PRESERVED_BY_CONNECTION.remove(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isPreserved(Connection conn) {
|
||||||
|
return PRESERVED_BY_CONNECTION.containsKey(conn);
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean restore(Connection conn, boolean preserveOnFailure) {
|
private static boolean restore(Connection conn, boolean preserveOnFailure) {
|
||||||
|
PRESERVED_BY_CONNECTION.remove(conn);
|
||||||
ResetState resetState = RESET_STATE_BY_CONNECTION.remove(conn);
|
ResetState resetState = RESET_STATE_BY_CONNECTION.remove(conn);
|
||||||
if (resetState == null) {
|
if (resetState == null) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -111,7 +111,9 @@ public final class JsonRpcServer {
|
|||||||
jdbcExecutor,
|
jdbcExecutor,
|
||||||
succeeded,
|
succeeded,
|
||||||
requiresSessionAffinity(method, params),
|
requiresSessionAffinity(method, params),
|
||||||
evictAfterRequest(method)
|
evictAfterRequest(method),
|
||||||
|
endsSessionAffinity(method),
|
||||||
|
preservesSchemaContext()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,6 +317,15 @@ public final class JsonRpcServer {
|
|||||||
List<String> statements = gson.fromJson(params.get("statements"), statementsType);
|
List<String> statements = gson.fromJson(params.get("statements"), statementsType);
|
||||||
return agent.executeTransaction(statements, stringOrNull(params, "schema"));
|
return agent.executeTransaction(statements, stringOrNull(params, "schema"));
|
||||||
}
|
}
|
||||||
|
if (AgentProtocol.METHOD_BEGIN_MANUAL_TRANSACTION.equals(method)) {
|
||||||
|
return agent.beginManualTransaction(stringOrNull(params, "schema"));
|
||||||
|
}
|
||||||
|
if (AgentProtocol.METHOD_COMMIT_MANUAL_TRANSACTION.equals(method)) {
|
||||||
|
return agent.commitManualTransaction();
|
||||||
|
}
|
||||||
|
if (AgentProtocol.METHOD_ROLLBACK_MANUAL_TRANSACTION.equals(method)) {
|
||||||
|
return agent.rollbackManualTransaction();
|
||||||
|
}
|
||||||
if (AgentProtocol.METHOD_EXECUTE_BATCH.equals(method)) {
|
if (AgentProtocol.METHOD_EXECUTE_BATCH.equals(method)) {
|
||||||
Type statementsType = new TypeToken<List<String>>() {}.getType();
|
Type statementsType = new TypeToken<List<String>>() {}.getType();
|
||||||
List<String> statements = gson.fromJson(params.get("statements"), statementsType);
|
List<String> statements = gson.fromJson(params.get("statements"), statementsType);
|
||||||
@@ -422,6 +433,9 @@ public final class JsonRpcServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean requiresSessionAffinity(String method, JsonObject params) {
|
private boolean requiresSessionAffinity(String method, JsonObject params) {
|
||||||
|
if (AgentProtocol.METHOD_BEGIN_MANUAL_TRANSACTION.equals(method)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (AgentProtocol.METHOD_EXECUTE_QUERY.equals(method)
|
if (AgentProtocol.METHOD_EXECUTE_QUERY.equals(method)
|
||||||
|| AgentProtocol.METHOD_EXECUTE_QUERY_PAGE.equals(method)
|
|| AgentProtocol.METHOD_EXECUTE_QUERY_PAGE.equals(method)
|
||||||
@@ -447,6 +461,23 @@ public final class JsonRpcServer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean endsSessionAffinity(String method) {
|
||||||
|
return AgentProtocol.METHOD_COMMIT_MANUAL_TRANSACTION.equals(method)
|
||||||
|
|| AgentProtocol.METHOD_ROLLBACK_MANUAL_TRANSACTION.equals(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean preservesSchemaContext() {
|
||||||
|
Connection connection = agent.getConnection();
|
||||||
|
if (connection == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return !connection.getAutoCommit();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean evictAfterRequest(String method) {
|
private static boolean evictAfterRequest(String method) {
|
||||||
return AgentProtocol.METHOD_GET_EXPLAIN_INFO.equals(method);
|
return AgentProtocol.METHOD_GET_EXPLAIN_INFO.equals(method);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,6 +300,22 @@ class AbstractJdbcAgentTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void rejectsOneShotTransactionWhenManualTransactionIsOpen() {
|
||||||
|
TrackingConnection tracking = new TrackingConnection();
|
||||||
|
TestAgent agent = new TestAgent(tracking);
|
||||||
|
agent.connect(new ConnectParams());
|
||||||
|
agent.beginManualTransaction(null);
|
||||||
|
|
||||||
|
IllegalStateException error = assertThrows(
|
||||||
|
IllegalStateException.class,
|
||||||
|
() -> agent.executeTransaction(Collections.singletonList("UPDATE A SET ID = 1"), null)
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals("Cannot start a one-shot transaction while a manual transaction is open", error.getMessage());
|
||||||
|
assertEquals(Collections.singletonList("setAutoCommit:false"), tracking.calls);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void preservesPlSqlBlockTerminatorDuringTransactionExecution() {
|
void preservesPlSqlBlockTerminatorDuringTransactionExecution() {
|
||||||
TrackingConnection tracking = new TrackingConnection();
|
TrackingConnection tracking = new TrackingConnection();
|
||||||
|
|||||||
@@ -150,6 +150,42 @@ class CommonJavaCompatibilityTest {
|
|||||||
assertEquals("Example JDBC", result.getAsJsonObject("databaseInfo").get("driverName").getAsString());
|
assertEquals("Example JDBC", result.getAsJsonObject("databaseInfo").get("driverName").getAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void jsonRpcServerDispatchesInteractiveTransactionMethods() {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
MinimalAgent agent = new MinimalAgent() {
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> beginManualTransaction(String schema) {
|
||||||
|
calls.add("begin:" + schema);
|
||||||
|
return Collections.singletonMap("ok", (Object) true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> commitManualTransaction() {
|
||||||
|
calls.add("commit");
|
||||||
|
return Collections.singletonMap("ok", (Object) true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> rollbackManualTransaction() {
|
||||||
|
calls.add("rollback");
|
||||||
|
return Collections.singletonMap("ok", (Object) true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
JsonRpcServer server = new JsonRpcServer(agent);
|
||||||
|
|
||||||
|
assertTrue(JsonParser.parseString(server.handleRequest(
|
||||||
|
"{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"begin_manual_transaction\",\"params\":{\"schema\":\"APP\"}}"
|
||||||
|
)).getAsJsonObject().has("result"));
|
||||||
|
assertTrue(JsonParser.parseString(server.handleRequest(
|
||||||
|
"{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"commit_manual_transaction\",\"params\":{}}"
|
||||||
|
)).getAsJsonObject().has("result"));
|
||||||
|
assertTrue(JsonParser.parseString(server.handleRequest(
|
||||||
|
"{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"rollback_manual_transaction\",\"params\":{}}"
|
||||||
|
)).getAsJsonObject().has("result"));
|
||||||
|
assertEquals(List.of("begin:APP", "commit", "rollback"), calls);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multiSessionServerCreatesAndClosesIndependentAgents() throws Exception {
|
void multiSessionServerCreatesAndClosesIndependentAgents() throws Exception {
|
||||||
java.util.List<TrackingAgent> created = new java.util.ArrayList<>();
|
java.util.List<TrackingAgent> created = new java.util.ArrayList<>();
|
||||||
|
|||||||
@@ -1869,6 +1869,65 @@ class JdbcConnectionPoolingTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void interactiveTransactionPinsConnectionUntilCommit() {
|
||||||
|
AtomicInteger physicalOpens = new AtomicInteger();
|
||||||
|
AtomicInteger requestIds = new AtomicInteger();
|
||||||
|
String url = h2Url("manual_transaction");
|
||||||
|
try (MultiSessionJsonRpcServer server = server(url, physicalOpens, 2)) {
|
||||||
|
openSession(server, requestIds, "transaction");
|
||||||
|
query(server, requestIds, "transaction", "CREATE TABLE ITEMS (ID INT)", null);
|
||||||
|
|
||||||
|
result(request(
|
||||||
|
server,
|
||||||
|
requestIds,
|
||||||
|
AgentProtocol.METHOD_BEGIN_MANUAL_TRANSACTION,
|
||||||
|
sessionParams("transaction")
|
||||||
|
));
|
||||||
|
query(server, requestIds, "transaction", "INSERT INTO ITEMS VALUES (1)", null);
|
||||||
|
|
||||||
|
openSession(server, requestIds, "observer");
|
||||||
|
JsonObject beforeCommit = query(server, requestIds, "observer", "SELECT COUNT(*) FROM ITEMS", null);
|
||||||
|
assertEquals(0, beforeCommit.getAsJsonArray("rows").get(0).getAsJsonArray().get(0).getAsInt());
|
||||||
|
|
||||||
|
result(request(
|
||||||
|
server,
|
||||||
|
requestIds,
|
||||||
|
AgentProtocol.METHOD_COMMIT_MANUAL_TRANSACTION,
|
||||||
|
sessionParams("transaction")
|
||||||
|
));
|
||||||
|
JsonObject afterCommit = query(server, requestIds, "observer", "SELECT COUNT(*) FROM ITEMS", null);
|
||||||
|
assertEquals(1, afterCommit.getAsJsonArray("rows").get(0).getAsJsonArray().get(0).getAsInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void interactiveTransactionRestoresSchemaBeforeReturningConnection() {
|
||||||
|
AtomicInteger physicalOpens = new AtomicInteger();
|
||||||
|
AtomicInteger requestIds = new AtomicInteger();
|
||||||
|
String url = h2Url("manual_transaction_schema");
|
||||||
|
try (MultiSessionJsonRpcServer server = server(url, physicalOpens, 2)) {
|
||||||
|
openSession(server, requestIds, "transaction-schema");
|
||||||
|
query(server, requestIds, "transaction-schema", "CREATE SCHEMA IF NOT EXISTS APP", null);
|
||||||
|
|
||||||
|
JsonObject beginParams = sessionParams("transaction-schema");
|
||||||
|
beginParams.addProperty("schema", "APP");
|
||||||
|
result(request(server, requestIds, AgentProtocol.METHOD_BEGIN_MANUAL_TRANSACTION, beginParams));
|
||||||
|
JsonObject inTransaction = query(server, requestIds, "transaction-schema", "SELECT CURRENT_SCHEMA", null);
|
||||||
|
assertEquals("APP", inTransaction.getAsJsonArray("rows").get(0).getAsJsonArray().get(0).getAsString());
|
||||||
|
|
||||||
|
result(request(
|
||||||
|
server,
|
||||||
|
requestIds,
|
||||||
|
AgentProtocol.METHOD_COMMIT_MANUAL_TRANSACTION,
|
||||||
|
sessionParams("transaction-schema")
|
||||||
|
));
|
||||||
|
openSession(server, requestIds, "schema-observer");
|
||||||
|
JsonObject afterCommit = query(server, requestIds, "schema-observer", "SELECT CURRENT_SCHEMA", null);
|
||||||
|
assertEquals("PUBLIC", afterCommit.getAsJsonArray("rows").get(0).getAsJsonArray().get(0).getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void affinityDetectionCoversCommonSessionStateStatements() {
|
void affinityDetectionCoversCommonSessionStateStatements() {
|
||||||
assertTrue(JdbcConnectionAffinity.requiresSessionAffinity("SET search_path TO app"));
|
assertTrue(JdbcConnectionAffinity.requiresSessionAffinity("SET search_path TO app"));
|
||||||
|
|||||||
+71
@@ -150,6 +150,46 @@ class OceanBaseOracleAgentTest {
|
|||||||
Assertions.assertEquals(List.of(), queryTimeouts);
|
Assertions.assertEquals(List.of(), queryTimeouts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void supportsCommitAndRollbackForInteractiveTransactions() {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
OceanBaseOracleAgent agent = new OceanBaseOracleAgent();
|
||||||
|
TestSupport.setPrivateConnection(agent, transactionConnection(calls));
|
||||||
|
|
||||||
|
agent.beginManualTransaction(null);
|
||||||
|
Assertions.assertEquals(List.of("setAutoCommit:false"), calls);
|
||||||
|
agent.commitManualTransaction();
|
||||||
|
Assertions.assertEquals(List.of("setAutoCommit:false", "commit", "setAutoCommit:true"), calls);
|
||||||
|
|
||||||
|
agent.beginManualTransaction(null);
|
||||||
|
agent.rollbackManualTransaction();
|
||||||
|
Assertions.assertEquals(
|
||||||
|
List.of("setAutoCommit:false", "commit", "setAutoCommit:true", "setAutoCommit:false", "rollback", "setAutoCommit:true"),
|
||||||
|
calls
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void failedCommitKeepsTransactionOpenSoItCanBeRolledBack() throws SQLException {
|
||||||
|
List<String> calls = new ArrayList<>();
|
||||||
|
boolean[] failCommit = {true};
|
||||||
|
OceanBaseOracleAgent agent = new OceanBaseOracleAgent();
|
||||||
|
Connection connection = transactionConnection(calls, failCommit);
|
||||||
|
TestSupport.setPrivateConnection(agent, connection);
|
||||||
|
|
||||||
|
agent.beginManualTransaction(null);
|
||||||
|
Assertions.assertThrows(RuntimeException.class, agent::commitManualTransaction);
|
||||||
|
Assertions.assertFalse(connection.getAutoCommit());
|
||||||
|
|
||||||
|
failCommit[0] = false;
|
||||||
|
Assertions.assertDoesNotThrow(agent::rollbackManualTransaction);
|
||||||
|
Assertions.assertTrue(connection.getAutoCommit());
|
||||||
|
Assertions.assertEquals(
|
||||||
|
List.of("setAutoCommit:false", "commit", "rollback", "setAutoCommit:true"),
|
||||||
|
calls
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void synchronizesSessionTimeoutForEveryQueryEntryPoint() {
|
void synchronizesSessionTimeoutForEveryQueryEntryPoint() {
|
||||||
List<String> sql = new ArrayList<>();
|
List<String> sql = new ArrayList<>();
|
||||||
@@ -847,6 +887,37 @@ class OceanBaseOracleAgentTest {
|
|||||||
return executionConnection(sql, new ArrayList<>(), List.of());
|
return executionConnection(sql, new ArrayList<>(), List.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Connection transactionConnection(List<String> calls) {
|
||||||
|
return transactionConnection(calls, new boolean[] {false});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Connection transactionConnection(List<String> calls, boolean[] failCommit) {
|
||||||
|
boolean[] autoCommit = {true};
|
||||||
|
return proxy(Connection.class, (method, args) -> {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "getAutoCommit":
|
||||||
|
return autoCommit[0];
|
||||||
|
case "setAutoCommit":
|
||||||
|
autoCommit[0] = (Boolean) args[0];
|
||||||
|
calls.add("setAutoCommit:" + autoCommit[0]);
|
||||||
|
return null;
|
||||||
|
case "commit":
|
||||||
|
calls.add("commit");
|
||||||
|
if (failCommit[0]) {
|
||||||
|
throw new SQLException("commit failed");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
case "rollback":
|
||||||
|
calls.add("rollback");
|
||||||
|
return null;
|
||||||
|
case "isClosed":
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return defaultValue(method.getReturnType());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static Connection executionConnection(
|
private static Connection executionConnection(
|
||||||
List<String> sql,
|
List<String> sql,
|
||||||
List<Integer> queryTimeouts,
|
List<Integer> queryTimeouts,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { createContentSurfaceEventForwarders } from "@/lib/tabs/contentSurfaceEv
|
|||||||
import { isPreviewTab } from "@/lib/tabs/tabPresentation";
|
import { isPreviewTab } from "@/lib/tabs/tabPresentation";
|
||||||
import { resolveExecutableSql } from "@/lib/sql/sqlExecutionTarget";
|
import { resolveExecutableSql } from "@/lib/sql/sqlExecutionTarget";
|
||||||
import { effectiveDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";
|
import { effectiveDatabaseTypeForConnection } from "@/lib/database/jdbcDialect";
|
||||||
|
import { usesOracleStickyTransactionState } from "@/lib/database/databaseFeatureSupport";
|
||||||
import { GROUP_TAB_BAR_PORTAL } from "./groupTabBarPortal";
|
import { GROUP_TAB_BAR_PORTAL } from "./groupTabBarPortal";
|
||||||
import type { ContentAreaSurfaceEmits, ContentAreaSurfaceProps, QueryEditorSurfaceHandle, StatementRange } from "./querySurfaces";
|
import type { ContentAreaSurfaceEmits, ContentAreaSurfaceProps, QueryEditorSurfaceHandle, StatementRange } from "./querySurfaces";
|
||||||
import type { QueryTab } from "@/types/database";
|
import type { QueryTab } from "@/types/database";
|
||||||
@@ -108,7 +109,7 @@ const groupTabs = computed(() => {
|
|||||||
const activeTab = computed(() => groupTabs.value.find((tab) => tab.id === props.activeTabId) ?? groupTabs.value[0] ?? null);
|
const activeTab = computed(() => groupTabs.value.find((tab) => tab.id === props.activeTabId) ?? groupTabs.value[0] ?? null);
|
||||||
const activeConnection = computed(() => (activeTab.value ? connectionStore.getConfig(activeTab.value.connectionId) : undefined));
|
const activeConnection = computed(() => (activeTab.value ? connectionStore.getConfig(activeTab.value.connectionId) : undefined));
|
||||||
const showGroupToolbar = computed(() => activeTab.value?.mode === "query" && !isPreviewTab(activeTab.value));
|
const showGroupToolbar = computed(() => activeTab.value?.mode === "query" && !isPreviewTab(activeTab.value));
|
||||||
const isGroupOracleManualTransaction = computed(() => effectiveDatabaseTypeForConnection(activeConnection.value) === "oracle" && (activeTab.value?.autoCommit ?? true) === false);
|
const isGroupOracleManualTransaction = computed(() => usesOracleStickyTransactionState(effectiveDatabaseTypeForConnection(activeConnection.value)) && (activeTab.value?.autoCommit ?? true) === false);
|
||||||
// Each group previews the executable SQL of its own active tab (selection
|
// Each group previews the executable SQL of its own active tab (selection
|
||||||
// stored on the tab), not the focused tab's global selection.
|
// stored on the tab), not the focused tab's global selection.
|
||||||
// tabPlacement drives each pane's own bar position: the strip sits above,
|
// tabPlacement drives each pane's own bar position: the strip sits above,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
supportsTableImport,
|
supportsTableImport,
|
||||||
supportsTableVacuum,
|
supportsTableVacuum,
|
||||||
supportsTransaction,
|
supportsTransaction,
|
||||||
|
usesOracleStickyTransactionState,
|
||||||
usesConnectionOnlyQueryTarget,
|
usesConnectionOnlyQueryTarget,
|
||||||
usesTreeSchemaMode,
|
usesTreeSchemaMode,
|
||||||
schemaNodeHasLoadableName,
|
schemaNodeHasLoadableName,
|
||||||
@@ -160,10 +161,10 @@ describe("supportsTransaction", () => {
|
|||||||
expect(supportsTransaction("mysql")).toBe(true);
|
expect(supportsTransaction("mysql")).toBe(true);
|
||||||
expect(supportsTransaction("oracle")).toBe(true);
|
expect(supportsTransaction("oracle")).toBe(true);
|
||||||
expect(supportsTransaction("jdbc")).toBe(true);
|
expect(supportsTransaction("jdbc")).toBe(true);
|
||||||
|
expect(supportsTransaction("oceanbase-oracle")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns false for unsupported database types", () => {
|
it("returns false for unsupported database types", () => {
|
||||||
expect(supportsTransaction("oceanbase-oracle")).toBe(false);
|
|
||||||
expect(supportsTransaction("redis")).toBe(false);
|
expect(supportsTransaction("redis")).toBe(false);
|
||||||
expect(supportsTransaction("mongodb")).toBe(false);
|
expect(supportsTransaction("mongodb")).toBe(false);
|
||||||
expect(supportsTransaction("duckdb")).toBe(false);
|
expect(supportsTransaction("duckdb")).toBe(false);
|
||||||
@@ -198,6 +199,7 @@ describe("defaultAutoCommitForDbType", () => {
|
|||||||
expect(defaultAutoCommitForDbType("postgres", "manual")).toBe(false);
|
expect(defaultAutoCommitForDbType("postgres", "manual")).toBe(false);
|
||||||
expect(defaultAutoCommitForDbType("oracle", "manual")).toBe(false);
|
expect(defaultAutoCommitForDbType("oracle", "manual")).toBe(false);
|
||||||
expect(defaultAutoCommitForDbType("jdbc", "manual")).toBe(false);
|
expect(defaultAutoCommitForDbType("jdbc", "manual")).toBe(false);
|
||||||
|
expect(defaultAutoCommitForDbType("oceanbase-oracle", "manual")).toBe(false);
|
||||||
expect(defaultAutoCommitForDbType("mysql", "auto")).toBe(true);
|
expect(defaultAutoCommitForDbType("mysql", "auto")).toBe(true);
|
||||||
expect(defaultAutoCommitForDbType(undefined, "auto")).toBe(true);
|
expect(defaultAutoCommitForDbType(undefined, "auto")).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -208,11 +210,24 @@ describe("defaultAutoCommitForDbType", () => {
|
|||||||
expect(defaultAutoCommitForDbType("sqlite", "manual")).toBe(true);
|
expect(defaultAutoCommitForDbType("sqlite", "manual")).toBe(true);
|
||||||
expect(defaultAutoCommitForDbType("dameng", "manual")).toBe(true);
|
expect(defaultAutoCommitForDbType("dameng", "manual")).toBe(true);
|
||||||
expect(defaultAutoCommitForDbType("clickhouse", "manual")).toBe(true);
|
expect(defaultAutoCommitForDbType("clickhouse", "manual")).toBe(true);
|
||||||
expect(defaultAutoCommitForDbType("oceanbase-oracle", "manual")).toBe(true);
|
|
||||||
expect(defaultAutoCommitForDbType(undefined, "manual")).toBe(true);
|
expect(defaultAutoCommitForDbType(undefined, "manual")).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("usesOracleStickyTransactionState", () => {
|
||||||
|
it("enables sticky manual-transaction state for Oracle family", () => {
|
||||||
|
expect(usesOracleStickyTransactionState("oracle")).toBe(true);
|
||||||
|
expect(usesOracleStickyTransactionState("oceanbase-oracle")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps other databases on the generic transaction path", () => {
|
||||||
|
expect(usesOracleStickyTransactionState("mysql")).toBe(false);
|
||||||
|
expect(usesOracleStickyTransactionState("postgres")).toBe(false);
|
||||||
|
expect(usesOracleStickyTransactionState("jdbc")).toBe(false);
|
||||||
|
expect(usesOracleStickyTransactionState(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("supportsSqlInListPaste", () => {
|
describe("supportsSqlInListPaste", () => {
|
||||||
it("allows generic and SQL-like editors", () => {
|
it("allows generic and SQL-like editors", () => {
|
||||||
expect(supportsSqlInListPaste(undefined)).toBe(true);
|
expect(supportsSqlInListPaste(undefined)).toBe(true);
|
||||||
|
|||||||
@@ -257,7 +257,12 @@ export function usesPostgresLikeStructureCopy(dbType?: DatabaseType): boolean {
|
|||||||
return !!dbType && PG_LIKE_STRUCTURE_TYPES.has(dbType);
|
return !!dbType && PG_LIKE_STRUCTURE_TYPES.has(dbType);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TRANSACTION_SUPPORTED_TYPES: readonly string[] = ["postgres", "mysql", "oracle", "jdbc"];
|
const TRANSACTION_SUPPORTED_TYPES: readonly string[] = ["postgres", "mysql", "oracle", "jdbc", "oceanbase-oracle"];
|
||||||
|
|
||||||
|
/** Oracle-family databases that use the sticky manual-transaction UX. OceanBase
|
||||||
|
* Oracle mode runs the same transaction model as Oracle, so it shares the
|
||||||
|
* commit/rollback dirty-state behavior rather than the generic transaction path. */
|
||||||
|
const ORACLE_STICKY_TRANSACTION_TYPES: ReadonlySet<string> = new Set(["oracle", "oceanbase-oracle"]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the given database type supports explicit transaction control
|
* Returns true if the given database type supports explicit transaction control
|
||||||
@@ -311,6 +316,14 @@ export function rejectsAliasReferenceInHaving(dbType?: string): boolean {
|
|||||||
return !!dbType && HAVING_ALIAS_REJECTED_DATABASE_TYPES.has(dbType);
|
return !!dbType && HAVING_ALIAS_REJECTED_DATABASE_TYPES.has(dbType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the database type uses Oracle's sticky manual-transaction state
|
||||||
|
* (commit/rollback hidden until an unproven statement dirties the session).
|
||||||
|
*/
|
||||||
|
export function usesOracleStickyTransactionState(dbType?: string): boolean {
|
||||||
|
return !!dbType && ORACLE_STICKY_TRANSACTION_TYPES.has(dbType);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default auto-commit mode when opening a query tab for the given database type.
|
* Default auto-commit mode when opening a query tab for the given database type.
|
||||||
* Query tabs default to auto-commit; users can explicitly switch to manual transactions.
|
* Query tabs default to auto-commit; users can explicitly switch to manual transactions.
|
||||||
|
|||||||
+22
-15
@@ -125,12 +125,12 @@ describe("queryStore manual transaction expiry recovery", () => {
|
|||||||
expect(tab.result?.affected_rows).toBe(1);
|
expect(tab.result?.affected_rows).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("normalizes a stale manual OceanBase tab before query dispatch", async () => {
|
it("normalizes a stale manual tab for a non-transactional database before query dispatch", async () => {
|
||||||
mocks.getConnectionConfig.mockReturnValue({
|
mocks.getConnectionConfig.mockReturnValue({
|
||||||
id: "oceanbase-1",
|
id: "sqlite-1",
|
||||||
name: "OceanBase Oracle",
|
name: "SQLite",
|
||||||
db_type: "oceanbase-oracle",
|
db_type: "sqlite",
|
||||||
database: "SYS",
|
database: "main",
|
||||||
query_timeout_secs: 30,
|
query_timeout_secs: 30,
|
||||||
});
|
});
|
||||||
mocks.beginManualTransaction.mockRejectedValue(new Error("BEGIN manual transaction failed: Agent RPC error (-1): Unknown method: begin_manual_transaction"));
|
mocks.beginManualTransaction.mockRejectedValue(new Error("BEGIN manual transaction failed: Agent RPC error (-1): Unknown method: begin_manual_transaction"));
|
||||||
@@ -138,7 +138,7 @@ describe("queryStore manual transaction expiry recovery", () => {
|
|||||||
|
|
||||||
const { useQueryStore } = await import("@/stores/queryStore");
|
const { useQueryStore } = await import("@/stores/queryStore");
|
||||||
const store = useQueryStore();
|
const store = useQueryStore();
|
||||||
const tabId = store.createTab("oceanbase-1", "SYS", "Query", "query", "SYS");
|
const tabId = store.createTab("sqlite-1", "main", "Query", "query", "main");
|
||||||
// Simulate a manual-mode value restored from an older saved query tab.
|
// Simulate a manual-mode value restored from an older saved query tab.
|
||||||
store.setAutoCommit(tabId, false);
|
store.setAutoCommit(tabId, false);
|
||||||
|
|
||||||
@@ -153,13 +153,20 @@ describe("queryStore manual transaction expiry recovery", () => {
|
|||||||
expect(tab.result?.execution_error).not.toBe(true);
|
expect(tab.result?.execution_error).not.toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not fall back to auto-commit when a supported manual transaction fails to begin", async () => {
|
it.each(["oracle", "oceanbase-oracle"] as const)("does not fall back to auto-commit when a supported %s manual transaction fails to begin", async (databaseType) => {
|
||||||
mocks.beginManualTransaction.mockRejectedValue(new Error("manual transaction begin failed"));
|
mocks.beginManualTransaction.mockRejectedValue(new Error("manual transaction begin failed"));
|
||||||
mocks.executeMulti.mockResolvedValue(successfulSelect());
|
mocks.executeMulti.mockResolvedValue(successfulSelect());
|
||||||
|
mocks.getConnectionConfig.mockReturnValue({
|
||||||
|
id: `${databaseType}-1`,
|
||||||
|
name: databaseType,
|
||||||
|
db_type: databaseType,
|
||||||
|
database: "ORCL",
|
||||||
|
query_timeout_secs: 30,
|
||||||
|
});
|
||||||
|
|
||||||
const { useQueryStore } = await import("@/stores/queryStore");
|
const { useQueryStore } = await import("@/stores/queryStore");
|
||||||
const store = useQueryStore();
|
const store = useQueryStore();
|
||||||
const tabId = store.createTab("oracle-1", "ORCL", "Query", "query", "APP");
|
const tabId = store.createTab(`${databaseType}-1`, "ORCL", "Query", "query", "APP");
|
||||||
store.setAutoCommit(tabId, false);
|
store.setAutoCommit(tabId, false);
|
||||||
|
|
||||||
await store.executeTabSql(tabId, "SELECT 1 FROM DUAL");
|
await store.executeTabSql(tabId, "SELECT 1 FROM DUAL");
|
||||||
@@ -238,20 +245,20 @@ describe("queryStore manual transaction expiry recovery", () => {
|
|||||||
expect(tab.result?.rows).toEqual([[1]]);
|
expect(tab.result?.rows).toEqual([[1]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("surfaces ordinary query failures after normalizing a stale OceanBase tab", async () => {
|
it("surfaces ordinary query failures after normalizing a stale non-transactional tab", async () => {
|
||||||
mocks.getConnectionConfig.mockReturnValue({
|
mocks.getConnectionConfig.mockReturnValue({
|
||||||
id: "oceanbase-1",
|
id: "sqlite-1",
|
||||||
name: "OceanBase Oracle",
|
name: "SQLite",
|
||||||
db_type: "oceanbase-oracle",
|
db_type: "sqlite",
|
||||||
database: "SYS",
|
database: "main",
|
||||||
query_timeout_secs: 30,
|
query_timeout_secs: 30,
|
||||||
});
|
});
|
||||||
mocks.beginManualTransaction.mockRejectedValue(new Error("BEGIN manual transaction failed: Agent RPC error (-1): Unknown method: begin_manual_transaction"));
|
mocks.beginManualTransaction.mockRejectedValue(new Error("BEGIN manual transaction failed: Agent RPC error (-1): Unknown method: begin_manual_transaction"));
|
||||||
mocks.executeMulti.mockRejectedValue(new Error("OceanBase query failed"));
|
mocks.executeMulti.mockRejectedValue(new Error("SQLite query failed"));
|
||||||
|
|
||||||
const { useQueryStore } = await import("@/stores/queryStore");
|
const { useQueryStore } = await import("@/stores/queryStore");
|
||||||
const store = useQueryStore();
|
const store = useQueryStore();
|
||||||
const tabId = store.createTab("oceanbase-1", "SYS", "Query", "query", "SYS");
|
const tabId = store.createTab("sqlite-1", "main", "Query", "query", "main");
|
||||||
store.setAutoCommit(tabId, false);
|
store.setAutoCommit(tabId, false);
|
||||||
|
|
||||||
await store.executeTabSql(tabId, "SELECT missing_column FROM DUAL");
|
await store.executeTabSql(tabId, "SELECT missing_column FROM DUAL");
|
||||||
|
|||||||
@@ -558,11 +558,11 @@ describe("queryStore multi-statement errors", () => {
|
|||||||
expect(tab.results).toHaveLength(4);
|
expect(tab.results).toHaveLength(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("invalidates only the executing Oracle tab after successful CURRENT_SCHEMA changes", async () => {
|
it.each(["oracle", "oceanbase-oracle"] as const)("invalidates only the executing %s tab after successful CURRENT_SCHEMA changes", async (databaseType) => {
|
||||||
mocks.getConnectionConfig.mockReturnValue({
|
mocks.getConnectionConfig.mockReturnValue({
|
||||||
id: "oracle-1",
|
id: `${databaseType}-1`,
|
||||||
name: "Oracle",
|
name: databaseType,
|
||||||
db_type: "oracle",
|
db_type: databaseType,
|
||||||
database: "ORCL",
|
database: "ORCL",
|
||||||
query_timeout_secs: 30,
|
query_timeout_secs: 30,
|
||||||
});
|
});
|
||||||
@@ -572,8 +572,8 @@ describe("queryStore multi-statement errors", () => {
|
|||||||
.mockResolvedValueOnce([{ columns: [], rows: [], affected_rows: 0, execution_time_ms: 1 }]);
|
.mockResolvedValueOnce([{ columns: [], rows: [], affected_rows: 0, execution_time_ms: 1 }]);
|
||||||
const { useQueryStore } = await import("@/stores/queryStore");
|
const { useQueryStore } = await import("@/stores/queryStore");
|
||||||
const store = useQueryStore();
|
const store = useQueryStore();
|
||||||
const tabA = store.createTab("oracle-1", "ORCL", "Tab A");
|
const tabA = store.createTab(`${databaseType}-1`, "ORCL", "Tab A");
|
||||||
const tabB = store.createTab("oracle-1", "ORCL", "Tab B");
|
const tabB = store.createTab(`${databaseType}-1`, "ORCL", "Tab B");
|
||||||
// Exercise the explicit auto-commit execute-multi path.
|
// Exercise the explicit auto-commit execute-multi path.
|
||||||
store.setAutoCommit(tabA, true);
|
store.setAutoCommit(tabA, true);
|
||||||
store.setAutoCommit(tabB, true);
|
store.setAutoCommit(tabB, true);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import { redisCommandResultToQueryResult } from "@/lib/redis/redisQueryResult";
|
|||||||
import { nextRedisCommandDb } from "@/lib/redis/redisCommandSession";
|
import { nextRedisCommandDb } from "@/lib/redis/redisCommandSession";
|
||||||
import { isRedisMutatingCommand } from "@/lib/redis/redisCommandTable";
|
import { isRedisMutatingCommand } from "@/lib/redis/redisCommandTable";
|
||||||
import { usesAgentCursorForQuery } from "@/lib/database/databaseDriverManifest";
|
import { usesAgentCursorForQuery } from "@/lib/database/databaseDriverManifest";
|
||||||
import { defaultAutoCommitForDbType, supportsClearableQuerySchema, supportsTransaction } from "@/lib/database/databaseFeatureSupport";
|
import { defaultAutoCommitForDbType, supportsClearableQuerySchema, supportsTransaction, usesOracleStickyTransactionState } from "@/lib/database/databaseFeatureSupport";
|
||||||
import { canInsertTableRows, canUseKeylessRowPredicate, DBX_ROWID_COLUMN, editablePrimaryKeys, shouldIncludeSyntheticRowId, usesSyntheticRowIdKey } from "@/lib/table/tableEditing";
|
import { canInsertTableRows, canUseKeylessRowPredicate, DBX_ROWID_COLUMN, editablePrimaryKeys, shouldIncludeSyntheticRowId, usesSyntheticRowIdKey } from "@/lib/table/tableEditing";
|
||||||
import { TABLE_DATA_EXPORT_PAGE_SIZE } from "@/lib/table/tableDataExport";
|
import { TABLE_DATA_EXPORT_PAGE_SIZE } from "@/lib/table/tableDataExport";
|
||||||
import { tableMetaForDataTab } from "@/lib/table/tableDataTabMeta";
|
import { tableMetaForDataTab } from "@/lib/table/tableDataTabMeta";
|
||||||
@@ -4578,7 +4578,7 @@ export const useQueryStore = defineStore("query", () => {
|
|||||||
const tab = tabs.value.find((item) => item.id === id);
|
const tab = tabs.value.find((item) => item.id === id);
|
||||||
if (!tab?.txnSessionId) return;
|
if (!tab?.txnSessionId) return;
|
||||||
const dbType = effectiveDatabaseTypeForConnection(useConnectionStore().getConfig(tab.connectionId));
|
const dbType = effectiveDatabaseTypeForConnection(useConnectionStore().getConfig(tab.connectionId));
|
||||||
if (dbType === "oracle") tab.oracleTxnPossiblyDirty = true;
|
if (usesOracleStickyTransactionState(dbType)) tab.oracleTxnPossiblyDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reset only the Oracle sticky-dirty bit. Used when a session continues but
|
/** Reset only the Oracle sticky-dirty bit. Used when a session continues but
|
||||||
@@ -7009,7 +7009,7 @@ export const useQueryStore = defineStore("query", () => {
|
|||||||
executionDispatched = true;
|
executionDispatched = true;
|
||||||
// Only an initial manual execution classifies the user SQL (Oracle-only).
|
// Only an initial manual execution classifies the user SQL (Oracle-only).
|
||||||
// A later cursor-page fetch must neither set nor clear the sticky bit.
|
// A later cursor-page fetch must neither set nor clear the sticky bit.
|
||||||
const isInitialOracleManualExecution = effectiveDbType === "oracle" && !options?.pagination?.sessionId;
|
const isInitialOracleManualExecution = usesOracleStickyTransactionState(effectiveDbType) && !options?.pagination?.sessionId;
|
||||||
const classificationSql = isInitialOracleManualExecution ? queryBaseSql : undefined;
|
const classificationSql = isInitialOracleManualExecution ? queryBaseSql : undefined;
|
||||||
let manualTransactionRecoveryAttempted = false;
|
let manualTransactionRecoveryAttempted = false;
|
||||||
executionPromise = (async () => {
|
executionPromise = (async () => {
|
||||||
@@ -7059,14 +7059,14 @@ export const useQueryStore = defineStore("query", () => {
|
|||||||
// must neither set nor clear the bit, and the Core no-op (empty script)
|
// must neither set nor clear the bit, and the Core no-op (empty script)
|
||||||
// must neither set nor clear it. Otherwise any result that is not proven
|
// must neither set nor clear it. Otherwise any result that is not proven
|
||||||
// read-only dirties the session monotonically.
|
// read-only dirties the session monotonically.
|
||||||
if (tab.autoCommit === false && effectiveDbType === "oracle" && !options?.pagination?.sessionId && tab.txnSessionId) {
|
if (tab.autoCommit === false && usesOracleStickyTransactionState(effectiveDbType) && !options?.pagination?.sessionId && tab.txnSessionId) {
|
||||||
const rawResults = annotatedResults.results;
|
const rawResults = annotatedResults.results;
|
||||||
const isCoreNoOp = rawResults.length > 0 && rawResults.every((result) => result.manual_transaction_no_statement === true);
|
const isCoreNoOp = rawResults.length > 0 && rawResults.every((result) => result.manual_transaction_no_statement === true);
|
||||||
if (!isCoreNoOp && rawResults.some((result) => result.manual_transaction_proven_read_only !== true)) {
|
if (!isCoreNoOp && rawResults.some((result) => result.manual_transaction_proven_read_only !== true)) {
|
||||||
tab.oracleTxnPossiblyDirty = true;
|
tab.oracleTxnPossiblyDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const successfulOracleSchemaChanges = effectiveDbType === "oracle" ? results.filter((result) => result.execution_error !== true && isOracleCurrentSchemaStatement(result.sourceStatement)).length : 0;
|
const successfulOracleSchemaChanges = usesOracleStickyTransactionState(effectiveDbType) ? results.filter((result) => result.execution_error !== true && isOracleCurrentSchemaStatement(result.sourceStatement)).length : 0;
|
||||||
const successfulSapHanaSchemaChanges = effectiveDbType === "saphana" ? results.filter((result) => result.execution_error !== true && isSapHanaSetSchemaStatement(result.sourceStatement)).length : 0;
|
const successfulSapHanaSchemaChanges = effectiveDbType === "saphana" ? results.filter((result) => result.execution_error !== true && isSapHanaSetSchemaStatement(result.sourceStatement)).length : 0;
|
||||||
const sqlServerUseDatabase = effectiveDbType === "sqlserver" ? annotatedResults.sqlServerUseDatabase : undefined;
|
const sqlServerUseDatabase = effectiveDbType === "sqlserver" ? annotatedResults.sqlServerUseDatabase : undefined;
|
||||||
if (hiddenPrimaryKeys.length > 0 && results.length === 1) {
|
if (hiddenPrimaryKeys.length > 0 && results.length === 1) {
|
||||||
@@ -7297,7 +7297,7 @@ export const useQueryStore = defineStore("query", () => {
|
|||||||
clearOracleTxnPossiblyDirty(tab);
|
clearOracleTxnPossiblyDirty(tab);
|
||||||
tab.txnSessionId = undefined;
|
tab.txnSessionId = undefined;
|
||||||
tab.txnAutoRolledBack = false;
|
tab.txnAutoRolledBack = false;
|
||||||
} else if (tab.txnSessionId && executionDispatched && !options?.pagination?.sessionId && effectiveDatabaseTypeForConnection(useConnectionStore().getConfig(tab.connectionId)) === "oracle") {
|
} else if (tab.txnSessionId && executionDispatched && !options?.pagination?.sessionId && usesOracleStickyTransactionState(effectiveDatabaseTypeForConnection(useConnectionStore().getConfig(tab.connectionId)))) {
|
||||||
// Frontend timeout/cancel or mid-script failure: the statement may still
|
// Frontend timeout/cancel or mid-script failure: the statement may still
|
||||||
// have executed server-side while the manual session survives, so keep
|
// have executed server-side while the manual session survives, so keep
|
||||||
// the sticky dirty state fail-closed instead of a clean toolbar on a
|
// the sticky dirty state fail-closed instead of a clean toolbar on a
|
||||||
|
|||||||
@@ -5500,7 +5500,7 @@ pub async fn execute_in_manual_transaction_with_options(
|
|||||||
empty_query_result(0),
|
empty_query_result(0),
|
||||||
options.table_data_preview,
|
options.table_data_preview,
|
||||||
);
|
);
|
||||||
if db_type == Some(DatabaseType::Oracle) {
|
if matches!(db_type, Some(DatabaseType::Oracle | DatabaseType::OceanbaseOracle)) {
|
||||||
result = result.with_manual_transaction_no_statement();
|
result = result.with_manual_transaction_no_statement();
|
||||||
}
|
}
|
||||||
return Ok(vec![result]);
|
return Ok(vec![result]);
|
||||||
@@ -5562,11 +5562,12 @@ pub async fn execute_in_manual_transaction_with_options(
|
|||||||
// same non-zero count and every paired user statement is proven read-only;
|
// same non-zero count and every paired user statement is proven read-only;
|
||||||
// any mismatch is fail-closed (no marker). This is deliberately a
|
// any mismatch is fail-closed (no marker). This is deliberately a
|
||||||
// trust-boundary count/position pairing, not a SQL-equivalence parser.
|
// trust-boundary count/position pairing, not a SQL-equivalence parser.
|
||||||
let classification: Vec<bool> = if db_type == Some(DatabaseType::Oracle) {
|
let classification: Vec<bool> = if let Some(dialect) =
|
||||||
|
db_type.filter(|db_type| matches!(db_type, DatabaseType::Oracle | DatabaseType::OceanbaseOracle))
|
||||||
|
{
|
||||||
match options.classification_sql.as_deref() {
|
match options.classification_sql.as_deref() {
|
||||||
Some(classification_sql) => {
|
Some(classification_sql) => {
|
||||||
let user_statements =
|
let user_statements = crate::sql::split_sql_statements_for_database(classification_sql, dialect);
|
||||||
crate::sql::split_sql_statements_for_database(classification_sql, DatabaseType::Oracle);
|
|
||||||
let paired = user_statements.len() == statements.len() && !user_statements.is_empty();
|
let paired = user_statements.len() == statements.len() && !user_statements.is_empty();
|
||||||
if paired {
|
if paired {
|
||||||
user_statements.iter().map(|statement| is_oracle_proven_read_only_statement(statement)).collect()
|
user_statements.iter().map(|statement| is_oracle_proven_read_only_statement(statement)).collect()
|
||||||
|
|||||||
Reference in new issue
Block a user