summaryrefslogtreecommitdiff
path: root/java/demo/Freeze/library/BookI.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2002-03-13 17:40:34 +0000
committerMatthew Newhook <matthew@zeroc.com>2002-03-13 17:40:34 +0000
commit56ff80265761eda3f54ef343c3654dd1aa4cce0c (patch)
tree56ca3d6b054f7edfe5c1f06f131d81656f2111ed /java/demo/Freeze/library/BookI.java
parentAdded project files for Freeze/library demo (diff)
downloadice-56ff80265761eda3f54ef343c3654dd1aa4cce0c.tar.bz2
ice-56ff80265761eda3f54ef343c3654dd1aa4cce0c.tar.xz
ice-56ff80265761eda3f54ef343c3654dd1aa4cce0c.zip
Added Freeze/library demo.
Diffstat (limited to 'java/demo/Freeze/library/BookI.java')
-rw-r--r--java/demo/Freeze/library/BookI.java118
1 files changed, 118 insertions, 0 deletions
diff --git a/java/demo/Freeze/library/BookI.java b/java/demo/Freeze/library/BookI.java
new file mode 100644
index 00000000000..22bbbd1af8c
--- /dev/null
+++ b/java/demo/Freeze/library/BookI.java
@@ -0,0 +1,118 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+class BookI extends Book
+{
+ //
+ // No read/write mutexes in Java - hence use native
+ // syncronization.
+ //
+
+ public BookDescription
+ getBookDescription(Ice.Current current)
+ {
+ //
+ // Immutable.
+ //
+ return _description;
+ }
+
+ synchronized public String
+ getRenterName(Ice.Current current)
+ throws BookNotRentedException
+ {
+ if (_rentalCustomerName.length() == 0)
+ {
+ throw new BookNotRentedException();
+ }
+ return _rentalCustomerName;
+ }
+
+ synchronized public void
+ rentBook(String name, Ice.Current current)
+ throws BookRentedException
+ {
+ if (_rentalCustomerName.length() != 0)
+ {
+ throw new BookRentedException();
+ }
+ _rentalCustomerName = name;
+ }
+
+ synchronized public void
+ returnBook(Ice.Current current)
+ throws BookNotRentedException
+ {
+ if (_rentalCustomerName.length() != 0)
+ {
+ throw new BookNotRentedException();
+ }
+ _rentalCustomerName = new String();;
+ }
+
+ synchronized public void
+ destroy(Ice.Current current)
+ throws DatabaseException
+ {
+ try
+ {
+ _library.remove(_description);
+
+ //
+ // This can throw EvictorDeactivatedException (which
+ // indicates an internal error). The exception is
+ // currently ignored.
+ //
+ _evictor.destroyObject(createIdentity(_description.isbn));
+ }
+ catch(Freeze.DBNotFoundException ex)
+ {
+ //
+ // Raised by remove. Ignore.
+ //
+ }
+ catch(Freeze.DBException ex)
+ {
+ DatabaseException e = new DatabaseException();
+ e.message = ex.message;
+ throw e;
+ }
+ }
+
+ public static Ice.Identity
+ createIdentity(String isbn)
+ {
+ //
+ // Note that the identity category is important since the
+ // locator was installed for the category 'book'.
+ //
+ Ice.Identity ident = new Ice.Identity();
+ ident.category = "book";
+ ident.name = isbn;
+
+ return ident;
+ }
+
+ BookI(LibraryI library, Freeze.Evictor evictor)
+ {
+ _library = library;
+ _evictor = evictor;
+
+ //
+ // This could be avoided by having two constructors (one for
+ // new creation of a book, and the other for restoring a
+ // previously saved book).
+ //
+ _rentalCustomerName = new String();
+ }
+
+ private LibraryI _library;
+ private Freeze.Evictor _evictor;
+}