Last active
May 5, 2017 03:58
-
-
Save tjennings/cfc09cbe34d50f288b7771234ee3973f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/common/src/main/java/com/jes/services/EventsProcessor.java b/common/src/main/java/com/jes/services/EventsProcessor.java | |
index 614c6f4..761ae19 100644 | |
--- a/common/src/main/java/com/jes/services/EventsProcessor.java | |
+++ b/common/src/main/java/com/jes/services/EventsProcessor.java | |
@@ -7,6 +7,7 @@ import org.javalite.activejdbc.Base; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
+import java.sql.SQLException; | |
import java.util.concurrent.ConcurrentLinkedQueue; | |
import java.util.concurrent.locks.LockSupport; | |
@@ -47,25 +48,30 @@ public class EventsProcessor extends Thread { | |
private void flush() { | |
logger.debug("Flush main events queue..."); | |
- while(!queue.isEmpty()) { | |
- Event event = queue.poll(); | |
- try { | |
- openDBConnection(); | |
- if (event != null) { | |
- // TODO: temporary loggers to localize a problem! | |
- logger.info("Event is NEW: " + event.isNew()); | |
- logger.info("Event is MODIFIED: " + event.isModified()); | |
- if (event.isNew() || event.isModified()) { | |
- event.saveIt(); | |
- logger.info("Event saved"); | |
+ try { | |
+ openDBConnection(); | |
+ //TODO - working around an activejdbc bug where autocommit setting leaks state into the pool | |
+ Base.connection().setAutoCommit(true); | |
+ while(!queue.isEmpty()) { | |
+ Event event = queue.poll(); | |
+ if (event != null) { | |
+ try { | |
+ // TODO: temporary loggers to localize a problem! | |
+ logger.info("Event is NEW: " + event.isNew()); | |
+ logger.info("Event is MODIFIED: " + event.isModified()); | |
+ if (event.isNew() || event.isModified()) { | |
+ event.saveIt(); | |
+ logger.info("Event saved"); | |
+ } | |
+ } catch(Exception e) { | |
+ logger.error("Event: " + event, e); | |
+ } | |
+ } else { | |
+ logger.info("Event is NULL"); | |
} | |
- } else { | |
- logger.info("Event is NULL"); | |
- } | |
- } catch(Exception e) { | |
- closeDBConnection(); | |
- logger.error("Event: " + event, e); | |
} | |
+ } catch(Exception e) { | |
+ closeDBConnection(); | |
} | |
} | |
@@ -91,7 +97,7 @@ public class EventsProcessor extends Thread { | |
LockSupport.unpark(this); | |
} | |
- private void openDBConnection() { | |
+ private void openDBConnection() throws SQLException { | |
if (!Base.hasConnection()) { | |
DBUtil.openConnection(); | |
logger.info("DB connection opened"); | |
diff --git a/corrections/src/main/java/app/config/AppControllerConfig.java b/corrections/src/main/java/app/config/AppControllerConfig.java | |
index 8a98e55..8c4f51e 100644 | |
--- a/corrections/src/main/java/app/config/AppControllerConfig.java | |
+++ b/corrections/src/main/java/app/config/AppControllerConfig.java | |
@@ -21,6 +21,7 @@ public class AppControllerConfig extends AbstractControllerConfig { | |
@Override | |
public void before() { | |
super.before(); | |
+ //TODO - Do we really need to do this for every connection on every request? | |
for(Connection connection : DB.connections().values()) { | |
try { | |
connection.createStatement().execute("SET NAMES utf8mb4"); | |
@@ -29,6 +30,18 @@ public class AppControllerConfig extends AbstractControllerConfig { | |
} | |
} | |
} | |
+ | |
+ @Override | |
+ public void after() { | |
+ for (Connection connection : DB.connections().values()) { | |
+ try { | |
+ connection.setAutoCommit(true); | |
+ } catch(SQLException e) { | |
+ throw new RuntimeException("Switch to utf8mb4", e); | |
+ } | |
+ } | |
+ super.after(); | |
+ } | |
}, | |
new LoggingContextFilter(), | |
new AuthorizationFilter(), | |
diff --git a/corrections2/src/main/java/app/config/AppControllerConfig.java b/corrections2/src/main/java/app/config/AppControllerConfig.java | |
index e482da5..d4281ba 100644 | |
--- a/corrections2/src/main/java/app/config/AppControllerConfig.java | |
+++ b/corrections2/src/main/java/app/config/AppControllerConfig.java | |
@@ -29,6 +29,18 @@ public class AppControllerConfig extends AbstractControllerConfig { | |
} | |
} | |
} | |
+ | |
+ @Override | |
+ public void after() { | |
+ for (Connection connection : DB.connections().values()) { | |
+ try { | |
+ connection.setAutoCommit(true); | |
+ } catch(SQLException e) { | |
+ throw new RuntimeException("Switch to utf8mb4", e); | |
+ } | |
+ } | |
+ super.after(); | |
+ } | |
}, | |
new LoggingContextFilter(), | |
new AuthorizationFilter(), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment