server
Class DaoImpl

java.lang.Object
  extended by server.DaoImpl
All Implemented Interfaces:
DAO<java.lang.Long,java.io.Serializable>

public class DaoImpl
extends java.lang.Object
implements DAO<java.lang.Long,java.io.Serializable>

This class implements the client side of a DAO. This DAO is general enough to deal with any object that is serializable. The client DAO is not in charge of opening the communication channel. Instead, it receives the in and out channels from an Invoker. In this way, the users of the DAO do not have to worry about closing this channel.

Author:
Fernando

Field Summary
 
Fields inherited from interface server.DAO
ADD, DELETE, GET, HOST, PORT, SIZE, UPDATE
 
Constructor Summary
DaoImpl()
           
 
Method Summary
 void add(java.lang.Long key, java.io.Serializable value)
          Adds a new object into the database.
 void delete(java.lang.Long key)
          Removes an object from the database.
 java.io.Serializable get(java.lang.Long key)
          Returns a value, given a key.
 void setChannels(java.io.ObjectOutputStream newOut, java.io.ObjectInputStream newIn)
          This method establishes the channels that the DAO will use to communicate with the server side of the application.
 int size()
          Informs the number of elements stored in the database.
 void update(java.lang.Long key, java.io.Serializable value)
          Updates an object in the database.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DaoImpl

public DaoImpl()
Method Detail

setChannels

public final void setChannels(java.io.ObjectOutputStream newOut,
                              java.io.ObjectInputStream newIn)
This method establishes the channels that the DAO will use to communicate with the server side of the application.

Parameters:
newOut - channel to send data.
newIn - channel to receive data.

get

public final java.io.Serializable get(java.lang.Long key)
Returns a value, given a key.

Specified by:
get in interface DAO<java.lang.Long,java.io.Serializable>
Parameters:
key - the id of the object that must be found.
Returns:
V the value associated with the key K.

add

public final void add(java.lang.Long key,
                      java.io.Serializable value)
Adds a new object into the database.

Specified by:
add in interface DAO<java.lang.Long,java.io.Serializable>
Parameters:
key - the id of the object that will be inserted into the database.
value - the value associated with the key K.

delete

public final void delete(java.lang.Long key)
Removes an object from the database.

Specified by:
delete in interface DAO<java.lang.Long,java.io.Serializable>
Parameters:
key - the id of the object that will be removed.

update

public final void update(java.lang.Long key,
                         java.io.Serializable value)
Updates an object in the database.

Specified by:
update in interface DAO<java.lang.Long,java.io.Serializable>
Parameters:
key - the id of the object that will be replaced.
value - the new value of the object associated with the given key.

size

public final int size()
Informs the number of elements stored in the database.

Specified by:
size in interface DAO<java.lang.Long,java.io.Serializable>
Returns:
an integer number that tells how many objects are currently stored in the database.