Class LexoRankDaoImpl

java.lang.Object
com.atlassian.greenhopper.manager.lexorank.LexoRankDaoImpl
All Implemented Interfaces:
LexoRankDao

@Service public class LexoRankDaoImpl extends Object implements LexoRankDao
  • Field Details

    • ao

      @Autowired protected com.atlassian.activeobjects.external.ActiveObjects ao
  • Constructor Details

    • LexoRankDaoImpl

      public LexoRankDaoImpl()
  • Method Details

    • createMarkerRowsForRankField

      public void createMarkerRowsForRankField(long fieldId)
      Description copied from interface: LexoRankDao
      Creates the 'marker' rows for the given fieldId in the db. These marker rows represent the minimum and maximum rank rows for a rank field. They aid in rank to top and bottom operations.
      Specified by:
      createMarkerRowsForRankField in interface LexoRankDao
      Parameters:
      fieldId -
    • create

      public LexoRankRow create(long fieldId, long issueId, String rank)
      Description copied from interface: LexoRankDao
      Create a row in the db for the given rank, issueId and fieldId
      Specified by:
      create in interface LexoRankDao
      Parameters:
      fieldId -
      issueId -
      rank -
      Returns:
    • listIssueIdsByFieldIdAndIssueIds

      public List<Long> listIssueIdsByFieldIdAndIssueIds(long fieldId, List<Long> issueIds)
      Description copied from interface: LexoRankDao
      Returns a list of issue IDs for which a LexoRank row with fieldId and one of the given issueIds exists.
      Specified by:
      listIssueIdsByFieldIdAndIssueIds in interface LexoRankDao
      Parameters:
      fieldId -
      issueIds -
      Returns:
    • findByIssueIds

      public LexoRankRow[] findByIssueIds(long fieldId, Iterable<Long> issueIds)
      Description copied from interface: LexoRankDao
      Returns all rank rows for given item IDs.
      Specified by:
      findByIssueIds in interface LexoRankDao
      Parameters:
      fieldId -
      issueIds -
      Returns:
    • findByFieldId

      public LexoRankRow[] findByFieldId(long fieldId)
      Description copied from interface: LexoRankDao
      WARNING: Do not use unless you know what you are doing because it returns all issues (which can be 100k+) Returns all ranking rows by field id
      Specified by:
      findByFieldId in interface LexoRankDao
      Parameters:
      fieldId - the field id
      Returns:
      the ranking rows for this field id
    • getContext

      public LexoRankDaoContext getContext()
      We are going to add a little bit here that will hold a reference so we don't create the context every time.

      In the next release I am going to do this synchronized to validate the collation of the db also.

      Specified by:
      getContext in interface LexoRankDao
      Returns:
      the current context
    • findByIssueId

      public LexoRankRow[] findByIssueId(long issueId)
      Description copied from interface: LexoRankDao
      Returns all rank rows for a given issueId.
      Specified by:
      findByIssueId in interface LexoRankDao
      Parameters:
      issueId -
      Returns:
    • findByIssueIds

      public LexoRankRow[] findByIssueIds(Iterable<Long> issueIds)
      Description copied from interface: LexoRankDao
      Returns all rank rows for a given issueIds.
      Specified by:
      findByIssueIds in interface LexoRankDao
      Parameters:
      issueIds -
      Returns:
    • findByFieldAndIssueId

      public io.atlassian.fugue.Option<LexoRankRow> findByFieldAndIssueId(long fieldId, long issueId)
      Description copied from interface: LexoRankDao
      Finds a single rank row for the given fieldId and issueId
      Specified by:
      findByFieldAndIssueId in interface LexoRankDao
      Parameters:
      fieldId -
      issueId -
      Returns:
    • getByFieldAndIssueId

      public LexoRankRow getByFieldAndIssueId(long fieldId, long issueId)
      Description copied from interface: LexoRankDao
      Gets a single LexoRankRow object with the given fieldId and issueId
      Specified by:
      getByFieldAndIssueId in interface LexoRankDao
      Parameters:
      fieldId -
      issueId -
      Returns:
    • findMinimumMarkerRow

      public io.atlassian.fugue.Option<LexoRankRow> findMinimumMarkerRow(long fieldId)
      Description copied from interface: LexoRankDao
      Finds the minimum marker row for the given fieldId
      Specified by:
      findMinimumMarkerRow in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • getMinimumMarkerRow

      public LexoRankRow getMinimumMarkerRow(long fieldId)
      Specified by:
      getMinimumMarkerRow in interface LexoRankDao
    • findMaximumMarkerRow

      public io.atlassian.fugue.Option<LexoRankRow> findMaximumMarkerRow(long fieldId)
      Description copied from interface: LexoRankDao
      Finds the maximum marker row for the given fieldId
      Specified by:
      findMaximumMarkerRow in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • getMaximumMarkerRow

      public LexoRankRow getMaximumMarkerRow(long fieldId)
      Specified by:
      getMaximumMarkerRow in interface LexoRankDao
    • findMaximumRankLengthRow

      public io.atlassian.fugue.Option<LexoRankRow> findMaximumRankLengthRow(long fieldId)
      Description copied from interface: LexoRankDao
      Finds the issue row with the longest rank for the given fieldId
      Specified by:
      findMaximumRankLengthRow in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • getMinimumMarkerRowAndNextRow

      public LexoRankRow[] getMinimumMarkerRowAndNextRow(long fieldId)
      Description copied from interface: LexoRankDao
      Returns the minimum rank marker row and the next row ranked behind the minimum marker row for the given fieldId
      Specified by:
      getMinimumMarkerRowAndNextRow in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • getMaximumMarkerRowAndPreviousRow

      public LexoRankRow[] getMaximumMarkerRowAndPreviousRow(long fieldId)
      Description copied from interface: LexoRankDao
      Returns the maximum rank marker row and the previous row ranked before the maximum marker row for the given fieldId
      Specified by:
      getMaximumMarkerRowAndPreviousRow in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • getRowByRankAndNextRows

      public LexoRankRow[] getRowByRankAndNextRows(long fieldId, String rank, int howMany)
      Description copied from interface: LexoRankDao
      Returns the rank row with the given rank and howMany rows ranked after that row. The values are returned in ascending order sorted by rank field.
      Specified by:
      getRowByRankAndNextRows in interface LexoRankDao
      Parameters:
      fieldId -
      rank -
      Returns:
      the rank row with the given rank and howMany rows ranked after that row
    • getRowByRankAndNextRow

      public LexoRankRow[] getRowByRankAndNextRow(long fieldId, String rank)
      Description copied from interface: LexoRankDao
      Returns the rank row with the given rank and the row ranked after that row. The values are returned in ascending order sorted by rank field.
      Specified by:
      getRowByRankAndNextRow in interface LexoRankDao
      Parameters:
      fieldId -
      rank -
      Returns:
    • findNextOneByRank

      public LexoRankRow findNextOneByRank(long fieldId, String rank)
      Description copied from interface: LexoRankDao
      Find the next rank row (skipping over any duplicates)
      Specified by:
      findNextOneByRank in interface LexoRankDao
      Parameters:
      fieldId - is the rank field
      rank - is the rank value
      Returns:
      the rank row
    • getRowByRankAndPreviousRows

      public LexoRankRow[] getRowByRankAndPreviousRows(long fieldId, String rank, int howMany)
      Description copied from interface: LexoRankDao
      Returns the rank row with the given rank and howMany rows ranked before that row. The values are returned in descending order sorted by rank field.
      Specified by:
      getRowByRankAndPreviousRows in interface LexoRankDao
      Parameters:
      fieldId -
      rank -
      Returns:
      the rank row with the given rank and howMany rows ranked before that row
    • getRowByRankAndPreviousRow

      public LexoRankRow[] getRowByRankAndPreviousRow(long fieldId, String rank)
      Description copied from interface: LexoRankDao
      Returns the rank row with the given rank and the row ranked before that row. The values are returned in descending order sorted by rank field.
      Specified by:
      getRowByRankAndPreviousRow in interface LexoRankDao
      Parameters:
      fieldId -
      rank -
      Returns:
    • findIssueIdsByFieldId

      public Set<Long> findIssueIdsByFieldId(long fieldId)
      Description copied from interface: LexoRankDao
      Retrieves a Set of issueIds of rank rows for the given fieldId
      Specified by:
      findIssueIdsByFieldId in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • findFieldIdsInLexoRankTable

      public Collection<Long> findFieldIdsInLexoRankTable()
      Description copied from interface: LexoRankDao
      Retrieves a Collection of rank row IDs that require balancing.
      Specified by:
      findFieldIdsInLexoRankTable in interface LexoRankDao
      Returns:
    • findObsoleteFields

      public Collection<Long> findObsoleteFields()
      Description copied from interface: LexoRankDao
      Finds fields that no longer have a corresponding entry in Jira Core's customfield table.
      Specified by:
      findObsoleteFields in interface LexoRankDao
      Returns:
    • ranksCountByField

      public Map<Long,Long> ranksCountByField()
      Description copied from interface: LexoRankDao
      Gets the number of distinct ranks for a field in the db
      Specified by:
      ranksCountByField in interface LexoRankDao
      Returns:
    • acquireLock

      public LockOutcome acquireLock(Long rowIdToLock)
      Description copied from interface: LexoRankDao
      Attempts the acquire a database lock on the ID that represents a row in the LexoRank table. If successfull, a LockOutcome object is returned which can be used to unlock the rows this lock operation locked.
      Specified by:
      acquireLock in interface LexoRankDao
      Parameters:
      rowIdToLock -
      Returns:
    • acquireLock

      public LockOutcome acquireLock(LexoRankRow rowToLock)
      Description copied from interface: LexoRankDao
      Attempts the acquire a database lock on the given LexoRankRow that represents a row in the LexoRank table. If successfull, a LockOutcome object is returned which can be used to unlock the rows this lock operation locked.
      Specified by:
      acquireLock in interface LexoRankDao
      Parameters:
      rowToLock -
      Returns:
    • acquireLock

      public LockOutcome acquireLock(Set<LexoRankRow> rowsToLock)
      Description copied from interface: LexoRankDao
      Attempts the acquire a database lock on the given LexoRankRows that represent rows in the LexoRank table. If successfull, a LockOutcome object is returned which can be used to unlock the rows this lock operation locked.
      Specified by:
      acquireLock in interface LexoRankDao
      Parameters:
      rowsToLock -
      Returns:
    • acquireLock

      public LockOutcome acquireLock(LexoRankRow[] rowsToLock)
      Description copied from interface: LexoRankDao
      Attempts the acquire a database lock on the given LexoRankRows that represent rows in the LexoRank table. If successfull, a LockOutcome object is returned which can be used to unlock the rows this lock operation locked.
      Specified by:
      acquireLock in interface LexoRankDao
      Parameters:
      rowsToLock -
      Returns:
    • acquireLockByFieldId

      public LockOutcome acquireLockByFieldId(Long fieldId)
      Description copied from interface: LexoRankDao
      Attempts the acquire a database lock on all rows in the LexoRank table whom's fieldId matches the given fieldId. If successfull, a LockOutcome object is returned which can be used to unlock the rows this lock operation locked.
      Specified by:
      acquireLockByFieldId in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • releaseLock

      public void releaseLock(Lock lock)
      Description copied from interface: LexoRankDao
      Releases the lock on all rows locked by the given lock. This will clear out the lockHash and lockTime column for rows whom's current value match the given Lock object's hash and time.
      Specified by:
      releaseLock in interface LexoRankDao
      Parameters:
      lock -
    • deleteByIssueId

      public LockProcessOutcome<ServiceResult> deleteByIssueId(Lock lock, Long issueId)
      Description copied from interface: LexoRankDao
      Deletes rows for the given issueId
      Specified by:
      deleteByIssueId in interface LexoRankDao
      Parameters:
      lock -
      issueId -
      Returns:
    • deleteByLimitedIssueIds

      public LockProcessOutcome<ServiceResult> deleteByLimitedIssueIds(Lock lock, List<Long> issueIds)
      Description copied from interface: LexoRankDao
      Deletes rows for the given issueIds
      Specified by:
      deleteByLimitedIssueIds in interface LexoRankDao
      Parameters:
      lock -
      issueIds - of the issues. Must have less than 1000 elements otherwise the queries could fail on certain databases.
      Returns:
    • deleteByFieldIdNoLock

      public ServiceResult deleteByFieldIdNoLock(Long fieldId)
      Description copied from interface: LexoRankDao
      Deletes all rows for a given fieldId without locking them first.
      Specified by:
      deleteByFieldIdNoLock in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • deleteByFieldId

      public LockProcessOutcome<ServiceResult> deleteByFieldId(Lock lock, Long fieldId)
      Description copied from interface: LexoRankDao
      Deletes rows for the given fieldId
      Specified by:
      deleteByFieldId in interface LexoRankDao
      Parameters:
      lock -
      fieldId -
      Returns:
    • deleteByFieldIdAndIssueId

      public LockProcessOutcome<ServiceResult> deleteByFieldIdAndIssueId(Lock lock, Long fieldId, Long issueId)
      Description copied from interface: LexoRankDao
      Deletes a single rank row for the given fieldId and issueId
      Specified by:
      deleteByFieldIdAndIssueId in interface LexoRankDao
      Parameters:
      lock -
      fieldId -
      issueId -
      Returns:
    • deleteAll

      public ServiceResult deleteAll()
      Description copied from interface: LexoRankDao
      Deletes all rows.
      Specified by:
      deleteAll in interface LexoRankDao
      Returns:
    • save

      public LockProcessOutcome<ServiceOutcome<LexoRankRow>> save(Lock lock, LexoRankRow lexoRankRow)
      Description copied from interface: LexoRankDao
      Update a LexoRankRow.
      Specified by:
      save in interface LexoRankDao
      Parameters:
      lock - is the lock objects.
      lexoRankRow - the LexoRankRow to persist.
      Returns:
      outcome of the save.
    • unlockedSave

      public ServiceOutcome<LexoRankRow> unlockedSave(LexoRankRow lexoRankRow)
      Description copied from interface: LexoRankDao
      Update a LexoRankRow, without the need for it to be locked.
      Specified by:
      unlockedSave in interface LexoRankDao
      Parameters:
      lexoRankRow - the LexoRankRow to save
      Returns:
      service outcome.
    • getRowsAtBalanceBoundaryForFieldId

      public LexoRankRow[] getRowsAtBalanceBoundaryForFieldId(Long fieldId, LexoRankBucket bucketBeingMigratedFrom, LexoRankBucket bucketBeingMigratedTo)
      Description copied from interface: LexoRankDao
      Finds the 2 rows at the balance boundary for the given field id and bucket. The balance boundary is where the last migrated rank row and the next rank row to be migrated meet. An array with 2 LexoRankRow objects is returned where the first row is the row to be migrated and the second row is the row that was last migrated
      Specified by:
      getRowsAtBalanceBoundaryForFieldId in interface LexoRankDao
      Parameters:
      fieldId -
      bucketBeingMigratedFrom -
      bucketBeingMigratedTo -
      Returns:
    • existsRankForFieldId

      public boolean existsRankForFieldId(Long rankFieldId, String rank)
      Description copied from interface: LexoRankDao
      Checks if the given rank value already exists for the given rank field id.
      Specified by:
      existsRankForFieldId in interface LexoRankDao
      Parameters:
      rankFieldId -
      rank -
      Returns:
    • countDuplicateRowsForFieldId

      public Map<String,Long> countDuplicateRowsForFieldId(Long fieldId)
      Description copied from interface: LexoRankDao
      Returns a map of duplicate rank values and the amount of occurences of that rank value.
      Specified by:
      countDuplicateRowsForFieldId in interface LexoRankDao
      Parameters:
      fieldId -
      Returns:
    • listByFieldIdAndRank

      public List<LexoRankRow> listByFieldIdAndRank(Long fieldId, String rank)
      Description copied from interface: LexoRankDao
      Lists all the LexoRankRows for the given rank field id that have the given rank.
      Specified by:
      listByFieldIdAndRank in interface LexoRankDao
      Parameters:
      fieldId -
      rank -
      Returns:
    • getRowCountForFieldId

      public Integer getRowCountForFieldId(Long fieldId)
      Description copied from interface: LexoRankDao
      Get the number of rows for a given rank field.
      Specified by:
      getRowCountForFieldId in interface LexoRankDao
      Parameters:
      fieldId - Id of the rank field
      Returns:
      Number of rows for the specified rank field
    • getRowCountInBucket

      public long getRowCountInBucket(Long fieldId, LexoRankBucket containingBucket)
      Description copied from interface: LexoRankDao
      Get the number of rows for a given fieldId and bucket.
      Specified by:
      getRowCountInBucket in interface LexoRankDao
      Parameters:
      fieldId - Id of the rank field
      containingBucket -
      Returns:
      the number of rows for a given fieldId and bucket.
    • getRowCountInBucket

      public long getRowCountInBucket(Long fieldId, LexoRankBucket containingBucket, @Nullable LexoRankRow.RankRowType rankRowType)
      Description copied from interface: LexoRankDao
      Get the number of rows for a given fieldId, bucket and type.
      Specified by:
      getRowCountInBucket in interface LexoRankDao
      Parameters:
      fieldId - Id of the rank field
      containingBucket -
      rankRowType -
      Returns:
      the number of rows for a given fieldId, rowType and bucket.
    • getNumRowsWithInvalidBucket

      public long getNumRowsWithInvalidBucket(Long fieldId)
      Specified by:
      getNumRowsWithInvalidBucket in interface LexoRankDao
      Parameters:
      fieldId - is the rank field id
      Returns:
      the number of rows where BUCKET doesn't match the bucket encoded in the RANK field.
    • listIssueIdsBetween

      public List<Long> listIssueIdsBetween(long startIdInclusive, long endIdInclusive)
      Description copied from interface: LexoRankDao
      Get the stored issue IDs between startIdInclusive and endIdInclusive
      Specified by:
      listIssueIdsBetween in interface LexoRankDao
      Parameters:
      startIdInclusive -
      endIdInclusive -
      Returns:
    • find

      protected List<LexoRankRow> find(SqlSelectStatement selectStatement)