This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ccd5c3
commit baf1057
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...o/src/main/java/org/isisaddons/module/publishmq/dom/jdo/events/OutboxEventRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.isisaddons.module.publishmq.dom.jdo.events; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.isis.applib.annotation.DomainService; | ||
import org.apache.isis.applib.annotation.NatureOfService; | ||
import org.apache.isis.applib.annotation.Programmatic; | ||
import org.apache.isis.applib.query.QueryDefault; | ||
import org.apache.isis.applib.services.repository.RepositoryService; | ||
|
||
/** | ||
* Provides supporting functionality for querying and persisting | ||
* {@link OutboxEvent outbox event} entities. | ||
*/ | ||
@DomainService(nature = NatureOfService.DOMAIN) | ||
public class OutboxEventRepository { | ||
|
||
@Programmatic | ||
public Optional<OutboxEvent> findByTransactionIdAndSequence(final UUID transactionId, final int sequence) { | ||
return Optional.ofNullable( | ||
repositoryService.uniqueMatch( | ||
new QueryDefault<>(OutboxEvent.class, | ||
"findByTransactionIdAndSequence", | ||
"transactionId", transactionId, | ||
"sequence", sequence | ||
)) | ||
); | ||
} | ||
|
||
@Programmatic | ||
public List<OutboxEvent> findOldestUser() { | ||
return repositoryService.allMatches( | ||
new QueryDefault<>(OutboxEvent.class, "findOldest")); | ||
} | ||
|
||
|
||
@Programmatic | ||
public boolean deleteByTransactionIdAndSequence(final UUID transactionId, final int sequence) { | ||
Optional<OutboxEvent> outboxEventIfAny = findByTransactionIdAndSequence(transactionId, sequence); | ||
if(outboxEventIfAny.isPresent()) { | ||
repositoryService.removeAndFlush(outboxEventIfAny); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
|
||
@Inject | ||
RepositoryService repositoryService; | ||
|
||
} |