Class HibernateJournalDao

    • Constructor Detail

      • HibernateJournalDao

        public HibernateJournalDao​(org.hibernate.SessionFactory sessionFactory)
      • HibernateJournalDao

        public HibernateJournalDao​(org.hibernate.SessionFactory sessionFactory,
                                   com.atlassian.core.util.Clock clock)
    • Method Detail

      • enqueue

        public long enqueue​(@NonNull JournalEntry entry)
        Description copied from interface: JournalDao
        Adds the given entry to a journal.
        Specified by:
        enqueue in interface JournalDao
        Parameters:
        entry - entry to persist
        Returns:
        id generated for the entry
      • enqueue

        public void enqueue​(@NonNull Collection<JournalEntry> entries)
        Description copied from interface: JournalDao
        Adds a collection of given entries to a journal. Adding multiple records in one transaction is more efficient than inserting them one by one.
        Specified by:
        enqueue in interface JournalDao
        Parameters:
        entries - entries to persist
      • queueWithCustomCreationDate

        @Internal
        public void queueWithCustomCreationDate​(JournalEntry entry,
                                                Date creationDate)
      • findEntries

        public List<JournalEntry> findEntries​(@NonNull JournalIdentifier journalId,
                                              long afterId,
                                              long ignoreWithinMillis,
                                              int maxEntries)
        Description copied from interface: JournalDao
        Finds journal entries that were added after an entry with the given id but earlier than given milliseconds ago. Entries are returned in ascending order of their identifier.

        This method can miss some entries due to identifier assignment and entry insertion not being an atomic operation. The risk of missed entries can be reduced in two ways:

        1. Create new entries as close to transaction commit as possible.
        2. Increase ignoreSinceMillis value.
        Specified by:
        findEntries in interface JournalDao
        Parameters:
        journalId - only entries with this journal id will be returned
        afterId - only entries with id higher than this will be returned
        ignoreWithinMillis - only entries created this many milliseconds ago or earlier will be returned
        maxEntries - maximum number of entries to process
        Returns:
        journal entries that were added after an entry with the given id
      • findMostRecentEntryByMessage

        public com.atlassian.fugue.Option<JournalEntry> findMostRecentEntryByMessage​(@NonNull JournalIdentifier journalId,
                                                                                     String message)
        Description copied from interface: JournalDao
        Finds the most recent journal entry (if any) for the given journal that exactly matches the given journal entry message.

        Note that this operation is likely to EXTREMELY SLOW when the journal gets above a certain size. Do not use in production code.

        Specified by:
        findMostRecentEntryByMessage in interface JournalDao
        Parameters:
        journalId - only entries with this journal id will be returned
        message - the exact text of the journal entry message
        Returns:
        the Optional journal entry matching the search
      • removeEntriesOlderThan

        public int removeEntriesOlderThan​(@NonNull Date date)
        Description copied from interface: JournalDao
        Removes entries from all journals that were created before the given date.
        Specified by:
        removeEntriesOlderThan in interface JournalDao
        Parameters:
        date - only entried with a date later than this will be returned
        Returns:
        number of removed entries
      • findLatestEntry

        public com.atlassian.fugue.Option<JournalEntry> findLatestEntry​(@NonNull JournalIdentifier journalId,
                                                                        long ignoreWithinMillis)
        Description copied from interface: JournalDao
        Finds the latest journal entry if any.
        Specified by:
        findLatestEntry in interface JournalDao
        Parameters:
        journalId - identifier of the journal
        ignoreWithinMillis - only entry created this many milliseconds ago or earlier will be returned
        Returns:
        the latest journal entry
      • findEarliestEntry

        public com.atlassian.fugue.Option<JournalEntry> findEarliestEntry()
        Description copied from interface: JournalDao
        Finds the earliest journal entry if any.
        Specified by:
        findEarliestEntry in interface JournalDao
        Returns:
        the earliest journal entry across all journals
      • findEntry

        public JournalEntry findEntry​(long entryId)
        Description copied from interface: JournalDao
        Finds the specified journal entry, if it exists.
        Specified by:
        findEntry in interface JournalDao
        Parameters:
        entryId - identifier of the journal entry
        Returns:
        the journal entry matching the given id
      • countEntries

        public int countEntries​(@NonNull JournalIdentifier journalId,
                                long afterId,
                                long ignoreWithinMillis)
        Description copied from interface: JournalDao
        Counts the number of entries in a journal.
        Specified by:
        countEntries in interface JournalDao
        Parameters:
        journalId - identifier of the journal
        afterId - only entries with id higher than this will be returned
        ignoreWithinMillis - only entries created this many milliseconds ago or earlier will be returned
      • updateEntry

        public void updateEntry​(JournalEntry journalEntry)
        Description copied from interface: JournalDao
        Update a persistent journal entry
        Specified by:
        updateEntry in interface JournalDao
        Parameters:
        journalEntry - the journal entry must be persistent