Class DBBuildHistory
- java.lang.Object
-
- jetbrains.buildServer.serverSide.impl.history.DBBuildHistory
-
- All Implemented Interfaces:
BuildHistory
,BuildHistoryEx
public class DBBuildHistory extends Object implements BuildHistoryEx
-
-
Field Summary
Fields Modifier and Type Field Description static String
GET_ACTIVE_BUILD_TYPES
-
Constructor Summary
Constructors Constructor Description DBBuildHistory(EventDispatcher<BuildServerListener> eventDispatcher, SQLRunnerEx db, ResetCacheRegister cacheResetter, TestHistory testHistoryDelegate, MultiNodesEvents multiNodesEvents)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
buildsRemoved(String buildTypeId, BuildTypeRemovedBuilds predicate)
Accepts a build configuration id and a collection of removed finished builds ids.void
clearCache()
void
createEntry(HistoryBuild build, Date finishTime)
void
createEntryForNotStartedBuild(HistoryBuild build, Date finishTime)
HistoryQueryRunner
createHistoryQueryRunner(User user, boolean includePersonalBuildsIfNoUser, boolean includeCanceled, boolean orderByChanges)
List<SFinishedBuild>
findEntries(String buildTypeId, String buildNumber)
Returns list of finished builds with specified build number belonging to specified build configuration ordered by changes (the most recent first).Collection<SFinishedBuild>
findEntries(Collection<Long> buildIds)
Returns collection of finished builds corresponding to the specified build ids.List<SFinishedBuild>
findEntries(Collection<Long> buildIds, boolean addToCache)
Same asBuildHistory.findEntries(Collection)
but with additional parameter which controls whether the found builds should be cached or not.SFinishedBuild
findEntry(long buildId)
Finds entry with the specified id and cache the data internally.SFinishedBuild
findEntry(long buildId, boolean add2Cache)
Finds entry with the specified id and optionally cache it.SFinishedBuild
findEntry(String buildTypeId, String buildNumber)
Finds the most recent by changes entry inside specified configuration with specified build number.Collection<SBuildType>
getActiveBuildTypes(Date sinceDate)
Return a list of build configurations that have been active (i.e.Map<Long,String>
getBuildNumbers(Collection<Long> buildIds)
Returns build numbers of the specified buildsCollection<SBuildType>
getBuildTypesWithTest(SProject project, long testNameId)
Collection<SFinishedBuild>
getCachedEntries(Collection<Long> buildIds)
Same asBuildHistory.findEntries(Collection)
but returns only currently cached builds (does not attempt to load anything from database).Map<String,String>
getCacheStat()
Experimental, debug-only usage Is only available with "teamcity.buildhistory.buildsCache.statistics.enabled" server internal propertyList<SFinishedBuild>
getEntries(boolean includeCanceled)
Return whole build history for all build configurations of all projects.List<SFinishedBuild>
getEntriesBefore(SBuild beforeThisBuild, boolean successfulOnly)
Returns builds of the specified configuration started before the specified build (excluding the specified build).List<SFinishedBuild>
getEntriesBetween(long from, long to, boolean includeCanceled)
List<SFinishedBuild>
getEntriesSince(SBuild sinceBuildInclusive, BuildType buildType)
Returns builds of the specified configuration started after the specified build (including the specified build), ordered by changes.List<SFinishedBuild>
getHistoryByAgent(SBuildAgent agent, User user, boolean includeCanceled)
Returns the build history filtered by theagent
.List<SFinishedBuild>
getHistoryByAgentType(AgentType agent, User user, boolean includeCanceled)
Returns the build history filtered by theagent type
.static int
getInParamsSize(int numberOfParams)
For internal usage only.SFinishedBuild
getLastChangesBuild(String buildTypeId)
Returns last finished build with last changes in the specified configuration, excluding personal and canceled builds.long
getLastEntryId(boolean includeCanceled)
Date
getLastFinishedBuildDateOnAgent(SBuildAgent agent, Date finishTimeAfter)
Return last finished build that was started on the agent.SFinishedBuild
getLastSuccessfulChangesBuild(String buildTypeId)
Returns last successfully finished build with last changes in the specified configuration, personal and canceled builds are not consideredint
getNumberOfBuildsInBuildType(SBuildType buildType)
Return the number of all builds for this build configuration, including personal and canceled onesint
getNumberOfPinnedBuildsInBuildType(SBuildType buildType)
Return the number of pinned builds for this build configurationSet<Long>
getPinnedBuildsIds(Collection<Long> buildIds)
Accepts a collection of build ids and returns those which are pinned.List<STestRun>
getTestHistory(long testNameId, String buildTypeId, long userId, String branchName)
Order of the returned TestRuns is recent runs first, according to the starting order of the builds.List<STestRun>
getTestHistory(long testNameId, String buildTypeId, Filter<STestRun> filter)
Order of the returned TestRuns is recent runs first, according to the starting order of the builds.List<STestRun>
getTestHistory(long testNameId, SProject project, long userId, String branchName)
Order of the returned TestRuns is recent runs first, according to the starting order of the builds.List<STestRun>
getTestHistory(long testNameId, SProject project, Filter<STestRun> filter)
Order of the returned TestRuns is recent runs first, according to the starting order of the builds.static long
modId(BuildPromotionOwner build)
void
processEntries(String buildTypeId, User user, boolean includePersonalBuildsIfUserNotSpecified, boolean includeCanceled, boolean orderByChanges, ItemProcessor<SFinishedBuild> processor)
Process build history for the specified build configuration.void
processEntries(ItemProcessor<SFinishedBuild> itemProcessor)
Invokes the given ItemProcessor for all history records existing in the system.void
removeCachedEntry(long buildId)
Removes a single cached build from builds history cacheboolean
removeEntry(long buildId)
Removes finished build from the history.boolean
removeEntry(long buildId, String comment)
Removes finished build from the history with specified reason.void
removeEntry(SFinishedBuild finishedBuild)
Removes finished build from build history.void
removeEntry(SFinishedBuild entry, String comment)
Removing a finished build.void
removeEntry(SFinishedBuild entry, String comment, CleanupLevel cleanupLevel)
Removing a finished build.void
setAuditLogFactory(AuditLogFactory auditLogFactory)
void
setBuildFactory(BuildFactory buildFactory)
void
setBuildPromotionManager(BuildPromotionManager buildPromotionManager)
void
setBuildsHistoryCleaner(BuildsHistoryCleaner buildsHistoryCleaner)
void
setBuildsManager(BuildsManager buildsManager)
void
setProjectManager(ProjectManagerEx projectManager)
void
setQueryRunnerFactory(QueryRunnerFactory queryRunnerFactory)
void
setRunningBuildsCollection(RunningBuildsCollection runningBuildsCollection)
-
-
-
Field Detail
-
GET_ACTIVE_BUILD_TYPES
public static final String GET_ACTIVE_BUILD_TYPES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DBBuildHistory
public DBBuildHistory(@NotNull EventDispatcher<BuildServerListener> eventDispatcher, @NotNull SQLRunnerEx db, @NotNull ResetCacheRegister cacheResetter, @NotNull TestHistory testHistoryDelegate, @NotNull MultiNodesEvents multiNodesEvents)
-
-
Method Detail
-
setQueryRunnerFactory
public void setQueryRunnerFactory(@NotNull QueryRunnerFactory queryRunnerFactory)
-
setProjectManager
public void setProjectManager(@NotNull ProjectManagerEx projectManager)
-
setAuditLogFactory
public void setAuditLogFactory(@NotNull AuditLogFactory auditLogFactory)
-
setBuildPromotionManager
public void setBuildPromotionManager(@NotNull BuildPromotionManager buildPromotionManager)
-
setBuildsManager
public void setBuildsManager(@NotNull BuildsManager buildsManager)
-
setRunningBuildsCollection
public void setRunningBuildsCollection(@NotNull RunningBuildsCollection runningBuildsCollection)
-
setBuildFactory
public void setBuildFactory(@NotNull BuildFactory buildFactory)
-
setBuildsHistoryCleaner
public void setBuildsHistoryCleaner(@NotNull BuildsHistoryCleaner buildsHistoryCleaner)
-
getEntries
@NotNull public List<SFinishedBuild> getEntries(boolean includeCanceled)
Description copied from interface:BuildHistory
Return whole build history for all build configurations of all projects. Personal builds are not included. Build ordering is by start time.- Specified by:
getEntries
in interfaceBuildHistory
- Parameters:
includeCanceled
- true if cancelled builds should be included into result- Returns:
- list of builds, most recent first
-
processEntries
public void processEntries(@NotNull ItemProcessor<SFinishedBuild> itemProcessor)
Description copied from interface:BuildHistory
Invokes the given ItemProcessor for all history records existing in the system. Entries are pushed into the processor in the most-recent-first order.- Specified by:
processEntries
in interfaceBuildHistory
- Parameters:
itemProcessor
- processor for history entries
-
processEntries
public void processEntries(@NotNull String buildTypeId, @Nullable User user, boolean includePersonalBuildsIfUserNotSpecified, boolean includeCanceled, boolean orderByChanges, @NotNull ItemProcessor<SFinishedBuild> processor)
Description copied from interface:BuildHistory
Process build history for the specified build configuration. Personal builds are included if user is specified. Builds are processed using given processor.- Specified by:
processEntries
in interfaceBuildHistory
- Parameters:
buildTypeId
- internal id of build configurationuser
- if not null, personal builds of this user will be included into resultincludePersonalBuildsIfUserNotSpecified
- if true and user==null, all personal builds will be included into resultsincludeCanceled
- true if cancelled builds should be included into resultorderByChanges
- if true, builds are ordered by changes, i.e. most recent build with recent changes goes first; if false, most recent builds go first, regardless change orderprocessor
- processor for builds
-
getHistoryByAgent
@NotNull public List<SFinishedBuild> getHistoryByAgent(@NotNull SBuildAgent agent, @Nullable User user, boolean includeCanceled)
Description copied from interface:BuildHistory
Returns the build history filtered by theagent
.- Specified by:
getHistoryByAgent
in interfaceBuildHistory
- Parameters:
agent
- the build agentuser
- if set the result will contain only builds byuser
includeCanceled
- if set the result will include canceled builds as well- Returns:
- build history
-
getHistoryByAgentType
@NotNull public List<SFinishedBuild> getHistoryByAgentType(@NotNull AgentType agent, @Nullable User user, boolean includeCanceled)
Description copied from interface:BuildHistoryEx
Returns the build history filtered by theagent type
.- Specified by:
getHistoryByAgentType
in interfaceBuildHistoryEx
- Parameters:
agent
- the build agent typeuser
- if set the result will contain only builds byuser
includeCanceled
- if set the result will include calceled builds as well- Returns:
- build history
-
getLastFinishedBuildDateOnAgent
@Nullable public Date getLastFinishedBuildDateOnAgent(@NotNull SBuildAgent agent, @NotNull Date finishTimeAfter)
Description copied from interface:BuildHistory
Return last finished build that was started on the agent.- Specified by:
getLastFinishedBuildDateOnAgent
in interfaceBuildHistory
- Parameters:
agent
- agentfinishTimeAfter
- finish time lower bound- Returns:
- found build or null
-
getActiveBuildTypes
@NotNull public Collection<SBuildType> getActiveBuildTypes(@NotNull Date sinceDate)
Description copied from interface:BuildHistory
Return a list of build configurations that have been active (i.e. have any kind of finished/canceled/personal/etc. builds) since the specified date.- Specified by:
getActiveBuildTypes
in interfaceBuildHistory
- Returns:
- see above
-
getNumberOfBuildsInBuildType
public int getNumberOfBuildsInBuildType(@NotNull SBuildType buildType)
Description copied from interface:BuildHistoryEx
Return the number of all builds for this build configuration, including personal and canceled ones- Specified by:
getNumberOfBuildsInBuildType
in interfaceBuildHistoryEx
-
getNumberOfPinnedBuildsInBuildType
public int getNumberOfPinnedBuildsInBuildType(@NotNull SBuildType buildType)
Description copied from interface:BuildHistoryEx
Return the number of pinned builds for this build configuration- Specified by:
getNumberOfPinnedBuildsInBuildType
in interfaceBuildHistoryEx
-
getPinnedBuildsIds
@NotNull public Set<Long> getPinnedBuildsIds(@NotNull Collection<Long> buildIds)
Description copied from interface:BuildHistoryEx
Accepts a collection of build ids and returns those which are pinned.- Specified by:
getPinnedBuildsIds
in interfaceBuildHistoryEx
- Returns:
-
getBuildNumbers
@NotNull public Map<Long,String> getBuildNumbers(@NotNull Collection<Long> buildIds)
Description copied from interface:BuildHistoryEx
Returns build numbers of the specified builds- Specified by:
getBuildNumbers
in interfaceBuildHistoryEx
- Returns:
-
createHistoryQueryRunner
@NotNull public HistoryQueryRunner createHistoryQueryRunner(@Nullable User user, boolean includePersonalBuildsIfNoUser, boolean includeCanceled, boolean orderByChanges)
- Specified by:
createHistoryQueryRunner
in interfaceBuildHistoryEx
-
getEntriesBefore
@NotNull public List<SFinishedBuild> getEntriesBefore(@NotNull SBuild beforeThisBuild, boolean successfulOnly)
Description copied from interface:BuildHistory
Returns builds of the specified configuration started before the specified build (excluding the specified build). Personal builds are included, canceled builds are excluded. Returned builds are sorted by containing changes and than by build start time (if contain same changes). Recent builds go first.- Specified by:
getEntriesBefore
in interfaceBuildHistory
- Parameters:
beforeThisBuild
- returns build before this onesuccessfulOnly
- if only successful builds should be included.- Returns:
- see above
-
findEntry
@Nullable public SFinishedBuild findEntry(long buildId)
Description copied from interface:BuildHistory
Finds entry with the specified id and cache the data internally. Same as findEntry(buildId, true).- Specified by:
findEntry
in interfaceBuildHistory
- Parameters:
buildId
- specified build id.- Returns:
- entry with the specified id,
null
if it does not exist or invisible for the current user.
-
findEntry
@Nullable public SFinishedBuild findEntry(long buildId, boolean add2Cache)
Description copied from interface:BuildHistory
Finds entry with the specified id and optionally cache it.- Specified by:
findEntry
in interfaceBuildHistory
- Parameters:
buildId
- specified build id.add2Cache
- if true, the build will be added to internal caches- Returns:
- entry with the specified id,
null
if it does not exist or invisible for the current user.
-
findEntry
@Nullable public SFinishedBuild findEntry(@NotNull String buildTypeId, @NotNull String buildNumber)
Description copied from interface:BuildHistory
Finds the most recent by changes entry inside specified configuration with specified build number.- Specified by:
findEntry
in interfaceBuildHistory
- Parameters:
buildTypeId
- specified build configuration id.buildNumber
- specified build number.- Returns:
- entry with the specified number in the specified configuration,
null
if it does not exist or invisible for the current user.
-
findEntries
@NotNull public List<SFinishedBuild> findEntries(@NotNull String buildTypeId, @NotNull String buildNumber)
Description copied from interface:BuildHistory
Returns list of finished builds with specified build number belonging to specified build configuration ordered by changes (the most recent first).- Specified by:
findEntries
in interfaceBuildHistory
- Parameters:
buildTypeId
- build configuration idbuildNumber
- build number- Returns:
- collection of found builds
-
createEntry
public void createEntry(@NotNull HistoryBuild build, @NotNull Date finishTime)
- Specified by:
createEntry
in interfaceBuildHistoryEx
-
createEntryForNotStartedBuild
public void createEntryForNotStartedBuild(@NotNull HistoryBuild build, @NotNull Date finishTime)
- Specified by:
createEntryForNotStartedBuild
in interfaceBuildHistoryEx
-
removeEntry
public void removeEntry(@NotNull SFinishedBuild entry, @Nullable String comment, @NotNull CleanupLevel cleanupLevel)
Removing a finished build.- Specified by:
removeEntry
in interfaceBuildHistory
- Parameters:
entry
- the build to remove.comment
- comment to log to audit in case there is logged user.cleanupLevel
- data to clean.
-
removeEntry
public void removeEntry(@NotNull SFinishedBuild entry, @Nullable String comment)
Removing a finished build.- Specified by:
removeEntry
in interfaceBuildHistory
- Parameters:
entry
- the build to remove.
-
removeEntry
public boolean removeEntry(long buildId, @Nullable String comment)
Description copied from interface:BuildHistoryEx
Removes finished build from the history with specified reason.- Specified by:
removeEntry
in interfaceBuildHistoryEx
- Parameters:
buildId
- build identifier of the finished build.comment
- reason for audit why build is removed- Returns:
- true if the build was successfully removed
-
removeEntry
public void removeEntry(@NotNull SFinishedBuild finishedBuild)
Description copied from interface:BuildHistory
Removes finished build from build history.- Specified by:
removeEntry
in interfaceBuildHistory
-
removeEntry
public boolean removeEntry(long buildId)
Description copied from interface:BuildHistory
Removes finished build from the history.The removing build must be an instance of
SFinishedBuild
.- Specified by:
removeEntry
in interfaceBuildHistory
- Parameters:
buildId
- build identifier of the finished build.- Returns:
- true if the build was successfully removed
-
getLastChangesBuild
@Nullable public SFinishedBuild getLastChangesBuild(String buildTypeId)
Description copied from interface:BuildHistoryEx
Returns last finished build with last changes in the specified configuration, excluding personal and canceled builds.- Specified by:
getLastChangesBuild
in interfaceBuildHistoryEx
- Parameters:
buildTypeId
- specified configuration id.- Returns:
- last finished build in the specified configuration or
null
if there are no finished builds.
-
getLastSuccessfulChangesBuild
@Nullable public SFinishedBuild getLastSuccessfulChangesBuild(@NotNull String buildTypeId)
Description copied from interface:BuildHistoryEx
Returns last successfully finished build with last changes in the specified configuration, personal and canceled builds are not considered- Specified by:
getLastSuccessfulChangesBuild
in interfaceBuildHistoryEx
- Parameters:
buildTypeId
- specified configuration id.- Returns:
- last successfully finished build in the specified configuration (excluding personal) or
null
if there are no successfully finished builds.
-
getEntriesSince
@NotNull public List<SFinishedBuild> getEntriesSince(@Nullable SBuild sinceBuildInclusive, @NotNull BuildType buildType)
Description copied from interface:BuildHistory
Returns builds of the specified configuration started after the specified build (including the specified build), ordered by changes. History builds which contain changes older than in sinceBuildInclusive are not included.- Specified by:
getEntriesSince
in interfaceBuildHistory
- Parameters:
sinceBuildInclusive
- boundary for returning builds (inclusive), may be null - in this case all builds are returnedbuildType
- specified configuration.- Returns:
- see above
-
modId
public static long modId(BuildPromotionOwner build)
-
findEntries
@NotNull public Collection<SFinishedBuild> findEntries(@NotNull Collection<Long> buildIds)
Description copied from interface:BuildHistory
Returns collection of finished builds corresponding to the specified build ids. The collection will contain existing builds only. NOTE: RETURNED COLLECTION WILL NOT MAINTAIN REQUESTED ORDER!- Specified by:
findEntries
in interfaceBuildHistory
- Parameters:
buildIds
- id list to find builds with these ids.- Returns:
- collection of finished builds corresponding to the specified build ids.
-
findEntries
@NotNull public List<SFinishedBuild> findEntries(@NotNull Collection<Long> buildIds, boolean addToCache)
Description copied from interface:BuildHistory
Same asBuildHistory.findEntries(Collection)
but with additional parameter which controls whether the found builds should be cached or not.- Specified by:
findEntries
in interfaceBuildHistory
- Parameters:
buildIds
- id list to find builds with these ids.addToCache
- whether to put found builds in cache or not- Returns:
- collection of finished builds corresponding to the specified build ids.
-
getCachedEntries
@NotNull public Collection<SFinishedBuild> getCachedEntries(@NotNull Collection<Long> buildIds)
Description copied from interface:BuildHistoryEx
Same asBuildHistory.findEntries(Collection)
but returns only currently cached builds (does not attempt to load anything from database).- Specified by:
getCachedEntries
in interfaceBuildHistoryEx
- Parameters:
buildIds
- id list to find builds with these ids.
-
getLastEntryId
public long getLastEntryId(boolean includeCanceled)
- Specified by:
getLastEntryId
in interfaceBuildHistoryEx
-
getEntriesBetween
@NotNull public List<SFinishedBuild> getEntriesBetween(long from, long to, boolean includeCanceled)
- Specified by:
getEntriesBetween
in interfaceBuildHistoryEx
-
getTestHistory
@NotNull public List<STestRun> getTestHistory(long testNameId, @NotNull String buildTypeId, long userId, @Nullable String branchName)
Description copied from interface:BuildHistoryEx
Order of the returned TestRuns is recent runs first, according to the starting order of the builds. Multiple test runs in the build are NOT wrapped into MultiRun class, i.e. each test run is returned independently- Specified by:
getTestHistory
in interfaceBuildHistoryEx
buildTypeId
- required to set the build configuration for the test historyuserId
- if > 0, includes personal builds of the given userbranchName
- if not null, returns only builds which match given branchName- Returns:
- Test run objects for given test, recent builds go first
- See Also:
TestHistory
-
getTestHistory
@NotNull public List<STestRun> getTestHistory(long testNameId, @NotNull String buildTypeId, Filter<STestRun> filter)
Description copied from interface:BuildHistoryEx
Order of the returned TestRuns is recent runs first, according to the starting order of the builds. Multiple test runs in the build are NOT wrapped into MultiRun class, i.e. each test run is returned independently- Specified by:
getTestHistory
in interfaceBuildHistoryEx
buildTypeId
- required to set the build configuration for the test historyfilter
- additional filter for the returned test runs- Returns:
- Test run objects for given test, recent builds go first
- See Also:
TestHistory
-
getTestHistory
@NotNull public List<STestRun> getTestHistory(long testNameId, @NotNull SProject project, long userId, @Nullable String branchName)
Description copied from interface:BuildHistoryEx
Order of the returned TestRuns is recent runs first, according to the starting order of the builds. Multiple test runs in the build are NOT wrapped into MultiRun class, i.e. each test run is returned independently- Specified by:
getTestHistory
in interfaceBuildHistoryEx
project
- required to set the parent project, all returned test runs will belong to build configurations under this project and its subprojectsuserId
- if > 0, includes personal builds of the given userbranchName
- if not null, returns only builds which match given branchName- Returns:
- Test run objects for given test, recent builds go first
- See Also:
TestHistory
-
getTestHistory
@NotNull public List<STestRun> getTestHistory(long testNameId, @NotNull SProject project, Filter<STestRun> filter)
Description copied from interface:BuildHistoryEx
Order of the returned TestRuns is recent runs first, according to the starting order of the builds. Multiple test runs in the build are NOT wrapped into MultiRun class, i.e. each test run is returned independently- Specified by:
getTestHistory
in interfaceBuildHistoryEx
project
- required to set the parent project, all returned test runs will belong to build configurations under this project and its subprojectsfilter
- additional filter for the returned test runs- Returns:
- Test run objects for given test, recent builds go first
- See Also:
TestHistory
-
getBuildTypesWithTest
@NotNull public Collection<SBuildType> getBuildTypesWithTest(@NotNull SProject project, long testNameId)
- Specified by:
getBuildTypesWithTest
in interfaceBuildHistoryEx
- See Also:
TestHistory
-
clearCache
public void clearCache()
- Specified by:
clearCache
in interfaceBuildHistoryEx
-
removeCachedEntry
public void removeCachedEntry(long buildId)
Description copied from interface:BuildHistoryEx
Removes a single cached build from builds history cache- Specified by:
removeCachedEntry
in interfaceBuildHistoryEx
- Parameters:
buildId
- build id
-
buildsRemoved
public void buildsRemoved(@NotNull String buildTypeId, @NotNull BuildTypeRemovedBuilds predicate)
Description copied from interface:BuildHistoryEx
Accepts a build configuration id and a collection of removed finished builds ids. Cleans internal caches for builds in this collection.- Specified by:
buildsRemoved
in interfaceBuildHistoryEx
-
getCacheStat
@NotNull public Map<String,String> getCacheStat()
Experimental, debug-only usage Is only available with "teamcity.buildhistory.buildsCache.statistics.enabled" server internal property
-
getInParamsSize
public static int getInParamsSize(int numberOfParams)
For internal usage only.- Parameters:
numberOfParams
- number of parameters.- Returns:
- result.
-
-