Class BaseIdentifiersManager<INT>

    • Field Detail

      • myIdKindName

        @NotNull
        protected final String myIdKindName
      • myGuidGenerator

        @NotNull
        protected final GuidGenerator myGuidGenerator
      • myLogger

        @NotNull
        protected final Logger myLogger
    • Method Detail

      • loadMissingIdentifiersFromDB

        public void loadMissingIdentifiersFromDB()
      • registerBrandNewExternalId

        @NotNull
        public EntityId<INT> registerBrandNewExternalId​(@NotNull
                                                        String extId)
        Description copied from interface: IdentifiersManager
        Registers 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:
        registerBrandNewExternalId in interface IdentifiersManager<INT>
        Parameters:
        extId - the external identifier to register.
        Returns:
        new associated internal identifier.
      • generateNewExternalId

        @NotNull
        public String generateNewExternalId​(@Nullable
                                            String parentExtId,
                                            @NotNull
                                            String name,
                                            @Nullable
                                            Set<String> excludeAdditionalIds)
        Description copied from interface: ExternalIdGenerator
        Generates 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:
        generateNewExternalId in interface ExternalIdGenerator
        Overrides:
        generateNewExternalId in class BaseExternalIdGenerator
        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
      • findEntityIdByConfigId

        @Nullable
        public EntityId<INT> findEntityIdByConfigId​(@NotNull
                                                    String configId)
        Description copied from interface: IdentifiersManager
        Looks for a registered entity id by the given config id.
        Specified by:
        findEntityIdByConfigId in interface IdentifiersManager<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: IdentifiersManager
        Looks 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:
        refreshFromDbIfNecessary in interface IdentifiersManager<INT>
        Returns:
        found entity id or null when not found.
      • reassignInternalId

        public void reassignInternalId​(@NotNull
                                       EntityId<INT> entityId,
                                       @NotNull
                                       INT internalId,
                                       @Nullable
                                       CustomIdChangeApplier<INT> applier)
        Description copied from interface: IdentifiersManager
        Assigns 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 an IllegalArgumentException is 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:
        reassignInternalId in interface IdentifiersManager<INT>
      • reassignInternalIdInMemory

        public void reassignInternalIdInMemory​(@NotNull
                                               EntityId<INT> entityId,
                                               @NotNull
                                               INT internalId)
        Description copied from interface: IdentifiersManager
        Reassigns 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:
        reassignInternalIdInMemory in interface IdentifiersManager<INT>
      • deleteFromMaps

        protected void deleteFromMaps​(@NotNull
                                      EntityId<INT> entityId)
      • deleteFromCache

        protected void deleteFromCache​(@NotNull
                                       EntityId<INT> entityId)
      • updateEntitiesRemovedMark

        public void updateEntitiesRemovedMark​(@NotNull
                                              Set<INT> existingInternalIds)
      • isExternalIdAlias

        public boolean isExternalIdAlias​(@NotNull
                                         String externalId)
        Description copied from interface: IdentifiersManager
        Check whether the external id is an alias (but not a primary external id).
        Specified by:
        isExternalIdAlias in interface IdentifiersManager<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: IdentifiersManager
        Looks for the external identifier by the given internal one.
        Specified by:
        internalToExternal in interface IdentifiersManager<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: IdentifiersManager
        Looks for the external identifiers by the given internal ones.
        Specified by:
        internalToExternal in interface IdentifiersManager<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: IdentifiersManager
        Looks for the internal identifier by the given external one.
        Specified by:
        externalToInternal in interface IdentifiersManager<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: IdentifiersManager
        Looks for the internal identifiers by the given external ones
        Specified by:
        externalToInternal in interface IdentifiersManager<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: IdentifiersManager
        Looks for the internal identifier by the given config id.
        Specified by:
        configIdToInternal in interface IdentifiersManager<INT>
        Parameters:
        configId - config identifier (case insensitive).
        Returns:
        the internal identifier if found, or null if not found.
      • getAllExternalIds

        @NotNull
        public Set<String> getAllExternalIds​(@NotNull
                                             INT intId)
        Description copied from interface: IdentifiersManager
        Returns all external ids that correspond to the intId. There is a main one, or probably several aliases.

        If the intId is not found, empty set is returned.

        Specified by:
        getAllExternalIds in interface IdentifiersManager<INT>
        Parameters:
        intId - internal identifier (case sensitive).
        Returns:
        set of corresponding external ids
      • preprocessInternalId

        @NotNull
        protected abstract INT preprocessInternalId​(@NotNull
                                                    String internalId)
      • findInternalIdByConfigId

        @Nullable
        protected abstract INT findInternalIdByConfigId​(@NotNull
                                                        DBFunctions dbf,
                                                        @NotNull
                                                        String configId)
      • findExternalIdByInternalId

        @Nullable
        protected abstract String findExternalIdByInternalId​(@NotNull
                                                             DBFunctions dbf,
                                                             @NotNull
                                                             INT internalId)
      • generateNewIntId

        @NotNull
        protected abstract INT generateNewIntId​(@NotNull
                                                String newExtId)
      • 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)
      • getAllExtIdsSet

        @NotNull
        public Set<String> getAllExtIdsSet()