Class SlugAutoConfiguration
-
- All Implemented Interfaces:
@Configuration()@ConditionalOnClass(value = {EntityManager.class})@AutoConfigureAfter(value = {JpaBaseConfiguration.class}) public class SlugAutoConfigurationAuto-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.
-
-
Constructor Summary
Constructors Constructor Description SlugAutoConfiguration(ApplicationContext context, PlatformTransactionManager transactionManager)
-
Method Summary
Modifier and Type Method Description UnitconfigureSlugSupport()Initializes slug generation support after the application context is loaded. final BooleanslugExists(KClass<?> entityClass, String slug, Object entityId)Checks whether a given slug already exists in the database for the specified entity type. -
-
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 collisionsslug- the slug candidate to testentityId- the ID of the current entity (to exclude itself during updates)- Returns:
trueif the slug already exists for another entity,falseotherwise
-
-
-
-