
com.github.lontime.extquartz.common.JobStoreKind Maven / Gradle / Ivy
package com.github.lontime.extquartz.common;
import com.github.lontime.extquartz.configuration.JobStoreOption;
import com.github.lontime.extquartz.container.UpdateLockJobStoreTX;
import com.github.lontime.extquartz.impl.RedissonJobStore;
import org.quartz.impl.jdbcjobstore.JobStoreCMT;
import org.quartz.impl.jdbcjobstore.JobStoreSupport;
import org.quartz.impl.jdbcjobstore.JobStoreTX;
import org.quartz.simpl.RAMJobStore;
import org.quartz.spi.JobStore;
/**
* JobStoreKind.
* @author lontime
* @since 1.0
*/
public enum JobStoreKind {
/**
* Ram.
*/
RAM,
/**
* JobStoreTX.
*/
TX,
/**
* UpdateLockJobStoreTX.
*/
UPDATE_TX,
/**
* JobStoreCMT.
*/
CMT,
/**
* Redisson.
*/
REDISSON;
public JobStore toJobStore(JobStoreOption option) {
switch (this) {
case TX:
return buildJobStoreTX(option);
case UPDATE_TX:
return buildUpdateLockJobStoreTX(option);
case CMT:
return buildJobStoreCMT(option);
case REDISSON:
return buildJobStoreRedisson(option);
default:
return buildRAMJobStore(option);
}
}
private RedissonJobStore buildJobStoreRedisson(JobStoreOption option) {
final RedissonJobStore jobStore = new RedissonJobStore();
if (option.getMisfireThreshold() != null) {
jobStore.setMisfireThreshold(option.getMisfireThreshold());
}
if (option.getCheckClusterInterval() != null) {
jobStore.setClusterCheckinInterval(option.getCheckClusterInterval().toMillis());
}
if (option.getRedissonName() != null) {
jobStore.setRedissonName(option.getRedissonName());
}
return jobStore;
}
private JobStoreTX buildJobStoreTX(JobStoreOption option) {
final JobStoreTX tx = new JobStoreTX();
fillJobStoreSupport(tx, option);
return tx;
}
private JobStoreTX buildUpdateLockJobStoreTX(JobStoreOption option) {
final UpdateLockJobStoreTX tx = new UpdateLockJobStoreTX(option.getTablePrefix());
fillJobStoreSupport(tx, option);
return tx;
}
private JobStoreCMT buildJobStoreCMT(JobStoreOption option) {
final JobStoreCMT cmt = new JobStoreCMT();
fillJobStoreSupport(cmt, option);
if (option.getNonManagedTxDsName() != null) {
cmt.setNonManagedTXDataSource(option.getNonManagedTxDsName());
}
if (option.getDontSetNonManagedTXConnectionAutoCommitFalse() != null) {
cmt.setDontSetNonManagedTXConnectionAutoCommitFalse(option.getDontSetNonManagedTXConnectionAutoCommitFalse());
}
if (option.getTxIsolationLevelReadCommitted() != null) {
cmt.setTxIsolationLevelReadCommitted(option.getTxIsolationLevelReadCommitted());
}
return cmt;
}
private void fillJobStoreSupport(JobStoreSupport support, JobStoreOption option) {
fillDriverDelegateClass(support, option);
if (option.getDataSource() != null) {
support.setDataSource(option.getDataSource());
}
if (option.getTablePrefix() != null) {
support.setTablePrefix(option.getTablePrefix());
}
if (option.getUseProperties() != null && option.getUseProperties()) {
support.canUseProperties();
}
if (option.getCluster() != null) {
support.setIsClustered(option.getCluster());
}
if (option.getCheckClusterInterval() != null) {
support.setClusterCheckinInterval(option.getCheckClusterInterval().toMillis());
}
if (option.getMaxToRecoverAtATime() != null) {
support.setMaxMisfiresToHandleAtATime(option.getMaxToRecoverAtATime());
}
if (option.getDbRetryInterval() != null) {
support.setDbRetryInterval(option.getDbRetryInterval().toMillis());
}
if (option.getUseDBLocks() != null) {
support.setUseDBLocks(option.getUseDBLocks());
}
if (option.getLockOnInsert() != null) {
support.setLockOnInsert(option.getLockOnInsert());
}
if (option.getMisfireThreshold() != null) {
support.setMisfireThreshold(option.getMisfireThreshold());
}
if (option.getDontSetAutoCommitFalse() != null) {
support.setDontSetAutoCommitFalse(option.getDontSetAutoCommitFalse());
}
if (option.getTxIsolationLevelSequential() != null) {
support.setTxIsolationLevelSerializable(option.getTxIsolationLevelSequential());
}
if (option.getAcquireTriggersWithinLock() != null) {
support.setAcquireTriggersWithinLock(option.getAcquireTriggersWithinLock());
}
if (option.getSelectWithLockSQL() != null) {
support.setSelectWithLockSQL(option.getSelectWithLockSQL());
}
if (option.getMakeThreadsDaemons() != null) {
support.setMakeThreadsDaemons(option.getMakeThreadsDaemons());
}
if (option.getThreadsInheritInitializersClassLoadContext() != null) {
support.setThreadsInheritInitializersClassLoadContext(option.getThreadsInheritInitializersClassLoadContext());
}
if (option.getDoubleCheckLockMisfireHandler() != null) {
support.setDoubleCheckLockMisfireHandler(option.getDoubleCheckLockMisfireHandler());
}
}
private void fillDriverDelegateClass(JobStoreSupport support, JobStoreOption option) {
try {
if (option.getDriverDelegateClass() != null) {
support.setDriverDelegateClass(option.getDriverDelegateClass());
}
if (option.getDriverDelegateInitString() != null) {
support.setDriverDelegateInitString(option.getDriverDelegateInitString());
}
} catch (Exception e) {
}
}
private RAMJobStore buildRAMJobStore(JobStoreOption option) {
final RAMJobStore store = new RAMJobStore();
return store;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy