Class DefaultPersistenceService
java.lang.Object
it.ozimov.springboot.mail.service.defaultimpl.DefaultPersistenceService
- All Implemented Interfaces:
PersistenceService
@Service("defaultEmailPersistenceService")
@ConditionalOnExpression("\'${spring.mail.scheduler.enabled:false}\' == \'true\' && \'${spring.mail.scheduler.persistence.enabled:false}\' == \'true\'")
public class DefaultPersistenceService
extends Object
implements PersistenceService
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultPersistenceService(@NonNull org.springframework.data.redis.core.StringRedisTemplate orderingTemplate, @NonNull org.springframework.data.redis.core.RedisTemplate<String, EmailSchedulingData> valueTemplate) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(@NonNull EmailSchedulingData emailSchedulingData) Persist the EmailSchedulingData into the persistence service.voidaddAll(@NonNull Collection<EmailSchedulingData> emailSchedulingDataList) Persist all the EmailSchedulingData contained in the given collection into the persistence service.protected voidaddAllOps(Collection<EmailSchedulingData> emailSchedulingDataList) protected voidaddOps(EmailSchedulingData emailSchedulingData) Retrieve an Optional containing the EmailSchedulingData stored for the given emailSchedulingDataId, if the key exists and a value was found.getNextBatch(int batchMaxSize) Retrieves a batch of EmailSchedulingData from the persistence layer, such that up tobatchMaxSizeinstances are returned from a whatsoever priority level.getNextBatch(int priorityLevel, int batchMaxSize) Retrieves a batch of EmailSchedulingData from the persistence layer, such that up tobatchMaxSizeinstances are returned from a specific priority level.protected Collection<EmailSchedulingData>getNextBatchOps(String orderingKey, int batchMaxSize) protected EmailSchedulingDatabooleanRemove the EmailSchedulingData associated to the given id, returningtrueif the key was found in the persistence layer,falseotherwise.voidRemove all the EmailSchedulingData in the peristence layer.voidremoveAll(int priorityLevel) Remove all the EmailSchedulingData associated to the given priority level.voidremoveAll(@NonNull Collection<String> ids) Remove all the EmailSchedulingData associated to the ids in the given collection.protected boolean
-
Constructor Details
-
DefaultPersistenceService
@Autowired public DefaultPersistenceService(@Qualifier("orderingTemplate") @NonNull @NonNull org.springframework.data.redis.core.StringRedisTemplate orderingTemplate, @Qualifier("valueTemplate") @NonNull @NonNull org.springframework.data.redis.core.RedisTemplate<String, EmailSchedulingData> valueTemplate)
-
-
Method Details
-
add
Description copied from interface:PersistenceServicePersist the EmailSchedulingData into the persistence service. The key used to store the instance if the one returned by EmailSchedulingData.getId().Observe that in case of duplicate keys, the new values is used to override the oldest without any warning.
- Specified by:
addin interfacePersistenceService- Parameters:
emailSchedulingData- the data to be stored.
-
addOps
-
get
Description copied from interface:PersistenceServiceRetrieve an Optional containing the EmailSchedulingData stored for the given emailSchedulingDataId, if the key exists and a value was found.In case of no value forund the the given key, an empty Optional is returned.
- Specified by:
getin interfacePersistenceService- Parameters:
id- the emailSchedulingDataId used to store an EmailSchedulingData.- Returns:
- an optional containing the scheduling data of an email if any was found for the given emailSchedulingDataId; otherwise, an empty optional.
-
getOps
-
remove
Description copied from interface:PersistenceServiceRemove the EmailSchedulingData associated to the given id, returningtrueif the key was found in the persistence layer,falseotherwise.- Specified by:
removein interfacePersistenceService- Parameters:
id- the id of stored EmailSchedulingData.- Returns:
trueif the id exists and the value was successfully removed;falseotherwise.
-
removeOps
-
addAll
Description copied from interface:PersistenceServicePersist all the EmailSchedulingData contained in the given collection into the persistence service. The key used to store each the instance if the one returned by EmailSchedulingData.getId().Observe that in case of duplicate keys, the new values is used to override the oldest without any warning.
- Specified by:
addAllin interfacePersistenceService- Parameters:
emailSchedulingDataList- collection of EmailSchedulingData to be persisted
-
addAllOps
-
getNextBatch
Description copied from interface:PersistenceServiceRetrieves a batch of EmailSchedulingData from the persistence layer, such that up tobatchMaxSizeinstances are returned from a specific priority level.If no data is persisted, an empty collection is returned. If less than
batchMaxSizeare persisted,batchMaxSizeare returned.- Specified by:
getNextBatchin interfacePersistenceService- Parameters:
priorityLevel- the priority level from which we want to extract the batch.batchMaxSize- the desired size of the batch.- Returns:
- a batch of EmailSchedulingData to be retrieved from the persistence layer.
-
getNextBatchOps
-
getNextBatch
Description copied from interface:PersistenceServiceRetrieves a batch of EmailSchedulingData from the persistence layer, such that up tobatchMaxSizeinstances are returned from a whatsoever priority level.If no data is persisted, an empty collection is returned. If less than
batchMaxSizeare persisted,batchMaxSizeare returned.- Specified by:
getNextBatchin interfacePersistenceService- Parameters:
batchMaxSize- the desired size of the batch.- Returns:
- a batch of EmailSchedulingData to be retrieved from the persistence layer.
-
removeAll
public void removeAll()Description copied from interface:PersistenceServiceRemove all the EmailSchedulingData in the peristence layer.- Specified by:
removeAllin interfacePersistenceService
-
removeAll
public void removeAll(int priorityLevel) Description copied from interface:PersistenceServiceRemove all the EmailSchedulingData associated to the given priority level.- Specified by:
removeAllin interfacePersistenceService- Parameters:
priorityLevel- the id of the prioroty level that has to be erased.
-
removeAll
Description copied from interface:PersistenceServiceRemove all the EmailSchedulingData associated to the ids in the given collection. If for a specific id no key or value was found in the persistence layer, then the remove operation for that id is simply skipped.- Specified by:
removeAllin interfacePersistenceService- Parameters:
ids- a collection of ids of stored EmailSchedulingData.
-