edu.northwestern.at.wordhoard.server
Class WordHoardSessionImpl

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by edu.northwestern.at.wordhoard.server.WordHoardSessionImpl
All Implemented Interfaces:
WordHoardSession, java.io.Serializable, java.rmi.Remote

public class WordHoardSessionImpl
extends java.rmi.server.UnicastRemoteObject
implements WordHoardSession

Session remote object implementation.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
WordHoardSessionImpl()
          Creates a new session.
 
Method Summary
 java.lang.Long createOrUpdateAccount(Account account)
          Creates or updates an account.
 java.lang.Long createUserDataObject(UserDataObject userDataObject)
          Creates a user data object.
 void deleteAccount(java.lang.Long id)
          Deletes an account.
 void deleteUserDataObject(java.lang.Class udoClass, java.lang.Long id)
          Deletes a user data object.
 void deleteWordSet(WordSet wordSet)
          Deletes a word set.
 void endSession()
          Ends the session.
 java.util.List getAccounts()
          Gets all the accounts.
(package private) static void initialize()
          Initializes the class.
protected  int insertViaSQL(java.lang.String insertString, org.hibernate.Session session)
          Insert data via SQL.
 Account login(java.lang.String username, java.lang.String password)
          Logs in.
 void logMessage(int level, java.lang.String msg)
          Logs a message.
 void logout()
          Logs out.
 int performBatchInserts(java.lang.String[] insertStatements)
          Performs batch inserts using prepared MySQL insert statements.
 void tickle()
          Tickles the session.
 java.lang.String toString()
          Returns a string representation of the session.
 java.lang.Long updateUserDataObject(UserDataObject userDataObject, UserDataObjectUpdater userDataObjectUpdater)
          Updates a user data object.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WordHoardSessionImpl

WordHoardSessionImpl()
               throws java.rmi.RemoteException
Creates a new session.

Throws:
java.rmi.RemoteException
Method Detail

endSession

public void endSession()
                throws java.rmi.RemoteException
Ends the session.

Specified by:
endSession in interface WordHoardSession
Throws:
java.rmi.RemoteException

tickle

public void tickle()
            throws java.rmi.RemoteException
Tickles the session.

Clients should tickle their sessions every 30 minutes. Sessions which go untickled for 2 hours are considered to be dead and are timed out and terminated.

Specified by:
tickle in interface WordHoardSession
Throws:
java.rmi.RemoteException

logMessage

public void logMessage(int level,
                       java.lang.String msg)
                throws java.rmi.RemoteException
Logs a message.

Specified by:
logMessage in interface WordHoardSession
Parameters:
level - Log message level.
msg - Log message.
Throws:
java.rmi.RemoteException

login

public Account login(java.lang.String username,
                     java.lang.String password)
              throws java.rmi.RemoteException
Logs in.

Logins are not permitted using the special "system" account.

Specified by:
login in interface WordHoardSession
Parameters:
username - Username.
password - Password.
Returns:
Account record with password set to null if login successful. Null if login unsuccessful.
Throws:
java.rmi.RemoteException

logout

public void logout()
            throws java.rmi.RemoteException
Logs out.

Specified by:
logout in interface WordHoardSession
Throws:
java.rmi.RemoteException

getAccounts

public java.util.List getAccounts()
                           throws java.rmi.RemoteException,
                                  WordHoardError
Gets all the accounts.

Specified by:
getAccounts in interface WordHoardSession
Returns:
List of all accounts in increasing order by username, without the special "system" account.
Throws:
java.rmi.RemoteException
WordHoardError

createOrUpdateAccount

public java.lang.Long createOrUpdateAccount(Account account)
                                     throws java.rmi.RemoteException,
                                            WordHoardError
Creates or updates an account.

Specified by:
createOrUpdateAccount in interface WordHoardSession
Parameters:
account - Account.
Returns:
Id of the account.
Throws:
java.rmi.RemoteException
WordHoardError

deleteAccount

public void deleteAccount(java.lang.Long id)
                   throws java.rmi.RemoteException,
                          WordHoardError
Deletes an account.

Specified by:
deleteAccount in interface WordHoardSession
Parameters:
id - Account id.
Throws:
java.rmi.RemoteException
WordHoardError

toString

public java.lang.String toString()
Returns a string representation of the session.

Overrides:
toString in class java.rmi.server.RemoteObject
Returns:
String representation.

initialize

static void initialize()
                throws java.lang.Exception
Initializes the class.

Throws:
java.lang.Exception

createUserDataObject

public java.lang.Long createUserDataObject(UserDataObject userDataObject)
                                    throws java.rmi.RemoteException,
                                           WordHoardError,
                                           BadOwnerException,
                                           PersistenceException
Creates a user data object.

Specified by:
createUserDataObject in interface WordHoardSession
Parameters:
userDataObject - User data object.
Returns:
Id of the object.
Throws:
java.rmi.RemoteException
WordHoardError
BadOwnerException
PersistenceException

updateUserDataObject

public java.lang.Long updateUserDataObject(UserDataObject userDataObject,
                                           UserDataObjectUpdater userDataObjectUpdater)
                                    throws java.rmi.RemoteException,
                                           WordHoardError,
                                           BadOwnerException,
                                           PersistenceException
Updates a user data object.

Specified by:
updateUserDataObject in interface WordHoardSession
Parameters:
userDataObject - The user data object to update.
userDataObjectUpdater - Method which updates fields of user data object.
Returns:
true if update succeeds, false otherwise.
Throws:
BadOwnerException - if user is not logged in or is not the owner of the user data object.
java.rmi.RemoteException
WordHoardError
PersistenceException

deleteUserDataObject

public void deleteUserDataObject(java.lang.Class udoClass,
                                 java.lang.Long id)
                          throws java.rmi.RemoteException,
                                 WordHoardError,
                                 PersistenceException
Deletes a user data object.

Specified by:
deleteUserDataObject in interface WordHoardSession
Parameters:
udoClass - Class of user data object to delete.
id - ID of user data object to delete.
Throws:
PersistenceException
java.rmi.RemoteException
WordHoardError

deleteWordSet

public void deleteWordSet(WordSet wordSet)
                   throws java.rmi.RemoteException,
                          WordHoardError,
                          PersistenceException
Deletes a word set.

Specified by:
deleteWordSet in interface WordHoardSession
Parameters:
wordSet - The word set to delete.
Throws:
PersistenceException
java.rmi.RemoteException
WordHoardError

insertViaSQL

protected int insertViaSQL(java.lang.String insertString,
                           org.hibernate.Session session)
                    throws PersistenceException
Insert data via SQL.

Parameters:
insertString - The SQL insert string.
session - Persistence manager session.
Returns:
Count of objects inserted.
Throws:
PersistenceException -

This method provides for executing a MySQL batch insert query. This is much faster than using standard Hibernate facilities for batch inserts.


performBatchInserts

public int performBatchInserts(java.lang.String[] insertStatements)
                        throws java.rmi.RemoteException,
                               WordHoardError,
                               PersistenceException
Performs batch inserts using prepared MySQL insert statements.

Specified by:
performBatchInserts in interface WordHoardSession
Parameters:
insertStatements - String array of MySQL insert statements.
Returns:
count of inserts performed.
Throws:
PersistenceException
java.rmi.RemoteException
WordHoardError