fix(oceanbase-oracle): handle manual transactions on grid save/switch
This commit is contained in:
1 parent
30d8b3970a
commit
a19a4f595d
6 files changed
+302
-30
No files matched your search
@@ -949,6 +949,7 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
prepareFullReload?: () => void;
|
||||
customSaveHandler?: { save: ReturnType<typeof vi.fn> };
|
||||
manualTransactionSessionId?: string;
|
||||
ensureManualTransactionSession?: () => Promise<string>;
|
||||
refreshSavedRows?: ReturnType<typeof vi.fn>;
|
||||
onManualTransactionMutation?: ReturnType<typeof vi.fn>;
|
||||
connectionId?: string;
|
||||
@@ -958,6 +959,7 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
) {
|
||||
const emit = vi.fn();
|
||||
const currentPage = options.currentPage ?? ref(1);
|
||||
const ensureManualTransactionSession = ref(options.ensureManualTransactionSession);
|
||||
const result = ref<{ columns: string[]; rows: CellValue[][] }>({
|
||||
columns: ["id", "status"],
|
||||
rows: [
|
||||
@@ -985,6 +987,7 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
onExecuteSql: computed(() => options.onExecuteSql),
|
||||
customSaveHandler: computed(() => options.customSaveHandler),
|
||||
manualTransactionSessionId: computed(() => options.manualTransactionSessionId),
|
||||
ensureManualTransactionSession: computed(() => ensureManualTransactionSession.value),
|
||||
onManualTransactionMutation: options.onManualTransactionMutation,
|
||||
sql: computed(() => undefined),
|
||||
searchText: ref(""),
|
||||
@@ -1001,7 +1004,7 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
refreshSavedRows: options.refreshSavedRows,
|
||||
emit,
|
||||
});
|
||||
return { editor, emit, currentPage };
|
||||
return { editor, emit, currentPage, ensureManualTransactionSession };
|
||||
}
|
||||
|
||||
// https://github.com/t8y2/dbx/issues/8321: without a primary key the row is
|
||||
@@ -1148,6 +1151,53 @@ describe("useDataGridEditor saveChanges reload", () => {
|
||||
expect(emit).toHaveBeenCalledWith("reload", undefined, "", undefined, undefined, 100, 0);
|
||||
});
|
||||
|
||||
it("starts a manual transaction before saving an existing result grid", async () => {
|
||||
const statement = "UPDATE orders_test SET status='shipped' WHERE id=1";
|
||||
const ensureManualTransactionSession = vi.fn().mockResolvedValue("txn-grid-1");
|
||||
mocks.prepareDataGridSave.mockResolvedValue({ statements: [statement], rollbackStatements: [] });
|
||||
mocks.executeInManualTransaction.mockResolvedValue([{ affected_rows: 1 }]);
|
||||
|
||||
const { editor, ensureManualTransactionSession: transactionMode } = createSaveTestEditor();
|
||||
transactionMode.value = ensureManualTransactionSession;
|
||||
editor.dirtyRows.value.set(0, new Map([[1, "shipped"]]));
|
||||
await editor.saveChanges();
|
||||
|
||||
expect(ensureManualTransactionSession).toHaveBeenCalledOnce();
|
||||
expect(mocks.executeInManualTransaction).toHaveBeenCalledWith("txn-grid-1", statement, "app", undefined);
|
||||
expect(mocks.executeBatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("checks a keyless edit on the newly opened manual transaction session", async () => {
|
||||
mocks.prepareDataGridSave.mockResolvedValue({
|
||||
statements: ["UPDATE orders_test SET status='shipped' WHERE status = 'pending'"],
|
||||
rollbackStatements: [],
|
||||
keylessGuards: [keylessGuard],
|
||||
});
|
||||
mocks.executeInManualTransaction.mockResolvedValueOnce([{ columns: ["matches"], rows: [[1]] }]).mockResolvedValueOnce([{ affected_rows: 1 }]);
|
||||
const { editor } = createSaveTestEditor({ primaryKeys: [], ensureManualTransactionSession: vi.fn().mockResolvedValue("txn-grid-2") });
|
||||
editor.dirtyRows.value.set(0, new Map([[1, "shipped"]]));
|
||||
await editor.saveChanges();
|
||||
|
||||
expect(mocks.executeInManualTransaction.mock.calls[0]?.[0]).toBe("txn-grid-2");
|
||||
expect(mocks.executeInManualTransaction.mock.calls[0]?.[1]).toBe(keylessGuard.sql);
|
||||
expect(mocks.executeInManualTransaction.mock.calls[1]?.[0]).toBe("txn-grid-2");
|
||||
expect(mocks.executeQuery).not.toHaveBeenCalled();
|
||||
expect(mocks.executeBatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps edits pending if a manual transaction cannot start", async () => {
|
||||
mocks.prepareDataGridSave.mockResolvedValue({ statements: ["UPDATE orders_test SET status='shipped' WHERE id=1"], rollbackStatements: [] });
|
||||
const ensureManualTransactionSession = vi.fn().mockRejectedValue(new Error("BEGIN failed"));
|
||||
const { editor } = createSaveTestEditor({ ensureManualTransactionSession });
|
||||
editor.dirtyRows.value.set(0, new Map([[1, "shipped"]]));
|
||||
await editor.saveChanges();
|
||||
|
||||
expect(editor.saveError.value).toContain("BEGIN failed");
|
||||
expect(editor.dirtyRows.value.get(0)?.get(1)).toBe("shipped");
|
||||
expect(mocks.executeBatch).not.toHaveBeenCalled();
|
||||
expect(mocks.executeInManualTransaction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("marks the manual transaction dirty before a result-grid mutation can fail", async () => {
|
||||
const onManualTransactionMutation = vi.fn();
|
||||
mocks.prepareDataGridSave.mockResolvedValue({ statements: ["UPDATE orders_test SET status='shipped' WHERE id=1"], rollbackStatements: [] });
|
||||
|
||||
Reference in new issue
Block a user