Skip to content

Commit

Permalink
[UPDATE] 提升代码质量
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Yeh <[email protected]>
  • Loading branch information
alan-yeh committed Nov 30, 2023
1 parent 89c75c6 commit a678e51
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import lombok.Setter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.*;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

Expand All @@ -49,9 +50,12 @@ public class StarterConfiguration implements ImportAware {
private AnnotationMetadata importMetadata;

@Bean
public CacheAdvisor cacheAdvisor(){
public CacheAdvisor cacheAdvisor() {
var attributes = AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));

return new CacheAdvisor(attributes.getNumber("order"));
if (attributes != null) {
return new CacheAdvisor(attributes.getNumber("order"));
} else {
return new CacheAdvisor(Ordered.HIGHEST_PRECEDENCE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportAware;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

Expand All @@ -47,8 +48,11 @@ public class StarterConfiguration implements ImportAware {
@Bean
public LogAdvisor logAdvisor() {
var attributes = AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes(EnableLogPoint.class.getName(), false));

return new LogAdvisor(attributes.getNumber("order"));
if (attributes != null) {
return new LogAdvisor(attributes.getNumber("order"));
} else {
return new LogAdvisor(Ordered.LOWEST_PRECEDENCE);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Http Appender 需要的属性 -->
<springProperty scope="context" name="COLLECTOR_SERVER" source="central.logging.http.server" defaultValue="http://127.0.0.1:3400/logging"/>
<springProperty scope="context" name="COLLECTOR_SERVER" source="central.logging.http.server" defaultValue="http://central-logging/logging"/>
<springProperty scope="context" name="COLLECTOR_PATH" source="central.logging.http.path" defaultValue="central"/>

<!-- 日志需要的属性 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public HttpStatus getStatus() {
}

@Override
public ResponseBody getBody() {
public Body getBody() {
return new ResponseBody(this.headers, this.response.body());
}

Expand Down
30 changes: 15 additions & 15 deletions central-stdlib/src/main/java/central/sql/proxy/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public interface Mapper<E extends Entity> {
* @param conditions 参数条件,如果条件为空,将清空表
* @return 受影响的数据量
*/
long deleteBy(@Nonnull Conditions<? extends E> conditions);
long deleteBy(@Nullable Conditions<? extends E> conditions);

/**
* 清空表
Expand Down Expand Up @@ -156,7 +156,7 @@ public interface Mapper<E extends Entity> {
* @return 数据实体
*/
@Nullable
E findById(@Nullable String id, Columns<? extends E> columns);
E findById(@Nullable String id, @Nullable Columns<? extends E> columns);

/**
* 根据主键查询
Expand All @@ -179,7 +179,7 @@ public interface Mapper<E extends Entity> {
* @return 数据实体列表
*/
@Nonnull
List<E> findByIds(@Nullable List<String> ids, Columns<? extends E> columns);
List<E> findByIds(@Nullable List<String> ids, @Nullable Columns<? extends E> columns);

/**
* 根据条件获取第一条数据
Expand All @@ -189,7 +189,7 @@ public interface Mapper<E extends Entity> {
* @return 实体数据
*/
@Nullable
E findFirstBy(@Nonnull Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);
E findFirstBy(@Nullable Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);

/**
* 根据条件获取第一条数据
Expand All @@ -200,7 +200,7 @@ public interface Mapper<E extends Entity> {
* @return 实体数据
*/
@Nullable
E findFirstBy(@Nullable Columns<? extends E> columns, @Nonnull Conditions<? extends E> conditions, @Nullable Orders<E> orders);
E findFirstBy(@Nullable Columns<? extends E> columns, @Nullable Conditions<? extends E> conditions, @Nullable Orders<E> orders);

/**
* 根据条件获取第一条数据
Expand All @@ -209,7 +209,7 @@ public interface Mapper<E extends Entity> {
* @return 实体数据
*/
@Nullable
E findFirstBy(@Nonnull Conditions<? extends E> conditions);
E findFirstBy(@Nullable Conditions<? extends E> conditions);

/**
* 根据条件获取第一条数据
Expand All @@ -219,7 +219,7 @@ public interface Mapper<E extends Entity> {
* @return 实体数据
*/
@Nullable
E findFirstBy(@Nullable Columns<? extends E> columns, @Nonnull Conditions<? extends E> conditions);
E findFirstBy(@Nullable Columns<? extends E> columns, @Nullable Conditions<? extends E> conditions);

/**
* 根据条件获取实体列表
Expand All @@ -231,7 +231,7 @@ public interface Mapper<E extends Entity> {
* @return 实体列表
*/
@Nonnull
List<E> findBy(@Nullable Long first, @Nullable Long offset, @Nonnull Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);
List<E> findBy(@Nullable Long first, @Nullable Long offset, @Nullable Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);

/**
* 根据条件获取实体列表
Expand All @@ -244,7 +244,7 @@ public interface Mapper<E extends Entity> {
* @return 实体列表
*/
@Nonnull
List<E> findBy(@Nullable Long first, @Nullable Long offset, @Nullable Columns<? extends E> columns, @Nonnull Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);
List<E> findBy(@Nullable Long first, @Nullable Long offset, @Nullable Columns<? extends E> columns, @Nullable Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);

/**
* 根据条件获取实体列表
Expand All @@ -254,7 +254,7 @@ public interface Mapper<E extends Entity> {
* @return 实体列表
*/
@Nonnull
List<E> findBy(@Nonnull Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);
List<E> findBy(@Nullable Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);

/**
* 根据条件获取实体列表
Expand All @@ -265,7 +265,7 @@ public interface Mapper<E extends Entity> {
* @return 实体列表
*/
@Nonnull
List<E> findBy(@Nullable Columns<? extends E> columns, @Nonnull Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);
List<E> findBy(@Nullable Columns<? extends E> columns, @Nullable Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);


/**
Expand All @@ -275,7 +275,7 @@ public interface Mapper<E extends Entity> {
* @return 实体列表
*/
@Nonnull
List<E> findBy(@Nonnull Conditions<? extends E> conditions);
List<E> findBy(@Nullable Conditions<? extends E> conditions);

/**
* 根据条件获取实体列表
Expand All @@ -285,7 +285,7 @@ public interface Mapper<E extends Entity> {
* @return 实体列表
*/
@Nonnull
List<E> findBy(@Nullable Columns<? extends E> columns, @Nonnull Conditions<? extends E> conditions);
List<E> findBy(@Nullable Columns<? extends E> columns, @Nullable Conditions<? extends E> conditions);

/**
* 获取所有数据
Expand Down Expand Up @@ -324,7 +324,7 @@ public interface Mapper<E extends Entity> {
* @return 分页结果
*/
@Nonnull
Page<E> findPageBy(@Nonnull Long pageIndex, @Nonnull Long pageSize, @Nonnull Conditions<? extends E> conditions, @Nonnull Orders<? extends E> orders);
Page<E> findPageBy(@Nonnull Long pageIndex, @Nonnull Long pageSize, @Nullable Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);

/**
* 根据条件分页查询数据
Expand All @@ -337,7 +337,7 @@ public interface Mapper<E extends Entity> {
* @return 分页结果
*/
@Nonnull
Page<E> findPageBy(@Nonnull Long pageIndex, @Nonnull Long pageSize, @Nullable Columns<? extends E> columns, @Nonnull Conditions<? extends E> conditions, @Nonnull Orders<? extends E> orders);
Page<E> findPageBy(@Nonnull Long pageIndex, @Nonnull Long pageSize, @Nullable Columns<? extends E> columns, @Nullable Conditions<? extends E> conditions, @Nullable Orders<? extends E> orders);

/**
* 询查表的数据量
Expand Down

0 comments on commit a678e51

Please sign in to comment.