summaryrefslogtreecommitdiff
path: root/java/demo/Database/library/BookQueryResultI.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2008-08-18 14:11:56 -0230
committerMatthew Newhook <matthew@zeroc.com>2008-08-18 14:11:56 -0230
commit81092d2fedc964062ac30f03cad4bb6469aafa1b (patch)
treea442196a518fae1a1eaa2ff9185142a73460807f /java/demo/Database/library/BookQueryResultI.java
parentremove QueryActiveException. (diff)
downloadice-81092d2fedc964062ac30f03cad4bb6469aafa1b.tar.bz2
ice-81092d2fedc964062ac30f03cad4bb6469aafa1b.tar.xz
ice-81092d2fedc964062ac30f03cad4bb6469aafa1b.zip
SQL setup is now more automatic.
Diffstat (limited to 'java/demo/Database/library/BookQueryResultI.java')
-rw-r--r--java/demo/Database/library/BookQueryResultI.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/java/demo/Database/library/BookQueryResultI.java b/java/demo/Database/library/BookQueryResultI.java
new file mode 100644
index 00000000000..ae650fe111a
--- /dev/null
+++ b/java/demo/Database/library/BookQueryResultI.java
@@ -0,0 +1,109 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+import Demo.*;
+
+class BookQueryResultI extends _BookQueryResultDisp
+{
+ // The query result owns the java.sql.Connection object until
+ // destroyed.
+ BookQueryResultI(Ice.Logger logger, RequestContext context, java.sql.ResultSet rs)
+ {
+ _logger = logger;
+ _context = context;
+ _rs = rs;
+ }
+
+ synchronized public java.util.List<BookDescription>
+ next(int n, Ice.BooleanHolder destroyed, Ice.Current current)
+ {
+ if(_destroyed)
+ {
+ throw new Ice.ObjectNotExistException();
+ }
+ destroyed.value = false;
+ java.util.List<BookDescription> l = new java.util.LinkedList<BookDescription>();
+ if(n <= 0)
+ {
+ return l;
+ }
+ boolean next = true;
+ try
+ {
+ for(int i = 0; i < n && next; ++i)
+ {
+ l.add(BookI.extractDescription(_context, _rs, current.adapter));
+ next = _rs.next();
+ }
+ }
+ catch(java.sql.SQLException e)
+ {
+ // Log the error, and raise an UnknownException.
+ error(e);
+ Ice.UnknownException ex = new Ice.UnknownException();
+ ex.initCause(e);
+ throw ex;
+ }
+
+ if(!next)
+ {
+ try
+ {
+ destroyed.value = true;
+ destroy(current);
+ }
+ catch(Exception e)
+ {
+ // Ignore.
+ }
+ }
+
+ return l;
+ }
+
+ synchronized public void
+ destroy(Ice.Current current)
+ {
+ if(_destroyed)
+ {
+ throw new Ice.ObjectNotExistException();
+ }
+ _destroyed = true;
+ _context.release();
+
+ current.adapter.remove(current.id);
+ }
+
+ // Called on application shutdown by the Library.
+ synchronized public void
+ shutdown()
+ {
+ if(!_destroyed)
+ {
+ _destroyed = true;
+ _context.release();
+ }
+ }
+
+ private void
+ error(Exception ex)
+ {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.PrintWriter pw = new java.io.PrintWriter(sw);
+ ex.printStackTrace(pw);
+ pw.flush();
+ _logger.error("BookQueryResultI: error:\n" + sw.toString());
+ }
+
+ private Ice.Logger _logger;
+ private RequestContext _context;
+ private java.sql.ResultSet _rs;
+ private boolean _destroyed = false;
+}
+