Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Lock wait timeout exceeded; try restarting transaction" #211

Merged
merged 2 commits into from
Mar 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.ff4j.utils.JdbcUtils.closeStatement;
import static org.ff4j.utils.JdbcUtils.executeUpdate;
import static org.ff4j.utils.JdbcUtils.isTableExist;
import static org.ff4j.utils.JdbcUtils.rollback;

import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -144,10 +145,10 @@ public boolean saveEvent(Event evt) {

// Commit TX
sqlConn.commit();

} catch(Exception exc) {
rollback(sqlConn);
throw new AuditAccessException("Cannot insert event into DB (" + exc.getClass() + ") "+ exc.getCause(), exc);

} finally {
closeStatement(stmt);
closeConnection(sqlConn);
Expand Down
20 changes: 13 additions & 7 deletions ff4j-core/src/main/java/org/ff4j/store/JdbcFeatureStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,21 @@ public void update(Feature fp) {
ps = sqlConn.prepareStatement(getQueryBuilder().deleteAllFeatureCustomProperties());
ps.setString(1, fpExist.getUid());
ps.executeUpdate();
closeStatement(ps);
ps = null;

// CREATE PROPERTIES
createCustomProperties(fp.getUid(), fp.getCustomProperties().values());

} catch (SQLException sqlEX) {
throw new FeatureAccessException(CANNOT_CHECK_FEATURE_EXISTENCE_ERROR_RELATED_TO_DATABASE, sqlEX);
} finally {
// CREATE CUSTOM PROPERTIES
for (Property property : fp.getCustomProperties().values()) {
ps = createCustomProperty(sqlConn, fp.getUid(), property);
closeStatement(ps);
closeConnection(sqlConn);
ps = null;
}
} catch (SQLException sqlEX) {
throw new FeatureAccessException(CANNOT_CHECK_FEATURE_EXISTENCE_ERROR_RELATED_TO_DATABASE, sqlEX);
} finally {
closeStatement(ps);
closeConnection(sqlConn);
}
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -558,6 +563,7 @@ public void createCustomProperties(String uid, Collection <Property<?> > props)
sqlConn.commit();

} catch (SQLException sqlEX) {
rollback(sqlConn);
throw new FeatureAccessException(CANNOT_CHECK_FEATURE_EXISTENCE_ERROR_RELATED_TO_DATABASE, sqlEX);
} finally {
closeStatement(ps);
Expand Down