|
18 | 18 | import io.r2dbc.spi.ConnectionFactory;
|
19 | 19 | import io.r2dbc.spi.Row;
|
20 | 20 | import io.r2dbc.spi.RowMetadata;
|
| 21 | +import org.springframework.data.annotation.Transient; |
21 | 22 | import reactor.core.publisher.Flux;
|
22 | 23 | import reactor.core.publisher.Mono;
|
23 | 24 |
|
24 | 25 | import java.beans.FeatureDescriptor;
|
| 26 | +import java.lang.reflect.Field; |
25 | 27 | import java.util.Collections;
|
26 | 28 | import java.util.List;
|
27 | 29 | import java.util.Map;
|
28 | 30 | import java.util.Optional;
|
| 31 | +import java.util.Objects; |
29 | 32 | import java.util.function.BiFunction;
|
30 | 33 | import java.util.function.Function;
|
31 | 34 | import java.util.stream.Collectors;
|
| 35 | +import java.util.stream.StreamSupport; |
32 | 36 |
|
33 | 37 | import org.reactivestreams.Publisher;
|
34 | 38 | import org.springframework.beans.BeansException;
|
@@ -161,6 +165,26 @@ public R2dbcEntityTemplate(DatabaseClient databaseClient, ReactiveDataAccessStra
|
161 | 165 | this.projectionFactory = new SpelAwareProxyProjectionFactory();
|
162 | 166 | }
|
163 | 167 |
|
| 168 | + public <T> String getColumnName(Class<T> tableType, Field field) { |
| 169 | + Transient annotation = field.getDeclaredAnnotation(Transient.class); |
| 170 | + if (annotation != null) { |
| 171 | + throw new MappingException("This Column has Transient annotation"); |
| 172 | + } |
| 173 | + |
| 174 | + org.springframework.data.relational.core.mapping.Column columnAnnotation = |
| 175 | + field.getDeclaredAnnotation(org.springframework.data.relational.core.mapping.Column.class); |
| 176 | + if (columnAnnotation != null) { |
| 177 | + return columnAnnotation.value(); |
| 178 | + } |
| 179 | + |
| 180 | + return StreamSupport.stream(Objects.requireNonNull(mappingContext.getPersistentEntity(tableType)).spliterator(), false) |
| 181 | + .filter(column -> field.equals(column.getField())) |
| 182 | + .findFirst() |
| 183 | + .orElseThrow(() -> new MappingException("This Column name is not matched")) |
| 184 | + .getColumnName() |
| 185 | + .toString(); |
| 186 | + } |
| 187 | + |
164 | 188 | @Override
|
165 | 189 | public DatabaseClient getDatabaseClient() {
|
166 | 190 | return this.databaseClient;
|
|
0 commit comments