com.primix.vlib.ejb.impl
Class OperationsBean

java.lang.Object
  |
  +--com.primix.vlib.ejb.impl.OperationsBean
All Implemented Interfaces:
EnterpriseBean, IMailMessageConstants, java.io.Serializable, SessionBean
Direct Known Subclasses:
BookQueryBean

public class OperationsBean
extends java.lang.Object
implements SessionBean, IMailMessageConstants

Implementation of the IOperations stateless session bean.

Implenents a number of stateless operations for the front end.

Version:
$Id: OperationsBean.java,v 1.7 2001/08/27 22:19:12 hship Exp $
Author:
Howard Ship
See Also:
Serialized Form

Field Summary
static java.lang.String MAIL_QUEUE_JNDI_NAME
           
 
Fields inherited from interface com.primix.vlib.ejb.IMailMessageConstants
CONTENT, EMAIL_ADDRESS, SUBJECT
 
Constructor Summary
OperationsBean()
           
 
Method Summary
 java.lang.Integer addBook(java.util.Map attributes)
          Adds a new book, verifying that the publisher and holder actually exist.
 java.lang.Integer addBook(java.util.Map attributes, java.lang.String publisherName)
          Adds a book, which will be owned and held by the specified owner.
protected  void addSubstringSearch(StatementAssembly assembly, java.lang.String column, java.lang.String value)
           
 Book borrowBook(java.lang.Integer bookPrimaryKey, java.lang.Integer borrowerPrimaryKey)
          Finds the book and borrower (by thier primary keys) and updates the book.
protected  StatementAssembly buildBaseBookQuery()
           
protected  StatementAssembly buildBasePersonQuery()
           
protected  void close(java.sql.Connection connection, IStatement statement, java.sql.ResultSet resultSet)
          Closes the resultSet (if not null), then the statement (if not null), then the Connection (if not null).
protected  Book convertRowToBook(java.sql.ResultSet set, java.lang.Object[] columns)
          Translates the next row from the result set into a Book.
protected  Person convertRowToPerson(java.sql.ResultSet set, java.lang.Object[] columns)
          Translates the next row from the result set into a Person.
 Book deleteBook(java.lang.Integer bookPrimaryKey)
           
 void ejbActivate()
          Does nothing, not invoked in stateless session beans.
 void ejbCreate()
          Sets up the bean.
 void ejbPassivate()
          Does nothing, not invoked in stateless session beans.
 void ejbRemove()
          Closes the mail queue session, if it has been opened.
 Book getBook(java.lang.Integer primaryKey)
          Retrieves a single Book by its primary key.
 java.util.Map getBookAttributes(java.lang.Integer primaryKey)
           
protected  java.sql.Connection getConnection()
          Gets a new connection from the data source.
protected  QueueSender getMailQueueSender()
           
protected  QueueSession getMailQueueSession()
           
 Person getPerson(java.lang.Integer primaryKey)
          Gets the Person for primary key.
 java.util.Map getPersonAttributes(java.lang.Integer primaryKey)
           
 Person[] getPersons()
          Fetchs all IPerson beans in the database and converts them to Person objects.
 Publisher[] getPublishers()
           
 Person login(java.lang.String email, java.lang.String password)
           
 Person registerNewUser(java.lang.String firstName, java.lang.String lastName, java.lang.String email, java.lang.String password)
          Attempts to register a new user, first checking that the e-mail and names are unique.
 Book returnBook(java.lang.Integer bookPrimaryKey)
           
protected  void sendMail(java.lang.String emailAddress, java.lang.String subject, java.lang.String content)
           
 void setSessionContext(SessionContext value)
           
 void transferBooks(java.lang.Integer newOwnerPrimaryKey, java.lang.Integer[] books)
          Transfers a number of books to a new owner.
 void updateBook(java.lang.Integer bookPK, java.util.Map attributes)
          Updates a book.
 void updateBook(java.lang.Integer bookPK, java.util.Map attributes, java.lang.String publisherName)
          Updates a book, adding a new Publisher at the same time.
 void updatePerson(java.lang.Integer primaryKey, java.util.Map attributes)
           
 void updatePersons(Person[] updated, java.lang.Integer[] resetPassword, java.lang.Integer[] deleted, java.lang.Integer adminPK)
           
 void updatePublishers(Publisher[] updated, java.lang.Integer[] deleted)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAIL_QUEUE_JNDI_NAME

public static final java.lang.String MAIL_QUEUE_JNDI_NAME
Constructor Detail

OperationsBean

public OperationsBean()
Method Detail

ejbCreate

public void ejbCreate()
Sets up the bean. Locates the DataSource for the bean as jdbc/dataSource within the ENC; this data source is later used by getConnection().

ejbRemove

public void ejbRemove()
Closes the mail queue session, if it has been opened.
Specified by:
ejbRemove in interface SessionBean

ejbPassivate

public void ejbPassivate()
Does nothing, not invoked in stateless session beans.
Specified by:
ejbPassivate in interface SessionBean

setSessionContext

public void setSessionContext(SessionContext value)
Specified by:
setSessionContext in interface SessionBean

ejbActivate

public void ejbActivate()
Does nothing, not invoked in stateless session beans.
Specified by:
ejbActivate in interface SessionBean

borrowBook

public Book borrowBook(java.lang.Integer bookPrimaryKey,
                       java.lang.Integer borrowerPrimaryKey)
                throws FinderException,
                       java.rmi.RemoteException,
                       BorrowException
Finds the book and borrower (by thier primary keys) and updates the book.

The attributes of the borrowed book is returned.


addBook

public java.lang.Integer addBook(java.util.Map attributes)
                          throws CreateException,
                                 java.rmi.RemoteException
Adds a new book, verifying that the publisher and holder actually exist.

addBook

public java.lang.Integer addBook(java.util.Map attributes,
                                 java.lang.String publisherName)
                          throws CreateException,
                                 java.rmi.RemoteException
Adds a book, which will be owned and held by the specified owner.

The publisherName may either be the name of a known publisher, or a new name. A new IPublisher will be created as necessary.

Returns the newly created book, as a Map of attributes.


updateBook

public void updateBook(java.lang.Integer bookPK,
                       java.util.Map attributes)
                throws FinderException,
                       java.rmi.RemoteException
Updates a book.

Returns the updated book.

Parameters:
bookPK - The primary key of the book to update.

updateBook

public void updateBook(java.lang.Integer bookPK,
                       java.util.Map attributes,
                       java.lang.String publisherName)
                throws CreateException,
                       FinderException,
                       java.rmi.RemoteException
Updates a book, adding a new Publisher at the same time.
Parameters:
bookPK - The primary key of the book to update.
attributes - attributes to change
publisherName - The name of the new publisher.
Throws:
FinderException - if the book, holder or publisher can not be located.
CreateException - if the IPublisher can not be created.

updatePerson

public void updatePerson(java.lang.Integer primaryKey,
                         java.util.Map attributes)
                  throws FinderException,
                         java.rmi.RemoteException

getPublishers

public Publisher[] getPublishers()

getPersons

public Person[] getPersons()
Fetchs all IPerson beans in the database and converts them to Person objects. Returns the Persons sorted by last name, then first.

getPerson

public Person getPerson(java.lang.Integer primaryKey)
                 throws FinderException
Gets the Person for primary key.
Throws:
FinderException - if the Person does not exist.

login

public Person login(java.lang.String email,
                    java.lang.String password)
             throws java.rmi.RemoteException,
                    LoginException

getPersonAttributes

public java.util.Map getPersonAttributes(java.lang.Integer primaryKey)
                                  throws FinderException,
                                         java.rmi.RemoteException

getBook

public Book getBook(java.lang.Integer primaryKey)
             throws FinderException
Retrieves a single Book by its primary key.
Throws:
FinderException - if the Book does not exist.

getBookAttributes

public java.util.Map getBookAttributes(java.lang.Integer primaryKey)
                                throws FinderException,
                                       java.rmi.RemoteException

registerNewUser

public Person registerNewUser(java.lang.String firstName,
                              java.lang.String lastName,
                              java.lang.String email,
                              java.lang.String password)
                       throws RegistrationException,
                              CreateException,
                              java.rmi.RemoteException
Attempts to register a new user, first checking that the e-mail and names are unique. Returns the primary key of the new IPerson.

deleteBook

public Book deleteBook(java.lang.Integer bookPrimaryKey)
                throws RemoveException,
                       java.rmi.RemoteException

transferBooks

public void transferBooks(java.lang.Integer newOwnerPrimaryKey,
                          java.lang.Integer[] books)
                   throws FinderException,
                          java.rmi.RemoteException
Transfers a number of books to a new owner.

updatePublishers

public void updatePublishers(Publisher[] updated,
                             java.lang.Integer[] deleted)
                      throws FinderException,
                             RemoveException,
                             java.rmi.RemoteException

updatePersons

public void updatePersons(Person[] updated,
                          java.lang.Integer[] resetPassword,
                          java.lang.Integer[] deleted,
                          java.lang.Integer adminPK)
                   throws FinderException,
                          RemoveException,
                          java.rmi.RemoteException

convertRowToBook

protected Book convertRowToBook(java.sql.ResultSet set,
                                java.lang.Object[] columns)
                         throws java.sql.SQLException
Translates the next row from the result set into a Book.

This works with queries generated by buildBaseBookQuery().


buildBaseBookQuery

protected StatementAssembly buildBaseBookQuery()

addSubstringSearch

protected void addSubstringSearch(StatementAssembly assembly,
                                  java.lang.String column,
                                  java.lang.String value)

close

protected void close(java.sql.Connection connection,
                     IStatement statement,
                     java.sql.ResultSet resultSet)
Closes the resultSet (if not null), then the statement (if not null), then the Connection (if not null). Exceptions are written to System.out.

getConnection

protected java.sql.Connection getConnection()
Gets a new connection from the data source.

buildBasePersonQuery

protected StatementAssembly buildBasePersonQuery()

convertRowToPerson

protected Person convertRowToPerson(java.sql.ResultSet set,
                                    java.lang.Object[] columns)
                             throws java.sql.SQLException
Translates the next row from the result set into a Person.

This works with queries generated by buildBasePersonQuery().


returnBook

public Book returnBook(java.lang.Integer bookPrimaryKey)
                throws java.rmi.RemoteException,
                       FinderException

getMailQueueSession

protected QueueSession getMailQueueSession()
                                    throws NamingException,
                                           JMSException

getMailQueueSender

protected QueueSender getMailQueueSender()
                                  throws NamingException,
                                         JMSException

sendMail

protected void sendMail(java.lang.String emailAddress,
                        java.lang.String subject,
                        java.lang.String content)
                 throws EJBException