summaryrefslogtreecommitdiff
path: root/java/demo/Database/library/SQLRequestContext.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2008-08-22 12:07:39 -0230
committerMatthew Newhook <matthew@zeroc.com>2008-08-22 12:07:39 -0230
commitba630ccacc8ee0b1735e263569107a5f309a3a2d (patch)
treeadbf1c264aae37bef60eb42350b203391ad3e2e1 /java/demo/Database/library/SQLRequestContext.java
parentMoved to using a dispatch interceptor model. (diff)
downloadice-ba630ccacc8ee0b1735e263569107a5f309a3a2d.tar.bz2
ice-ba630ccacc8ee0b1735e263569107a5f309a3a2d.tar.xz
ice-ba630ccacc8ee0b1735e263569107a5f309a3a2d.zip
use a library per session.
Diffstat (limited to 'java/demo/Database/library/SQLRequestContext.java')
-rw-r--r--java/demo/Database/library/SQLRequestContext.java35
1 files changed, 23 insertions, 12 deletions
diff --git a/java/demo/Database/library/SQLRequestContext.java b/java/demo/Database/library/SQLRequestContext.java
index 114c7a0558f..2b3050a9975 100644
--- a/java/demo/Database/library/SQLRequestContext.java
+++ b/java/demo/Database/library/SQLRequestContext.java
@@ -16,9 +16,9 @@
// request, or if obtain is called it must be destroyed manually by
// calling destroy.
//
-// When the request context is destroyed, the transaction is rolled
-// back, if not already committed, and all allocated resources are
-// released,
+// When the request context is destroyed, the transaction is either
+// automatically committed or rolled back, depending whether the
+// request executed successfully.
//
class SQLRequestContext
{
@@ -31,6 +31,16 @@ class SQLRequestContext
}
}
+ public static void
+ initialize(Ice.Logger logger, ConnectionPool pool)
+ {
+ assert _logger == null;
+ assert _pool == null;
+
+ _logger = logger;
+ _pool = pool;
+ }
+
public java.sql.PreparedStatement
prepareStatement(String sql)
throws java.sql.SQLException
@@ -66,6 +76,7 @@ class SQLRequestContext
public void
destroy(boolean commit)
{
+ // Must only be called on an obtained context.
assert _obtain;
destroyInternal(commit);
}
@@ -80,11 +91,9 @@ class SQLRequestContext
_logger.error(prefix + ": error:\n" + sw.toString());
}
- SQLRequestContext(Ice.Logger logger, ConnectionPool pool)
+ SQLRequestContext()
{
- _logger = logger;
- _pool = pool;
- _conn = pool.acquire();
+ _conn = _pool.acquire();
synchronized(_contextMap)
{
@@ -105,11 +114,13 @@ class SQLRequestContext
{
synchronized(_contextMap)
{
- // Remove the current context from the map.
+ // Remove the current context from the thread->context
+ // map.
SQLRequestContext context = _contextMap.remove(Thread.currentThread());
assert context != null;
}
+ // If the context was obtained then don't destroy.
if(!_obtain)
{
destroyInternal(commit);
@@ -154,16 +165,16 @@ class SQLRequestContext
_statements.clear();
_conn = null;
- _pool = null;
}
// A map of threads to request contexts.
private static java.util.Map<Thread, SQLRequestContext> _contextMap =
new java.util.HashMap<Thread, SQLRequestContext>();
- private Ice.Logger _logger;
- private boolean _trace = false;
- private ConnectionPool _pool;
+ private static Ice.Logger _logger = null;
+ private static ConnectionPool _pool = null;
+
+ private boolean _trace = true;
private java.util.List<java.sql.Statement> _statements = new java.util.LinkedList<java.sql.Statement>();
private java.sql.Connection _conn;
private boolean _obtain = false;