Package org.exoplatform.agenda.storage
Class CalendarSubscriptionStorage
java.lang.Object
org.exoplatform.agenda.storage.CalendarSubscriptionStorage
Maps calendar subscriptions and the occurrences they imported between their
rows and their models (EXO-90278). No cache: the job reads a row right after
claiming it, and must read what the claim just wrote.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMost occurrence rows read for one subscription: comfortably above what an import keeps, so that the rows of occurrences a feed dropped are read too. -
Constructor Summary
ConstructorsConstructorDescriptionCalendarSubscriptionStorage(CalendarSubscriptionDAO subscriptionDAO, CalendarSubscriptionEventDAO subscriptionEventDAO) Builds the storage. -
Method Summary
Modifier and TypeMethodDescriptionbooleanClaims a subscription for a node, due or not.booleanClaims a due subscription for a node.org.exoplatform.agenda.model.CalendarSubscriptioncreate(org.exoplatform.agenda.model.CalendarSubscription subscription) Inserts a subscription.voiddelete(long id) Deletes a subscription and its occurrence rows; the events are the caller's.voiddeleteEvent(long id) Deletes an occurrence row.org.exoplatform.agenda.model.CalendarSubscriptiongetByCalendarId(long calendarId) Reads the subscription of a calendar.org.exoplatform.agenda.model.CalendarSubscriptiongetById(long id) Reads a subscription.org.exoplatform.agenda.model.CalendarSubscriptiongetByUrlKey(String urlKey) Reads a user's subscription to a URL.List<org.exoplatform.agenda.model.CalendarSubscription> getByUser(long userIdentityId, int limit) Reads a user's subscriptions, oldest first.Lists the subscriptions due and unclaimed.List<org.exoplatform.agenda.model.CalendarSubscriptionEvent> getEvents(long subscriptionId) Reads the occurrence rows of a subscription.booleanrecordFailure(long id, String node, Date attempt, String lastError, Date nextRefreshDate) Records a failed refresh and releases the claim.booleanrecordSuccess(long id, String node, String urlKey, String etag, String lastModified, String contentHash, Integer refreshMinutes, Date attempt, boolean truncated, Date nextRefreshDate) Records a successful refresh and releases the claim.booleanReleases a node's claim.org.exoplatform.agenda.model.CalendarSubscriptionEventsaveEvent(org.exoplatform.agenda.model.CalendarSubscriptionEvent event) Inserts or updates an occurrence row.booleanPoints a subscription at a new URL, due at once.
-
Field Details
-
MAX_EVENT_ROWS
public static final int MAX_EVENT_ROWSMost occurrence rows read for one subscription: comfortably above what an import keeps, so that the rows of occurrences a feed dropped are read too.- See Also:
-
-
Constructor Details
-
CalendarSubscriptionStorage
@Autowired public CalendarSubscriptionStorage(CalendarSubscriptionDAO subscriptionDAO, CalendarSubscriptionEventDAO subscriptionEventDAO) Builds the storage.- Parameters:
subscriptionDAO- the subscription rowssubscriptionEventDAO- the occurrence rows
-
-
Method Details
-
getById
public org.exoplatform.agenda.model.CalendarSubscription getById(long id) Reads a subscription.- Parameters:
id- technical identifier- Returns:
- the subscription, or null
-
getByCalendarId
public org.exoplatform.agenda.model.CalendarSubscription getByCalendarId(long calendarId) Reads the subscription of a calendar.- Parameters:
calendarId- technical identifier of the calendar- Returns:
- the subscription, or null
-
getByUrlKey
Reads a user's subscription to a URL.- Parameters:
urlKey- the key of the user and the URL- Returns:
- the subscription, or null
-
getByUser
public List<org.exoplatform.agenda.model.CalendarSubscription> getByUser(long userIdentityId, int limit) Reads a user's subscriptions, oldest first.- Parameters:
userIdentityId- identity identifier of the userlimit- most subscriptions read- Returns:
- the subscriptions
-
create
public org.exoplatform.agenda.model.CalendarSubscription create(org.exoplatform.agenda.model.CalendarSubscription subscription) Inserts a subscription. The insert is flushed, so that the engine's refusal of a second subscription of the user to the URL surfaces here.- Parameters:
subscription- the subscription, without identifier- Returns:
- the stored subscription, or null when a subscription with the same URL key or calendar already exists
-
updateUrl
Points a subscription at a new URL, due at once.- Parameters:
id- technical identifierurlEncrypted- the new URL encryptedurlKey- the key of the new URLnow- the instant it becomes due- Returns:
- false when the user already subscribes to that URL
-
getDueIds
Lists the subscriptions due and unclaimed.- Parameters:
now- the current instantstaleBefore- a claim older than this no longer countslimit- the batch- Returns:
- technical identifiers, the longest waiting first
-
claimDue
Claims a due subscription for a node.- Parameters:
id- technical identifiernode- the nodenow- the current instantstaleBefore- a claim older than this may be taken over- Returns:
- true when the node now holds it
-
claim
Claims a subscription for a node, due or not.- Parameters:
id- technical identifiernode- the nodenow- the current instantstaleBefore- a claim older than this may be taken over- Returns:
- true when the node now holds it
-
release
Releases a node's claim.- Parameters:
id- technical identifiernode- the node- Returns:
- true when released
-
recordSuccess
public boolean recordSuccess(long id, String node, String urlKey, String etag, String lastModified, String contentHash, Integer refreshMinutes, Date attempt, boolean truncated, Date nextRefreshDate) Records a successful refresh and releases the claim.- Parameters:
id- technical identifiernode- the node holding the claimurlKey- the key of the URL readetag- the entity tag readlastModified- the Last-Modified header readcontentHash- digest of the bodyrefreshMinutes- interval the feed advertised, null for noneattempt- when the refresh rantruncated- whether part of the feed was left outnextRefreshDate- when the next refresh is due- Returns:
- true when recorded
-
recordFailure
public boolean recordFailure(long id, String node, Date attempt, String lastError, Date nextRefreshDate) Records a failed refresh and releases the claim.- Parameters:
id- technical identifiernode- the node holding the claimattempt- when the refresh ranlastError- message code of the failurenextRefreshDate- when the next attempt is due- Returns:
- true when recorded
-
delete
public void delete(long id) Deletes a subscription and its occurrence rows; the events are the caller's.- Parameters:
id- technical identifier
-
getEvents
Reads the occurrence rows of a subscription.- Parameters:
subscriptionId- technical identifier of the subscription- Returns:
- the rows, oldest first
-
saveEvent
public org.exoplatform.agenda.model.CalendarSubscriptionEvent saveEvent(org.exoplatform.agenda.model.CalendarSubscriptionEvent event) Inserts or updates an occurrence row.- Parameters:
event- the row; an identifier of 0 inserts- Returns:
- the row as stored
-
deleteEvent
public void deleteEvent(long id) Deletes an occurrence row.- Parameters:
id- technical identifier of the row
-