Class BaseIdentifiersManager<INT>
- java.lang.Object
-
- jetbrains.buildServer.serverSide.identifiers.BaseExternalIdGenerator
-
- jetbrains.buildServer.serverSide.identifiers.BaseIdentifiersManager<INT>
-
- All Implemented Interfaces:
ExternalIdGenerator,IdentifiersManager<INT>
- Direct Known Subclasses:
BaseValidatingIdentifiersManager
public abstract class BaseIdentifiersManager<INT> extends BaseExternalIdGenerator implements IdentifiersManager<INT>
-
-
Field Summary
Fields Modifier and Type Field Description protected DBFunctionsProvidermyDbfProviderprotected GuidGeneratormyGuidGeneratorprotected StringmyIdKindNameprotected LoggermyLoggerprotected ServerResponsibilitymyServerResponsibility
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseIdentifiersManager(String entityTableName, String mappingTableName, String idKindName, DBFunctionsProvider dbfProvider, GuidGenerator guidGenerator, ServerResponsibility serverResponsibility)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description INTconfigIdToInternal(String configId)Looks for the internal identifier by the given config id.voidconsumeEntityIds(Consumer<EntityId<INT>> consumer)Consumes entityIds in this managerprotected voiddeleteFromCache(EntityId<INT> entityId)protected voiddeleteFromMaps(EntityId<INT> entityId)protected voidensureCanChangeIdsMapping(String actionDescription)booleanexternalIdSatisfiesConvention(String externalId, String entityName, String parentExtId)Returns true if provided external id satisfies convention used to generate new idsINTexternalToInternal(String extId)Looks for the internal identifier by the given external one.List<INT>externalToInternal(List<String> extIds)Looks for the internal identifiers by the given external onesEntityId<INT>findEntityIdByConfigId(String configId)Looks for a registered entity id by the given config id.EntityId<INT>findEntityIdByExternalId(String extId)Looks for a registered entity id by the given external id.EntityId<INT>findEntityIdByInternalId(INT intId)Looks for a registered entity id by the given internal id.protected abstract StringfindExternalIdByInternalId(DBFunctions dbf, INT internalId)protected abstract INTfindInternalIdByConfigId(DBFunctions dbf, String configId)EntityId<INT>generateAndRegisterBrandNewExternalId(String parentExtId, String name)Generates a unique external identifier by the given parent external identifier and a user string (usually name), and register the just generated identifier as a brand new one.StringgenerateNewExternalId(String parentExtId, String name, Set<String> excludeAdditionalIds)Generates a new external id based on the given name and (optionally) parent external id.protected abstract INTgenerateNewIntId(String newExtId)Set<String>getAllExternalIds()Provides with all known external identifiers.Set<String>getAllExternalIds(INT intId)Returns all external ids that correspond to theintId.Set<String>getAllExtIdsSet()Set<INT>getAllInternalIds()Provides with all known internal identifiers.protected abstract Class<INT>getType()Should return type of entity which is then used to properly construct SQL queries with temp tables.protected abstract voidinsertNewEntityInDB(DBFunctions dbf, INT intId, String configId)protected abstract voidinsertNewPairInDB(DBFunctions dbf, INT intId, String extId)StringinternalToExternal(INT intId)Looks for the external identifier by the given internal one.List<String>internalToExternal(List<INT> intIds)Looks for the external identifiers by the given internal ones.booleanisExternalIdAlias(String externalId)Check whether the external id is an alias (but not a primary external id).voidloadMissingIdentifiersFromDB()voidmarkRemoved(EntityId<INT> entityId, String originProjectIntId)Marks specified entityId as removed and sets the origin project internal id to the given valuevoidmodifyConfigId(EntityId<INT> entityId, String newConfigId, CustomIdChangeApplier<String> configApplier)Modifies the given config identifier to the given new one.voidmodifyExternalId(EntityId<INT> entityId, String newExternalId, CustomIdChangeApplier<String> externalApplier)Modifies the given external identifier to the given new one.protected abstract INTpreprocessInternalId(String internalId)voidreassignInternalId(EntityId<INT> entityId, INT internalId, CustomIdChangeApplier<INT> applier)Assigns the specified internalId to the given entity and runs provided applier after that.voidreassignInternalIdInMemory(EntityId<INT> entityId, INT internalId)Reassigns internal id in memory only, does not change anything in database.EntityId<INT>refreshFromDbIfNecessary(String extId, String configId)Looks for a registered entity id by the given config id and ext id and refresh from db if necessary.EntityId<INT>registerBrandNewExternalId(String extId)Registers the given external identifier with a brand new internal one.voidregisterEntities(Collection<EntityId<INT>> entities)EntityId<INT>registerOrReuseExternalAndConfigId(String extId, String configId)Registers the given external identifier and config id pair.booleanremoveExternalIdAlias(String externalIdAlias)Removes the external id alias (but not a primary external id) from the model and database.voidresetRemoved(Collection<EntityId<INT>> entityIds)Resets removed mark for the given entityIdvoidupdateEntitiesRemovedMark(Set<INT> existingInternalIds)voidvalidateExternalId(String extId, EntityId<INT> curObjId)Validates given external identifier-
Methods inherited from class jetbrains.buildServer.serverSide.identifiers.BaseExternalIdGenerator
generateNewExternalId, generateNewId, generateNewId, isExternalIdOccupied, regenerateExternalId
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.serverSide.identifiers.ExternalIdGenerator
generateNewExternalId, regenerateExternalId
-
-
-
-
Field Detail
-
myIdKindName
@NotNull protected final String myIdKindName
-
myDbfProvider
@NotNull protected final DBFunctionsProvider myDbfProvider
-
myGuidGenerator
@NotNull protected final GuidGenerator myGuidGenerator
-
myServerResponsibility
@NotNull protected final ServerResponsibility myServerResponsibility
-
myLogger
@NotNull protected final Logger myLogger
-
-
Constructor Detail
-
BaseIdentifiersManager
protected BaseIdentifiersManager(@NotNull String entityTableName, @NotNull String mappingTableName, @NotNull String idKindName, @NotNull DBFunctionsProvider dbfProvider, @NotNull GuidGenerator guidGenerator, @NotNull ServerResponsibility serverResponsibility)
-
-
Method Detail
-
loadMissingIdentifiersFromDB
public void loadMissingIdentifiersFromDB()
-
registerBrandNewExternalId
@NotNull public EntityId<INT> registerBrandNewExternalId(@NotNull String extId)
Description copied from interface:IdentifiersManagerRegisters the given external identifier with a brand new internal one. If such external identifier was already registered, the correspondent internal one is dropped (and is not reused).- Specified by:
registerBrandNewExternalIdin interfaceIdentifiersManager<INT>- Parameters:
extId- the external identifier to register.- Returns:
- new associated internal identifier.
-
registerOrReuseExternalAndConfigId
@NotNull public EntityId<INT> registerOrReuseExternalAndConfigId(@NotNull String extId, @Nullable String configId) throws InvalidIdentifierException
Description copied from interface:IdentifiersManagerRegisters the given external identifier and config id pair. If specified config id exists in database it's internal id will be used, otherwise new internal id will be generated.- Specified by:
registerOrReuseExternalAndConfigIdin interfaceIdentifiersManager<INT>- Parameters:
extId- the external identifier to register.configId- the config identifier to register, if null new config id is generated.- Returns:
- associated internal identifier.
- Throws:
InvalidIdentifierException
-
generateAndRegisterBrandNewExternalId
@NotNull public EntityId<INT> generateAndRegisterBrandNewExternalId(@Nullable String parentExtId, @NotNull String name) throws InvalidIdentifierException
Description copied from interface:IdentifiersManagerGenerates a unique external identifier by the given parent external identifier and a user string (usually name), and register the just generated identifier as a brand new one.- Specified by:
generateAndRegisterBrandNewExternalIdin interfaceIdentifiersManager<INT>- Parameters:
parentExtId- the parent's external identifier (optional).name- the user string (name).- Returns:
- just created identifiers pair.
- Throws:
InvalidIdentifierException
-
generateNewExternalId
@NotNull public String generateNewExternalId(@Nullable String parentExtId, @NotNull String name, @Nullable Set<String> excludeAdditionalIds)
Description copied from interface:ExternalIdGeneratorGenerates a new external id based on the given name and (optionally) parent external id. May adjust the case of the name part of the id to comply with external id conventions- Specified by:
generateNewExternalIdin interfaceExternalIdGenerator- Overrides:
generateNewExternalIdin classBaseExternalIdGenerator- Parameters:
parentExtId- the parent's external identifier (optional).name- the user string (name).excludeAdditionalIds- an additional set of ids that are already used (i.e. the result should not be one of them). The current assigned external ids are excluded by default.- Returns:
- new external id
-
externalIdSatisfiesConvention
public boolean externalIdSatisfiesConvention(@NotNull String externalId, @NotNull String entityName, @NotNull String parentExtId)Description copied from interface:ExternalIdGeneratorReturns true if provided external id satisfies convention used to generate new ids- Specified by:
externalIdSatisfiesConventionin interfaceExternalIdGenerator- Overrides:
externalIdSatisfiesConventionin classBaseExternalIdGenerator- Parameters:
externalId- external ids to checkentityName- name of the entity whose external id is to be verifiedparentExtId- parent external id- Returns:
- see above
-
validateExternalId
public void validateExternalId(@NotNull String extId, @Nullable EntityId<INT> curObjId)Description copied from interface:IdentifiersManagerValidates given external identifier- Specified by:
validateExternalIdin interfaceIdentifiersManager<INT>- Parameters:
extId- identifier to validate
-
findEntityIdByInternalId
@Nullable public EntityId<INT> findEntityIdByInternalId(@NotNull INT intId)
Description copied from interface:IdentifiersManagerLooks for a registered entity id by the given internal id.- Specified by:
findEntityIdByInternalIdin interfaceIdentifiersManager<INT>- Parameters:
intId- internal id.- Returns:
- found entity id or null when not found.
-
findEntityIdByConfigId
@Nullable public EntityId<INT> findEntityIdByConfigId(@NotNull String configId)
Description copied from interface:IdentifiersManagerLooks for a registered entity id by the given config id.- Specified by:
findEntityIdByConfigIdin interfaceIdentifiersManager<INT>- Parameters:
configId- config id, case insensitive.- Returns:
- found entity id or null when not found.
-
refreshFromDbIfNecessary
@Nullable public EntityId<INT> refreshFromDbIfNecessary(@NotNull String extId, @Nullable String configId)
Description copied from interface:IdentifiersManagerLooks for a registered entity id by the given config id and ext id and refresh from db if necessary. Called by secondary nodes while loading new entities- Specified by:
refreshFromDbIfNecessaryin interfaceIdentifiersManager<INT>- Returns:
- found entity id or null when not found.
-
findEntityIdByExternalId
@Nullable public EntityId<INT> findEntityIdByExternalId(@NotNull String extId)
Description copied from interface:IdentifiersManagerLooks for a registered entity id by the given external id.- Specified by:
findEntityIdByExternalIdin interfaceIdentifiersManager<INT>- Returns:
- found entity id or null when not found.
-
modifyExternalId
public void modifyExternalId(@NotNull EntityId<INT> entityId, @NotNull String newExternalId, @Nullable CustomIdChangeApplier<String> externalApplier) throws DuplicateExternalIdException, NoSuchExternalIdExceptionDescription copied from interface:IdentifiersManagerModifies the given external identifier to the given new one.- Specified by:
modifyExternalIdin interfaceIdentifiersManager<INT>- Parameters:
entityId- the entity id where to modify its external id.newExternalId- the new external id.externalApplier- external procedure to make changes in files when successful.- Throws:
DuplicateExternalIdException- thrown when such external identifier already exists.NoSuchExternalIdException
-
reassignInternalId
public void reassignInternalId(@NotNull EntityId<INT> entityId, @NotNull INT internalId, @Nullable CustomIdChangeApplier<INT> applier)Description copied from interface:IdentifiersManagerAssigns the specified internalId to the given entity and runs provided applier after that. The internalId should come from an entityId present in DB and marked as removed, otherwise anIllegalArgumentExceptionis thrown. Makes the extId of the given internalId becomes an alias for the entityId. Also creates a new deleted entity with extId='{entityId.extId}_Detached', intId={entityId.intId}, cfgId={entityId.cfgId}, so that {entityId.intId} can then be specified as internalId to in this method.- Specified by:
reassignInternalIdin interfaceIdentifiersManager<INT>
-
reassignInternalIdInMemory
public void reassignInternalIdInMemory(@NotNull EntityId<INT> entityId, @NotNull INT internalId)Description copied from interface:IdentifiersManagerReassigns internal id in memory only, does not change anything in database. Should be used in case of multi node event about internal id changes.- Specified by:
reassignInternalIdInMemoryin interfaceIdentifiersManager<INT>
-
modifyConfigId
public void modifyConfigId(@NotNull EntityId<INT> entityId, @NotNull String newConfigId, @Nullable CustomIdChangeApplier<String> configApplier) throws DuplicateConfigIdExceptionDescription copied from interface:IdentifiersManagerModifies the given config identifier to the given new one.- Specified by:
modifyConfigIdin interfaceIdentifiersManager<INT>- Parameters:
entityId- the entity id where to modify its config id.newConfigId- the new config id.configApplier- external procedure to make changes in files when successful.- Throws:
DuplicateConfigIdException
-
markRemoved
public void markRemoved(@NotNull EntityId<INT> entityId, @Nullable String originProjectIntId)Description copied from interface:IdentifiersManagerMarks specified entityId as removed and sets the origin project internal id to the given value- Specified by:
markRemovedin interfaceIdentifiersManager<INT>
-
resetRemoved
public void resetRemoved(@NotNull Collection<EntityId<INT>> entityIds)Description copied from interface:IdentifiersManagerResets removed mark for the given entityId- Specified by:
resetRemovedin interfaceIdentifiersManager<INT>
-
updateEntitiesRemovedMark
public void updateEntitiesRemovedMark(@NotNull Set<INT> existingInternalIds)
-
consumeEntityIds
public void consumeEntityIds(@NotNull Consumer<EntityId<INT>> consumer)Description copied from interface:IdentifiersManagerConsumes entityIds in this manager- Specified by:
consumeEntityIdsin interfaceIdentifiersManager<INT>
-
removeExternalIdAlias
public boolean removeExternalIdAlias(@NotNull String externalIdAlias) throws FailedToRemoveExternalIdAliasDescription copied from interface:IdentifiersManagerRemoves the external id alias (but not a primary external id) from the model and database. If no nether alias nor internal id found, just silently returns.- Specified by:
removeExternalIdAliasin interfaceIdentifiersManager<INT>- Parameters:
externalIdAlias- the alias to remove.- Returns:
- whether the entry was really removed (from the database).
- Throws:
FailedToRemoveExternalIdAlias- when could not remove.
-
isExternalIdAlias
public boolean isExternalIdAlias(@NotNull String externalId)Description copied from interface:IdentifiersManagerCheck whether the external id is an alias (but not a primary external id).- Specified by:
isExternalIdAliasin interfaceIdentifiersManager<INT>- Parameters:
externalId- the external id to check.- Returns:
- whether the externalId is an alias
-
internalToExternal
@Nullable public String internalToExternal(@Nullable INT intId)
Description copied from interface:IdentifiersManagerLooks for the external identifier by the given internal one.- Specified by:
internalToExternalin interfaceIdentifiersManager<INT>- Parameters:
intId- internal identifier (case sensitive).- Returns:
- the external identifier if found, or null if not found.
-
internalToExternal
@NotNull public List<String> internalToExternal(@NotNull List<INT> intIds)
Description copied from interface:IdentifiersManagerLooks for the external identifiers by the given internal ones.- Specified by:
internalToExternalin interfaceIdentifiersManager<INT>- Parameters:
intIds- list of internal IDs. Nulls are allowed.- Returns:
- List of external IDs. List size is always equal to initial one. For unknown IDs null will be returned
-
externalToInternal
@Nullable public INT externalToInternal(@Nullable String extId)
Description copied from interface:IdentifiersManagerLooks for the internal identifier by the given external one.- Specified by:
externalToInternalin interfaceIdentifiersManager<INT>- Parameters:
extId- external identifier (case insensitive).- Returns:
- the internal identifier if found, or null if not found.
-
externalToInternal
@NotNull public List<INT> externalToInternal(@NotNull List<String> extIds)
Description copied from interface:IdentifiersManagerLooks for the internal identifiers by the given external ones- Specified by:
externalToInternalin interfaceIdentifiersManager<INT>- Parameters:
extIds- list of external IDs. Nulls are allowed.- Returns:
- List of internal IDs. List size is always equal to initial one. For unknown IDs null will be returned
-
configIdToInternal
@Nullable public INT configIdToInternal(@Nullable String configId)
Description copied from interface:IdentifiersManagerLooks for the internal identifier by the given config id.- Specified by:
configIdToInternalin interfaceIdentifiersManager<INT>- Parameters:
configId- config identifier (case insensitive).- Returns:
- the internal identifier if found, or null if not found.
-
getAllInternalIds
@NotNull public Set<INT> getAllInternalIds()
Description copied from interface:IdentifiersManagerProvides with all known internal identifiers.- Specified by:
getAllInternalIdsin interfaceIdentifiersManager<INT>- Returns:
- internal identifiers as a set of case-sensitive strings.
-
getAllExternalIds
@NotNull public Set<String> getAllExternalIds()
Description copied from interface:IdentifiersManagerProvides with all known external identifiers.- Specified by:
getAllExternalIdsin interfaceIdentifiersManager<INT>- Returns:
- external identifiers as a set of case-insensitive strings.
-
getAllExternalIds
@NotNull public Set<String> getAllExternalIds(@NotNull INT intId)
Description copied from interface:IdentifiersManagerReturns all external ids that correspond to theintId. There is a main one, or probably several aliases.If the
intIdis not found, empty set is returned.- Specified by:
getAllExternalIdsin interfaceIdentifiersManager<INT>- Parameters:
intId- internal identifier (case sensitive).- Returns:
- set of corresponding external ids
-
preprocessInternalId
@NotNull protected abstract INT preprocessInternalId(@NotNull String internalId)
-
registerEntities
public void registerEntities(@NotNull Collection<EntityId<INT>> entities)
-
findInternalIdByConfigId
@Nullable protected abstract INT findInternalIdByConfigId(@NotNull DBFunctions dbf, @NotNull String configId)
-
findExternalIdByInternalId
@Nullable protected abstract String findExternalIdByInternalId(@NotNull DBFunctions dbf, @NotNull INT internalId)
-
insertNewEntityInDB
protected abstract void insertNewEntityInDB(@NotNull DBFunctions dbf, @NotNull INT intId, @NotNull String configId)
-
insertNewPairInDB
protected abstract void insertNewPairInDB(@NotNull DBFunctions dbf, @NotNull INT intId, @NotNull String extId)
-
getType
@NotNull protected abstract Class<INT> getType()
Should return type of entity which is then used to properly construct SQL queries with temp tables.- Returns:
- see above
-
ensureCanChangeIdsMapping
protected void ensureCanChangeIdsMapping(String actionDescription)
-
-