Beispiel #1
0
  public synchronized BookPrx createBook(BookDescription description, Ice.Current current)
      throws DatabaseException, BookExistsException {
    BookPrx book = isbnToBook(description.isbn, current.adapter);

    try {
      book.ice_ping();

      //
      // The book already exists.
      //
      throw new BookExistsException();
    } catch (Ice.ObjectNotExistException e) {
      //
      // Book doesn't exist, ignore the exception.
      //
    }

    //
    // Create a new book Servant.
    //
    BookI bookI = new BookI(this);
    bookI.description = description;

    Ice.Identity ident = createBookIdentity(description.isbn);

    //
    // Create a new Ice Object in the evictor, using the new
    // identity and the new Servant.
    //
    // This can throw EvictorDeactivatedException (which indicates
    // an internal error). The exception is currently ignored.
    //
    _evictor.add(bookI, ident);

    try {
      //
      // Add the isbn number to the authors map.
      //
      String[] isbnSeq = _authors.get(description.authors);
      int length = (isbnSeq == null) ? 0 : isbnSeq.length;
      String[] newIsbnSeq = new String[length + 1];

      if (isbnSeq != null) {
        System.arraycopy(isbnSeq, 0, newIsbnSeq, 0, length);
      }
      newIsbnSeq[length] = description.isbn;

      _authors.fastPut(description.authors, newIsbnSeq);

      return book;
    } catch (Freeze.DatabaseException ex) {
      DatabaseException e = new DatabaseException();
      e.message = ex.message;
      throw e;
    }
  }
Beispiel #2
0
  //
  // No locking is necessary since no internal mutable state is
  // accessed.
  //
  public BookPrx findByIsbn(String isbn, Ice.Current current) throws DatabaseException {
    try {
      BookPrx book = isbnToBook(isbn, current.adapter);
      book.ice_ping();

      return book;
    } catch (Ice.ObjectNotExistException ex) {
      //
      // Book doesn't exist, return a null proxy.
      //
      return null;
    }
  }