summaryrefslogtreecommitdiff
path: root/java/demo/Database/library/LibraryI.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2008-08-22 11:34:11 -0230
committerMatthew Newhook <matthew@zeroc.com>2008-08-22 11:34:11 -0230
commitb6477cc39b9fc204c9bd960ce893dfaed32c8d47 (patch)
tree5d95b60d462fb21da2b32c51f60b4c6884d21640 /java/demo/Database/library/LibraryI.java
parentmore fixes to JDBC demo (diff)
downloadice-b6477cc39b9fc204c9bd960ce893dfaed32c8d47.tar.bz2
ice-b6477cc39b9fc204c9bd960ce893dfaed32c8d47.tar.xz
ice-b6477cc39b9fc204c9bd960ce893dfaed32c8d47.zip
Moved to using a dispatch interceptor model.
Diffstat (limited to 'java/demo/Database/library/LibraryI.java')
-rw-r--r--java/demo/Database/library/LibraryI.java64
1 files changed, 15 insertions, 49 deletions
diff --git a/java/demo/Database/library/LibraryI.java b/java/demo/Database/library/LibraryI.java
index 7f01f9f87c6..ac160b629cc 100644
--- a/java/demo/Database/library/LibraryI.java
+++ b/java/demo/Database/library/LibraryI.java
@@ -20,17 +20,11 @@ class LibraryI extends _LibraryDisp
queryByIsbn(String isbn, BookDescriptionHolder first, BookQueryResultPrxHolder result, Ice.Current current)
throws NoResultsException
{
- SessionI session = SessionI.getSession(current.id);
- if(session == null)
- {
- // No associated session.
- throw new Ice.ObjectNotExistException();
- }
- session.reapQueries();
-
- SQLRequestContext context = SQLRequestContext.getCurrentContext();
+ SessionSQLRequestContext context = (SessionSQLRequestContext)SQLRequestContext.getCurrentContext();
assert context != null;
+ context.getSession().reapQueries();
+
try
{
java.sql.PreparedStatement stmt = context.prepareStatement("SELECT * FROM books WHERE isbn LIKE ?");
@@ -47,16 +41,14 @@ class LibraryI extends _LibraryDisp
// The SQLRequestContext is now owned by the query
// implementation.
context.obtain();
- BookQueryResultI impl = new BookQueryResultI(_logger, context, rs);
+ BookQueryResultI impl = new BookQueryResultI(context, rs);
result.value = BookQueryResultPrxHelper.uncheckedCast(current.adapter.addWithUUID(impl));
- session.add(result.value, impl);
+ context.getSession().add(result.value, impl);
}
}
catch(java.sql.SQLException e)
{
- // Log the error, and raise an UnknownException.
- error(e);
- Ice.UnknownException ex = new Ice.UnknownException();
+ JDBCException ex = new JDBCException();
ex.initCause(e);
throw ex;
}
@@ -66,17 +58,11 @@ class LibraryI extends _LibraryDisp
queryByAuthor(String author, BookDescriptionHolder first, BookQueryResultPrxHolder result, Ice.Current current)
throws NoResultsException
{
- SessionI session = SessionI.getSession(current.id);
- if(session == null)
- {
- // No associated session.
- throw new Ice.ObjectNotExistException();
- }
- session.reapQueries();
-
- SQLRequestContext context = SQLRequestContext.getCurrentContext();
+ SessionSQLRequestContext context = (SessionSQLRequestContext)SQLRequestContext.getCurrentContext();
assert context != null;
+ context.getSession().reapQueries();
+
try
{
// Find each of the authors.
@@ -118,16 +104,14 @@ class LibraryI extends _LibraryDisp
{
// The SQLRequestContext is now owned by the query implementation.
context.obtain();
- BookQueryResultI impl = new BookQueryResultI(_logger, context, rs);
+ BookQueryResultI impl = new BookQueryResultI(context, rs);
result.value = BookQueryResultPrxHelper.uncheckedCast(current.adapter.addWithUUID(impl));
- session.add(result.value, impl);
+ context.getSession().add(result.value, impl);
}
}
catch(java.sql.SQLException e)
{
- // Log the error, and raise an UnknownException.
- error(e);
- Ice.UnknownException ex = new Ice.UnknownException();
+ JDBCException ex = new JDBCException();
ex.initCause(e);
throw ex;
}
@@ -137,7 +121,7 @@ class LibraryI extends _LibraryDisp
createBook(String isbn, String title, java.util.List<String> authors, Ice.Current current)
throws BookExistsException
{
- SQLRequestContext context = SQLRequestContext.getCurrentContext();
+ SessionSQLRequestContext context = (SessionSQLRequestContext)SQLRequestContext.getCurrentContext();
assert context != null;
try
{
@@ -211,35 +195,17 @@ class LibraryI extends _LibraryDisp
assert count == 1;
}
- // Commit the transaction.
- context.commit();
-
return BookPrxHelper.uncheckedCast(current.adapter.createProxy(BookI.createIdentity(bookId)));
}
catch(java.sql.SQLException e)
{
- // Log the error, and raise an UnknownException.
- error(e);
- Ice.UnknownException ex = new Ice.UnknownException();
+ JDBCException ex = new JDBCException();
ex.initCause(e);
throw ex;
}
}
- LibraryI(Ice.Logger logger)
- {
- _logger = logger;
- }
-
- private void
- error(Exception ex)
+ LibraryI()
{
- java.io.StringWriter sw = new java.io.StringWriter();
- java.io.PrintWriter pw = new java.io.PrintWriter(sw);
- ex.printStackTrace(pw);
- pw.flush();
- _logger.error("LibraryI: error:\n" + sw.toString());
}
-
- private Ice.Logger _logger;
}