kiurubeans
Class EntityHandler

java.lang.Object
  |
  +--kiurubeans.KiuruHandler
        |
        +--kiurubeans.EntityHandler
All Implemented Interfaces:
EnumType
Direct Known Subclasses:
ContactPerson, KiuruSpace, SpaceGroup

public abstract class EntityHandler
extends KiuruHandler

Representation of a database entity.


Field Summary
static int DELETE_RECORD
          Deletes record from database & clears attributes
static int GET_RECORD
          Updates attributes from database based on current ID information
static int POST_RECORD
          Saves current record from database, provided that attributes are ok.
static int RESET_RECORD
          Clears attributes.
 
Fields inherited from class kiurubeans.KiuruHandler
NO_ACTION
 
Constructor Summary
EntityHandler()
          Dummy empty constructor.
 
Method Summary
 void clearEmptyParameters(javax.servlet.http.HttpServletRequest request)
          Ensures empty request parameters are clearer when entity is posted.
protected  void defaultAction()
          Performs action based on actionType.
abstract  void deleteRecord()
          Deletes current record from database.
protected abstract  boolean doCheckModifyRight()
          Implementation of modify rights checking.
protected  void doClearActionState(javax.servlet.http.HttpServletRequest request)
          Default implementation of clearing action state.
abstract  boolean getAddingNew()
          Returns if entity is in a state of adding a new record.
protected  int getMaxState()
          Returns current max state value.
abstract  void getRecord()
          Retrieves record from database according to current Id field(s) value(s).
 boolean hasModifyRight()
          Returns true if current user has full rights to modify current entity.
abstract  void postRecord()
          Saves record to database.
abstract  void resetRecord()
          Clears field values.
 
Methods inherited from class kiurubeans.KiuruHandler
addError, addNotice, doClearEmptyParameters, getEnumState, getError, getLangId, getOk, getUser, performAction, resetActionState, resetErrorState, setEnumState, setError, setOk, setUser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET_RECORD

public static final int GET_RECORD
Updates attributes from database based on current ID information

See Also:
Constant Field Values

RESET_RECORD

public static final int RESET_RECORD
Clears attributes. Used when adding a new record

See Also:
Constant Field Values

DELETE_RECORD

public static final int DELETE_RECORD
Deletes record from database & clears attributes

See Also:
Constant Field Values

POST_RECORD

public static final int POST_RECORD
Saves current record from database, provided that attributes are ok.

See Also:
Constant Field Values
Constructor Detail

EntityHandler

public EntityHandler()
Dummy empty constructor.

Method Detail

getMaxState

protected int getMaxState()
Returns current max state value. Inherited classes may override this when new states are introduced.

Overrides:
getMaxState in class KiuruHandler
Returns:
max state value

doCheckModifyRight

protected abstract boolean doCheckModifyRight()
Implementation of modify rights checking.

Returns:
true is user can modify entity.
See Also:
hasModifyRight()

hasModifyRight

public boolean hasModifyRight()
Returns true if current user has full rights to modify current entity. Descendant classes may introduce more detailed modification constraints.

Note! User must be set when calling this method.

Returns:
true is user can modify entity  @see #doCheckModifyRight()

defaultAction

protected void defaultAction()
                      throws java.lang.Exception
Performs action based on actionType. Called from performAction. Descendant classes should override this and call the same method in inherited class as default.

Specified by:
defaultAction in class KiuruHandler
Throws:
java.lang.Exception - If something went wrong during actual executed action.
See Also:
KiuruHandler.performAction()

getRecord

public abstract void getRecord()
                        throws java.lang.Exception
Retrieves record from database according to current Id field(s) value(s).

Id field(s) are defined in descendant classes. Method implements also user rights check, eg. if user has no right to retrieve the record, empty object is returned instead.

Throws:
java.lang.Exception - if there is a problem with DB connection

resetRecord

public abstract void resetRecord()
Clears field values.

Result should be equivalent to constructing a new object. Nothing is saved to database.


deleteRecord

public abstract void deleteRecord()
                           throws java.lang.Exception
Deletes current record from database.

Actually applies deleted=true. Object is cleared after deletion.

Throws:
java.lang.Exception - if there is a problem with DB connection

postRecord

public abstract void postRecord()
                         throws java.lang.Exception
Saves record to database.

If field values are not valid, sets Ok property to false.

Throws:
java.lang.Exception - if there is a problem with DB connection

doClearActionState

protected void doClearActionState(javax.servlet.http.HttpServletRequest request)
Default implementation of clearing action state. Descendant classes may override this.

Specified by:
doClearActionState in class KiuruHandler
Parameters:
request - The request-object of the JSP.
See Also:
KiuruHandler.resetActionState(HttpServletRequest)

getAddingNew

public abstract boolean getAddingNew()
Returns if entity is in a state of adding a new record. Implementation depends of a descendand class.

Returns:
True if the record doesn't exist in the database, yet

clearEmptyParameters

public void clearEmptyParameters(javax.servlet.http.HttpServletRequest request)
Ensures empty request parameters are clearer when entity is posted.

If bean is used in a JSP, this should be called in the beginning of page. If form content is "" or null it is not sent via HTTP, so those fields must be cleared manually. Method may be called from a handler or UI page.

Overrides:
clearEmptyParameters in class KiuruHandler
Parameters:
request - HTTP request with parameters
See Also:
KiuruHandler.doClearEmptyParameters(HttpServletRequest)