com.atlassian.greenhopper.manager.lexorank
Class LexoRankDaoImpl

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

@Service
public class LexoRankDaoImpl
extends java.lang.Object
implements LexoRankDao


Field Summary
protected  com.atlassian.activeobjects.external.ActiveObjects ao
           
 
Constructor Summary
LexoRankDaoImpl()
           
 
Method Summary
 LockOutcome acquireLock(LexoRankRow[] rowsToLock, LexoRankDaoContext ctx)
          Attempts the acquire a database lock on the given LexoRankRows that represent rows in the LexoRank table.
 LockOutcome acquireLock(LexoRankRow rowToLock, LexoRankDaoContext ctx)
          Attempts the acquire a database lock on the given LexoRankRow that represents a row in the LexoRank table.
 LockOutcome acquireLock(java.lang.Long rowIdToLock, LexoRankDaoContext ctx)
          Attempts the acquire a database lock on the ID that represents a row in the LexoRank table.
 LockOutcome acquireLock(java.util.Set<LexoRankRow> rowsToLock, LexoRankDaoContext ctx)
          Attempts the acquire a database lock on the given LexoRankRows that represent rows in the LexoRank table.
 LockOutcome acquireLockByFieldId(java.lang.Long fieldId, LexoRankDaoContext ctx)
          Attempts the acquire a database lock on all rows in the LexoRank table whom's fieldId matches the given fieldId.
 java.util.Map<java.lang.String,java.lang.Long> countDuplicateRowsForFieldId(java.lang.Long fieldId, LexoRankDaoContext ctx)
          Returns a map of duplicate rank values and the amount of occurences of that rank value.
 LexoRankRow create(long fieldId, long issueId, java.lang.String rank)
          Create a row in the db for the given rank, issueId and fieldId
 int createBulk(long fieldId, java.util.Map<java.lang.Long,java.lang.String> issuesIdToRankMap)
          Creates a batch of LexoRank rows in one statement
 void createMarkerRowsForRankField(long fieldId)
          Creates the 'marker' rows for the given fieldId in the db.
 ServiceOutcome<java.lang.Void> deleteAll(LexoRankDaoContext ctx)
          Deletes all rows.
 LockProcessOutcome<ServiceOutcome<java.lang.Void>> deleteByFieldId(Lock lock, java.lang.Long fieldId, LexoRankDaoContext ctx)
          Deletes rows for the given fieldId
 LockProcessOutcome<ServiceOutcome<java.lang.Void>> deleteByFieldIdAndIssueId(Lock lock, java.lang.Long fieldId, java.lang.Long issueId, LexoRankDaoContext ctx)
          Deletes a single rank row for the given fieldId and issueId
 LockProcessOutcome<ServiceOutcome<java.lang.Void>> deleteByIssueId(Lock lock, java.lang.Long issueId, LexoRankDaoContext ctx)
          Deletes rows for the given issueId
 boolean existsRankForFieldId(java.lang.Long rankFieldId, java.lang.String rank, LexoRankDaoContext ctx)
          Checks if the given rank value already exists for the given rank field id.
protected  java.util.List<LexoRankRow> find(SqlSelectStatement selectStatement)
           
 com.atlassian.fugue.Option<LexoRankRow> findByFieldAndIssueId(long fieldId, long issueId, LexoRankDaoContext ctx)
          Finds a single rank row for the given fieldId and issueId
 LexoRankRow[] findByFieldId(long fieldId, LexoRankDaoContext ctx)
          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
 LexoRankRow[] findByIssueId(long issueId, LexoRankDaoContext ctx)
          Returns all rank rows for a given issueId.
 java.util.Collection<java.lang.Long> findFieldsNeedingBalancing()
          Retrieves a Collection of rank row IDs that require balancing.
 java.util.Set<java.lang.Long> findIssueIdsByFieldId(long fieldId)
          Retrieves a Set of issueIds of rank rows for the given fieldId
 com.atlassian.fugue.Option<LexoRankRow> findMaximumMarkerRow(long fieldId, LexoRankDaoContext ctx)
          Finds the maximum marker row for the given fieldId
 com.atlassian.fugue.Option<LexoRankRow> findMinimumMarkerRow(long fieldId, LexoRankDaoContext ctx)
          Finds the minimum marker row for the given fieldId
 LexoRankRow findNextOneByRank(long fieldId, java.lang.String rank, LexoRankDaoContext ctx)
          Find the next rank row (skipping over any duplicates)
 LexoRankRow getByFieldAndIssueId(long fieldId, long issueId, LexoRankDaoContext ctx)
          Gets a single LexoRankRow object with the given fieldId and issueId
 LexoRankDaoContext getContext()
          Returns a LexoRankDaoContext object that should be passed to any methods on the LexoRankDao that require it.
 LexoRankRow getMaximumMarkerRow(long fieldId, LexoRankDaoContext ctx)
           
 LexoRankRow[] getMaximumMarkerRowAndPreviousRow(long fieldId, LexoRankDaoContext ctx)
          Returns the maximum rank marker row and the previous row ranked before the maximum marker row for the given fieldId
 LexoRankRow getMinimumMarkerRow(long fieldId, LexoRankDaoContext ctx)
           
 LexoRankRow[] getMinimumMarkerRowAndNextRow(long fieldId, LexoRankDaoContext ctx)
          Returns the minimum rank marker row and the next row ranked behind the minimum marker row for the given fieldId
 LexoRankRow[] getRowByRankAndNextRow(long fieldId, java.lang.String rank, LexoRankDaoContext ctx)
          Returns the rank row with the given rank and the row ranked after that row.
 LexoRankRow[] getRowByRankAndPreviousRow(long fieldId, java.lang.String rank, LexoRankDaoContext ctx)
          Returns the rank row with the given rank and the row ranked before that row.
 LexoRankRow[] getRowsAtBalanceBoundaryForFieldId(java.lang.Long fieldId, LexoRankBucket bucketBeingMigratedFrom, LexoRankBucket bucketBeingMigratedTo, LexoRankDaoContext ctx)
          Finds the 2 rows at the balance boundary for the given field id and bucket.
 java.util.List<LexoRankRow> listByFieldIdAndRank(java.lang.Long fieldId, java.lang.String rank, LexoRankDaoContext ctx)
          Lists all the LexoRankRows for the given rank field id that have the given rank.
 java.util.List<java.lang.Long> listIssueIdsByFieldIdAndIssueIds(long fieldId, java.util.List<java.lang.Long> issueIds)
          Returns a list of issue IDs for which a LexoRank row with fieldId and one of the given issueIds exists.
 java.util.Map<java.lang.Long,java.lang.Long> ranksCountByField()
          Gets the number of distinct ranks for a field in the db
 void releaseLock(Lock lock, LexoRankDaoContext ctx)
          Releases the lock on all rows locked by the given lock.
 LockProcessOutcome<ServiceOutcome<LexoRankRow>> save(Lock lock, LexoRankRow lexoRankRow, LexoRankDaoContext ctx)
          Update a LexoRankRow.
 ServiceOutcome<LexoRankRow> unlockedSave(LexoRankRow lexoRankRow, LexoRankDaoContext ctx)
          Update a LexoRankRow, without the need for it to be locked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ao

protected com.atlassian.activeobjects.external.ActiveObjects ao
Constructor Detail

LexoRankDaoImpl

public LexoRankDaoImpl()
Method Detail

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

create

public LexoRankRow create(long fieldId,
                          long issueId,
                          java.lang.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
Returns:

createBulk

public int createBulk(long fieldId,
                      java.util.Map<java.lang.Long,java.lang.String> issuesIdToRankMap)
Description copied from interface: LexoRankDao
Creates a batch of LexoRank rows in one statement

Specified by:
createBulk in interface LexoRankDao
Returns:
the number of ranks inserted

listIssueIdsByFieldIdAndIssueIds

public java.util.List<java.lang.Long> listIssueIdsByFieldIdAndIssueIds(long fieldId,
                                                                       java.util.List<java.lang.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
Returns:

findByFieldId

public LexoRankRow[] findByFieldId(long fieldId,
                                   LexoRankDaoContext ctx)
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

find

protected java.util.List<LexoRankRow> find(SqlSelectStatement selectStatement)

getContext

public LexoRankDaoContext getContext()
Description copied from interface: LexoRankDao
Returns a LexoRankDaoContext object that should be passed to any methods on the LexoRankDao that require it. Once finished, the context should be closed.

Specified by:
getContext in interface LexoRankDao
Returns:

findByIssueId

public LexoRankRow[] findByIssueId(long issueId,
                                   LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Returns all rank rows for a given issueId.

Specified by:
findByIssueId in interface LexoRankDao
Returns:

findByFieldAndIssueId

public com.atlassian.fugue.Option<LexoRankRow> findByFieldAndIssueId(long fieldId,
                                                                     long issueId,
                                                                     LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Finds a single rank row for the given fieldId and issueId

Specified by:
findByFieldAndIssueId in interface LexoRankDao
Returns:

getByFieldAndIssueId

public LexoRankRow getByFieldAndIssueId(long fieldId,
                                        long issueId,
                                        LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Gets a single LexoRankRow object with the given fieldId and issueId

Specified by:
getByFieldAndIssueId in interface LexoRankDao
Returns:

findMinimumMarkerRow

public com.atlassian.fugue.Option<LexoRankRow> findMinimumMarkerRow(long fieldId,
                                                                    LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Finds the minimum marker row for the given fieldId

Specified by:
findMinimumMarkerRow in interface LexoRankDao
Returns:

getMinimumMarkerRow

public LexoRankRow getMinimumMarkerRow(long fieldId,
                                       LexoRankDaoContext ctx)
Specified by:
getMinimumMarkerRow in interface LexoRankDao

findMaximumMarkerRow

public com.atlassian.fugue.Option<LexoRankRow> findMaximumMarkerRow(long fieldId,
                                                                    LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Finds the maximum marker row for the given fieldId

Specified by:
findMaximumMarkerRow in interface LexoRankDao
Returns:

getMaximumMarkerRow

public LexoRankRow getMaximumMarkerRow(long fieldId,
                                       LexoRankDaoContext ctx)
Specified by:
getMaximumMarkerRow in interface LexoRankDao

getMinimumMarkerRowAndNextRow

public LexoRankRow[] getMinimumMarkerRowAndNextRow(long fieldId,
                                                   LexoRankDaoContext ctx)
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
Returns:

getMaximumMarkerRowAndPreviousRow

public LexoRankRow[] getMaximumMarkerRowAndPreviousRow(long fieldId,
                                                       LexoRankDaoContext ctx)
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
Returns:

getRowByRankAndNextRow

public LexoRankRow[] getRowByRankAndNextRow(long fieldId,
                                            java.lang.String rank,
                                            LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Returns the rank row with the given rank and the row ranked after that row.

Specified by:
getRowByRankAndNextRow in interface LexoRankDao
Returns:

findNextOneByRank

public LexoRankRow findNextOneByRank(long fieldId,
                                     java.lang.String rank,
                                     LexoRankDaoContext ctx)
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

getRowByRankAndPreviousRow

public LexoRankRow[] getRowByRankAndPreviousRow(long fieldId,
                                                java.lang.String rank,
                                                LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Returns the rank row with the given rank and the row ranked before that row.

Specified by:
getRowByRankAndPreviousRow in interface LexoRankDao
Returns:

findIssueIdsByFieldId

public java.util.Set<java.lang.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
Returns:

findFieldsNeedingBalancing

public java.util.Collection<java.lang.Long> findFieldsNeedingBalancing()
Description copied from interface: LexoRankDao
Retrieves a Collection of rank row IDs that require balancing.

Specified by:
findFieldsNeedingBalancing in interface LexoRankDao
Returns:

ranksCountByField

public java.util.Map<java.lang.Long,java.lang.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(java.lang.Long rowIdToLock,
                               LexoRankDaoContext ctx)
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
Returns:

acquireLock

public LockOutcome acquireLock(LexoRankRow rowToLock,
                               LexoRankDaoContext ctx)
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
Returns:

acquireLock

public LockOutcome acquireLock(java.util.Set<LexoRankRow> rowsToLock,
                               LexoRankDaoContext ctx)
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
Returns:

acquireLock

public LockOutcome acquireLock(LexoRankRow[] rowsToLock,
                               LexoRankDaoContext ctx)
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
Returns:

acquireLockByFieldId

public LockOutcome acquireLockByFieldId(java.lang.Long fieldId,
                                        LexoRankDaoContext ctx)
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
Returns:

releaseLock

public void releaseLock(Lock lock,
                        LexoRankDaoContext ctx)
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

deleteByIssueId

public LockProcessOutcome<ServiceOutcome<java.lang.Void>> deleteByIssueId(Lock lock,
                                                                          java.lang.Long issueId,
                                                                          LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Deletes rows for the given issueId

Specified by:
deleteByIssueId in interface LexoRankDao
Returns:

deleteByFieldId

public LockProcessOutcome<ServiceOutcome<java.lang.Void>> deleteByFieldId(Lock lock,
                                                                          java.lang.Long fieldId,
                                                                          LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Deletes rows for the given fieldId

Specified by:
deleteByFieldId in interface LexoRankDao
Returns:

deleteByFieldIdAndIssueId

public LockProcessOutcome<ServiceOutcome<java.lang.Void>> deleteByFieldIdAndIssueId(Lock lock,
                                                                                    java.lang.Long fieldId,
                                                                                    java.lang.Long issueId,
                                                                                    LexoRankDaoContext ctx)
Description copied from interface: LexoRankDao
Deletes a single rank row for the given fieldId and issueId

Specified by:
deleteByFieldIdAndIssueId in interface LexoRankDao
Returns:

deleteAll

public ServiceOutcome<java.lang.Void> deleteAll(LexoRankDaoContext ctx)
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,
                                                            LexoRankDaoContext ctx)
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,
                                                LexoRankDaoContext ctx)
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(java.lang.Long fieldId,
                                                        LexoRankBucket bucketBeingMigratedFrom,
                                                        LexoRankBucket bucketBeingMigratedTo,
                                                        LexoRankDaoContext ctx)
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
Returns:

existsRankForFieldId

public boolean existsRankForFieldId(java.lang.Long rankFieldId,
                                    java.lang.String rank,
                                    LexoRankDaoContext ctx)
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
Returns:

countDuplicateRowsForFieldId

public java.util.Map<java.lang.String,java.lang.Long> countDuplicateRowsForFieldId(java.lang.Long fieldId,
                                                                                   LexoRankDaoContext ctx)
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
Returns:

listByFieldIdAndRank

public java.util.List<LexoRankRow> listByFieldIdAndRank(java.lang.Long fieldId,
                                                        java.lang.String rank,
                                                        LexoRankDaoContext ctx)
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
Returns:


Copyright © 2007-2014 Atlassian. All Rights Reserved.