Class SlugAutoConfiguration

  • All Implemented Interfaces:

    @Configuration()@ConditionalOnClass(value = {EntityManager.class})@AutoConfigureAfter(value = {JpaBaseConfiguration.class}) 
    public class SlugAutoConfiguration
    
                        

    Auto-configuration class for enabling slug generation in JPA entities.

    This configuration is activated automatically when a bean annotated with EnableSlug is present in the application context and when JPA is available.

    It initializes and registers the ISlugGenerator implementation defined in the @EnableSlug(generator = ...) annotation and sets up a ISlugProvider for managing unique slug generation with collision handling.

    The configuration ensures slugs are unique per entity type by checking the database using a TransactionTemplate.

    Slug creation logic is executed during application startup, leveraging a PostConstruct lifecycle method.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      SlugAutoConfiguration(ApplicationContext context, PlatformTransactionManager transactionManager)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      Unit configureSlugSupport() Initializes slug generation support after the application context is loaded.
      final Boolean slugExists(KClass<?> entityClass, String slug, Object entityId) Checks whether a given slug already exists in the database for the specified entity type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SlugAutoConfiguration

        SlugAutoConfiguration(ApplicationContext context, PlatformTransactionManager transactionManager)
    • Method Detail

      • configureSlugSupport

        @PostConstruct()@Transactional() Unit configureSlugSupport()

        Initializes slug generation support after the application context is loaded.

        This method scans for beans annotated with EnableSlug, retrieves the configured ISlugGenerator, and registers a ISlugProvider responsible for generating unique slugs for entities implementing ISlugSupport.

      • slugExists

         final Boolean slugExists(KClass<?> entityClass, String slug, Object entityId)

        Checks whether a given slug already exists in the database for the specified entity type.

        Parameters:
        entityClass - the entity class to check for slug collisions
        slug - the slug candidate to test
        entityId - the ID of the current entity (to exclude itself during updates)
        Returns:

        true if the slug already exists for another entity, false otherwise