2.17.2: 2011-06-17

net.sf.basedb.core
Class ReporterBatcher

java.lang.Object
  extended by net.sf.basedb.core.AbstractBatcher
      extended by net.sf.basedb.core.BasicBatcher<ReporterData>
          extended by net.sf.basedb.core.ReporterBatcher
All Implemented Interfaces:
AccessControlled, Batcher

public class ReporterBatcher
extends BasicBatcher<ReporterData>

Batcher class for reporters.

Version:
2.0
Author:
Samuel, Nicklas

Field Summary
private  Set<String> batchedExternalIds
          A set containing all batched but not yet flushed external reporter id:s.
private  Date entryDate
          Date to to give new reporters.
private  List<ExtendedProperty> extendedProperties
          The extended properties for reporters
private  org.hibernate.Query findReporter
          A query to find reporters by the external id.
private  String updateSource
          A string to hold the name of the source, used to update the reporters.
 
Fields inherited from class net.sf.basedb.core.BasicBatcher
debugEnabled, logParam
 
Fields inherited from class net.sf.basedb.core.AbstractBatcher
debugSqlEnabled, logSql
 
Constructor Summary
ReporterBatcher(DbControl dc)
           
 
Method Summary
 boolean exists(String externalId, boolean checkInsertQueue, boolean checkDb)
          Check if a reporter with a given external id exists in the database or has been added to the batch queue of insertion.
 void flushInsert()
          Flush and clear the internal cache of external reporter id:s.
 ReporterData getByExternalId(String externalId)
          Get a reporter when you know the external id.
 ReporterData getByExternalId(String externalId, boolean errorIfNotFound)
          Get a reporter when you know the external id.
static ReporterBatcher getNew(DbControl dc)
          Create a new batcher for reporters.
 Item getType()
          Get the type of item supported by the batcher.
 void insert(ReporterData data)
          Insert and add the external reporter id to the internal cache.
 boolean isInInsertQueue(String externalId)
           
(package private)  void onBeforeCommit(ReporterData data, Transactional.Action action)
          Set the last update date to today's date and change the last source of update.
 void setUpdateSource(String source)
          Set the source that was used when updating the reporters.
 void validate(ReporterData data)
          Validate all properties for the reporter object: The data object is not null The name or external id is not null or too long The description or symbol is not too long All of the extendable properties using the ExtendedProperty.validateValue(Object) method
 
Methods inherited from class net.sf.basedb.core.BasicBatcher
checkPermission, delete, delete, flush, flushDelete, flushUpdate, getPermissions, getPluginPermissions, getPropertyValue, getTotalInsertCount, hasPermission, initPermissions, onBeforeClose, setPropertyValue, update
 
Methods inherited from class net.sf.basedb.core.AbstractBatcher
analyzeTable, close, getBatchSize, getDbControl, getSessionControl, isClosed, setBatchSize, setDbControl, updateLastAccess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

updateSource

private String updateSource
A string to hold the name of the source, used to update the reporters.


entryDate

private final Date entryDate
Date to to give new reporters.


extendedProperties

private final List<ExtendedProperty> extendedProperties
The extended properties for reporters

See Also:
ExtendedProperties

batchedExternalIds

private final Set<String> batchedExternalIds
A set containing all batched but not yet flushed external reporter id:s. Used by the exists method so a client application can avoid exception if trying to insert duplicate records.


findReporter

private org.hibernate.Query findReporter
A query to find reporters by the external id.

Constructor Detail

ReporterBatcher

ReporterBatcher(DbControl dc)
          throws BaseException
Throws:
BaseException
Method Detail

getNew

public static ReporterBatcher getNew(DbControl dc)
                              throws BaseException
Create a new batcher for reporters.

Parameters:
dc - The DbControl to use for database access and permission checking
Returns:
A new instance of ReporterBatcher.
Throws:
BaseException - If there is an error

getType

public Item getType()
Description copied from class: BasicBatcher
Get the type of item supported by the batcher. The returned value is one of the values defined in the Item enumeration.

Specified by:
getType in class BasicBatcher<ReporterData>
Returns:
A value indicating the type of item
See Also:
Item

insert

public void insert(ReporterData data)
            throws BaseException
Insert and add the external reporter id to the internal cache.

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

flushInsert

public void flushInsert()
                 throws DatabaseException
Flush and clear the internal cache of external reporter id:s.

Overrides:
flushInsert in class BasicBatcher<ReporterData>
Throws:
DatabaseException

validate

public void validate(ReporterData data)
              throws InvalidDataException,
                     InvalidUseOfNullException
Validate all properties for the reporter object:

Specified by:
validate in class BasicBatcher<ReporterData>
Parameters:
data - Data object to validate
Throws:
InvalidDataException - If the data object is invalid
InvalidUseOfNullException

onBeforeCommit

void onBeforeCommit(ReporterData data,
                    Transactional.Action action)
              throws BaseException
Set the last update date to today's date and change the last source of update.

Overrides:
onBeforeCommit in class BasicBatcher<ReporterData>
Parameters:
data - Object to update
action - The action
Throws:
BaseException

exists

public boolean exists(String externalId,
                      boolean checkInsertQueue,
                      boolean checkDb)
               throws BaseException
Check if a reporter with a given external id exists in the database or has been added to the batch queue of insertion.

Parameters:
externalId - The external id of the reporter
checkInsertQueue - If the insert queue should be checked or not
checkDb - If the database should be checked or not
Throws:
BaseException - If there is an error

isInInsertQueue

public boolean isInInsertQueue(String externalId)

getByExternalId

public ReporterData getByExternalId(String externalId)
                             throws ItemNotFoundException,
                                    BaseException
Get a reporter when you know the external id. This method only checks the database, not the insertion batch queue. It is possible that the exists(String, boolean, boolean) method returns true, but this method throws an ItemNotFoundException.

Parameters:
externalId - The external id of the reporter
Returns:
A ReporterData object
Throws:
ItemNotFoundException - If a reporter with the given id isn't found
BaseException - If there is another error

getByExternalId

public ReporterData getByExternalId(String externalId,
                                    boolean errorIfNotFound)
Get a reporter when you know the external id. This method only checks the database, not the insertion batch queue. It is possible that the exists(String, boolean, boolean) method returns true, but this method throws an ItemNotFoundException.

Parameters:
externalId - The external id of the reporter
errorIfNotFound - If an ItemNotFoundException should be thrown if the reporter isn't found
Returns:
A ReporterData object, or null if not found
Throws:
ItemNotFoundException - If a reporter with the given id isn't found and the errorIfNotFound parameter is true
BaseException - If there is another error

setUpdateSource

public void setUpdateSource(String source)
Set the source that was used when updating the reporters. This must be set before committing this batcher otherwise the column for last update source will be set to n/a.

Parameters:
source - The source to be set. The format of the source string should be like: "[item_type]:[item_name]"
Throws:
StringTooLongException - If the source is longer that ReporterData.MAX_LAST_SOURCE_LENGTH

2.17.2: 2011-06-17