Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 97 #99

Merged
merged 8 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion infobip-spring-data-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-jdbc-annotation-processor-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion infobip-spring-data-jdbc-annotation-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-jdbc-annotation-processor</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion infobip-spring-data-jdbc-querydsl-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-jdbc-querydsl-boot-starter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion infobip-spring-data-jdbc-querydsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-jdbc-querydsl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion infobip-spring-data-jpa-querydsl-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-jpa-querydsl-boot-starter</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion infobip-spring-data-jpa-querydsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-jpa-querydsl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion infobip-spring-data-r2dbc-querydsl-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-r2dbc-querydsl-boot-starter</artifactId>
Expand Down
32 changes: 31 additions & 1 deletion infobip-spring-data-r2dbc-querydsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
<parent>
<groupId>com.infobip</groupId>
<artifactId>infobip-spring-data-querydsl</artifactId>
<version>9.0.6</version>
<version>9.0.7-SNAPSHOT</version>
</parent>

<artifactId>infobip-spring-data-r2dbc-querydsl</artifactId>

<properties>
<jasync-r2dbc-mysql.version>2.1.13</jasync-r2dbc-mysql.version>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -51,6 +55,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
<optional>true</optional>
</dependency>

<!--TEST-->
<dependency>
<groupId>io.r2dbc</groupId>
Expand All @@ -69,5 +79,25 @@
<artifactId>HikariCP</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.jasync-sql</groupId>
<artifactId>jasync-r2dbc-mysql</artifactId>
<version>${jasync-r2dbc-mysql.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.infobip</groupId>
<artifactId>infobip-mysql-testcontainers-spring-boot-starter</artifactId>
<version>${infobip-testcontainers.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.infobip.spring.data.r2dbc;

import com.querydsl.sql.MySQLTemplates;
import com.querydsl.sql.SQLTemplates;
import io.r2dbc.spi.Parameters;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.r2dbc.core.binding.BindMarkersFactory;
Expand All @@ -9,12 +11,33 @@
class QuerydslParameterBinder {

private final BindMarkersFactory bindMarkersFactory;
private final boolean useNumberedBindParameters;

QuerydslParameterBinder(BindMarkersFactory bindMarkersFactory) {
QuerydslParameterBinder(BindMarkersFactory bindMarkersFactory, SQLTemplates sqlTemplates) {
this.bindMarkersFactory = bindMarkersFactory;
this.useNumberedBindParameters = resolve(sqlTemplates);
}

private boolean resolve(SQLTemplates sqlTemplates) {

if(sqlTemplates instanceof MySQLTemplates) {
return true;
}

return false;
}

DatabaseClient.GenericExecuteSpec bind(DatabaseClient databaseClient, List<Object> bindings, String sql) {

if(useNumberedBindParameters) {
var spec = databaseClient.sql(sql);
var index = 0;
for (Object binding : bindings) {
spec = spec.bind(index++, binding);
}
return spec;
}

var parameterNameToParameterValue = parameterNameToParameterValue(bindings);
var sqlWithParameterNames = getSqlWithParameterNames(parameterNameToParameterValue, sql);
var spec = databaseClient.sql(sqlWithParameterNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ public class QuerydslR2dbcRepositoryFactory extends R2dbcRepositoryFactory {

public QuerydslR2dbcRepositoryFactory(R2dbcEntityOperations operations,
SQLQueryFactory sqlQueryFactory,
DatabaseClient databaseClient) {
DatabaseClient databaseClient,
SQLTemplates sqlTemplates) {
super(operations);
this.sqlQueryFactory = sqlQueryFactory;
this.converter = operations.getConverter();
this.databaseClient = databaseClient;
this.querydslParameterBinder = new QuerydslParameterBinder(
BindMarkersFactoryResolver.resolve(databaseClient.getConnectionFactory()));
BindMarkersFactoryResolver.resolve(databaseClient.getConnectionFactory()), sqlTemplates);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.infobip.spring.data.r2dbc;

import com.querydsl.sql.SQLQueryFactory;
import com.querydsl.sql.SQLTemplates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.r2dbc.core.R2dbcEntityOperations;
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactoryBean;
Expand All @@ -30,14 +31,15 @@ public class QuerydslR2dbcRepositoryFactoryBean<T extends Repository<S, ID>, S,

private SQLQueryFactory sqlQueryFactory;
private DatabaseClient databaseClient;
private SQLTemplates sqlTemplates;

protected QuerydslR2dbcRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
super(repositoryInterface);
}

@Override
protected RepositoryFactorySupport getFactoryInstance(R2dbcEntityOperations operations) {
return new QuerydslR2dbcRepositoryFactory(operations, sqlQueryFactory, databaseClient);
return new QuerydslR2dbcRepositoryFactory(operations, sqlQueryFactory, databaseClient, sqlTemplates);
}

@Autowired
Expand All @@ -50,4 +52,9 @@ public void setDatabaseClient(DatabaseClient databaseClient) {
super.setDatabaseClient(databaseClient);
this.databaseClient = databaseClient;
}

@Autowired
public void setSqlTemplates(SQLTemplates sqlTemplates) {
this.sqlTemplates = sqlTemplates;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.infobip.spring.data.r2dbc;

import com.infobip.testcontainers.spring.mysql.MySQLContainerInitializer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.test.context.MergedContextConfiguration;

import java.util.List;

public class MysqlExclusionContextLoader extends SpringBootContextLoader {

@Override
protected List<ApplicationContextInitializer<?>> getInitializers(MergedContextConfiguration config,
SpringApplication application) {
var initializers = super.getInitializers(config, application)
.stream()
.filter(initializer -> !(initializer instanceof MySQLContainerInitializer))
.toList();
return initializers;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package com.infobip.spring.data.r2dbc;

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

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

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.TestConstructor;
import org.springframework.test.context.*;
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)
@ContextConfiguration(loader = MysqlExclusionContextLoader.class)
@SpringBootTest(classes = Main.class)
public abstract class TestBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TestConfiguration {
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"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.infobip.spring.data.r2dbc.mysql;

import com.infobip.spring.data.r2dbc.EnableQuerydslR2dbcRepositories;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Profile;

@Profile("mysql")
@EnableQuerydslR2dbcRepositories
@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,22 @@
package com.infobip.spring.data.r2dbc.mysql;

import com.infobip.testcontainers.spring.mssql.MSSQLServerContainerInitializer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.test.context.MergedContextConfiguration;

import java.util.List;

public class MssqlExclusionContextLoader extends SpringBootContextLoader {

@Override
protected List<ApplicationContextInitializer<?>> getInitializers(MergedContextConfiguration config,
SpringApplication application) {
var initializers = super.getInitializers(config, application)
.stream()
.filter(initializer -> !(initializer instanceof MSSQLServerContainerInitializer))
.toList();
return initializers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.infobip.spring.data.r2dbc.mysql;

import com.infobip.spring.data.r2dbc.TestConfiguration;
import org.springframework.context.annotation.*;

@Import(TestConfiguration.class)
@Profile("mysql")
@Configuration
public class MySqlConfiguration {
}
Loading
Loading