Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using Spring R2DBC repositories can I provide my own custom R2dbcEntityTemplate?

I can make required tweaks via:

@EnableR2dbcRepositories(repositoryBaseClass = BaseRepo::class)

but this is too high level. Essentially I override top level method with custom behaviour which needs to be done at R2dbcEntityTemplate.class level so would be great if I could provide custom R2DBC teamplate. I tried declaring bean but it doesn't pick mine, predictably due to being hardcoded in:

/*
 * (non-Javadoc)
 * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getTargetRepository(org.springframework.data.repository.core.RepositoryInformation)
 */
@Override
protected Object getTargetRepository(RepositoryInformation information) {

    RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information.getDomainType(),
            information);

    return getTargetRepositoryViaReflection(information, entityInformation,
            new R2dbcEntityTemplate(this.databaseClient, this.dataAccessStrategy), this.converter);
}
like image 252
Aubergine Avatar asked Dec 22 '25 00:12

Aubergine


1 Answers

Instead of repositoryBaseClass, you can use

@EnableR2dbcRepositories(repositoryFactoryBeanClass = MyR2dbcRepositoryFactoryBean.class)

Then on your MyR2dbcRepositoryFactoryBean you can set your own R2dbcEntityTemplate use the method setEntityOperations

like image 89
Zinc Avatar answered Dec 23 '25 18:12

Zinc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!