feat: 完善代码

This commit is contained in:
wangyu 2024-07-01 10:59:37 +08:00
parent d191ec10e3
commit 80b050ed63

View File

@ -9,11 +9,9 @@ import com.flyfish.framework.repository.DefaultReactiveRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor; import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.r2dbc.core.R2dbcEntityOperations; import org.springframework.data.r2dbc.core.R2dbcEntityOperations;
import org.springframework.data.r2dbc.core.StatementMapper; import org.springframework.data.r2dbc.core.StatementMapper;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.query.Criteria; import org.springframework.data.relational.core.query.Criteria;
import org.springframework.r2dbc.core.DatabaseClient; import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.r2dbc.core.Parameter; import org.springframework.r2dbc.core.Parameter;
@ -31,19 +29,6 @@ class AssociationWriter implements MetadataHandler {
private final Supplier<R2dbcEntityOperations> operations; private final Supplier<R2dbcEntityOperations> operations;
/**
* 通过持久化属性获取真实的列名
*
* @param property 属性
* @return 结果
*/
private String getColumnName(PersistentProperty<?> property) {
if (property instanceof RelationalPersistentProperty) {
return ((RelationalPersistentProperty) property).getColumnName().getReference();
}
return property.getName();
}
/** /**
* 处理association * 处理association
* *
@ -182,9 +167,8 @@ class AssociationWriter implements MetadataHandler {
*/ */
private Mono<Domain> execute(DatabaseClient databaseClient, PreparedOperation<?> operation, Domain entity) { private Mono<Domain> execute(DatabaseClient databaseClient, PreparedOperation<?> operation, Domain entity) {
return databaseClient.sql(operation) return databaseClient.sql(operation)
.map((row -> entity)) .fetch()
.all() .rowsUpdated()
.defaultIfEmpty(entity) .thenReturn(entity);
.last();
} }
} }