Last update: 2011-06-23

org.proteios.core
Class BasicBatcher<D extends BatchableData>

java.lang.Object
  extended by org.proteios.core.AbstractBatcher
      extended by org.proteios.core.BasicBatcher<D>
All Implemented Interfaces:
AccessControlled, Batcher
Direct Known Subclasses:
PeakBatcher, PeakListBatcher

public abstract class BasicBatcher<D extends BatchableData>
extends AbstractBatcher
implements AccessControlled

This is an abstract class for batching functionallity. Add all objects and then call flush to send the batch to the database. BasicBatcher can also have a limit on the batch size, when the batch is full BasicBatcher will automatically call flush to send the current batch to the database.

Version:
2.0
Author:
Samuel, Nicklas
Last modified
$Date: 2010-01-02 22:12:32 +0100 (Sat, 02 Jan 2010) $

Method Summary
 void checkPermission(Permission permission)
          Checks if the logged in user has the specified permission on this item.
 void delete(D data)
          Delete a data object.
 void delete(int id)
          Delete a data object by id.
 void flush()
          Flush the batcher and send all remaining items in memory to the database.
 void flushDelete()
          Flush the SQL delete command buffer.
 void flushInsert()
          Flush the SQL insert command buffer.
 void flushUpdate()
          Flush the SQL insert command buffer.
 int getTotalInsertCount()
           
abstract  Item getType()
          Get the type of item supported by the batcher.
 boolean hasPermission(Permission permission)
          Checks if the logged in user has the specified permission on this item.
 void insert(D data)
          Insert a data object.
 void update(D data)
          Update a data object.
abstract  void validate(D data)
          Validate the data, since no validation is possible in set methods of the data object.
 
Methods inherited from class org.proteios.core.AbstractBatcher
close, getBatchSize, getDbControl, getSessionControl, isClosed, setBatchSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasPermission

public final boolean hasPermission(Permission permission)
Checks if the logged in user has the specified permission on this item. The default implementation only checks the role keys for permissions. A subclass may not override this method since it would make it possible to bypass security checks.

Subclasses that needs to check other keys, should override the initPermissions(int,int) method instead.

Specified by:
hasPermission in interface AccessControlled
Parameters:
permission - A value from the Permission class
Returns:
TRUE if the user has the permission, FALSE otherwise

checkPermission

public final void checkPermission(Permission permission)
                           throws PermissionDeniedException
Checks if the logged in user has the specified permission on this item. If not, a PermissionDeniedException is thrown.

Specified by:
checkPermission in interface AccessControlled
Parameters:
permission - A value from the Permission class
Throws:
PermissionDeniedException - If the logged in user doesn't have the requested permission

flush

public void flush()
           throws BaseException
Description copied from interface: Batcher
Flush the batcher and send all remaining items in memory to the database.

Specified by:
flush in interface Batcher
Throws:
BaseException - If there is an error
See Also:
Batcher.close()

insert

public void insert(D data)
            throws InvalidDataException,
                   PermissionDeniedException,
                   BaseException
Insert a data object. The data object will not be synchronized with the database. The object values may be modified.

Parameters:
data - Data object to be inserted
Throws:
InvalidDataException - If the data is null or it doesn't validate against the validate(BatchableData) method
PermissionDeniedException - If the logged in user doesn't have create permission
BaseException - If there is another error

update

public void update(D data)
            throws InvalidDataException,
                   PermissionDeniedException,
                   BaseException
Update a data object. The data object will not be synchronized with the database. The object values may be modified.

Parameters:
data - Data object to be updated
Throws:
InvalidDataException - If the data is null or it doesn't validate against the validate(BatchableData) method
PermissionDeniedException - If the logged in user doesn't have write permission
BaseException - If there is another error

delete

public void delete(D data)
            throws InvalidDataException,
                   PermissionDeniedException,
                   BaseException
Delete a data object.

Parameters:
data - Data object to be deleted
Throws:
InvalidDataException - If the data is null
PermissionDeniedException - If the logged in user doesn't have delete permission
BaseException - If there is another error

delete

public void delete(int id)
            throws PermissionDeniedException,
                   BaseException
Delete a data object by id.

Parameters:
id - Id of the object to be deleted
Throws:
PermissionDeniedException - If the logged in user doesn't have delete permission
BaseException - If there is another error

flushInsert

public void flushInsert()
                 throws DatabaseException
Flush the SQL insert command buffer. Sends the remaining SQL commands in the batch to the database for execution.

Throws:
DatabaseException - Thrown if there is a database error.

flushUpdate

public void flushUpdate()
                 throws DatabaseException
Flush the SQL insert command buffer. Sends the remaining SQL commands in the batch to the database for execution.

Throws:
DatabaseException - Thrown if there is a database error.

flushDelete

public void flushDelete()
                 throws DatabaseException
Flush the SQL delete command buffer. Sends the remaining SQL commands in the batch to the database for execution.

Throws:
DatabaseException - Thrown if there is a database error.

validate

public abstract void validate(D data)
                       throws InvalidDataException
Validate the data, since no validation is possible in set methods of the data object. Ie. this is very similar to case 2 validation for items.

Parameters:
data - Data object to validate
Throws:
InvalidDataException - If the data object is invalid

getType

public abstract Item getType()
Get the type of item supported by the batcher. The returned value is one of the values defined in the Item enumeration.

Returns:
A value indicating the type of item
See Also:
Item

getTotalInsertCount

public int getTotalInsertCount()

Last update: 2011-06-23