web stats
Mirth Community - View Single Post - Best practices for managing DB connections and objects
View Single Post
Old 04-13-2016, 10:06 AM
ahart ahart is offline
OBX.2 Kenobi
Join Date: Oct 2014
Posts: 56
ahart is on a distinguished road
Question Best practices for managing DB connections and objects

So, I have a Mirth application where most all of the logic is in JavaScript.
I have code template functions where I have been consolidating all the common logic, much of which has to do with db operations, inserting rows, updating rows, searching for information.

Since many of these code template functions are called from within loops, I want to minimize the costly db operations, like getting db connections, preparing statements.

So, the way I'm currently doing it is that the calling script (the source transformer, a javascript writer destination, etc.) makes the db connection and prepares the statements, and so my code template functions expect global variables to exist for the db connection, the PreparedStatement objects they might need.

I could make many of the code template functions self contained, i.e., they make their own db connection, prepare a statement, and then execute it, but this would not accomplish that goal.

So, I'd like to figure out the best way to centralize this code. How do most people approach this? DB connections and PreparedStatement objects in the global map? Global channel map? Maybe a function template with loose declarations outside of a function?

What are the best practices? Specifically, for developing db related code template functions...
Reply With Quote