Skip to content

Commit

Permalink
added example for issue 105
Browse files Browse the repository at this point in the history
  • Loading branch information
lpandzic committed Oct 31, 2024
1 parent 7f8086a commit fe928b9
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 0 deletions.
42 changes: 42 additions & 0 deletions infobip-spring-data-r2dbc-custom-fragment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.8-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-r2dbc-custom-fragment</artifactId>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>infobip-spring-data-r2dbc-querydsl-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>

<!--TEST-->
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-mssql</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.infobip.test;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

@SpringBootApplication
public class Main {

public static void main(String[] args) {

new SpringApplicationBuilder(Main.class).run(args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.infobip.test;

import lombok.With;
import org.springframework.data.annotation.Id;

public record Person(
@With
@Id
Long id,

String firstName,

String lastName
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.infobip.test;

import com.infobip.spring.data.r2dbc.QuerydslR2dbcRepository;

public interface PersonRepository extends QuerydslR2dbcRepository<Person, Long>, ReactivePagingRepository<Person> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.infobip.test;

import lombok.AllArgsConstructor;
import org.junit.jupiter.api.Test;

@AllArgsConstructor
public class QuerydslR2dbcRepositoryTest extends TestBase {

private final PersonRepository repository;

@Test
void shouldSaveWithVarArgs() {
repository.simplePaging("");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.infobip.test;

import reactor.core.publisher.Mono;

public interface ReactivePagingRepository<T> {

Mono<T> simplePaging(String string);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.infobip.test;

import com.infobip.spring.data.r2dbc.QuerydslR2dbcFragment;
import org.springframework.context.annotation.Lazy;
import reactor.core.publisher.Mono;

public class ReactivePagingRepositoryImpl<T> implements ReactivePagingRepository<T> {

private final QuerydslR2dbcFragment querydslR2dbcFragment;

public ReactivePagingRepositoryImpl(@Lazy QuerydslR2dbcFragment querydslR2dbcFragment) {
this.querydslR2dbcFragment = querydslR2dbcFragment;
}

@Override
public Mono<T> simplePaging(String string) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.infobip.test;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestConstructor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@ActiveProfiles("mssql")
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@TestInstance(PER_CLASS)
@SpringBootTest(classes = Main.class)
public abstract class TestBase {

@Autowired
private List<ReactiveCrudRepository<?, ?>> repositories;

@AfterEach
public void clearRepositories() {
block(Flux.concat(repositories.stream()
.map(ReactiveCrudRepository::deleteAll)
.collect(Collectors.toList()))
.collectList());
}

private <T> T block(Mono<T> mono) {
return mono.block(Duration.ofSeconds(10));
}

<T> List<T> block(Flux<T> flux) {
return block(flux.collectList());
}

protected Mono<Void> given(Mono<?>... ts) {
return Flux.concat(Stream.of(ts).collect(Collectors.toList())).last().then();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.infobip.test;

import lombok.AllArgsConstructor;
import org.flywaydb.core.Flyway;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@AllArgsConstructor
@Configuration
public class TestConfiguration {

private final Environment env;

@Bean(initMethod = "migrate")
public Flyway flyway() {
return new Flyway(Flyway.configure()
.baselineOnMigrate(true)
.locations(env.getRequiredProperty("spring.flyway.locations"))
.dataSource(
env.getRequiredProperty("spring.flyway.url"),
env.getRequiredProperty("spring.flyway.username"),
env.getRequiredProperty("spring.flyway.password"))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
spring:
r2dbc:
url: r2dbc:pool:mssql://<host>:<port>/InfobipSpringDataJdbcQuerydslTest
flyway:
locations: "classpath:db/migration/mssql"
url: jdbc:sqlserver://<host>:<port>;database=InfobipSpringDataJdbcQuerydslTest;trustServerCertificate=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE TABLE Person (
Id BIGINT IDENTITY,
FirstName NVARCHAR(20) NOT NULL,
LastName NVARCHAR(50) NOT NULL,
CONSTRAINT PK_Person PRIMARY KEY (Id)
);

CREATE TABLE PersonSettings (
Id BIGINT IDENTITY,
PersonId BIGINT NOT NULL,
CONSTRAINT PK_PersonSettings PRIMARY KEY (Id),
CONSTRAINT FK_PersonSettings_PersonId FOREIGN KEY (PersonId) REFERENCES Person(Id) ON DELETE CASCADE
);

CREATE TABLE NoArgsEntity (
Id BIGINT IDENTITY,
Value NVARCHAR(20),
CONSTRAINT PK_NoArgsEntity PRIMARY KEY (Id),
);

CREATE TABLE TransientEntity (
Id BIGINT IDENTITY,
Value NVARCHAR(20),
CONSTRAINT PK_TransientEntity PRIMARY KEY (Id),
);

CREATE TABLE PagingEntity (
Id BIGINT IDENTITY,
Value NVARCHAR(20),
CONSTRAINT PK_PagingEntity PRIMARY KEY (Id),
);

CREATE TABLE sorting_entity (
id BIGINT IDENTITY,
foo_bar NVARCHAR(20),
CONSTRAINT PK_sorting_entity PRIMARY KEY (id),
);
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<module>infobip-spring-data-jdbc-annotation-processor-common</module>
<module>infobip-spring-data-r2dbc-querydsl</module>
<module>infobip-spring-data-r2dbc-querydsl-boot-starter</module>
<module>infobip-spring-data-r2dbc-custom-fragment</module>
</modules>

<developers>
Expand Down

0 comments on commit fe928b9

Please sign in to comment.