Skip to content

Commit

Permalink
Merge pull request #8 from ClearXs/1.1.x
Browse files Browse the repository at this point in the history
1.1.x
  • Loading branch information
ClearXs authored Feb 23, 2024
2 parents 7acf707 + 0b72ac1 commit 64e5fe2
Show file tree
Hide file tree
Showing 62 changed files with 338 additions and 138 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cc.allio</groupId>
<artifactId>uno</artifactId>
<packaging>pom</packaging>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
<description>构建大型应用需要的基本能力 --- all in one</description>
<url>https://github.com/b6688c/uno</url>

Expand Down
2 changes: 1 addition & 1 deletion uno-auto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>uno</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions uno-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cc.allio</groupId>
<artifactId>uno-bom</artifactId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
<packaging>pom</packaging>

<properties>
<!-- 统一版本管理 -->
<uno.version>1.1.6-beta.1</uno.version>
<uno.version>1.1.6</uno.version>
<!-- 序列化框架 -->
<protostuff.version>1.5.9</protostuff.version>
<!-- google SPI -->
Expand Down
2 changes: 1 addition & 1 deletion uno-components/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>uno</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion uno-components/uno-component-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>uno-components</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion uno-components/uno-component-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>uno-components</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion uno-components/uno-component-netty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>uno-components</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
</parent>

<artifactId>uno-component-netty</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion uno-components/uno-component-sequential/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>uno-components</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion uno-components/uno-component-websocket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>uno-components</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion uno-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>uno</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
23 changes: 23 additions & 0 deletions uno-core/src/main/java/cc/allio/uno/core/api/EqualsTo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package cc.allio.uno.core.api;

import java.util.Collection;
import java.util.Optional;

/**
* Java中接口类型不存在{@link Object#equals(Object)}方法,该接口的定义为了能够使得Java接口能够有类似的方法。
* <p>另外一个目的是提供显示的接口来实现{@code equals}方法,避免在调试环节不知道为何两个对象相等。</p>
Expand All @@ -17,4 +20,24 @@ public interface EqualsTo<T> {
* @return ture if equivalent
*/
boolean equalsTo(T other);

/**
* 判断给定的集合中是否包含该对象
*
* @param collection collection
* @return T
*/
default boolean in(Collection<T> collection) {
return collection.stream().anyMatch(this::equalsTo);
}

/**
* 判断当前对象是否在给定的collection,如果在则返回相等的对象
*
* @param collection collection
* @return optional T
*/
default Optional<T> filter(Collection<T> collection) {
return collection.stream().filter(this::equalsTo).findFirst();
}
}
4 changes: 2 additions & 2 deletions uno-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>uno</artifactId>
<groupId>cc.allio</groupId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
</parent>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>

<artifactId>uno-data</artifactId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
<description>
summary: uno数据层操作,包含于数据源、mybatis-plus、reactive-jpa、elasticsearch、influxdb等
features: 提供数据聚合等操作
Expand Down
2 changes: 1 addition & 1 deletion uno-data/uno-data-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cc.allio</groupId>
<artifactId>uno-data</artifactId>
<version>1.1.6-beta.1</version>
<version>1.1.6</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cc.allio.uno.data.orm.dsl;

import cc.allio.uno.core.api.EqualsTo;
import cc.allio.uno.core.env.Envs;
import cc.allio.uno.core.util.StringUtils;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.util.Objects;
import java.util.regex.Pattern;

/**
Expand All @@ -16,7 +18,7 @@
*/
@Getter
@EqualsAndHashCode(of = "name")
public class DSLName implements Comparable<DSLName> {
public class DSLName implements Comparable<DSLName>, EqualsTo<DSLName> {

// 当前存入的dsl name
private String name;
Expand All @@ -26,7 +28,7 @@ public class DSLName implements Comparable<DSLName> {
private static final String HUMP_REGULAR = "^[a-z]+(?:[A-Z][a-z]*)*$";
private static final Pattern HUMP_PATTERN = Pattern.compile(HUMP_REGULAR);

private static final String UNDERLINE_REGULAR = "^[a-zA-Z]+(?:_[a-zA-Z]+)*$";
private static final String UNDERLINE_REGULAR = "^[a-z]+(?:_[a-z]+)*$";
private static final Pattern UNDERLINE_PATTERN = Pattern.compile(UNDERLINE_REGULAR);

/**
Expand All @@ -50,6 +52,46 @@ public class DSLName implements Comparable<DSLName> {
public static final NameFeature LOWER_CASE_FEATURE = new LowerCaseFeature();
public static final NameFeature UPPER_CASE_FEATURE = new UpperCaseFeature();

private void setFeature(NameFeature... features) {
this.feature = new AggregateNameFeature(features);
}

/**
* 把当前存入的sql name进行格式化
*
* @return 格式化后的name
*/
public String format() {
return getFeature().format(getName());
}

/**
* 根据指定的名称特性
*
* @param feature the feature
* @return format the name
*/
public String format(NameFeature feature) {
if (feature == null) {
throw new IllegalArgumentException("NameFeature is null");
}
return feature.format(getName());
}

@Override
public int compareTo(DSLName o) {
return this.name.compareTo(o.name);
}

@Override
public boolean equalsTo(DSLName other) {
// 如果名称不匹配,则尝试使用format
if (!this.name.equals(other.name)) {
return format().equals(other.name);
}
return true;
}

/**
* 获取name feature
*
Expand Down Expand Up @@ -129,37 +171,6 @@ public static String toUnderline(String hump) {
return DSLName.of(hump, UNDERLINE_FEATURE).format();
}

private void setFeature(NameFeature... features) {
this.feature = new AggregateNameFeature(features);
}

/**
* 把当前存入的sql name进行格式化
*
* @return 格式化后的name
*/
public String format() {
return getFeature().format(getName());
}

/**
* 根据指定的名称特性
*
* @param feature the feature
* @return format the name
*/
public String format(NameFeature feature) {
if (feature == null) {
throw new IllegalArgumentException("NameFeature is null");
}
return feature.format(getName());
}

@Override
public int compareTo(DSLName o) {
return this.name.compareTo(o.name);
}

/**
* 名称特性
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cc.allio.uno.core.bean.MapWrapper;
import cc.allio.uno.core.bean.ObjectWrapper;
import cc.allio.uno.core.bean.ValueWrapper;
import cc.allio.uno.core.type.TypeOperatorFactory;
import cc.allio.uno.core.type.Types;
import cc.allio.uno.core.util.*;
import cc.allio.uno.core.util.template.ExpressionTemplate;
Expand Down Expand Up @@ -44,6 +45,12 @@
* <li>获取{@link ColumnDef}</li>
* <li>获取主键的{@link ColumnDef}</li>
* <li>基于{@link ColumnDef}获取对应的值</li>
* <li>增强所有get value方法,根据{@link ColumnDef#getDataType()}转换对应值类型</li>
* </ul>
* <p>注意:</p>
* <ul>
* <li>该类所有getXX方法的字段名称全是驼峰命名,除了{@link #getValueByColumn(String)}、{@link #getValueByColumn(ColumnDef)}</li>
* <li>所有setXX方法的字段名称全是驼峰命名</li>
* </ul>
*
* @author jiangwei
Expand Down Expand Up @@ -72,6 +79,7 @@ public class PojoWrapper<T> implements ValueWrapper {
// 非主键字段
@Getter
private List<ColumnDef> notPkColumns;
private Map<DSLName, ColumnDef> columnDefMap;

// 内置ValueWrapper做装饰作用
private final ValueWrapper valueWrapper;
Expand All @@ -96,12 +104,12 @@ public class PojoWrapper<T> implements ValueWrapper {
}

PojoWrapper(Class<?> pojoClass) {
init(pojoClass);
if (Types.isMap(pojoClass)) {
this.valueWrapper = new MapWrapper();
} else {
this.valueWrapper = new ObjectWrapper(pojoClass);
}
init(pojoClass);
}

void init(Class<?> pojoClass) {
Expand All @@ -112,6 +120,7 @@ void init(Class<?> pojoClass) {
this.pkColumn = columnDefs.stream().filter(ColumnDef::isPk).findFirst().orElse(null);
this.deletedColumn = columnDefs.stream().filter(ColumnDef::isDeleted).findFirst().orElse(null);
this.notPkColumns = columnDefs.stream().filter(columnDef -> !columnDef.isPk()).toList();
this.columnDefMap = columnDefs.stream().collect(Collectors.toMap(ColumnDef::getDslName, f -> f));
}

/**
Expand All @@ -129,7 +138,7 @@ public Object getPKValue() {
* @return the value
*/
public Object getValueByColumn(String column) {
return getForce(column);
return getForce(DSLName.of(column, DSLName.HUMP_FEATURE).format());
}

/**
Expand Down Expand Up @@ -363,7 +372,7 @@ public Collection<DSLName> getColumnDSLName() {
}

/**
* 获取columns values 集合
* 获取columns values 集合.
*
* @return Object
*/
Expand All @@ -385,7 +394,22 @@ public PropertyDescriptor find(String name, Class<?> clazz) {

@Override
public <K> Mono<K> get(String name, Class<K> fieldType) {
return valueWrapper.get(name, fieldType);
return valueWrapper.get(name, fieldType)
.flatMap(value -> {
DSLName dslName = DSLName.of(name, DSLName.UNDERLINE_FEATURE);
Optional<DSLName> filterDslName = dslName.filter(columnDefMap.keySet());
return Mono.justOrEmpty(filterDslName)
.flatMap(columnDslName -> {
ColumnDef columnDef = columnDefMap.get(columnDslName);
return Mono.justOrEmpty(Optional.ofNullable(columnDef))
.map(ColumnDef::getDataType)
.map(DataType::getDslType)
.mapNotNull(dslType -> TypeRegistry.getInstance().findJavaType(dslType.getJdbcType()))
.map(javaType -> TypeOperatorFactory.translator(javaType.getJavaType()).convert(value));
})
.cast(fieldType)
.defaultIfEmpty(value);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public boolean equalsTo(Class<?> otherJavaType) {
public boolean equals(Object o) {
return Objects.equals(this, o);
}

}
Loading

0 comments on commit 64e5fe2

Please sign in to comment.