Holger's
Java API

com.antelmann.timeregister
Class PunchDBClient

java.lang.Object
  extended by com.antelmann.timeregister.AbstractPunchDB
      extended by com.antelmann.timeregister.PunchDBClient
All Implemented Interfaces:
Licensed, PunchAdminDB, PunchDB

public class PunchDBClient
extends AbstractPunchDB
implements PunchAdminDB, Licensed

uses a NetConnection to communicate to a PunchDBServer that handles requests. Punch requests are verified and stored on the server (including the server's notification of its listeners). The listeners here are maintaned locally and have no association w/ the server; the are called in addition to any listeners on the server side.

Author:
Holger Antelmann
See Also:
PunchDBServer

Field Summary
 
Fields inherited from class com.antelmann.timeregister.AbstractPunchDB
listeners
 
Constructor Summary
PunchDBClient(NetConnection connection)
          Deprecated.  
PunchDBClient(String server)
          uses the standard port
PunchDBClient(String server, int port)
           
 
Method Summary
 void close()
           
 void delete(Holiday h)
           
 void delete(PunchData entry)
          deletes the given entry from the database without any consistency checking.
 void delete(WorkUnit unit)
           
 void delete(WorkUnitValidator schedule)
           
 void deleteUser(User user)
          use with caution: this also deletes all associated records of the given user
 PunchData getFirstPunch(User user)
          if user is null, the first punch of all is returned.
 HolidayCalendar getHolidays()
           
 PunchData getLastPunch(User user)
          if user is null, the last punch of all is returned.
 NetConnection getNetConnection()
           
 PunchDataAnalyzer getPunchData(User user, Date from, Date until, String location, String activity)
          retrieves the relevant set of Punchdata objects in a PunchDataAnalyzer
 Map<Object,TimeUser> getUsers()
          returns an unmodifiable view of the users, mapping the id to a TimeUser
 List<WorkUnit> getWorkUnits(User user, WorkUnit.Type type, Date beginFrom, Date beginUntil, String activity)
          retrieves the relevant set of WorkUnit objects
 List<WorkUnit> getWorkUnitsFor(User user, Date date)
          returns all work units that enclose the given time based on the given user (or all users if user is null).
 Map<String,WorkUnitValidator> getWorkUnitValidators(Filter<WorkUnitValidator> filter)
          filter may be null, in which case no restrictions apply and all validators found will be returned
 void insert(Holiday h)
           
 void insert(WorkUnit unit)
          inserts the given unit into the database
 void insertUser(User user)
           
 void ping()
          simply checks connectivity
 void punch(PunchData entry)
          first verifies the PunchData, then stores it, and finally calls the listeners.
 void reconnect(String serverName, int port)
          allows to reconnect to a server; closes the exising connection if applicable
 void save(WorkUnitValidator schedule)
          if the schedule exists (based on equals(Object)), it will be updated; otherwise the entry will be created
 void setNetConnection(NetConnection connection)
           
 void store(PunchData entry)
          used by the final punch(PunchData) method to delegate the database storing.
 void updatePassword(User user)
          updates the permanent storage with the password that is now present in the user
 void updateUser(User user)
           
 
Methods inherited from class com.antelmann.timeregister.AbstractPunchDB
addPunchListener, getPunchListeners, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.antelmann.timeregister.PunchDB
addPunchListener
 

Constructor Detail

PunchDBClient

public PunchDBClient(String server)
              throws IOException
uses the standard port

Throws:
IOException
See Also:
PunchServerFrame.getStandardPort()

PunchDBClient

public PunchDBClient(String server,
                     int port)
              throws IOException
Throws:
IOException

PunchDBClient

@Deprecated
public PunchDBClient(NetConnection connection)
Deprecated. 

shouldn't be used as an appropriate connection is to be created by the other constructors

Method Detail

getNetConnection

public NetConnection getNetConnection()

setNetConnection

public void setNetConnection(NetConnection connection)

close

public void close()
           throws IOException
Throws:
IOException

reconnect

public void reconnect(String serverName,
                      int port)
               throws IOException
allows to reconnect to a server; closes the exising connection if applicable

Throws:
IOException

punch

public void punch(PunchData entry)
           throws DatabaseException,
                  FormatException
Description copied from class: AbstractPunchDB
first verifies the PunchData, then stores it, and finally calls the listeners. Normally, this method should not be overridden! If you do, you may either call this super method, or handle verification, storing and listener notification yourself.

Specified by:
punch in interface PunchDB
Overrides:
punch in class AbstractPunchDB
Throws:
FormatException - if the employee is already checked in/out, or if there is a punch that occured thereafter, or if the first punch for the user is a checkout.
DatabaseException
See Also:
PunchDataAnalyzer.verifyPunch(PunchDB, PunchData), AbstractPunchDB.store(PunchData), AbstractPunchDB.addPunchListener(PunchListener)

store

public void store(PunchData entry)
           throws DatabaseException
Description copied from class: AbstractPunchDB
used by the final punch(PunchData) method to delegate the database storing. (Note that a PunchAdminDB makes this method public)

Specified by:
store in interface PunchAdminDB
Specified by:
store in class AbstractPunchDB
Throws:
DatabaseException
See Also:
PunchDB.punch(PunchData)

delete

public void delete(PunchData entry)
            throws DatabaseException,
                   UnsupportedOperationException
Description copied from interface: PunchAdminDB
deletes the given entry from the database without any consistency checking.

Specified by:
delete in interface PunchAdminDB
Throws:
DatabaseException
UnsupportedOperationException

getPunchData

public PunchDataAnalyzer getPunchData(User user,
                                      Date from,
                                      Date until,
                                      String location,
                                      String activity)
                               throws DatabaseException
Description copied from interface: PunchDB
retrieves the relevant set of Punchdata objects in a PunchDataAnalyzer

Specified by:
getPunchData in interface PunchDB
Parameters:
user - limits retrieval by employee; if null, this limit does not apply
from - limits retrieval by begin date; if null, this limit does not apply
until - limits retrieval by end date; if null, this limit does not apply
Returns:
a set of PunchData objects
Throws:
DatabaseException
See Also:
PunchData

getLastPunch

public PunchData getLastPunch(User user)
                       throws DatabaseException
Description copied from interface: PunchDB
if user is null, the last punch of all is returned. If no punch data is available, null is returned.

Specified by:
getLastPunch in interface PunchDB
Throws:
DatabaseException

getFirstPunch

public PunchData getFirstPunch(User user)
                        throws DatabaseException
Description copied from interface: PunchDB
if user is null, the first punch of all is returned. If no punch data is available, null is returned.

Specified by:
getFirstPunch in interface PunchDB
Throws:
DatabaseException

getUsers

public Map<Object,TimeUser> getUsers()
                              throws DatabaseException
Description copied from interface: PunchDB
returns an unmodifiable view of the users, mapping the id to a TimeUser

Specified by:
getUsers in interface PunchDB
Throws:
DatabaseException

updatePassword

public void updatePassword(User user)
                    throws DatabaseException
Description copied from interface: PunchDB
updates the permanent storage with the password that is now present in the user

Specified by:
updatePassword in interface PunchDB
Throws:
DatabaseException
See Also:
UserImpl.setPassword(char[]), UserImpl.getPasswordHash()

deleteUser

public void deleteUser(User user)
                throws DatabaseException
Description copied from interface: PunchAdminDB
use with caution: this also deletes all associated records of the given user

Specified by:
deleteUser in interface PunchAdminDB
Throws:
DatabaseException

updateUser

public void updateUser(User user)
                throws DatabaseException
Specified by:
updateUser in interface PunchAdminDB
Throws:
DatabaseException

insertUser

public void insertUser(User user)
                throws DatabaseException
Specified by:
insertUser in interface PunchAdminDB
Throws:
DatabaseException

insert

public void insert(WorkUnit unit)
            throws DatabaseException
Description copied from interface: PunchAdminDB
inserts the given unit into the database

Specified by:
insert in interface PunchAdminDB
Throws:
DatabaseException

delete

public void delete(WorkUnit unit)
            throws DatabaseException
Specified by:
delete in interface PunchAdminDB
Throws:
DatabaseException

getWorkUnits

public List<WorkUnit> getWorkUnits(User user,
                                   WorkUnit.Type type,
                                   Date beginFrom,
                                   Date beginUntil,
                                   String activity)
                            throws DatabaseException
Description copied from interface: PunchAdminDB
retrieves the relevant set of WorkUnit objects

Specified by:
getWorkUnits in interface PunchAdminDB
Parameters:
user - limits retrieval by employee; if null, this limit does not apply
type - limits retrieval by type; if null, this limit does not apply
beginFrom - limits retrieval by begin date no earlier than given; if null, this limit does not apply
beginUntil - limits retrieval by begin date no later than given; if null, this limit does not apply
activity - limits retrieval by activity; if null, this limit does not apply
Returns:
a set of PunchData objects
Throws:
DatabaseException
See Also:
PunchData

getWorkUnitsFor

public List<WorkUnit> getWorkUnitsFor(User user,
                                      Date date)
                               throws DatabaseException
Description copied from interface: PunchAdminDB
returns all work units that enclose the given time based on the given user (or all users if user is null). There could be multiple WorkUnit objects even for a single user, as there is always the option of a conflicting unit.

Specified by:
getWorkUnitsFor in interface PunchAdminDB
Throws:
DatabaseException

getWorkUnitValidators

public Map<String,WorkUnitValidator> getWorkUnitValidators(Filter<WorkUnitValidator> filter)
                                                    throws DatabaseException
Description copied from interface: PunchAdminDB
filter may be null, in which case no restrictions apply and all validators found will be returned

Specified by:
getWorkUnitValidators in interface PunchAdminDB
Throws:
DatabaseException

save

public void save(WorkUnitValidator schedule)
          throws DatabaseException
Description copied from interface: PunchAdminDB
if the schedule exists (based on equals(Object)), it will be updated; otherwise the entry will be created

Specified by:
save in interface PunchAdminDB
Throws:
DatabaseException

delete

public void delete(WorkUnitValidator schedule)
            throws DatabaseException
Specified by:
delete in interface PunchAdminDB
Throws:
DatabaseException

getHolidays

public HolidayCalendar getHolidays()
                            throws DatabaseException
Specified by:
getHolidays in interface PunchAdminDB
Throws:
DatabaseException

insert

public void insert(Holiday h)
            throws DatabaseException
Specified by:
insert in interface PunchAdminDB
Throws:
DatabaseException

delete

public void delete(Holiday h)
            throws DatabaseException
Specified by:
delete in interface PunchAdminDB
Throws:
DatabaseException

ping

public void ping()
          throws DatabaseException
simply checks connectivity

Throws:
DatabaseException


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads