From f4472d4504e605ccb9deac347297092fe7214740 Mon Sep 17 00:00:00 2001 From: Zhang Lizhi Date: Mon, 8 Apr 2024 21:59:51 +0800 Subject: [PATCH] Fix closing transaction manager (#2753) --- .../relational/jdbc/JdbcHelper.java | 23 +++++++++++-------- .../jdbc/JdbcTransactionManager.java | 5 +++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/legend-engine-xts-persistence/legend-engine-xt-persistence-component/legend-engine-xt-persistence-component-relational-core/src/main/java/org/finos/legend/engine/persistence/components/relational/jdbc/JdbcHelper.java b/legend-engine-xts-persistence/legend-engine-xt-persistence-component/legend-engine-xt-persistence-component-relational-core/src/main/java/org/finos/legend/engine/persistence/components/relational/jdbc/JdbcHelper.java index 723927863ec..6ed2ea8ebed 100644 --- a/legend-engine-xts-persistence/legend-engine-xt-persistence-component/legend-engine-xt-persistence-component-relational-core/src/main/java/org/finos/legend/engine/persistence/components/relational/jdbc/JdbcHelper.java +++ b/legend-engine-xts-persistence/legend-engine-xt-persistence-component/legend-engine-xt-persistence-component-relational-core/src/main/java/org/finos/legend/engine/persistence/components/relational/jdbc/JdbcHelper.java @@ -129,17 +129,20 @@ public void revertTransaction() @Override public void closeTransactionManager() { - try - { - this.transactionManager.close(); - } - catch (SQLException e) - { - throw new RuntimeException(e); - } - finally + if (this.transactionManager != null) { - this.transactionManager = null; + try + { + this.transactionManager.close(); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + finally + { + this.transactionManager = null; + } } } diff --git a/legend-engine-xts-persistence/legend-engine-xt-persistence-component/legend-engine-xt-persistence-component-relational-core/src/main/java/org/finos/legend/engine/persistence/components/relational/jdbc/JdbcTransactionManager.java b/legend-engine-xts-persistence/legend-engine-xt-persistence-component/legend-engine-xt-persistence-component-relational-core/src/main/java/org/finos/legend/engine/persistence/components/relational/jdbc/JdbcTransactionManager.java index 2dfa4abb349..464f3d28605 100644 --- a/legend-engine-xts-persistence/legend-engine-xt-persistence-component/legend-engine-xt-persistence-component-relational-core/src/main/java/org/finos/legend/engine/persistence/components/relational/jdbc/JdbcTransactionManager.java +++ b/legend-engine-xts-persistence/legend-engine-xt-persistence-component/legend-engine-xt-persistence-component-relational-core/src/main/java/org/finos/legend/engine/persistence/components/relational/jdbc/JdbcTransactionManager.java @@ -40,7 +40,10 @@ public JdbcTransactionManager(Connection connection) throws SQLException public void close() throws SQLException { - this.statement.close(); + if (this.statement != null) + { + this.statement.close(); + } } public void beginTransaction() throws SQLException