Skip to content

Commit

Permalink
#13424 fixes the mysql lockup issue (#13426)
Browse files Browse the repository at this point in the history
* #13424 fixes the mysql lockup issue

* #13424 closes the preparedstatement
  • Loading branch information
wezell authored and dsilvam committed Jan 18, 2018
1 parent b016a94 commit 5742c18
Showing 1 changed file with 18 additions and 38 deletions.
56 changes: 18 additions & 38 deletions dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -1224,4 +1204,4 @@ private static void setTimestampWithTimezone(PreparedStatement statement, int pa
}
}

}
}

0 comments on commit 5742c18

Please sign in to comment.