Spring data R2DBC without spring

Hi is there any replacement for spring-boot-starter-data-r2dbc with Guice? I'm mostly interested in something close to the ReactiveCrudRepository<> with R2DBC compatibility where it can just codegen a lot of boilerplate code.
11 Replies
JavaBot
JavaBot5d ago
This post has been reserved for your question.
Hey @Annabelle! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st5d ago
Isn't guice for dependency injection? Why would you use that with Spring and how does that relate to DB repositories?
JavaBot
JavaBot5d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Annabelle
AnnabelleOP5d ago
Code generation Crud repository generates mapping code to classes And also you can just define methods in interface and it will generate code for it based on args and also supports custom query over decorators Its not possible to use this library without spring I think. I tried for some time. But im looking if there are like different libraries that can do the same and work with Guice
dan1st
dan1st5d ago
but what code do you want to generate?
Annabelle
AnnabelleOP5d ago
One sec I'll send example
dan1st
dan1st5d ago
If you want to generate custom code, there are ways to do it oh I didn't notice you want something without Spring If you want to generate code at compile-time, take a look at annotation processors While this is not what Spring does, it might be better for your use-case With that, you can find e.g. annotated interfaces and generate implementations of them or you could generate arbitrary classes
Annabelle
AnnabelleOP5d ago
So for example I had this:
@Service
@Repository
public interface DiscordUserRepository extends ReactiveCrudRepository<DiscordUserDTO, UUID> {

Mono<DiscordUserDTO> getDiscordUserById(UUID uuid);

Mono<DiscordUserDTO> getDiscordUserBySpigotId(int uuid);

Mono<DiscordUserDTO> getDiscordUserByDiscordId(String discordId);
}
@Service
@Repository
public interface DiscordUserRepository extends ReactiveCrudRepository<DiscordUserDTO, UUID> {

Mono<DiscordUserDTO> getDiscordUserById(UUID uuid);

Mono<DiscordUserDTO> getDiscordUserBySpigotId(int uuid);

Mono<DiscordUserDTO> getDiscordUserByDiscordId(String discordId);
}
This all part of spring-boot-starter-data-r2dbc so for example if you use Spring bean and for example request DI for DiscordUserRepository I think it binds this interface to generated class internally. But I tried for example using the provided class R2dbcRepositoryFactory with factory.getRepository(T::class.java) But that gets me an error <TRepository> referenced from a method is not visible from class loader: 'app' This is a Guice error I kinda don't want to build my library for it.. Was checking to either hack spring-boot-starter-data-r2dbc to work or like find alternative that Is based on reactor-core. And I honestly don't mind if there are no libs that do code-gen I'm mostly looking into just having kind of a mini ORM like SQL builder or something like that to avoid having to write SQL in code directly. ------------ Okay, actually I got ReactiveCrudRepository to work For anyone interested in a solution how to get this working in Guice. First, you should be able to bind R2dbcRepositoryFactory instance can be createad with ConnectionFactories -> DatabaseClient-> R2dbcEntityTemplate -> R2dbcRepositoryFactory. In my case I just created a custom factory class since I inject my config from APP. You can create a custom Provider<T> where you just inject this factory and call getRepository, and this should just work for you without any issues. This did not work in my case since I have a logic that dynamically loads into custom ClassLoader, and if you have this case you can just call factory.setBeanClassLoader(classLoader) to set it to the custom class-loader you need. And this pretty much solved my issue.
JavaBot
JavaBot5d ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Annabelle
AnnabelleOP5d ago
There is actually nothing special beside just creating R2dbcRepositoryFactory somewhere and calling getRepository These deps are only needed.
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>${dep.r2dbc.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>${dep.r2dbc.spring.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>${dep.r2dbc.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>${dep.r2dbc.spring.version}</version>
</dependency>
Just had issue where the Repository interface was not present in the java default class-loader which is only in my specific use-case and should work instantly without any other setup.
JavaBot
JavaBot5d ago
Post Closed
This post has been closed by <@703553909720875048>.

Did you find this page helpful?