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.BambooHibernateObjectDao<Plan>
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
ConstructorsConstructorDescriptionPlanHibernateDao(TransactionAndHibernateTemplate transactionTemplate, BambooClusterSettings bambooClusterSettings) -
Method Summary
Modifier and TypeMethodDescriptionvoidclearInvalidFlagForBranchesOfChain(long masterId) <E extends Plan>
longFinds the count of all entities that implement the given Class<E extends Plan>
longcountWithRestriction(@NotNull Class<E> aClass, @NotNull BiFunction<jakarta.persistence.criteria.CriteriaBuilder, jakarta.persistence.criteria.Root<? extends Plan>, jakarta.persistence.criteria.Predicate> predicateSupplier) Finds the count of all entities that implement the given class and satisfy the provided restrictionvoidRemoves the given entity from the databasefilterFavouritedPlans(@NotNull Collection<? extends ImmutableChain> plans, @NotNull com.atlassian.user.User user) Return a collection ofTopLevelPlans that are a subset of the givenPlans collection that are favourited by theUserFinds all the entities that implement the givenClassfindAllPlans(Class<P> planType) Return aPlancollection for specified plan type.findAllPlans(Class<P> planType, int firstResult, int maxResults) Return aPlancollection for specified plan type.findAllPlansByProject(@NotNull Project project, Class<P> planType) <P extends Plan>
PFind an entity by its idfindPlansByProject(@NotNull Project project, Class<P> planType) getAllPlanKeys(Class<P> planType) Returns all plan keys of a particular type, including the plans marked for deletion.<P extends Plan>
@NotNull Collection<P> getAllPlansMarkedForDeletion(Class<P> planType) Returns a list ofPlans that areImmutableDeletable.isMarkedForDeletion()for the given type<P extends Plan>
longgetAllPlansMarkedForDeletionCount(Class<P> planType) Returns a count ofPlans that areImmutableDeletable.isMarkedForDeletion()for the given typeintgetBranchCount(@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 BambooEntityOidgetMaxPlanOid(int serverKey, @NotNull BambooEntityType entityType) Returns the maxBambooEntityOidthat's currently in use of the specified entity type, with the given server key.<P extends Plan>
PgetPlanByKey(@NotNull PlanKey planKey, Class<P> aClass) Return aPlanthat matches the given key<P extends Plan>
PgetPlanByKey(@NotNull String planKey, Class<P> aClass) Return aPlanthat matches the given key<P extends Plan>
PgetPlanByPartialKeyAndName(@NotNull PlanKey partialPlanKey, @NotNull String planName, Class<P> planType) getPlanClass(@NotNull PlanKey planKey) intgetPlanCount(@NotNull ProjectIdentifier projectIdentifier) How many plans currently exist in aproject.<P extends Plan>
intgetPlanCount(Class<P> planType) How many plans filtered byClasscurrently exist@Nullable PlanIdentifiergetPlanIdentifierForPermissionCheckingByKey(@NotNull String planKey) Return aPlanskeleton providing ONLY id and key, that matches the given key This method should be used only for permission checking using Acegi IfJobkey is provided as a parameter, parent Chain will be returned anyway, as Acegi assertions are defined only forTopLevelPlans<P extends Plan>
@NotNull List<PlanIdentifier> getPlanIdentifiersForProject(@NotNull ProjectIdentifier project, @NotNull Class<P> planType, boolean includeMarkedForDeletion) Returns minimal data about all plans in the given projectgetPlanKeys(Class<P> planType) Returns all plan keys of a particular type, NOT including the plans marked for deletion.getPlanKeysPlanIdsMapping(@NotNull Class<P> aClass) booleanisChainNameConflicting(@NotNull String projectKey, long idOfChainBeingVerified, @NotNull String planName) Verifies whether aChainname is unique with the given projectbooleanisPlanKeyConflicting(@NotNull PlanKey planKey) Verifies whether aPlankey is unique within whole Bamboo installationbooleanisPlanKeyConflicting(@NotNull PlanKey planKey, long idOfChainBeingVerified) Verifies whether aPlankey is unique within whole Bamboo installationvoidmarkPlanForDeletion(PlanKey planKey) Efficiently marks a plan to be deletedvoidSaves the given entity.voidsetPlanDiscriminatorRegistry(PlanDiscriminatorRegistry planDiscriminatorRegistry) voidPerforms a cleanup task to markChainBranchobjects that have a masterPlanthat is marked to be deleted, but is not marked as deleted.voidPerforms a cleanup task to markJobobjects that have aPlanorChainStagethat is marked to be deleted, but it itself was not marked as deleted.voidMethods inherited from class com.atlassian.bamboo.persistence3.BambooHibernateObjectWithOidDao
findByOidMethods inherited from class com.atlassian.bamboo.persistence3.BambooHibernateObjectDao
convertSearchTermToLikeExpression, deleteAll, executeCountQuery, findAll, merge, saveAllMethods inherited from class org.springframework.orm.hibernate5.support.HibernateDaoSupport
checkDaoConfig, createHibernateTemplate, currentSession, getHibernateTemplate, getSessionFactory, setHibernateTemplate, setSessionFactoryMethods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDaoMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.atlassian.bamboo.persistence3.BambooObjectDao
deleteAll, findAll, merge, saveAllMethods 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:PlanDaoReturn aPlanthat matches the given key- Specified by:
getPlanByKeyin interfacePlanDao- Parameters:
planKey-- Returns:
- plan
-
getPlanByKey
Description copied from interface:PlanDaoReturn aPlanthat matches the given key- Specified by:
getPlanByKeyin interfacePlanDao- Parameters:
planKey-- Returns:
- plan
-
getPlanIdentifierForPermissionCheckingByKey
@Nullable public @Nullable PlanIdentifier getPlanIdentifierForPermissionCheckingByKey(@NotNull @NotNull String planKey) Description copied from interface:PlanDaoReturn aPlanskeleton providing ONLY id and key, that matches the given key This method should be used only for permission checking using Acegi IfJobkey is provided as a parameter, parent Chain will be returned anyway, as Acegi assertions are defined only forTopLevelPlans- Specified by:
getPlanIdentifierForPermissionCheckingByKeyin interfacePlanDao- Parameters:
planKey-- Returns:
- plan
-
getPlanClass
- Specified by:
getPlanClassin interfacePlanDao
-
findById
Description copied from interface:BambooObjectDaoFind an entity by its id- Specified by:
findByIdin interfaceBambooObjectDao<T extends Plan>- Overrides:
findByIdin 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:PlanDaoVerifies whether aChainname is unique with the given project- Specified by:
isChainNameConflictingin 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:PlanDaoVerifies whether aPlankey is unique within whole Bamboo installation- Specified by:
isPlanKeyConflictingin 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:PlanDaoVerifies whether aPlankey is unique within whole Bamboo installation- Specified by:
isPlanKeyConflictingin 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 <P extends Plan> P getPlanByPartialKeyAndName(@NotNull @NotNull PlanKey partialPlanKey, @NotNull @NotNull String planName, Class<P> planType) Description copied from interface:PlanDao- Specified by:
getPlanByPartialKeyAndNamein interfacePlanDao- Parameters:
partialPlanKey-planName-planType-- Returns:
- plan
-
getPlanCount
Description copied from interface:PlanDaoHow many plans filtered byClasscurrently exist- Specified by:
getPlanCountin interfacePlanDao- Parameters:
planType-- Returns:
- how many plans exist in the database
-
getPlanCount
Description copied from interface:PlanDaoHow many plans currently exist in aproject.- Specified by:
getPlanCountin 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:PlanDaoReturns all plan keys of a particular type, NOT including the plans marked for deletion.- Specified by:
getPlanKeysin interfacePlanDao
-
getAllPlanKeys
Description copied from interface:PlanDaoReturns all plan keys of a particular type, including the plans marked for deletion.- Specified by:
getAllPlanKeysin interfacePlanDao
-
getJobKeys
Description copied from interface:PlanDaoReturn all plan keys of Jobs that belong to a Chain- Specified by:
getJobKeysin interfacePlanDao- Parameters:
chainKey- key of a Chain- Returns:
- list of Job keys
-
findPlansByProject
@NotNull public <P extends Plan> @NotNull List<P> findPlansByProject(@NotNull @NotNull Project project, Class<P> planType) Description copied from interface:PlanDao- Specified by:
findPlansByProjectin interfacePlanDao- Parameters:
project-planType-- Returns:
- plans for specifid project
-
findAllPlansByProject
@NotNull public <P extends Plan> @NotNull List<P> findAllPlansByProject(@NotNull @NotNull Project project, Class<P> planType) Description copied from interface:PlanDao- Specified by:
findAllPlansByProjectin interfacePlanDao- Parameters:
project-planType-- Returns:
- plans for specifid project
-
findAll
Description copied from interface:BambooObjectDaoFinds all the entities that implement the givenClass- Specified by:
findAllin interfaceBambooObjectDao<T extends Plan>- Overrides:
findAllin classBambooHibernateObjectDao<Plan>- Parameters:
aClass- class of entity- Returns:
- entities
-
countAll
Description copied from interface:BambooObjectDaoFinds the count of all entities that implement the given Class- Specified by:
countAllin interfaceBambooObjectDao<T extends Plan>- Overrides:
countAllin classBambooHibernateObjectDao<Plan>
-
countWithRestriction
public <E extends Plan> long countWithRestriction(@NotNull @NotNull Class<E> aClass, @NotNull @NotNull BiFunction<jakarta.persistence.criteria.CriteriaBuilder, jakarta.persistence.criteria.Root<? extends Plan>, jakarta.persistence.criteria.Predicate> predicateSupplier) Description copied from interface:BambooObjectDaoFinds the count of all entities that implement the given class and satisfy the provided restriction- Specified by:
countWithRestrictionin interfaceBambooObjectDao<T extends Plan>- Overrides:
countWithRestrictionin classBambooHibernateObjectDao<Plan>
-
findAllPlans
Description copied from interface:PlanDaoReturn aPlancollection for specified plan type. Does not include plans marked for deletion.- Specified by:
findAllPlansin interfacePlanDao- Type Parameters:
P-- Parameters:
planType- type of plan to be selected from DB- Returns:
Plancollection for specified plan type
-
findAllPlans
@NotNull public <P extends Plan> @NotNull List<P> findAllPlans(Class<P> planType, int firstResult, int maxResults) Description copied from interface:PlanDaoReturn aPlancollection for specified plan type. Does not include plans marked for deletion.- Specified by:
findAllPlansin interfacePlanDao- Type Parameters:
P-- Parameters:
planType- type of plan to be selected from DBfirstResult- firstResult for a paginated resultsmaxResults- maximum number of results to return- Returns:
Plancollection 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:PlanDaoReturn a collection ofTopLevelPlans that are a subset of the givenPlans collection that are favourited by theUser- Specified by:
filterFavouritedPlansin interfacePlanDao- Parameters:
plans-user-- Returns:
- favoritedBuilds
-
getAllPlansMarkedForDeletion
@NotNull public <P extends Plan> @NotNull Collection<P> getAllPlansMarkedForDeletion(Class<P> planType) Description copied from interface:PlanDaoReturns a list ofPlans that areImmutableDeletable.isMarkedForDeletion()for the given type- Specified by:
getAllPlansMarkedForDeletionin interfacePlanDao- Returns:
- plansMarkedForDeletion
-
getAllPlansMarkedForDeletionCount
Description copied from interface:PlanDaoReturns a count ofPlans that areImmutableDeletable.isMarkedForDeletion()for the given type- Specified by:
getAllPlansMarkedForDeletionCountin interfacePlanDao- Returns:
- number of plans of a requested type scheduled for deletion
-
save
Description copied from interface:BambooObjectDaoSaves the given entity. If the entity implementation is an instance ofEntityObjectthis method will: - updateEntityObject.getLastModificationDate()- setEntityObject.getCreationDate()if the object has not been saved- Specified by:
savein interfaceBambooObjectDao<T extends Plan>- Overrides:
savein classBambooHibernateObjectDao<Plan>- Parameters:
plan- entity to be saved
-
getBranchesForChain
Description copied from interface:PlanDaoReturns all branches which have the given chain as their master- Specified by:
getBranchesForChainin interfacePlanDao- Parameters:
chain- master plan- Returns:
- all branches which have the given chain as their master
-
getBranchesForJob
- Specified by:
getBranchesForJobin interfacePlanDao
-
getBranchIdentifiersForChain
@NotNull public @NotNull List<ChainBranchIdentifier> getBranchIdentifiersForChain(@NotNull @NotNull PlanIdentifier plan) Description copied from interface:PlanDaoReturns minimal data about all branches which have the given chain as their master- Specified by:
getBranchIdentifiersForChainin interfacePlanDao- Parameters:
plan- master- Returns:
- all branches which have the given chain as their master
-
getPlanIdentifiersForProject
@NotNull public <P extends Plan> @NotNull List<PlanIdentifier> getPlanIdentifiersForProject(@NotNull @NotNull ProjectIdentifier project, @NotNull @NotNull Class<P> planType, boolean includeMarkedForDeletion) Description copied from interface:PlanDaoReturns minimal data about all plans in the given project- Specified by:
getPlanIdentifiersForProjectin 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:PlanDaoReturns the number of branches that exist for the given plan- Specified by:
getBranchCountin interfacePlanDao- Parameters:
plan- to count branches of- Returns:
- the number of branches that exist for the given plan
-
getBranchesCount
Description copied from interface:PlanDaoReturns the number of branches that exist for master plans in Bamboo. Only returns masters plans which HAVE branches. Others are omitted.- Specified by:
getBranchesCountin interfacePlanDao- Returns:
- List of pairs of plan id and their branches count
-
markPlanForDeletion
Description copied from interface:PlanDaoEfficiently marks a plan to be deleted- Specified by:
markPlanForDeletionin interfacePlanDao- Parameters:
planKey-
-
syncDeletionStatusOfPlans
public void syncDeletionStatusOfPlans()Description copied from interface:PlanDaoPerforms a cleanup task to markPlanobjects that have aProjectthat is marked to be deleted, but is not marked as deleted.- Specified by:
syncDeletionStatusOfPlansin interfacePlanDao
-
syncDeletionStatusOfJobs
public void syncDeletionStatusOfJobs()Description copied from interface:PlanDaoPerforms a cleanup task to markJobobjects that have aPlanorChainStagethat is marked to be deleted, but it itself was not marked as deleted.- Specified by:
syncDeletionStatusOfJobsin interfacePlanDao
-
syncDeletionStatusOfChainBranches
public void syncDeletionStatusOfChainBranches()Description copied from interface:PlanDaoPerforms a cleanup task to markChainBranchobjects that have a masterPlanthat is marked to be deleted, but is not marked as deleted.- Specified by:
syncDeletionStatusOfChainBranchesin interfacePlanDao
-
getMaxPlanOid
@Nullable public @Nullable BambooEntityOid getMaxPlanOid(int serverKey, @NotNull @NotNull BambooEntityType entityType) Description copied from interface:PlanDaoReturns the maxBambooEntityOidthat'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_BRANCHReturns null if no OIDs are in use of the specified type with the given server key.- Specified by:
getMaxPlanOidin interfacePlanDao
-
getFavouritePlansIds
@NotNull public @NotNull Set<Long> getFavouritePlansIds(@NotNull @NotNull com.atlassian.user.User user) Description copied from interface:PlanDaoReturn a collection of Favourite plan ids.- Specified by:
getFavouritePlansIdsin interfacePlanDao- Parameters:
user-- Returns:
- favouritePlansIds
-
getPlanKeysPlanIdsMapping
public <P extends Plan> Map<PlanKey,Long> getPlanKeysPlanIdsMapping(@NotNull @NotNull Class<P> aClass) - Specified by:
getPlanKeysPlanIdsMappingin interfacePlanDao- Returns:
- mapping between plans' keys and their ids for given plan class.
-
clearInvalidFlagForBranchesOfChain
public void clearInvalidFlagForBranchesOfChain(long masterId) - Specified by:
clearInvalidFlagForBranchesOfChainin interfacePlanDao
-
getBranchKeysForChain
Description copied from interface:PlanDaoReturns the keys of branches that have as master the chain identified by the given chainKey.- Specified by:
getBranchKeysForChainin 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:BambooObjectDaoRemoves the given entity from the database- Specified by:
deletein interfaceBambooObjectDao<T extends Plan>- Overrides:
deletein classBambooHibernateObjectDao<Plan>- Parameters:
plan- entity to be removed
-