Class DefaultSqlStorageProvider
java.lang.Object
org.jobrunr.storage.AbstractStorageProvider
org.jobrunr.storage.sql.common.DefaultSqlStorageProvider
- All Implemented Interfaces:
AutoCloseable, SqlStorageProvider, StorageProvider
- Direct Known Subclasses:
DB2StorageProvider, H2StorageProvider, MariaDbStorageProvider, MySqlStorageProvider, OracleStorageProvider, PostgresStorageProvider, SqLiteStorageProvider, SQLServerStorageProvider
public class DefaultSqlStorageProvider
extends AbstractStorageProvider
implements SqlStorageProvider
-
Nested Class Summary
Nested classes/interfaces inherited from interface StorageProvider
StorageProvider.StorageProviderInfo -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DataSourceprotected final Dialectprotected final StringFields inherited from interface StorageProvider
BATCH_SIZE -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefaultSqlStorageProvider(DataSource dataSource, Dialect dialect, String tablePrefix, StorageProviderUtils.DatabaseOptions databaseOptions) protectedDefaultSqlStorageProvider(DataSource dataSource, Dialect dialect, String tablePrefix, StorageProviderUtils.DatabaseOptions databaseOptions, RateLimiter changeListenerNotificationRateLimit) DefaultSqlStorageProvider(DataSource dataSource, Dialect dialect, StorageProviderUtils.DatabaseOptions databaseOptions) DefaultSqlStorageProvider(DataSource dataSource, Dialect dialect, StorageProviderUtils.DatabaseOptions databaseOptions, RateLimiter changeListenerNotificationRateLimit) -
Method Summary
Modifier and TypeMethodDescriptionvoidannounceBackgroundJobServer(BackgroundJobServerStatus serverStatus) protected BackgroundJobServerTablebackgroundJobServerTable(Connection connection) longCounts all the jobs matching the givenStateName.intdeleteJobsPermanently(StateName state, Instant updatedBefore) voiddeleteMetadata(String name) voiddeleteMetadata(String name, String owner) intDeletes theJobwith the given id and returns the amount of deleted jobs (either 0 or 1).intDeletes theRecurringJobwith the given id.getCarbonAwareJobList(Instant deadlineBefore, AmountRequest amountRequest) Returns all carbon aware jobs with a deadline before the givenInstant.protected DatabaseCreatorgetDistinctJobSignatures(StateName... states) getJobById(UUID id) Returns theJobwith the given id or throws aJobNotFoundExceptionif the job does not existgetJobList(StateName state, Instant updatedBefore, AmountRequest amountRequest) getJobList(StateName state, AmountRequest amountRequest) Returns all the jobs matching the givenStateNameandAmountRequest.Returns the statistics of the jobs (amount enqueued, amount scheduled, ...) Important: in most cases, this results in a intensive query.getJobsToProcess(BackgroundJobServer backgroundJobServer, AmountRequest amountRequest) getMetadata(String name) getMetadata(String name, String owner) getRecurringJobLatestScheduledInstant(String recurringJobId, StateName... states) Returns the scheduled instant of the lastJob, in one of the given states, created by theRecurringJobwith the given recurringJobId.Returns a listRecurringJobs.getScheduledJobs(Instant scheduledBefore, AmountRequest amountRequest) protected JobStatsViewjobStatsView(Connection connection) protected JobTablejobTable(Connection connection) protected MetadataTablemetadataTable(Connection connection) voidpublishTotalAmountOfSucceededJobs(int amount) booleanrecurringJobsUpdated(Long recurringJobsUpdatedHash) protected RecurringJobTablerecurringJobTable(Connection connection) intremoveTimedOutBackgroundJobServers(Instant heartbeatOlderThan) Save theJoband increases the version if saving succeeded.voidsaveMetadata(JobRunrMetadata metadata) saveRecurringJob(RecurringJob recurringJob) Saves aRecurringJobto the database.voidsetJobMapper(JobMapper jobMapper) voidsetUpStorageProvider(StorageProviderUtils.DatabaseOptions databaseOptions) This method allows to reinitialize the StorageProvider.booleansignalBackgroundJobServerAlive(BackgroundJobServerStatus serverStatus) voidsignalBackgroundJobServerStopped(BackgroundJobServerStatus serverStatus) Methods inherited from class AbstractStorageProvider
addJobStorageOnChangeListener, close, getStorageProviderInfo, notifyJobStatsOnChangeListeners, notifyJobStatsOnChangeListenersIf, notifyMetadataChangeListeners, notifyMetadataChangeListenersIf, notifyMetadataChangeListenersOnCurrentThread, removeJobStorageOnChangeListener, validatePollInterval, validateRecurringJobIntervalModifier and TypeMethodDescriptionvoidAllows to listen for changes related tojobs.voidclose()protected voidprotected voidnotifyJobStatsOnChangeListenersIf(boolean mustNotify) protected voidprotected voidnotifyMetadataChangeListenersIf(boolean mustNotify) protected voidvoidRemove the given listener that listens for changes toJobsfinal voidvalidatePollInterval(Duration pollInterval) final voidvalidateRecurringJobInterval(Duration durationBetweenRecurringJobInstances) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface StorageProvider
getJobById, getJobs, getScheduledJobsModifier and TypeMethodDescriptiondefault JobgetJobById(JobId jobId) Returns theJobwith the given id or throws aJobNotFoundExceptionif the job does not existgetJobs(StateName state, PageRequest pageRequest) getScheduledJobs(Instant scheduledBefore, PageRequest pageRequest)
-
Field Details
-
dataSource
-
dialect
-
tablePrefix
-
-
Constructor Details
-
DefaultSqlStorageProvider
public DefaultSqlStorageProvider(DataSource dataSource, Dialect dialect, StorageProviderUtils.DatabaseOptions databaseOptions) -
DefaultSqlStorageProvider
public DefaultSqlStorageProvider(DataSource dataSource, Dialect dialect, String tablePrefix, StorageProviderUtils.DatabaseOptions databaseOptions) -
DefaultSqlStorageProvider
public DefaultSqlStorageProvider(DataSource dataSource, Dialect dialect, StorageProviderUtils.DatabaseOptions databaseOptions, RateLimiter changeListenerNotificationRateLimit) -
DefaultSqlStorageProvider
protected DefaultSqlStorageProvider(DataSource dataSource, Dialect dialect, String tablePrefix, StorageProviderUtils.DatabaseOptions databaseOptions, RateLimiter changeListenerNotificationRateLimit)
-
-
Method Details
-
setJobMapper
- Specified by:
setJobMapperin interfaceStorageProvider
-
setUpStorageProvider
Description copied from interface:StorageProviderThis method allows to reinitialize the StorageProvider. It can be used if you are using Flyway or Liquibase to setup your database manually.By default, this method is automatically called on construction of the StorageProvider
- Specified by:
setUpStorageProviderin interfaceStorageProvider- Parameters:
databaseOptions- defines whether to set up the StorageProvider or validate whether the StorageProvider is set up correctly.
-
announceBackgroundJobServer
- Specified by:
announceBackgroundJobServerin interfaceStorageProvider
-
signalBackgroundJobServerAlive
- Specified by:
signalBackgroundJobServerAlivein interfaceStorageProvider
-
signalBackgroundJobServerStopped
- Specified by:
signalBackgroundJobServerStoppedin interfaceStorageProvider
-
getBackgroundJobServers
- Specified by:
getBackgroundJobServersin interfaceStorageProvider
-
getLongestRunningBackgroundJobServerId
- Specified by:
getLongestRunningBackgroundJobServerIdin interfaceStorageProvider
-
removeTimedOutBackgroundJobServers
- Specified by:
removeTimedOutBackgroundJobServersin interfaceStorageProvider
-
saveMetadata
- Specified by:
saveMetadatain interfaceStorageProvider
-
getMetadata
- Specified by:
getMetadatain interfaceStorageProvider
-
getMetadata
- Specified by:
getMetadatain interfaceStorageProvider
-
deleteMetadata
- Specified by:
deleteMetadatain interfaceStorageProvider
-
deleteMetadata
- Specified by:
deleteMetadatain interfaceStorageProvider
-
save
Description copied from interface:StorageProviderSave theJoband increases the version if saving succeeded.- Specified by:
savein interfaceStorageProvider- Parameters:
jobToSave- the job to save- Returns:
- the same job with an increased version
-
save
Description copied from interface:StorageProvider- Specified by:
savein interfaceStorageProvider- Parameters:
jobs- the list of jobs to save- Returns:
- the same list of jobs with an increased version
-
getJobById
Description copied from interface:StorageProviderReturns theJobwith the given id or throws aJobNotFoundExceptionif the job does not exist- Specified by:
getJobByIdin interfaceStorageProvider- Parameters:
id- the id of the Job to fetch- Returns:
- the requested Job
-
countJobs
Description copied from interface:StorageProviderCounts all the jobs matching the givenStateName.- Specified by:
countJobsin interfaceStorageProvider- Parameters:
state- the StateName to test eachJobagainst- Returns:
- the amount of jobs matching the given
StateName.
-
deletePermanently
Description copied from interface:StorageProviderDeletes theJobwith the given id and returns the amount of deleted jobs (either 0 or 1).- Specified by:
deletePermanentlyin interfaceStorageProvider- Parameters:
id- the id of the Job to delete- Returns:
- 1 if the job with the given id was deleted, 0 otherwise
-
deleteJobsPermanently
- Specified by:
deleteJobsPermanentlyin interfaceStorageProvider
-
getDistinctJobSignatures
- Specified by:
getDistinctJobSignaturesin interfaceStorageProvider
-
getRecurringJobLatestScheduledInstant
Description copied from interface:StorageProviderReturns the scheduled instant of the lastJob, in one of the given states, created by theRecurringJobwith the given recurringJobId.- Specified by:
getRecurringJobLatestScheduledInstantin interfaceStorageProvider- Parameters:
recurringJobId- the id of the RecurringJob for which to get the latest scheduled instantstates- the possible states for theJob(can be empty, then match against all possible states)- Returns:
- the scheduled instant of the last created
Job
-
saveRecurringJob
Description copied from interface:StorageProviderSaves aRecurringJobto the database. If aRecurringJobwith the same id exists, it will be overwritten- Specified by:
saveRecurringJobin interfaceStorageProvider- Parameters:
recurringJob- the RecurringJob to save- Returns:
- the same RecurringJob
-
getRecurringJobs
Description copied from interface:StorageProviderReturns a listRecurringJobs.- Specified by:
getRecurringJobsin interfaceStorageProvider- Returns:
- a list
RecurringJobs.
-
recurringJobsUpdated
- Specified by:
recurringJobsUpdatedin interfaceStorageProvider
-
deleteRecurringJob
Description copied from interface:StorageProviderDeletes theRecurringJobwith the given id.- Specified by:
deleteRecurringJobin interfaceStorageProvider- Parameters:
id- the id of the RecurringJob to delete- Returns:
- 1 if the RecurringJob with the given id was deleted, 0 otherwise
-
getJobStats
Description copied from interface:StorageProviderReturns the statistics of the jobs (amount enqueued, amount scheduled, ...) Important: in most cases, this results in a intensive query. JobRunr is designed to not call this method too often to limit database CPU utilization. If you need access to this info, please use aJobStatsChangeListenerand register it using theStorageProvider.addJobStorageOnChangeListener(StorageProviderChangeListener).- Specified by:
getJobStatsin interfaceStorageProvider- Returns:
- the
JobStats
-
publishTotalAmountOfSucceededJobs
public void publishTotalAmountOfSucceededJobs(int amount) - Specified by:
publishTotalAmountOfSucceededJobsin interfaceStorageProvider
-
getDatabaseCreator
-
jobTable
-
recurringJobTable
-
backgroundJobServerTable
-
metadataTable
-
jobStatsView
-