Package net.sf.basedb.core
Class ReporterBatcher
- All Implemented Interfaces:
AutoCloseable
,AccessControlled
,Batcher
Batcher class for reporters.
- Version:
- 2.0
- Author:
- Samuel, Nicklas
-
Field Summary
Modifier and TypeFieldDescriptionA set containing all batched but not yet flushed external reporter id:s.private final Date
Date to to give new reporters.private final List<ExtendedProperty>
The extended properties for reportersprivate Query<ReporterData>
A query to find reporters by the external id.private String
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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Check if a reporter with a given external id exists in the database or has been added to the batch queue of insertion.void
Flush and clear the internal cache of external reporter id:s.getByExternalId
(String externalId) Get a reporter when you know the external id.getByExternalId
(String externalId, boolean errorIfNotFound) Get a reporter when you know the external id.static ReporterBatcher
Create a new batcher for reporters.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 theExtendedProperty.validateValue(Object)
methodMethods 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
-
Field Details
-
updateSource
A string to hold the name of the source, used to update the reporters. -
entryDate
Date to to give new reporters. -
extendedProperties
The extended properties for reporters- See Also:
-
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
A query to find reporters by the external id.
-
-
Constructor Details
-
ReporterBatcher
ReporterBatcher(DbControl dc) throws BaseException - Throws:
BaseException
-
-
Method Details
-
getNew
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
Description copied from class:BasicBatcher
Get the type of item supported by the batcher. The returned value is one of the values defined in theItem
enumeration.- Specified by:
getType
in classBasicBatcher<ReporterData>
- Returns:
- A value indicating the type of item
- See Also:
-
insert
Insert and add the external reporter id to the internal cache.- Overrides:
insert
in classBasicBatcher<ReporterData>
- Parameters:
data
- Data object to be inserted- Throws:
InvalidDataException
- If the data is null or it doesn't validate against theBasicBatcher.validate(BatchableData)
methodPermissionDeniedException
- If the logged in user doesn't have create permissionBaseException
- If there is another error
-
flushInsert
Flush and clear the internal cache of external reporter id:s.- Overrides:
flushInsert
in classBasicBatcher<ReporterData>
- Throws:
DatabaseException
-
validate
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
- Specified by:
validate
in classBasicBatcher<ReporterData>
- Parameters:
data
- Data object to validate- Throws:
InvalidDataException
- If the data object is invalidInvalidUseOfNullException
-
onBeforeCommit
Set the last update date to today's date and change the last source of update.- Overrides:
onBeforeCommit
in classBasicBatcher<ReporterData>
- Parameters:
data
- Object to updateaction
- 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 reportercheckInsertQueue
- If the insert queue should be checked or notcheckDb
- If the database should be checked or not- Throws:
BaseException
- If there is an error
-
isInInsertQueue
-
getByExternalId
Get a reporter when you know the external id. This method only checks the database, not the insertion batch queue. It is possible that theexists(String, boolean, boolean)
method returns true, but this method throws anItemNotFoundException
.- Parameters:
externalId
- The external id of the reporter- Returns:
- A
ReporterData
object - Throws:
ItemNotFoundException
- If a reporter with the given id isn't foundBaseException
- If there is another error
-
getByExternalId
Get a reporter when you know the external id. This method only checks the database, not the insertion batch queue. It is possible that theexists(String, boolean, boolean)
method returns true, but this method throws anItemNotFoundException
.- Parameters:
externalId
- The external id of the reportererrorIfNotFound
- 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 trueBaseException
- If there is another error
-
setUpdateSource
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 thatReporterData.MAX_LAST_SOURCE_LENGTH
-