Class Database

java.lang.Object
  extended byDatabase
All Implemented Interfaces:
IDataBaseAccess

public class Database
extends Object
implements IDataBaseAccess


Constructor Summary
Database()
           
 
Method Summary
 boolean bind(int id, String adress)
          This binds the peers address to his id in the CNS, now he is marked as online.
 boolean checkPassword(int id, String pwd)
          This methode is used to check the peers identity.
 boolean connect()
          This methode connects the CNS to his DB.
 String getEmail(int id)
          Returns the email of the peer identified by id.
 String getFirstName(int id)
          Returns the first Name of the peer identified by id.
 String getImageURL(int id)
          Returns an URL to an image of the peer identified by id.
 String getLastName(int id)
          Returns the Last Name of the peer identified by id.
 String[] getSearchFields()
          This methode is used to get a list of searchable colums used for the search(java.lang.String, java.lang.String) method.
 boolean isOnline(int id)
          Returns true if the peer identified by id is online.
 String lookup(int id)
          Before we can send messages we need there address.
 int register(String first, String last, String email, String pwd, String land, String url)
          The first time the user starts an Caltella client, we has to register.
 boolean removePeer(int id)
          If ever called, this methode would remove the peer from the DB.
 int[] search(String colume, String searchString)
          Search the DB for one or more peers and return there ID's
 boolean setAllAtOnce(int id, String newFirstName, String newLastName, String newEmail, String newPassword, String newImageURL)
          This is mainly used to decrease network and DB load by sending all data at once.
 boolean setEmail(int id, String email)
           
 boolean setFirstName(int id, String firstname)
           
 boolean setImageURL(int id, String url)
           
 boolean setLastName(int id, String last)
           
 boolean setPassword(int id, String newPassword)
           
 boolean setStatus(int id, boolean status)
           
 boolean unbind(int id)
          This methode will change the peers status to offline.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Database

public Database()
Method Detail

connect

public boolean connect()
Description copied from interface: IDataBaseAccess
This methode connects the CNS to his DB.

Specified by:
connect in interface IDataBaseAccess

register

public int register(String first,
                    String last,
                    String email,
                    String pwd,
                    String land,
                    String url)
Description copied from interface: IDataBaseAccess
The first time the user starts an Caltella client, we has to register. This methode does just that.

Specified by:
register in interface IDataBaseAccess
Returns:
id The unice identification of the user. required for basicly all requests to the CNS.

bind

public boolean bind(int id,
                    String adress)
Description copied from interface: IDataBaseAccess
This binds the peers address to his id in the CNS, now he is marked as online.

No password is needed since the other methodes don't need them ether.

Specified by:
bind in interface IDataBaseAccess
Parameters:
id - The peers id number address A String of the form host:port we get host using the InetAddress.getLocalHost() methode.
Returns:
true if binding was successful
See Also:
InetAddress, IDataBaseAccess.unbind(int), IDataBaseAccess.lookup(int)

unbind

public boolean unbind(int id)
Description copied from interface: IDataBaseAccess
This methode will change the peers status to offline.

Specified by:
unbind in interface IDataBaseAccess
See Also:
IDataBaseAccess.unbind(int)

lookup

public String lookup(int id)
Description copied from interface: IDataBaseAccess
Before we can send messages we need there address. This methode those just that. You may use the IDataBaseAccess.search(java.lang.String, java.lang.String) methode to get the id.

Specified by:
lookup in interface IDataBaseAccess
Returns:
A String representing the address (in the form of host:port) of the peer
See Also:
IDataBaseAccess.bind(int, String)

setFirstName

public boolean setFirstName(int id,
                            String firstname)
Specified by:
setFirstName in interface IDataBaseAccess

setLastName

public boolean setLastName(int id,
                           String last)
Specified by:
setLastName in interface IDataBaseAccess

setEmail

public boolean setEmail(int id,
                        String email)
Specified by:
setEmail in interface IDataBaseAccess

setStatus

public boolean setStatus(int id,
                         boolean status)

setImageURL

public boolean setImageURL(int id,
                           String url)
Specified by:
setImageURL in interface IDataBaseAccess

setPassword

public boolean setPassword(int id,
                           String newPassword)
Specified by:
setPassword in interface IDataBaseAccess

removePeer

public boolean removePeer(int id)
Description copied from interface: IDataBaseAccess
If ever called, this methode would remove the peer from the DB.

Specified by:
removePeer in interface IDataBaseAccess

getFirstName

public String getFirstName(int id)
Description copied from interface: IDataBaseAccess
Returns the first Name of the peer identified by id.

Specified by:
getFirstName in interface IDataBaseAccess

getLastName

public String getLastName(int id)
Description copied from interface: IDataBaseAccess
Returns the Last Name of the peer identified by id.

Specified by:
getLastName in interface IDataBaseAccess

getEmail

public String getEmail(int id)
Description copied from interface: IDataBaseAccess
Returns the email of the peer identified by id.

Specified by:
getEmail in interface IDataBaseAccess

isOnline

public boolean isOnline(int id)
Description copied from interface: IDataBaseAccess
Returns true if the peer identified by id is online.

Specified by:
isOnline in interface IDataBaseAccess

getImageURL

public String getImageURL(int id)
Description copied from interface: IDataBaseAccess
Returns an URL to an image of the peer identified by id.

Specified by:
getImageURL in interface IDataBaseAccess

checkPassword

public boolean checkPassword(int id,
                             String pwd)
Description copied from interface: IDataBaseAccess
This methode is used to check the peers identity. It should be called before any write accsess to the DB.

Specified by:
checkPassword in interface IDataBaseAccess

getSearchFields

public String[] getSearchFields()
Description copied from interface: IDataBaseAccess
This methode is used to get a list of searchable colums used for the IDataBaseAccess.search(java.lang.String, java.lang.String) method.

Specified by:
getSearchFields in interface IDataBaseAccess
Returns:
An array of String representing the names of the colums where a search is possible.

search

public int[] search(String colume,
                    String searchString)
Description copied from interface: IDataBaseAccess
Search the DB for one or more peers and return there ID's

Specified by:
search in interface IDataBaseAccess
Returns:
An array of id's of all peers matching the searchString in the specified colum.
See Also:
IDataBaseAccess.getSearchFields()

setAllAtOnce

public boolean setAllAtOnce(int id,
                            String newFirstName,
                            String newLastName,
                            String newEmail,
                            String newPassword,
                            String newImageURL)
This is mainly used to decrease network and DB load by sending all data at once.

Specified by:
setAllAtOnce in interface IDataBaseAccess
Returns:
true if successful