Holger's
Java API

com.antelmann.timeregister
Class SQLPunchDB

java.lang.Object
  extended by com.antelmann.timeregister.AbstractPunchDB
      extended by com.antelmann.timeregister.SQLPunchDB
All Implemented Interfaces:
Licensed, PunchAdminDB, PunchDB
Direct Known Subclasses:
OdbcPunchDB

public class SQLPunchDB
extends AbstractPunchDB
implements PunchAdminDB, Licensed

implements a PunchDB based on a JDBC connection

Author:
Holger Antelmann

Field Summary
static String CHECK_IN
           
static String CHECK_OUT
           
protected  String employeeAdminField
           
protected  String employeeBarcodeField
           
protected  String employeeCommentField
           
protected  String employeeEnabledField
           
protected  String employeeIdField
           
protected  String employeeNameField
           
protected  String employeePasswordField
           
protected  String employeeReadAllField
           
protected  String employeeReadField
           
protected  String employeeScheduleField
           
protected  String employeeTableName
           
protected  String holidayDateField
           
protected  String holidayNameField
           
protected  String holidayTableName
           
protected  String punchActivityField
           
protected  String punchCheckField
           
protected  String punchCommentField
           
protected  String punchEmployeeField
           
protected  String punchLocationField
           
protected  String punchTableName
           
protected  String punchTimeField
           
protected  String scheduleDayBeginField
           
protected  String scheduleFriBreakField
           
protected  String scheduleFriField
           
protected  String scheduleIntervalBeginField
           
protected  String scheduleIntervalCheckinField
           
protected  String scheduleIntervalEndField
           
protected  String scheduleIntervalNameField
           
protected  String scheduleIntervalTableName
           
protected  String scheduleMaxTimeField
           
protected  String scheduleMinTimeField
           
protected  String scheduleMonBreakField
           
protected  String scheduleMonField
           
protected  String scheduleNameField
           
protected  String scheduleSatBreakField
           
protected  String scheduleSatField
           
protected  String scheduleSunBreakField
           
protected  String scheduleSunField
           
protected  String scheduleTableName
           
protected  String scheduleThuBreakField
           
protected  String scheduleThuField
           
protected  String scheduleTueBreakField
           
protected  String scheduleTueField
           
protected  String scheduleWedBreakField
           
protected  String scheduleWedField
           
protected  String unitActivityField
           
protected  String unitApprovedField
           
protected  String unitBeginField
           
protected  String unitBreakField
           
protected  String unitCommentField
           
protected  String unitEmployeeField
           
protected  String unitEndField
           
protected  String unitTableName
           
protected  String unitTypeField
           
 
Fields inherited from class com.antelmann.timeregister.AbstractPunchDB
listeners
 
Constructor Summary
SQLPunchDB(Connection connection, Properties properties)
           
 
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 wv)
           
 void deleteUser(User user)
          use with caution: this also deletes all associated records of the given user
protected  List<WorkUnit> extractUnits(ResultSet rs, Map<Object,TimeUser> users, Filter<WorkUnit> filter)
           
protected  TimeUser extractUser(ResultSet rs)
           
protected  Map<String,WorkUnitValidator> extractValidators(ResultSet rs, Filter<WorkUnitValidator> filter)
           
 String[] getActivities()
          returns a list of activities contained in the database
 Connection getConnection()
           
 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.
 String getPassword(String employee)
           
protected  PunchData getPunch(User user, boolean first)
           
 PunchDataAnalyzer getPunchData(User user, Date from, Date until, String location, String activity)
          retrieves the relevant set of Punchdata objects in a PunchDataAnalyzer
 User getUser(String id)
           
 Map<Object,TimeUser> getUsers()
          uses TimeUser objects
 List<WorkUnit> getWorkUnits(Filter<WorkUnit> filter)
           
 List<WorkUnit> getWorkUnits(User user, WorkUnit.Type type, Date beginAfter, Date beginBefore, 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).
 WorkUnitValidator getWorkUnitValidator(String name)
          may return null if the given name was not found
 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)
           
 boolean isInUse(WorkUnitValidator wv)
          checks whether any user uses this validator
 void save(WorkUnitValidator wv)
          if the validator exists, it will be updated; otherwise the entry will be created
 void store(PunchData entry)
          used by the final punch(PunchData) method to delegate the database storing.
protected  void storeUser(ResultSet rs, User user)
           
 void updatePassword(User user)
          updates the permanent storage with the password that is now present in the user
 void updateUser(User user)
           
protected  void updateWorkUnitValidator(ResultSet rs, WorkUnitValidator wv, boolean insert)
           
 void verifyConsistency()
           
 
Methods inherited from class com.antelmann.timeregister.AbstractPunchDB
addPunchListener, getPunchListeners, punch, 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, punch
 

Field Detail

CHECK_IN

public static final String CHECK_IN
See Also:
Constant Field Values

CHECK_OUT

public static final String CHECK_OUT
See Also:
Constant Field Values

employeeTableName

protected String employeeTableName

employeeNameField

protected String employeeNameField

employeePasswordField

protected String employeePasswordField

employeeCommentField

protected String employeeCommentField

employeeIdField

protected String employeeIdField

employeeEnabledField

protected String employeeEnabledField

employeeReadField

protected String employeeReadField

employeeReadAllField

protected String employeeReadAllField

employeeAdminField

protected String employeeAdminField

employeeScheduleField

protected String employeeScheduleField

employeeBarcodeField

protected String employeeBarcodeField

punchTableName

protected String punchTableName

punchEmployeeField

protected String punchEmployeeField

punchTimeField

protected String punchTimeField

punchCheckField

protected String punchCheckField

punchLocationField

protected String punchLocationField

punchActivityField

protected String punchActivityField

punchCommentField

protected String punchCommentField

unitTableName

protected String unitTableName

unitBeginField

protected String unitBeginField

unitEndField

protected String unitEndField

unitEmployeeField

protected String unitEmployeeField

unitTypeField

protected String unitTypeField

unitActivityField

protected String unitActivityField

unitCommentField

protected String unitCommentField

unitApprovedField

protected String unitApprovedField

unitBreakField

protected String unitBreakField

scheduleTableName

protected String scheduleTableName

scheduleNameField

protected String scheduleNameField

scheduleDayBeginField

protected String scheduleDayBeginField

scheduleMaxTimeField

protected String scheduleMaxTimeField

scheduleMinTimeField

protected String scheduleMinTimeField

scheduleMonField

protected String scheduleMonField

scheduleTueField

protected String scheduleTueField

scheduleWedField

protected String scheduleWedField

scheduleThuField

protected String scheduleThuField

scheduleFriField

protected String scheduleFriField

scheduleSatField

protected String scheduleSatField

scheduleSunField

protected String scheduleSunField

scheduleMonBreakField

protected String scheduleMonBreakField

scheduleTueBreakField

protected String scheduleTueBreakField

scheduleWedBreakField

protected String scheduleWedBreakField

scheduleThuBreakField

protected String scheduleThuBreakField

scheduleFriBreakField

protected String scheduleFriBreakField

scheduleSatBreakField

protected String scheduleSatBreakField

scheduleSunBreakField

protected String scheduleSunBreakField

scheduleIntervalTableName

protected String scheduleIntervalTableName

scheduleIntervalNameField

protected String scheduleIntervalNameField

scheduleIntervalBeginField

protected String scheduleIntervalBeginField

scheduleIntervalEndField

protected String scheduleIntervalEndField

scheduleIntervalCheckinField

protected String scheduleIntervalCheckinField

holidayTableName

protected String holidayTableName

holidayDateField

protected String holidayDateField

holidayNameField

protected String holidayNameField
Constructor Detail

SQLPunchDB

public SQLPunchDB(Connection connection,
                  Properties properties)
           throws SQLException
Throws:
SQLException
Method Detail

getConnection

public Connection getConnection()

close

public void close()
           throws IOException
Throws:
IOException

getUsers

public Map<Object,TimeUser> getUsers()
                              throws DatabaseException
uses TimeUser objects

Specified by:
getUsers in interface PunchDB
Throws:
DatabaseException
See Also:
TimeUser

getUser

public User getUser(String id)
             throws DatabaseException
Throws:
DatabaseException

extractUser

protected TimeUser extractUser(ResultSet rs)
                        throws SQLException,
                               DatabaseException
Throws:
SQLException
DatabaseException

getPassword

public String getPassword(String employee)
                   throws DatabaseException,
                          IllegalArgumentException
Throws:
DatabaseException
IllegalArgumentException

verifyConsistency

public void verifyConsistency()
                       throws DatabaseException,
                              FormatException
Throws:
DatabaseException
FormatException

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
Description copied from interface: PunchAdminDB
deletes the given entry from the database without any consistency checking.

Specified by:
delete in interface PunchAdminDB
Throws:
DatabaseException

delete

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

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

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

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

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

storeUser

protected void storeUser(ResultSet rs,
                         User user)
                  throws SQLException
Throws:
SQLException

getPunch

protected PunchData getPunch(User user,
                             boolean first)
                      throws DatabaseException
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

getWorkUnits

public List<WorkUnit> getWorkUnits(User user,
                                   WorkUnit.Type type,
                                   Date beginAfter,
                                   Date beginBefore,
                                   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
beginAfter - limits retrieval by begin date no earlier than given; if null, this limit does not apply
beginBefore - 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

getWorkUnits

public List<WorkUnit> getWorkUnits(Filter<WorkUnit> filter)
                            throws DatabaseException
Throws:
DatabaseException

extractUnits

protected List<WorkUnit> extractUnits(ResultSet rs,
                                      Map<Object,TimeUser> users,
                                      Filter<WorkUnit> filter)
                               throws SQLException,
                                      DatabaseException
Throws:
SQLException
DatabaseException

isInUse

public boolean isInUse(WorkUnitValidator wv)
                throws DatabaseException
checks whether any user uses this validator

Throws:
DatabaseException

delete

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

save

public void save(WorkUnitValidator wv)
          throws DatabaseException
if the validator exists, it will be updated; otherwise the entry will be created

Specified by:
save in interface PunchAdminDB
Throws:
DatabaseException

updateWorkUnitValidator

protected void updateWorkUnitValidator(ResultSet rs,
                                       WorkUnitValidator wv,
                                       boolean insert)
                                throws SQLException
Throws:
SQLException

getWorkUnitValidator

public WorkUnitValidator getWorkUnitValidator(String name)
                                       throws DatabaseException
may return null if the given name was not found

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

extractValidators

protected Map<String,WorkUnitValidator> extractValidators(ResultSet rs,
                                                          Filter<WorkUnitValidator> filter)
                                                   throws SQLException
Throws:
SQLException

getActivities

public String[] getActivities()
                       throws DatabaseException
returns a list of activities contained in the database

Throws:
DatabaseException

delete

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

insert

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

getHolidays

public HolidayCalendar getHolidays()
                            throws DatabaseException
Specified by:
getHolidays in interface PunchAdminDB
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