Package com.atlassian.bamboo.plan
Class PlanHibernateDao<T extends Plan>
java.lang.Object
org.springframework.dao.support.DaoSupport
org.springframework.orm.hibernate5.support.HibernateDaoSupport
com.atlassian.bamboo.persistence3.StatelessSessionHibernateDaoSupport
com.atlassian.bamboo.persistence3.BambooHibernateObjectDao<E>
com.atlassian.bamboo.persistence3.BambooHibernateObjectWithOidDao<Plan>
com.atlassian.bamboo.plan.PlanHibernateDao<T>
- All Implemented Interfaces:
BambooObjectDao<Plan>
,BambooObjectWithOidDao<Plan>
,PlanDao
,org.springframework.beans.factory.InitializingBean
public class PlanHibernateDao<T extends Plan>
extends BambooHibernateObjectWithOidDao<Plan>
implements PlanDao
ATTENTION: All methods that create, modify or remove entities, must increment the appropriate version number.
This needs to be handled manually, look at the existing methods like 'save'.
-
Field Summary
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
-
Constructor Summary
ConstructorDescriptionPlanHibernateDao
(TransactionAndHibernateTemplate transactionTemplate, BambooClusterSettings bambooClusterSettings) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clearInvalidFlagForBranchesOfChain
(long masterId) void
Removes the given entity from the databasefilterFavouritedPlans
(@NotNull Collection<? extends ImmutableChain> plans, @NotNull com.atlassian.user.User user) Return a collection ofTopLevelPlan
s that are a subset of the givenPlan
s collection that are favourited by theUser
findAllPlans
(Class<T> planType) Return aPlan
collection for specified plan type.findAllPlans
(Class<T> planType, int firstResult, int maxResults) Return aPlan
collection for specified plan type.findAllPlansByProject
(@NotNull Project project, Class<T> planType) <E extends Plan>
EFind an entity by its idfindPlansByProject
(@NotNull Project project, Class<T> planType) getAllPlanKeys
(Class<T> planType) Returns all plan keys of a particular type, including the plans marked for deletion.<T extends Plan>
@NotNull Collection<T>getAllPlansMarkedForDeletion
(Class<T> planType) Returns a list ofPlan
s that areImmutableDeletable.isMarkedForDeletion()
for the given type<T extends Plan>
longgetAllPlansMarkedForDeletionCount
(Class<T> planType) Returns a count ofPlan
s that areImmutableDeletable.isMarkedForDeletion()
for the given typeint
getBranchCount
(@NotNull ImmutablePlan plan) Returns the number of branches that exist for the given planReturns the number of branches that exist for master plans in Bamboo.@NotNull List<ChainBranch>
Returns all branches which have the given chain as their mastergetBranchesForJob
(Job job) @NotNull List<ChainBranchIdentifier>
getBranchIdentifiersForChain
(@NotNull PlanIdentifier plan) Returns minimal data about all branches which have the given chain as their mastergetBranchKeysForChain
(@NotNull PlanKey chainKey) Returns the keys of branches that have as master the chain identified by the given chainKey.getFavouritePlansIds
(@NotNull com.atlassian.user.User user) Return a collection of Favourite plan ids.getJobKeys
(@NotNull PlanKey chainKey) Return all plan keys of Jobs that belong to a Chain@Nullable BambooEntityOid
getMaxPlanOid
(int serverKey, @NotNull BambooEntityType entityType) Returns the maxBambooEntityOid
that's currently in use of the specified entity type, with the given server key.<T extends Plan>
TgetPlanByKey
(@NotNull PlanKey planKey, Class<T> aClass) Return aPlan
that matches the given key<T extends Plan>
TgetPlanByKey
(@NotNull String planKey, Class<T> aClass) Return aPlan
that matches the given key<T extends Plan>
TgetPlanByPartialKeyAndName
(@NotNull PlanKey partialPlanKey, @NotNull String planName, Class<T> planType) getPlanClass
(@NotNull PlanKey planKey) int
getPlanCount
(@NotNull ProjectIdentifier projectIdentifier) How many plans currently exist in aproject
.<T extends Plan>
intgetPlanCount
(Class<T> planType) How many plans filtered byClass
currently exist@Nullable PlanIdentifier
getPlanIdentifierForPermissionCheckingByKey
(@NotNull String planKey) Return aPlan
skeleton providing ONLY id and key, that matches the given key This method should be used only for permission checking using Acegi IfJob
key is provided as a parameter, parent Chain will be returned anyway, as Acegi assertions are defined only forTopLevelPlan
s<T extends Plan>
@NotNull List<PlanIdentifier>getPlanIdentifiersForProject
(@NotNull ProjectIdentifier project, @NotNull Class<T> planType, boolean includeMarkedForDeletion) Returns minimal data about all plans in the given projectgetPlanKeys
(Class<T> planType) Returns all plan keys of a particular type, NOT including the plans marked for deletion.getPlanKeysPlanIdsMapping
(@NotNull Class<T> aClass) boolean
isChainNameConflicting
(@NotNull String projectKey, long idOfChainBeingVerified, @NotNull String planName) Verifies whether aChain
name is unique with the given projectboolean
isPlanKeyConflicting
(@NotNull PlanKey planKey) Verifies whether aPlan
key is unique within whole Bamboo installationboolean
isPlanKeyConflicting
(@NotNull PlanKey planKey, long idOfChainBeingVerified) Verifies whether aPlan
key is unique within whole Bamboo installationvoid
markPlanForDeletion
(PlanKey planKey) Efficiently marks a plan to be deletedvoid
Saves the given entity.void
setPlanDiscriminatorRegistry
(PlanDiscriminatorRegistry planDiscriminatorRegistry) void
Performs a cleanup task to markChainBranch
objects that have a masterPlan
that is marked to be deleted, but is not marked as deleted.void
Performs a cleanup task to markJob
objects that have aPlan
orChainStage
that is marked to be deleted, but it itself was not marked as deleted.void
Methods inherited from class com.atlassian.bamboo.persistence3.BambooHibernateObjectWithOidDao
findByOid
Methods inherited from class com.atlassian.bamboo.persistence3.BambooHibernateObjectDao
convertSearchTermToLikeExpression, countAll, countWithRestriction, deleteAll, executeCountQuery, findAll, merge, saveAll
Methods inherited from class com.atlassian.bamboo.persistence3.StatelessSessionHibernateDaoSupport
getCacheAwareHibernateTemplate
Methods inherited from class org.springframework.orm.hibernate5.support.HibernateDaoSupport
checkDaoConfig, createHibernateTemplate, currentSession, getHibernateTemplate, getSessionFactory, setHibernateTemplate, setSessionFactory
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.atlassian.bamboo.persistence3.BambooObjectDao
countAll, countWithRestriction, deleteAll, findAll, merge, saveAll
Methods inherited from interface com.atlassian.bamboo.persistence3.BambooObjectWithOidDao
findByOid
-
Constructor Details
-
PlanHibernateDao
public PlanHibernateDao(TransactionAndHibernateTemplate transactionTemplate, BambooClusterSettings bambooClusterSettings)
-
-
Method Details
-
getPlanByKey
Description copied from interface:PlanDao
Return aPlan
that matches the given key- Specified by:
getPlanByKey
in interfacePlanDao
- Returns:
- plan
-
getPlanByKey
Description copied from interface:PlanDao
Return aPlan
that matches the given key- Specified by:
getPlanByKey
in interfacePlanDao
- Returns:
- plan
-
getPlanIdentifierForPermissionCheckingByKey
@Nullable public @Nullable PlanIdentifier getPlanIdentifierForPermissionCheckingByKey(@NotNull @NotNull String planKey) Description copied from interface:PlanDao
Return aPlan
skeleton providing ONLY id and key, that matches the given key This method should be used only for permission checking using Acegi IfJob
key is provided as a parameter, parent Chain will be returned anyway, as Acegi assertions are defined only forTopLevelPlan
s- Specified by:
getPlanIdentifierForPermissionCheckingByKey
in interfacePlanDao
- Returns:
- plan
-
getPlanClass
- Specified by:
getPlanClass
in interfacePlanDao
-
findById
Description copied from interface:BambooObjectDao
Find an entity by its id- Specified by:
findById
in interfaceBambooObjectDao<T extends Plan>
- Overrides:
findById
in classBambooHibernateObjectDao<Plan>
- Parameters:
id
- id of entityaClass
- class of entity- Returns:
- entity
-
isChainNameConflicting
public boolean isChainNameConflicting(@NotNull @NotNull String projectKey, long idOfChainBeingVerified, @NotNull @NotNull String planName) Description copied from interface:PlanDao
Verifies whether aChain
name is unique with the given project- Specified by:
isChainNameConflicting
in interfacePlanDao
- Parameters:
projectKey
- of the project to look for the plan inidOfChainBeingVerified
- the id of the plan that has to be ignored during lookup (when you're saving a Plan, you should supply the plan id here)planName
- - name of the plan inside the project: this is just the plan component of the name (i.e does not include the project component)- Returns:
- true if the name is in conflict
-
isPlanKeyConflicting
Description copied from interface:PlanDao
Verifies whether aPlan
key is unique within whole Bamboo installation- Specified by:
isPlanKeyConflicting
in interfacePlanDao
- Parameters:
planKey
- key of the plan to be searched for in the database- Returns:
- true if plan key is conflicting
-
isPlanKeyConflicting
Description copied from interface:PlanDao
Verifies whether aPlan
key is unique within whole Bamboo installation- Specified by:
isPlanKeyConflicting
in interfacePlanDao
- Parameters:
planKey
- key of the plan to be searched for in the databaseidOfChainBeingVerified
- id of plan that is verified (i.e. if that plan uses the key, it's not a duplicate key)- Returns:
- true if plan key is conflicting
-
getPlanByPartialKeyAndName
@Nullable public <T extends Plan> T getPlanByPartialKeyAndName(@NotNull @NotNull PlanKey partialPlanKey, @NotNull @NotNull String planName, Class<T> planType) Description copied from interface:PlanDao
- Specified by:
getPlanByPartialKeyAndName
in interfacePlanDao
- Returns:
- plan
-
getPlanCount
Description copied from interface:PlanDao
How many plans filtered byClass
currently exist- Specified by:
getPlanCount
in interfacePlanDao
- Returns:
- how many plans exist in the database
-
getPlanCount
Description copied from interface:PlanDao
How many plans currently exist in aproject
.- Specified by:
getPlanCount
in interfacePlanDao
- Parameters:
projectIdentifier
- identifier of the project- Returns:
- how many plans exist in the database in a project, excluding ones marked for deletion
-
getPlanKeys
Description copied from interface:PlanDao
Returns all plan keys of a particular type, NOT including the plans marked for deletion.- Specified by:
getPlanKeys
in interfacePlanDao
-
getAllPlanKeys
Description copied from interface:PlanDao
Returns all plan keys of a particular type, including the plans marked for deletion.- Specified by:
getAllPlanKeys
in interfacePlanDao
-
getJobKeys
Description copied from interface:PlanDao
Return all plan keys of Jobs that belong to a Chain- Specified by:
getJobKeys
in interfacePlanDao
- Parameters:
chainKey
- key of a Chain- Returns:
- list of Job keys
-
findPlansByProject
@NotNull public <T extends Plan> @NotNull List<T> findPlansByProject(@NotNull @NotNull Project project, Class<T> planType) Description copied from interface:PlanDao
- Specified by:
findPlansByProject
in interfacePlanDao
- Returns:
- plans for specifid project
-
findAllPlansByProject
@NotNull public <T extends Plan> @NotNull List<T> findAllPlansByProject(@NotNull @NotNull Project project, Class<T> planType) Description copied from interface:PlanDao
- Specified by:
findAllPlansByProject
in interfacePlanDao
- Returns:
- plans for specifid project
-
findAllPlans
Description copied from interface:PlanDao
Return aPlan
collection for specified plan type. Does not include plans marked for deletion.- Specified by:
findAllPlans
in interfacePlanDao
- Parameters:
planType
- type of plan to be selected from DB- Returns:
Plan
collection for specified plan type
-
findAllPlans
@NotNull public <T extends Plan> @NotNull List<T> findAllPlans(Class<T> planType, int firstResult, int maxResults) Description copied from interface:PlanDao
Return aPlan
collection for specified plan type. Does not include plans marked for deletion.- Specified by:
findAllPlans
in interfacePlanDao
- Parameters:
planType
- type of plan to be selected from DBfirstResult
- firstResult for a paginated resultsmaxResults
- maximum number of results to return- Returns:
Plan
collection for specified plan type
-
setPlanDiscriminatorRegistry
-
filterFavouritedPlans
public List<ImmutableChain> filterFavouritedPlans(@NotNull @NotNull Collection<? extends ImmutableChain> plans, @NotNull @NotNull com.atlassian.user.User user) Description copied from interface:PlanDao
Return a collection ofTopLevelPlan
s that are a subset of the givenPlan
s collection that are favourited by theUser
- Specified by:
filterFavouritedPlans
in interfacePlanDao
- Returns:
- favoritedBuilds
-
getAllPlansMarkedForDeletion
@NotNull public <T extends Plan> @NotNull Collection<T> getAllPlansMarkedForDeletion(Class<T> planType) Description copied from interface:PlanDao
Returns a list ofPlan
s that areImmutableDeletable.isMarkedForDeletion()
for the given type- Specified by:
getAllPlansMarkedForDeletion
in interfacePlanDao
- Returns:
- plansMarkedForDeletion
-
getAllPlansMarkedForDeletionCount
Description copied from interface:PlanDao
Returns a count ofPlan
s that areImmutableDeletable.isMarkedForDeletion()
for the given type- Specified by:
getAllPlansMarkedForDeletionCount
in interfacePlanDao
- Returns:
- number of plans of a requested type scheduled for deletion
-
save
Description copied from interface:BambooObjectDao
Saves the given entity. If the entity implementation is an instance ofEntityObject
this method will: - updateEntityObject.getLastModificationDate()
- setEntityObject.getCreationDate()
if the object has not been saved- Specified by:
save
in interfaceBambooObjectDao<T extends Plan>
- Overrides:
save
in classBambooHibernateObjectDao<Plan>
- Parameters:
plan
- entity to be saved
-
getBranchesForChain
Description copied from interface:PlanDao
Returns all branches which have the given chain as their master- Specified by:
getBranchesForChain
in interfacePlanDao
- Parameters:
chain
- master plan- Returns:
- all branches which have the given chain as their master
-
getBranchesForJob
- Specified by:
getBranchesForJob
in interfacePlanDao
-
getBranchIdentifiersForChain
@NotNull public @NotNull List<ChainBranchIdentifier> getBranchIdentifiersForChain(@NotNull @NotNull PlanIdentifier plan) Description copied from interface:PlanDao
Returns minimal data about all branches which have the given chain as their master- Specified by:
getBranchIdentifiersForChain
in interfacePlanDao
- Parameters:
plan
- master- Returns:
- all branches which have the given chain as their master
-
getPlanIdentifiersForProject
@NotNull public <T extends Plan> @NotNull List<PlanIdentifier> getPlanIdentifiersForProject(@NotNull @NotNull ProjectIdentifier project, @NotNull @NotNull Class<T> planType, boolean includeMarkedForDeletion) Description copied from interface:PlanDao
Returns minimal data about all plans in the given project- Specified by:
getPlanIdentifiersForProject
in interfacePlanDao
- Parameters:
project
- - to get plans forplanType
- to filter plans byincludeMarkedForDeletion
- - true if you want to include any results currently marked for deletion- Returns:
- plansIdentifiers matching the above criteria.
-
getBranchCount
Description copied from interface:PlanDao
Returns the number of branches that exist for the given plan- Specified by:
getBranchCount
in interfacePlanDao
- Parameters:
plan
- to count branches of- Returns:
- the number of branches that exist for the given plan
-
getBranchesCount
Description copied from interface:PlanDao
Returns the number of branches that exist for master plans in Bamboo. Only returns masters plans which HAVE branches. Others are omitted.- Specified by:
getBranchesCount
in interfacePlanDao
- Returns:
- List of pairs of plan id and their branches count
-
markPlanForDeletion
Description copied from interface:PlanDao
Efficiently marks a plan to be deleted- Specified by:
markPlanForDeletion
in interfacePlanDao
-
syncDeletionStatusOfPlans
public void syncDeletionStatusOfPlans()Description copied from interface:PlanDao
Performs a cleanup task to markPlan
objects that have aProject
that is marked to be deleted, but is not marked as deleted.- Specified by:
syncDeletionStatusOfPlans
in interfacePlanDao
-
syncDeletionStatusOfJobs
public void syncDeletionStatusOfJobs()Description copied from interface:PlanDao
Performs a cleanup task to markJob
objects that have aPlan
orChainStage
that is marked to be deleted, but it itself was not marked as deleted.- Specified by:
syncDeletionStatusOfJobs
in interfacePlanDao
-
syncDeletionStatusOfChainBranches
public void syncDeletionStatusOfChainBranches()Description copied from interface:PlanDao
Performs a cleanup task to markChainBranch
objects that have a masterPlan
that is marked to be deleted, but is not marked as deleted.- Specified by:
syncDeletionStatusOfChainBranches
in interfacePlanDao
-
getMaxPlanOid
@Nullable public @Nullable BambooEntityOid getMaxPlanOid(int serverKey, @NotNull @NotNull BambooEntityType entityType) Description copied from interface:PlanDao
Returns the maxBambooEntityOid
that's currently in use of the specified entity type, with the given server key. Allowed entity types: -BambooEntityType.CHAIN
-BambooEntityType.JOB
-BambooEntityType.CHAIN_BRANCH
-BambooEntityType.JOB_BRANCH
Returns null if no OIDs are in use of the specified type with the given server key.- Specified by:
getMaxPlanOid
in interfacePlanDao
-
getFavouritePlansIds
@NotNull public @NotNull Set<Long> getFavouritePlansIds(@NotNull @NotNull com.atlassian.user.User user) Description copied from interface:PlanDao
Return a collection of Favourite plan ids.- Specified by:
getFavouritePlansIds
in interfacePlanDao
- Returns:
- favouritePlansIds
-
getPlanKeysPlanIdsMapping
public <T extends Plan> Map<PlanKey,Long> getPlanKeysPlanIdsMapping(@NotNull @NotNull Class<T> aClass) - Specified by:
getPlanKeysPlanIdsMapping
in interfacePlanDao
- Returns:
- mapping between plans' keys and their ids for given plan class.
-
clearInvalidFlagForBranchesOfChain
public void clearInvalidFlagForBranchesOfChain(long masterId) - Specified by:
clearInvalidFlagForBranchesOfChain
in interfacePlanDao
-
getBranchKeysForChain
Description copied from interface:PlanDao
Returns the keys of branches that have as master the chain identified by the given chainKey.- Specified by:
getBranchKeysForChain
in interfacePlanDao
- Parameters:
chainKey
- the key of the chain that is the master of the desired branches.- Returns:
- the keys of branches that have as master the chain identified by the given chainKey.
-
delete
Description copied from interface:BambooObjectDao
Removes the given entity from the database- Specified by:
delete
in interfaceBambooObjectDao<T extends Plan>
- Overrides:
delete
in classBambooHibernateObjectDao<Plan>
- Parameters:
plan
- entity to be removed
-