Skip to content

Commit

Permalink
feat: [uno-data] improve influxdb and add MetaAcceptor for dynamic ch…
Browse files Browse the repository at this point in the history
…ange to Meta (like Table ColumnDef...) data. [uno-test] add prelude help in test-container lifecycle add extra code.
  • Loading branch information
ClearXs committed Apr 21, 2024
1 parent 97093a0 commit 3077cde
Show file tree
Hide file tree
Showing 178 changed files with 6,976 additions and 1,755 deletions.
3 changes: 3 additions & 0 deletions uno-core/src/main/java/cc/allio/uno/core/type/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ public static int signum(Object value) {
* @return String
*/
public static String toString(Object value) {
if (value == null) {
return StringPool.EMPTY;
}
return Optional.ofNullable(TypeOperatorFactory.translator(value.getClass()))
.map(operator -> operator.fromString(value))
.orElse(value.toString());
Expand Down
8 changes: 8 additions & 0 deletions uno-core/src/main/java/cc/allio/uno/core/util/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -869,4 +869,12 @@ public static boolean isBetween(Date nowTime, Date startTime, Date endTime) {
return nowDate.after(startDate) && nowTime.before(endTime);
}

/**
* get computer epoch time. it is 1970-01-01 08:00:00
*
* @return the epoch time
*/
public static Date getEpochTime() {
return new Date(0);
}
}
15 changes: 15 additions & 0 deletions uno-core/src/main/java/cc/allio/uno/core/util/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -81,4 +83,17 @@ public static <V> Stream<V> streamExpand(V... values) {
return Stream.of(v);
});
}


/**
* functional mapping getter to setter
* <p>for example: {@code mapping(User::getName, User::setName)}</p>
*
* @param getter the getter function object
* @param setter the setter function object
* @param <T> the value type
*/
public static <T> void mapping(Supplier<T> getter, Consumer<T> setter) {
setter.accept(getter.get());
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
package cc.allio.uno.data.orm.dsl;

import cc.allio.uno.core.api.EqualsTo;
import cc.allio.uno.core.api.Self;
import cc.allio.uno.core.type.TypeOperatorFactory;
import cc.allio.uno.data.orm.dsl.type.DataType;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import cc.allio.uno.data.orm.dsl.type.JavaType;
import cc.allio.uno.data.orm.dsl.type.TypeRegistry;
import lombok.*;

import java.util.Objects;
import java.util.Optional;

/**
* SQL字段定义
* DSL字段定义
*
* @author j.x
* @date 2023/4/12 19:35
* @see ColumnDefBuilder
* @since 1.1.4
*/
@Data
@Builder
@EqualsAndHashCode(of = {"dslName", "dataType"})
public class ColumnDef implements EqualsTo<ColumnDef> {
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ColumnDef implements EqualsTo<ColumnDef>, Meta<ColumnDef> {

// 字段名称
private DSLName dslName;
// 字段注释
private String comment;
// 数据类型
private cc.allio.uno.data.orm.dsl.type.DataType dataType;
private DataType dataType;
// 默认值
private Object defaultValue;
// 是否为主键
Expand All @@ -47,12 +50,6 @@ public class ColumnDef implements EqualsTo<ColumnDef> {
// 已删除值
private Object deleted;

@Override
public boolean equalsTo(ColumnDef other) {
return Objects.equals(this.getDslName(), other.getDslName())
&& dataType.equalsTo(other.getDataType());
}

/**
* 给定字段值按照当前{@link cc.allio.uno.data.orm.dsl.type.DataType}进行转换
*
Expand All @@ -64,11 +61,210 @@ public Object castValue(Object ori) {
.map(DataType::getDslType)
.flatMap(dslType -> {
int jdbcType = dslType.getJdbcType();
cc.allio.uno.data.orm.dsl.type.JavaType<?> javaType = cc.allio.uno.data.orm.dsl.type.TypeRegistry.getInstance().findJavaType(jdbcType);
JavaType<?> javaType = TypeRegistry.getInstance().findJavaType(jdbcType);
return Optional.ofNullable(javaType);
})
.map(j -> TypeOperatorFactory.translator(j.getJavaType()))
.map(typeOperator -> typeOperator.convert(ori))
.orElse(null);
}


@Override
public boolean equalsTo(ColumnDef other) {
return Objects.equals(this.getDslName(), other.getDslName())
&& dataType.equalsTo(other.getDataType());
}

/**
* get {@link ColumnDefBuilder} builder
*
* @return the {@link ColumnDefBuilder} instance
*/
public static ColumnDefBuilder builder() {
return new ColumnDefBuilder();
}

/**
* {@link ColumnDef} builder
*/
public static class ColumnDefBuilder implements Self<ColumnDefBuilder> {
// 字段名称
private DSLName dslName;
// 字段注释
private String comment;
// 数据类型
private DataType dataType;
// 默认值
private Object defaultValue;
// 是否为主键
private boolean isPk;
// 是否为外键
private boolean isFk;
// 是否不为null
private boolean isNonNull;
// 是否为null
private boolean isNull;
// 是否唯一
private boolean isUnique;
// 是否是删除标识字段
private boolean isDeleted;
// 未删除值
private Object undeleted;
// 已删除值
private Object deleted;

/**
* build column name
*
* @param dslName the dsl name
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder dslName(DSLName dslName) {
this.dslName = dslName;
return self();
}

/**
* build column comment
*
* @param comment the comment
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder comment(String comment) {
this.comment = comment;
return self();
}

/**
* build column data type
*
* @param dataType the data type
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder dataType(DataType dataType) {
this.dataType = dataType;
return self();
}

/**
* build column default value
*
* @param defaultValue the default value
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder defaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
return self();
}

/**
* build column is pk
*
* @param isPk the is pk
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder isPk(Boolean isPk) {
this.isPk = isPk;
return self();
}

/**
* build column is fk
*
* @param isFk the is fk
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder isFk(Boolean isFk) {
this.isFk = isFk;
return self();
}

/**
* build column is non null
*
* @param isNonNull the is non null
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder isNonNull(Boolean isNonNull) {
this.isNonNull = isNonNull;
return self();
}

/**
* build column is null
*
* @param isNull the is null
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder isNull(Boolean isNull) {
this.isNull = isNull;
return self();
}

/**
* build column is unique
*
* @param isUnique the is unique
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder isUnique(Boolean isUnique) {
this.isUnique = isUnique;
return self();
}

/**
* build column is deleted
*
* @param isDeleted the is deleted
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder isDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
return self();
}

/**
* build undeleted
*
* @param undeleted the undeleted
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder undeleted(Object undeleted) {
this.undeleted = undeleted;
return self();
}

/**
* build deleted
*
* @param deleted the deleted
* @return {@link ColumnDefBuilder}
*/
public ColumnDefBuilder deleted(Object deleted) {
this.deleted = deleted;
return self();
}

/**
* build {@link ColumnDef}
*
* @return {@link ColumnDef}
*/
public ColumnDef build() {
return new ColumnDef(
dslName,
comment,
dataType,
defaultValue,
isPk,
isFk,
isNonNull,
isNull,
isUnique,
isDeleted,
undeleted,
deleted);
}
}
}
Loading

0 comments on commit 3077cde

Please sign in to comment.