Skip to content

Commit a8d46de

Browse files
committed
#220 - Rebase.
1 parent 6c6c57a commit a8d46de

15 files changed

+188
-149
lines changed

Diff for: src/main/java/org/springframework/data/r2dbc/core/DefaultDatabaseClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ private <R> FetchSpec<R> exchange(BiFunction<Row, RowMetadata, R> mappingFunctio
10381038
StatementMapper.InsertSpec insert = mapper.createInsert(this.table);
10391039

10401040
for (SqlIdentifier column : this.byName.keySet()) {
1041-
insert = insert.withColumn(dataAccessStrategy.toSql(column), this.byName.get(column));
1041+
insert = insert.withColumn(column, this.byName.get(column));
10421042
}
10431043

10441044
PreparedOperation<?> operation = mapper.getMappedObject(insert);
@@ -1161,7 +1161,7 @@ private <MR> FetchSpec<MR> exchange(Object toInsert, BiFunction<Row, RowMetadata
11611161
for (SqlIdentifier column : outboundRow.keySet()) {
11621162
SettableValue settableValue = outboundRow.get(column);
11631163
if (settableValue.hasValue()) {
1164-
insert = insert.withColumn(dataAccessStrategy.toSql(column), settableValue);
1164+
insert = insert.withColumn(column, settableValue);
11651165
}
11661166
}
11671167

Diff for: src/main/java/org/springframework/data/r2dbc/core/DefaultStatementMapper.java

+2-22
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
package org.springframework.data.r2dbc.core;
1717

1818
import java.util.ArrayList;
19-
import java.util.Collection;
2019
import java.util.List;
2120

22-
import org.springframework.data.domain.Sort;
2321
import org.springframework.data.mapping.context.MappingContext;
2422
import org.springframework.data.r2dbc.dialect.BindMarkers;
2523
import org.springframework.data.r2dbc.dialect.BindTarget;
@@ -101,8 +99,8 @@ private PreparedOperation<Select> getMappedObject(SelectSpec selectSpec,
10199

102100
if (selectSpec.getSort().isSorted()) {
103101

104-
Sort mappedSort = this.updateMapper.getMappedObject(selectSpec.getSort(), entity);
105-
selectBuilder.orderBy(createOrderByFields(table, mappedSort));
102+
List<OrderByField> sort = this.updateMapper.getMappedSort(table, selectSpec.getSort(), entity);
103+
selectBuilder.orderBy(sort);
106104
}
107105

108106
if (selectSpec.getLimit() > 0) {
@@ -133,24 +131,6 @@ protected List<Expression> getSelectList(SelectSpec selectSpec, @Nullable Relati
133131
return mapped;
134132
}
135133

136-
private Collection<? extends OrderByField> createOrderByFields(Table table, Sort sortToUse) {
137-
138-
List<OrderByField> fields = new ArrayList<>();
139-
140-
for (Sort.Order order : sortToUse) {
141-
142-
OrderByField orderByField = OrderByField.from(table.column(order.getProperty()));
143-
144-
if (order.getDirection() != null) {
145-
fields.add(order.isAscending() ? orderByField.asc() : orderByField.desc());
146-
} else {
147-
fields.add(orderByField);
148-
}
149-
}
150-
151-
return fields;
152-
}
153-
154134
/*
155135
* (non-Javadoc)
156136
* @see org.springframework.data.r2dbc.function.StatementMapper#getMappedObject(org.springframework.data.r2dbc.function.StatementMapper.InsertSpec)

Diff for: src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4545
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
4646
import org.springframework.data.relational.core.sql.Functions;
47+
import org.springframework.data.relational.core.sql.SqlIdentifier;
4748
import org.springframework.data.util.ProxyUtils;
4849
import org.springframework.util.Assert;
4950

@@ -174,7 +175,7 @@ public Mono<Long> count(Query query, Class<?> entityClass) throws DataAccessExce
174175
return doCount(query, entityClass, getTableName(entityClass));
175176
}
176177

177-
Mono<Long> doCount(Query query, Class<?> entityClass, String tableName) {
178+
Mono<Long> doCount(Query query, Class<?> entityClass, SqlIdentifier tableName) {
178179

179180
RelationalPersistentEntity<?> entity = getRequiredEntity(entityClass);
180181
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
@@ -211,12 +212,13 @@ public Mono<Boolean> exists(Query query, Class<?> entityClass) throws DataAccess
211212
return doExists(query, entityClass, getTableName(entityClass));
212213
}
213214

214-
Mono<Boolean> doExists(Query query, Class<?> entityClass, String tableName) {
215+
Mono<Boolean> doExists(Query query, Class<?> entityClass, SqlIdentifier tableName) {
215216

216217
RelationalPersistentEntity<?> entity = getRequiredEntity(entityClass);
217218
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
218219

219-
String columnName = entity.hasIdProperty() ? entity.getRequiredIdProperty().getColumnName() : "*";
220+
SqlIdentifier columnName = entity.hasIdProperty() ? entity.getRequiredIdProperty().getColumnName()
221+
: SqlIdentifier.unquoted("*");
220222

221223
StatementMapper.SelectSpec selectSpec = statementMapper //
222224
.createSelect(tableName) //
@@ -248,7 +250,7 @@ public <T> Flux<T> select(Query query, Class<T> entityClass) throws DataAccessEx
248250
return doSelect(query, entityClass, getTableName(entityClass), entityClass).all();
249251
}
250252

251-
<T> RowsFetchSpec<T> doSelect(Query query, Class<?> entityClass, String tableName, Class<T> returnType) {
253+
<T> RowsFetchSpec<T> doSelect(Query query, Class<?> entityClass, SqlIdentifier tableName, Class<T> returnType) {
252254

253255
RelationalPersistentEntity<?> entity = getRequiredEntity(entityClass);
254256
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
@@ -310,7 +312,7 @@ public Mono<Integer> update(Query query, Update update, Class<?> entityClass) th
310312
return doUpdate(query, update, entityClass, getTableName(entityClass));
311313
}
312314

313-
Mono<Integer> doUpdate(Query query, Update update, Class<?> entityClass, String tableName) {
315+
Mono<Integer> doUpdate(Query query, Update update, Class<?> entityClass, SqlIdentifier tableName) {
314316

315317
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
316318

@@ -339,7 +341,7 @@ public Mono<Integer> delete(Query query, Class<?> entityClass) throws DataAccess
339341
return doDelete(query, entityClass, getTableName(entityClass));
340342
}
341343

342-
Mono<Integer> doDelete(Query query, Class<?> entityClass, String tableName) {
344+
Mono<Integer> doDelete(Query query, Class<?> entityClass, SqlIdentifier tableName) {
343345

344346
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
345347

@@ -371,7 +373,7 @@ public <T> Mono<T> insert(T entity) throws DataAccessException {
371373
return doInsert(entity, getRequiredEntity(entity).getTableName());
372374
}
373375

374-
<T> Mono<T> doInsert(T entity, String tableName) {
376+
<T> Mono<T> doInsert(T entity, SqlIdentifier tableName) {
375377

376378
RelationalPersistentEntity<T> persistentEntity = getRequiredEntity(entity);
377379

@@ -434,7 +436,7 @@ private <T> Query getByIdQuery(T entity, RelationalPersistentEntity<?> persisten
434436
return Query.query(Criteria.where(persistentEntity.getRequiredIdProperty().getName()).is(id));
435437
}
436438

437-
String getTableName(Class<?> entityClass) {
439+
SqlIdentifier getTableName(Class<?> entityClass) {
438440
return getRequiredEntity(entityClass).getTableName();
439441
}
440442

@@ -447,7 +449,7 @@ private <T> RelationalPersistentEntity<T> getRequiredEntity(T entity) {
447449
return (RelationalPersistentEntity) getRequiredEntity(entityType);
448450
}
449451

450-
private <T> List<String> getSelectProjection(Query query, Class<T> returnType) {
452+
private <T> List<SqlIdentifier> getSelectProjection(Query query, Class<T> returnType) {
451453

452454
if (query.getColumns().isEmpty()) {
453455

@@ -457,14 +459,14 @@ private <T> List<String> getSelectProjection(Query query, Class<T> returnType) {
457459

458460
if (projectionInformation.isClosed()) {
459461
return projectionInformation.getInputProperties().stream().map(FeatureDescriptor::getName)
460-
.collect(Collectors.toList());
462+
.map(SqlIdentifier::unquoted).collect(Collectors.toList());
461463
}
462464
}
463465

464-
return Collections.singletonList("*");
466+
return Collections.singletonList(SqlIdentifier.unquoted("*"));
465467
}
466468

467-
return query.getColumns();
469+
return query.getColumns().stream().map(SqlIdentifier::unquoted).collect(Collectors.toList());
468470
}
469471

470472
private static ReactiveDataAccessStrategy getDataAccessStrategy(DatabaseClient databaseClient) {

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperationSupport.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import reactor.core.publisher.Mono;
1919

2020
import org.springframework.data.r2dbc.query.Query;
21+
import org.springframework.data.relational.core.sql.SqlIdentifier;
2122
import org.springframework.lang.Nullable;
2223
import org.springframework.util.Assert;
2324

@@ -35,7 +36,7 @@ class ReactiveDeleteOperationSupport implements ReactiveDeleteOperation {
3536
this.template = template;
3637
}
3738

38-
/*
39+
/*
3940
* (non-Javadoc)
4041
* @see org.springframework.data.r2dbc.core.ReactiveDeleteOperation#delete(java.lang.Class)
4142
*/
@@ -64,7 +65,7 @@ static class ReactiveDeleteSupport implements ReactiveDelete, TerminatingDelete
6465
this.tableName = tableName;
6566
}
6667

67-
/*
68+
/*
6869
* (non-Javadoc)
6970
* @see org.springframework.data.r2dbc.core.ReactiveDeleteOperation.DeleteWithTable#from(java.lang.String)
7071
*/
@@ -76,7 +77,7 @@ public DeleteWithQuery from(String tableName) {
7677
return new ReactiveDeleteSupport(this.template, this.domainType, this.query, tableName);
7778
}
7879

79-
/*
80+
/*
8081
* (non-Javadoc)
8182
* @see org.springframework.data.r2dbc.core.ReactiveDeleteOperation.DeleteWithQuery#matching(org.springframework.data.r2dbc.query.Query)
8283
*/
@@ -88,16 +89,17 @@ public TerminatingDelete matching(Query query) {
8889
return new ReactiveDeleteSupport(this.template, this.domainType, query, this.tableName);
8990
}
9091

91-
/*
92+
/*
9293
* (non-Javadoc)
9394
* @see org.springframework.data.r2dbc.core.ReactiveDeleteOperation.TerminatingDelete#all()
9495
*/
9596
public Mono<Integer> all() {
9697
return this.template.doDelete(this.query, this.domainType, getTableName());
9798
}
9899

99-
private String getTableName() {
100-
return this.tableName != null ? this.tableName : this.template.getTableName(this.domainType);
100+
private SqlIdentifier getTableName() {
101+
return this.tableName != null ? SqlIdentifier.unquoted(this.tableName)
102+
: this.template.getTableName(this.domainType);
101103
}
102104
}
103105
}

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveInsertOperationSupport.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import reactor.core.publisher.Mono;
1919

20+
import org.springframework.data.relational.core.sql.SqlIdentifier;
2021
import org.springframework.lang.Nullable;
2122
import org.springframework.util.Assert;
2223

@@ -84,8 +85,9 @@ public Mono<T> using(T object) {
8485
return this.template.doInsert(object, getTableName());
8586
}
8687

87-
private String getTableName() {
88-
return this.tableName != null ? this.tableName : this.template.getTableName(this.domainType);
88+
private SqlIdentifier getTableName() {
89+
return this.tableName != null ? SqlIdentifier.unquoted(this.tableName)
90+
: this.template.getTableName(this.domainType);
8991
}
9092
}
9193
}

Diff for: src/main/java/org/springframework/data/r2dbc/core/ReactiveSelectOperationSupport.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import reactor.core.publisher.Mono;
2020

2121
import org.springframework.data.r2dbc.query.Query;
22+
import org.springframework.data.relational.core.sql.SqlIdentifier;
2223
import org.springframework.lang.Nullable;
2324
import org.springframework.util.Assert;
2425

@@ -36,7 +37,7 @@ class ReactiveSelectOperationSupport implements ReactiveSelectOperation {
3637
this.template = template;
3738
}
3839

39-
/*
40+
/*
4041
* (non-Javadoc)
4142
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation#select(java.lang.Class)
4243
*/
@@ -69,7 +70,7 @@ static class ReactiveSelectSupport<T> implements ReactiveSelect<T> {
6970
this.tableName = tableName;
7071
}
7172

72-
/*
73+
/*
7374
* (non-Javadoc)
7475
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation.SelectWithTable#from(java.lang.String)
7576
*/
@@ -81,7 +82,7 @@ public SelectWithProjection<T> from(String tableName) {
8182
return new ReactiveSelectSupport<>(this.template, this.domainType, this.returnType, this.query, tableName);
8283
}
8384

84-
/*
85+
/*
8586
* (non-Javadoc)
8687
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation.SelectWithProjection#as(java.lang.Class)
8788
*/
@@ -93,7 +94,7 @@ public <R> SelectWithQuery<R> as(Class<R> returnType) {
9394
return new ReactiveSelectSupport<>(this.template, this.domainType, returnType, this.query, this.tableName);
9495
}
9596

96-
/*
97+
/*
9798
* (non-Javadoc)
9899
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation.SelectWithQuery#matching(org.springframework.data.r2dbc.query.Query)
99100
*/
@@ -105,7 +106,7 @@ public TerminatingSelect<T> matching(Query query) {
105106
return new ReactiveSelectSupport<>(this.template, this.domainType, this.returnType, query, this.tableName);
106107
}
107108

108-
/*
109+
/*
109110
* (non-Javadoc)
110111
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation.TerminatingSelect#count()
111112
*/
@@ -114,7 +115,7 @@ public Mono<Long> count() {
114115
return this.template.doCount(this.query, this.domainType, getTableName());
115116
}
116117

117-
/*
118+
/*
118119
* (non-Javadoc)
119120
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation.TerminatingSelect#exists()
120121
*/
@@ -123,7 +124,7 @@ public Mono<Boolean> exists() {
123124
return this.template.doExists(this.query, this.domainType, getTableName());
124125
}
125126

126-
/*
127+
/*
127128
* (non-Javadoc)
128129
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation.TerminatingSelect#first()
129130
*/
@@ -132,7 +133,7 @@ public Mono<T> first() {
132133
return this.template.doSelect(this.query.limit(1), this.domainType, getTableName(), this.returnType).first();
133134
}
134135

135-
/*
136+
/*
136137
* (non-Javadoc)
137138
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation.TerminatingSelect#one()
138139
*/
@@ -141,7 +142,7 @@ public Mono<T> one() {
141142
return this.template.doSelect(this.query.limit(2), this.domainType, getTableName(), this.returnType).one();
142143
}
143144

144-
/*
145+
/*
145146
* (non-Javadoc)
146147
* @see org.springframework.data.r2dbc.core.ReactiveSelectOperation.TerminatingSelect#all()
147148
*/
@@ -150,8 +151,9 @@ public Flux<T> all() {
150151
return this.template.doSelect(this.query, this.domainType, getTableName(), this.returnType).all();
151152
}
152153

153-
private String getTableName() {
154-
return this.tableName != null ? this.tableName : this.template.getTableName(this.domainType);
154+
private SqlIdentifier getTableName() {
155+
return this.tableName != null ? SqlIdentifier.unquoted(this.tableName)
156+
: this.template.getTableName(this.domainType);
155157
}
156158
}
157159
}

0 commit comments

Comments
 (0)