From 20d2c296be85c4d62db749a2b5155063ebeceba8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 10 Aug 2016 19:05:43 +0200 Subject: [server] Fix DbLog: No DELAYED for InnoDB --- .../openslx/bwlp/sat/database/mappers/DbLog.java | 40 ++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLog.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLog.java index 97ab8f15..69cd5a3d 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLog.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLog.java @@ -7,6 +7,8 @@ import org.openslx.bwlp.sat.database.Database; import org.openslx.bwlp.sat.database.MysqlConnection; import org.openslx.bwlp.sat.database.MysqlStatement; import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; import org.openslx.util.Util; public class DbLog { @@ -21,25 +23,27 @@ public class DbLog { * null) * @param description Human readable description of the action being * performed - * @throws SQLException */ - public static void log(String userId, String targetId, String description) { - if (description == null) { - description = ""; - } - try (MysqlConnection connection = Database.getConnection()) { - MysqlStatement stmt = connection.prepareStatement("INSERT DELAYED INTO actionlog" - + " (dateline, userid, targetid, description) VALUES" - + " (:dateline, :userid, :targetid, :description)"); - stmt.setLong("dateline", Util.unixTime()); - stmt.setString("userid", userId); - stmt.setString("targetid", targetId); - stmt.setString("description", description); - stmt.executeUpdate(); - connection.commit(); - } catch (SQLException e) { - LOGGER.error("Query failed in DbLog.log()", e); - } + public static void log(final String userId, final String targetId, final String description) { + final long timeStamp = Util.unixTime(); + QuickTimer.scheduleOnce(new Task() { + @Override + public void fire() { + try (MysqlConnection connection = Database.getConnection()) { + MysqlStatement stmt = connection.prepareStatement("INSERT INTO actionlog" + + " (dateline, userid, targetid, description) VALUES" + + " (:dateline, :userid, :targetid, :description)"); + stmt.setLong("dateline", timeStamp); + stmt.setString("userid", userId); + stmt.setString("targetid", targetId); + stmt.setString("description", description == null ? "" : description); + stmt.executeUpdate(); + connection.commit(); + } catch (SQLException e) { + LOGGER.error("Query failed in DbLog.log()", e); + } + } + }); } public static void log(UserInfo user, String targetId, String description) { -- cgit v1.2.3-55-g7522