From 5742c18cd2bd766e053a03b4c279028ba32f20e0 Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Thu, 18 Jan 2018 12:26:06 -0500 Subject: [PATCH] #13424 fixes the mysql lockup issue (#13426) * #13424 fixes the mysql lockup issue * #13424 closes the preparedstatement --- .../dotmarketing/common/db/DotConnect.java | 56 ++++++------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java b/dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java index b8a65097589f..ab6cd8bf6924 100644 --- a/dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java +++ b/dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java @@ -23,6 +23,9 @@ import com.dotmarketing.util.json.JSONObject; import static com.dotcms.util.CollectionsUtils.*; +import com.dotcms.business.CloseDBIfOpened; +import com.dotcms.business.WrapInTransaction; + /** * Description of the Class * @@ -1114,42 +1117,15 @@ public int executeUpdate (final String preparedStatement, * @return int rows affected * @throws DotDataException */ + public int executeUpdate (final String preparedStatement, Boolean logException, final Object... parameters) throws DotDataException { - final boolean isNewTransaction = DbConnectionFactory.startTransactionIfNeeded(); - Connection connection = null; - int rowsAffected = 0; - - try { - - connection = DbConnectionFactory.getConnection(); - rowsAffected = this.executeUpdate(connection, - preparedStatement, logException, parameters); + return this.executeUpdate(DbConnectionFactory.getConnection(), + preparedStatement, logException, parameters); - if (isNewTransaction) { - connection.commit(); - } - } catch (DotDataException e) { - if (isNewTransaction) { - this.rollback(connection); - } - throw e; - } catch (Exception e) { - if (logException) { - Logger.error(DotConnect.class, e.getMessage(), e); - } - throw new DotDataException(e.getMessage(), e); - } finally { - - if (isNewTransaction) { - closeQuietly(connection); - } - } - - return rowsAffected; } // executeUpdate. protected void rollback(final Connection connection) throws DotDataException { @@ -1186,29 +1162,33 @@ public int executeUpdate (final Connection connection, final String preparedStat * @return int rows affected * @throws DotDataException */ + @CloseDBIfOpened public int executeUpdate (final Connection connection, final String preparedStatementString, Boolean logException, final Object... parameters) throws DotDataException { - PreparedStatement preparedStatement = null; - int rowsAffected = 0; - + PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement(preparedStatementString); this.setParams(preparedStatement, parameters); - rowsAffected = preparedStatement.executeUpdate(); + return preparedStatement.executeUpdate(); } catch (SQLException e) { if (logException) { Logger.error(DotConnect.class, e.getMessage(), e); } throw new DotDataException(e.getMessage(), e); } finally { - - closeQuietly(preparedStatement); + if(null!= preparedStatement ) { + try { + preparedStatement.close(); + } catch (SQLException e) { + Logger.debug(this.getClass(), e.getMessage(),e); + } + } } - return rowsAffected; + } // executeUpdate. private static void setTimestampWithTimezone(PreparedStatement statement, int parameterIndex, Object timestamp) { @@ -1224,4 +1204,4 @@ private static void setTimestampWithTimezone(PreparedStatement statement, int pa } } -} \ No newline at end of file +}