Skip to content

Commit e200c02

Browse files
authored
Merge pull request #18 from ClearXs/1.1.x
feat: [uno-data] improve influxdb and add MetaAcceptor for dynamic ch…
2 parents a115227 + 3077cde commit e200c02

File tree

178 files changed

+6976
-1755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+6976
-1755
lines changed

uno-core/src/main/java/cc/allio/uno/core/type/Types.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ public static int signum(Object value) {
288288
* @return String
289289
*/
290290
public static String toString(Object value) {
291+
if (value == null) {
292+
return StringPool.EMPTY;
293+
}
291294
return Optional.ofNullable(TypeOperatorFactory.translator(value.getClass()))
292295
.map(operator -> operator.fromString(value))
293296
.orElse(value.toString());

uno-core/src/main/java/cc/allio/uno/core/util/DateUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,4 +869,12 @@ public static boolean isBetween(Date nowTime, Date startTime, Date endTime) {
869869
return nowDate.after(startDate) && nowTime.before(endTime);
870870
}
871871

872+
/**
873+
* get computer epoch time. it is 1970-01-01 08:00:00
874+
*
875+
* @return the epoch time
876+
*/
877+
public static Date getEpochTime() {
878+
return new Date(0);
879+
}
872880
}

uno-core/src/main/java/cc/allio/uno/core/util/Values.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import java.util.Arrays;
66
import java.util.Collection;
7+
import java.util.function.Consumer;
8+
import java.util.function.Supplier;
79
import java.util.stream.Stream;
810

911
/**
@@ -81,4 +83,17 @@ public static <V> Stream<V> streamExpand(V... values) {
8183
return Stream.of(v);
8284
});
8385
}
86+
87+
88+
/**
89+
* functional mapping getter to setter
90+
* <p>for example: {@code mapping(User::getName, User::setName)}</p>
91+
*
92+
* @param getter the getter function object
93+
* @param setter the setter function object
94+
* @param <T> the value type
95+
*/
96+
public static <T> void mapping(Supplier<T> getter, Consumer<T> setter) {
97+
setter.accept(getter.get());
98+
}
8499
}

uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ColumnDef.java

Lines changed: 210 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
package cc.allio.uno.data.orm.dsl;
22

33
import cc.allio.uno.core.api.EqualsTo;
4+
import cc.allio.uno.core.api.Self;
45
import cc.allio.uno.core.type.TypeOperatorFactory;
56
import cc.allio.uno.data.orm.dsl.type.DataType;
6-
import lombok.Builder;
7-
import lombok.Data;
8-
import lombok.EqualsAndHashCode;
7+
import cc.allio.uno.data.orm.dsl.type.JavaType;
8+
import cc.allio.uno.data.orm.dsl.type.TypeRegistry;
9+
import lombok.*;
910

1011
import java.util.Objects;
1112
import java.util.Optional;
1213

1314
/**
14-
* SQL字段定义
15+
* DSL字段定义
1516
*
1617
* @author j.x
1718
* @date 2023/4/12 19:35
19+
* @see ColumnDefBuilder
1820
* @since 1.1.4
1921
*/
2022
@Data
21-
@Builder
2223
@EqualsAndHashCode(of = {"dslName", "dataType"})
23-
public class ColumnDef implements EqualsTo<ColumnDef> {
24+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
25+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
26+
public class ColumnDef implements EqualsTo<ColumnDef>, Meta<ColumnDef> {
2427

2528
// 字段名称
2629
private DSLName dslName;
2730
// 字段注释
2831
private String comment;
2932
// 数据类型
30-
private cc.allio.uno.data.orm.dsl.type.DataType dataType;
33+
private DataType dataType;
3134
// 默认值
3235
private Object defaultValue;
3336
// 是否为主键
@@ -47,12 +50,6 @@ public class ColumnDef implements EqualsTo<ColumnDef> {
4750
// 已删除值
4851
private Object deleted;
4952

50-
@Override
51-
public boolean equalsTo(ColumnDef other) {
52-
return Objects.equals(this.getDslName(), other.getDslName())
53-
&& dataType.equalsTo(other.getDataType());
54-
}
55-
5653
/**
5754
* 给定字段值按照当前{@link cc.allio.uno.data.orm.dsl.type.DataType}进行转换
5855
*
@@ -64,11 +61,210 @@ public Object castValue(Object ori) {
6461
.map(DataType::getDslType)
6562
.flatMap(dslType -> {
6663
int jdbcType = dslType.getJdbcType();
67-
cc.allio.uno.data.orm.dsl.type.JavaType<?> javaType = cc.allio.uno.data.orm.dsl.type.TypeRegistry.getInstance().findJavaType(jdbcType);
64+
JavaType<?> javaType = TypeRegistry.getInstance().findJavaType(jdbcType);
6865
return Optional.ofNullable(javaType);
6966
})
7067
.map(j -> TypeOperatorFactory.translator(j.getJavaType()))
7168
.map(typeOperator -> typeOperator.convert(ori))
7269
.orElse(null);
7370
}
71+
72+
73+
@Override
74+
public boolean equalsTo(ColumnDef other) {
75+
return Objects.equals(this.getDslName(), other.getDslName())
76+
&& dataType.equalsTo(other.getDataType());
77+
}
78+
79+
/**
80+
* get {@link ColumnDefBuilder} builder
81+
*
82+
* @return the {@link ColumnDefBuilder} instance
83+
*/
84+
public static ColumnDefBuilder builder() {
85+
return new ColumnDefBuilder();
86+
}
87+
88+
/**
89+
* {@link ColumnDef} builder
90+
*/
91+
public static class ColumnDefBuilder implements Self<ColumnDefBuilder> {
92+
// 字段名称
93+
private DSLName dslName;
94+
// 字段注释
95+
private String comment;
96+
// 数据类型
97+
private DataType dataType;
98+
// 默认值
99+
private Object defaultValue;
100+
// 是否为主键
101+
private boolean isPk;
102+
// 是否为外键
103+
private boolean isFk;
104+
// 是否不为null
105+
private boolean isNonNull;
106+
// 是否为null
107+
private boolean isNull;
108+
// 是否唯一
109+
private boolean isUnique;
110+
// 是否是删除标识字段
111+
private boolean isDeleted;
112+
// 未删除值
113+
private Object undeleted;
114+
// 已删除值
115+
private Object deleted;
116+
117+
/**
118+
* build column name
119+
*
120+
* @param dslName the dsl name
121+
* @return {@link ColumnDefBuilder}
122+
*/
123+
public ColumnDefBuilder dslName(DSLName dslName) {
124+
this.dslName = dslName;
125+
return self();
126+
}
127+
128+
/**
129+
* build column comment
130+
*
131+
* @param comment the comment
132+
* @return {@link ColumnDefBuilder}
133+
*/
134+
public ColumnDefBuilder comment(String comment) {
135+
this.comment = comment;
136+
return self();
137+
}
138+
139+
/**
140+
* build column data type
141+
*
142+
* @param dataType the data type
143+
* @return {@link ColumnDefBuilder}
144+
*/
145+
public ColumnDefBuilder dataType(DataType dataType) {
146+
this.dataType = dataType;
147+
return self();
148+
}
149+
150+
/**
151+
* build column default value
152+
*
153+
* @param defaultValue the default value
154+
* @return {@link ColumnDefBuilder}
155+
*/
156+
public ColumnDefBuilder defaultValue(Object defaultValue) {
157+
this.defaultValue = defaultValue;
158+
return self();
159+
}
160+
161+
/**
162+
* build column is pk
163+
*
164+
* @param isPk the is pk
165+
* @return {@link ColumnDefBuilder}
166+
*/
167+
public ColumnDefBuilder isPk(Boolean isPk) {
168+
this.isPk = isPk;
169+
return self();
170+
}
171+
172+
/**
173+
* build column is fk
174+
*
175+
* @param isFk the is fk
176+
* @return {@link ColumnDefBuilder}
177+
*/
178+
public ColumnDefBuilder isFk(Boolean isFk) {
179+
this.isFk = isFk;
180+
return self();
181+
}
182+
183+
/**
184+
* build column is non null
185+
*
186+
* @param isNonNull the is non null
187+
* @return {@link ColumnDefBuilder}
188+
*/
189+
public ColumnDefBuilder isNonNull(Boolean isNonNull) {
190+
this.isNonNull = isNonNull;
191+
return self();
192+
}
193+
194+
/**
195+
* build column is null
196+
*
197+
* @param isNull the is null
198+
* @return {@link ColumnDefBuilder}
199+
*/
200+
public ColumnDefBuilder isNull(Boolean isNull) {
201+
this.isNull = isNull;
202+
return self();
203+
}
204+
205+
/**
206+
* build column is unique
207+
*
208+
* @param isUnique the is unique
209+
* @return {@link ColumnDefBuilder}
210+
*/
211+
public ColumnDefBuilder isUnique(Boolean isUnique) {
212+
this.isUnique = isUnique;
213+
return self();
214+
}
215+
216+
/**
217+
* build column is deleted
218+
*
219+
* @param isDeleted the is deleted
220+
* @return {@link ColumnDefBuilder}
221+
*/
222+
public ColumnDefBuilder isDeleted(Boolean isDeleted) {
223+
this.isDeleted = isDeleted;
224+
return self();
225+
}
226+
227+
/**
228+
* build undeleted
229+
*
230+
* @param undeleted the undeleted
231+
* @return {@link ColumnDefBuilder}
232+
*/
233+
public ColumnDefBuilder undeleted(Object undeleted) {
234+
this.undeleted = undeleted;
235+
return self();
236+
}
237+
238+
/**
239+
* build deleted
240+
*
241+
* @param deleted the deleted
242+
* @return {@link ColumnDefBuilder}
243+
*/
244+
public ColumnDefBuilder deleted(Object deleted) {
245+
this.deleted = deleted;
246+
return self();
247+
}
248+
249+
/**
250+
* build {@link ColumnDef}
251+
*
252+
* @return {@link ColumnDef}
253+
*/
254+
public ColumnDef build() {
255+
return new ColumnDef(
256+
dslName,
257+
comment,
258+
dataType,
259+
defaultValue,
260+
isPk,
261+
isFk,
262+
isNonNull,
263+
isNull,
264+
isUnique,
265+
isDeleted,
266+
undeleted,
267+
deleted);
268+
}
269+
}
74270
}

0 commit comments

Comments
 (0)