@ -30,6 +30,7 @@ import org.springframework.data.r2dbc.core.PreparedOperation;
import org.springframework.data.r2dbc.core.ReactiveDataAccessStrategy ;
import org.springframework.data.r2dbc.core.ReactiveDataAccessStrategy ;
import org.springframework.data.r2dbc.core.StatementMapper ;
import org.springframework.data.r2dbc.core.StatementMapper ;
import org.springframework.data.r2dbc.query.Criteria ;
import org.springframework.data.r2dbc.query.Criteria ;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty ;
import org.springframework.data.relational.core.sql.Functions ;
import org.springframework.data.relational.core.sql.Functions ;
import org.springframework.data.relational.core.sql.Select ;
import org.springframework.data.relational.core.sql.Select ;
import org.springframework.data.relational.core.sql.StatementBuilder ;
import org.springframework.data.relational.core.sql.StatementBuilder ;
@ -129,12 +130,12 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, I
Assert . notNull ( id , "Id must not be null!" ) ;
Assert . notNull ( id , "Id must not be null!" ) ;
List < String > columns = this . accessStrategy . getAllColumns ( this . entity . getJavaType ( ) ) ;
List < String > columns = this . accessStrategy . getAllColumns ( this . entity . getJavaType ( ) ) ;
String idColumnName = getIdColumn Name ( ) ;
String idProperty = getIdProperty ( ) . get Name ( ) ;
StatementMapper mapper = this . accessStrategy . getStatementMapper ( ) . forType ( this . entity . getJavaType ( ) ) ;
StatementMapper mapper = this . accessStrategy . getStatementMapper ( ) . forType ( this . entity . getJavaType ( ) ) ;
StatementMapper . SelectSpec selectSpec = mapper . createSelect ( this . entity . getTableName ( ) ) //
StatementMapper . SelectSpec selectSpec = mapper . createSelect ( this . entity . getTableName ( ) ) //
. withProjection ( columns ) //
. withProjection ( columns ) //
. withCriteria ( Criteria . where ( idColumnName ) . is ( id ) ) ;
. withCriteria ( Criteria . where ( idProperty ) . is ( id ) ) ;
PreparedOperation < ? > operation = mapper . getMappedObject ( selectSpec ) ;
PreparedOperation < ? > operation = mapper . getMappedObject ( selectSpec ) ;
@ -160,12 +161,12 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, I
Assert . notNull ( id , "Id must not be null!" ) ;
Assert . notNull ( id , "Id must not be null!" ) ;
String idColumnName = getIdColumn Name ( ) ;
String idProperty = getIdProperty ( ) . get Name ( ) ;
StatementMapper mapper = this . accessStrategy . getStatementMapper ( ) . forType ( this . entity . getJavaType ( ) ) ;
StatementMapper mapper = this . accessStrategy . getStatementMapper ( ) . forType ( this . entity . getJavaType ( ) ) ;
StatementMapper . SelectSpec selectSpec = mapper . createSelect ( this . entity . getTableName ( ) )
StatementMapper . SelectSpec selectSpec = mapper . createSelect ( this . entity . getTableName ( ) )
. withProjection ( Collections . singletonList ( idColumnName ) ) //
. withProjection ( Collections . singletonList ( idProperty ) ) //
. withCriteria ( Criteria . where ( idColumnName ) . is ( id ) ) ;
. withCriteria ( Criteria . where ( idProperty ) . is ( id ) ) ;
PreparedOperation < ? > operation = mapper . getMappedObject ( selectSpec ) ;
PreparedOperation < ? > operation = mapper . getMappedObject ( selectSpec ) ;
@ -217,12 +218,12 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, I
}
}
List < String > columns = this . accessStrategy . getAllColumns ( this . entity . getJavaType ( ) ) ;
List < String > columns = this . accessStrategy . getAllColumns ( this . entity . getJavaType ( ) ) ;
String idColumnName = getIdColumn Name ( ) ;
String idProperty = getIdProperty ( ) . get Name ( ) ;
StatementMapper mapper = this . accessStrategy . getStatementMapper ( ) . forType ( this . entity . getJavaType ( ) ) ;
StatementMapper mapper = this . accessStrategy . getStatementMapper ( ) . forType ( this . entity . getJavaType ( ) ) ;
StatementMapper . SelectSpec selectSpec = mapper . createSelect ( this . entity . getTableName ( ) ) //
StatementMapper . SelectSpec selectSpec = mapper . createSelect ( this . entity . getTableName ( ) ) //
. withProjection ( columns ) //
. withProjection ( columns ) //
. withCriteria ( Criteria . where ( idColumnName ) . in ( ids ) ) ;
. withCriteria ( Criteria . where ( idProperty ) . in ( ids ) ) ;
PreparedOperation < ? > operation = mapper . getMappedObject ( selectSpec ) ;
PreparedOperation < ? > operation = mapper . getMappedObject ( selectSpec ) ;
@ -238,7 +239,7 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, I
Table table = Table . create ( this . entity . getTableName ( ) ) ;
Table table = Table . create ( this . entity . getTableName ( ) ) ;
Select select = StatementBuilder //
Select select = StatementBuilder //
. select ( Functions . count ( table . column ( getIdColumnName ( ) ) ) ) //
. select ( Functions . count ( table . column ( getIdProperty ( ) . get ColumnName ( ) ) ) ) //
. from ( table ) //
. from ( table ) //
. build ( ) ;
. build ( ) ;
@ -260,7 +261,7 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, I
return this . databaseClient . delete ( ) //
return this . databaseClient . delete ( ) //
. from ( this . entity . getJavaType ( ) ) //
. from ( this . entity . getJavaType ( ) ) //
. table ( this . entity . getTableName ( ) ) //
. table ( this . entity . getTableName ( ) ) //
. matching ( Criteria . where ( getIdColumn Name ( ) ) . is ( id ) ) //
. matching ( Criteria . where ( getIdProperty ( ) . get Name ( ) ) . is ( id ) ) //
. fetch ( ) //
. fetch ( ) //
. rowsUpdated ( ) //
. rowsUpdated ( ) //
. then ( ) ;
. then ( ) ;
@ -285,7 +286,7 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, I
return this . databaseClient . delete ( ) //
return this . databaseClient . delete ( ) //
. from ( this . entity . getJavaType ( ) ) //
. from ( this . entity . getJavaType ( ) ) //
. table ( this . entity . getTableName ( ) ) //
. table ( this . entity . getTableName ( ) ) //
. matching ( Criteria . where ( getIdColumn Name ( ) ) . in ( ids ) ) //
. matching ( Criteria . where ( getIdProperty ( ) . get Name ( ) ) . in ( ids ) ) //
. fetch ( ) //
. fetch ( ) //
. rowsUpdated ( ) ;
. rowsUpdated ( ) ;
} ) . then ( ) ;
} ) . then ( ) ;
@ -339,12 +340,11 @@ public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, I
return this . databaseClient . delete ( ) . from ( this . entity . getTableName ( ) ) . then ( ) ;
return this . databaseClient . delete ( ) . from ( this . entity . getTableName ( ) ) . then ( ) ;
}
}
private String getIdColumnName ( ) {
private RelationalPersistentProperty getIdProperty ( ) {
return this . converter //
return this . converter //
. getMappingContext ( ) //
. getMappingContext ( ) //
. getRequiredPersistentEntity ( this . entity . getJavaType ( ) ) //
. getRequiredPersistentEntity ( this . entity . getJavaType ( ) ) //
. getRequiredIdProperty ( ) //
. getRequiredIdProperty ( ) ;
. getColumnName ( ) ;
}
}
}
}