diff options
author | Simon Rettberg | 2017-05-04 12:06:32 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-05-04 12:06:32 +0200 |
commit | 46bdd466d7165a1fd675301873b503d214403a18 (patch) | |
tree | 07cab5246e4a8d1858ee3bdbad755f7eaeec7a86 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers | |
parent | [server] Fix query parametrization (diff) | |
download | tutor-module-46bdd466d7165a1fd675301873b503d214403a18.tar.gz tutor-module-46bdd466d7165a1fd675301873b503d214403a18.tar.xz tutor-module-46bdd466d7165a1fd675301873b503d214403a18.zip |
[server] Try to work around dropped email notifications
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers')
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java index 79b16e66..b9209686 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbImage.java @@ -471,7 +471,7 @@ public class DbImage { /** * Mark given image for deletion. The image is marked for deletion by - * setting the expire timestamp to the current date, and by setting the + * setting the expire timestamp to the past, and by setting the * image disabled and invalid. Next time the cleanup task runs, the image * will be deleted. * @@ -485,17 +485,27 @@ public class DbImage { List<String> affectedList; try (MysqlConnection connection = Database.getConnection()) { // Disable version in question + MysqlStatement checkStmt = connection.prepareStatement("SELECT imageversionid FROM" + + " imageversion WHERE imageversionid = :versionid AND" + + " (expiretime > UNIX_TIMESTAMP() OR isvalid <> 0)"); MysqlStatement disableStmt = connection.prepareStatement("UPDATE imageversion SET" + " expiretime = 1234567890, isvalid = 0" + " WHERE imageversionid = :versionid"); affectedList = new ArrayList<>(imageVersionIds.length); for (String imageVersionId : imageVersionIds) { if (imageVersionId == null) continue; + // Query state explicitly instead of relying on affected rows, as it's + // broken depending on java version, mysql version and other things + checkStmt.setString("versionid", imageVersionId); + ResultSet cr = checkStmt.executeQuery(); + if (!cr.next()) + continue; + // Was not disabled already, do so disableStmt.setString("versionid", imageVersionId); - if (disableStmt.executeUpdate() != 0) { - affectedList.add(imageVersionId); - } + affectedList.add(imageVersionId); } + // Commit what we did so far + connection.commit(); if (!affectedList.isEmpty()) { updateLatestVersion(connection, affectedList.toArray(new String[affectedList.size()])); } @@ -712,8 +722,10 @@ public class DbImage { String imageBaseId) throws TNotFoundException, SQLException { if (imageBaseId == null) { imageBaseId = DbImage.getBaseIdForVersionId(connection, changingImageVersionId); - if (imageBaseId == null) + if (imageBaseId == null) { + LOGGER.warn("versionValidityChanged for non-existent version " + changingImageVersionId); throw new TNotFoundException(); + } } // Determine new latest version, as we might have to update the imagebase and lecture tables List<LocalImageVersion> versions = DbImage.getLocalImageVersions(connection, imageBaseId); @@ -741,8 +753,8 @@ public class DbImage { // Switch any lectures linking to this version if applicable if (changingVersion.isValid) { // The version that changed became valid. In case it was the latest version (by date), this is now - // the version to be used by auto-updating lectures. If it wasn't the latest version, the following call will - // do nothing + // the version to be used by auto-updating lectures. If it wasn't the latest version, the following + // call will do nothing DbLecture.autoUpdateUsedImage(connection, imageBaseId, latestVersion); } else { // The version that changed is now invalid. Switch any lecture using it to the latest |