Skip to content

Commit

Permalink
Merge pull request #25 from ClearXs/1.1.x
Browse files Browse the repository at this point in the history
fix[data]: verification postgresql and solve type problem and fix DbC…
  • Loading branch information
ClearXs authored Jul 21, 2024
2 parents a2a72d2 + 128f502 commit c9996a4
Show file tree
Hide file tree
Showing 36 changed files with 489 additions and 123 deletions.
4 changes: 2 additions & 2 deletions uno-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<druid.version>1.2.20</druid.version>
<mysql-connector.version>8.0.22</mysql-connector.version>
<oracle-connector.version>12.2.0.1</oracle-connector.version>
<postgresql-connector.version>42.2.22</postgresql-connector.version>
<postgresql-connector.version>42.7.3</postgresql-connector.version>
<sqlserver-connector.version>8.4.1.jre8</sqlserver-connector.version>
<mybatis-plus-dynamic.version>4.3.0</mybatis-plus-dynamic.version>
<!-- 空间数据处理 -->
Expand Down Expand Up @@ -417,4 +417,4 @@
<url>https://packages.aliyun.com/maven/repository/2300285-snapshot-JAW5GT/</url>
</snapshotRepository>
</distributionManagement>
</project>
</project>
7 changes: 3 additions & 4 deletions uno-core/src/main/java/cc/allio/uno/core/api/Single.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cc.allio.uno.core.api;

import cc.allio.uno.core.exception.Exceptions;
import cc.allio.uno.core.util.CollectionUtils;

import java.util.List;
import java.util.Map;
Expand All @@ -28,7 +27,7 @@ public interface Single<E> {
* @return the {@link Single} instance
*/
static <E> Single<E> from(List<E> list) {
if (CollectionUtils.isEmpty(list)) {
if (list == null) {
throw Exceptions.unNull("list");
}
return new InternalSingle<>(list.stream());
Expand All @@ -41,7 +40,7 @@ static <E> Single<E> from(List<E> list) {
* @return the {@link Single} instance
*/
static <E> Single<E> from(Set<E> set) {
if (CollectionUtils.isEmpty(set)) {
if (set == null) {
throw Exceptions.unNull("set");
}
return new InternalSingle<>(set.stream());
Expand All @@ -54,7 +53,7 @@ static <E> Single<E> from(Set<E> set) {
* @return the {@link Single} instance
*/
static <E, K, V> Single<E> from(Map<K, V> map) {
if (CollectionUtils.isEmpty(map)) {
if (map == null) {
throw Exceptions.unNull("map");
}
return (Single<E>) new InternalSingle<>(map.entrySet().stream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ public <T extends RuntimeException> T findUncheckedException(Class<T> errType) {
return (T) unchecked.get(errType);
}
var err = Single.from(unchecked.entrySet())
.forReturn(errEntry -> errEntry.getKey().isAssignableFrom(errType))
.forReturn(errEntry -> errType.isAssignableFrom(errEntry.getKey()))
.map(Map.Entry::getValue)
.orElse(null);

return (T) err;
}

Expand All @@ -62,7 +63,7 @@ public <T extends Throwable> T findCheckedException(Class<T> errType) {
return (T) checked.get(errType);
}
var err = Single.from(checked.entrySet())
.forReturn(errEntry -> errEntry.getKey().isAssignableFrom(errType))
.forReturn(errEntry -> errType.isAssignableFrom(errEntry.getKey()))
.map(Map.Entry::getValue)
.orElse(null);

Expand Down
2 changes: 2 additions & 0 deletions uno-core/src/main/java/cc/allio/uno/core/util/JsonUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cc.allio.uno.core.util;

import cc.allio.uno.core.exception.Exceptions;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.json.JsonReadFeature;
Expand Down Expand Up @@ -445,6 +446,7 @@ public static ObjectMapper newJsonMapper() {
// 失败处理
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
// 反序列化时,属性不存在的兼容处理s
mapper.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
// 单引号处理
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.Getter;
import lombok.Setter;

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

/**
Expand Down Expand Up @@ -47,12 +46,15 @@ public class DSLName implements Comparable<DSLName>, EqualsTo<DSLName>, Meta<DSL
private static final String NAME_FORM_LOWER_CASE = "lower-case";
// 名称以大写
private static final String NAME_FORM_UPPER_CASE = "upper-case";
// first upper case of name
private static final String FIRST_CHAR_UPPER_CASE = "first-upper-case";

public static final NameFeature UNDERLINE_FEATURE = new UnderlineFeature();
public static final NameFeature HUMP_FEATURE = new HumpFeature();
public static final NameFeature PLAIN_FEATURE = new PlainFeature();
public static final NameFeature LOWER_CASE_FEATURE = new LowerCaseFeature();
public static final NameFeature UPPER_CASE_FEATURE = new UpperCaseFeature();
public static final NameFeature FIRST_CHAR_UPPER_CASE_FEATURE = new FirstCharUpperCaseFeature();

public DSLName() {

Expand Down Expand Up @@ -91,7 +93,7 @@ public String format() {
* @return underline string
* @see #UNDERLINE_FEATURE
*/
public String formatUnderlie() {
public String formatUnderline() {
return format(UNDERLINE_FEATURE);
}

Expand Down Expand Up @@ -125,6 +127,16 @@ public String formatUpperCase() {
return format(UPPER_CASE_FEATURE);
}

/**
* format dsl name to first upper case
*
* @return first upper case name string
* @see #FIRST_CHAR_UPPER_CASE_FEATURE
*/
public String formatFirstNameUpperCase() {
return format(FIRST_CHAR_UPPER_CASE_FEATURE);
}

/**
* 根据指定的名称特性
*
Expand Down Expand Up @@ -163,11 +175,11 @@ public static DSLName of(String name) {
}

/**
* 创建SQLName 实例
* 创建{@link DSLName} 实例
*
* @param name name
* @param feature feature
* @return SQLName
* @return {@link DSLName}
*/
public static DSLName of(String name, NameFeature feature) {
DSLName sqlName = new DSLName();
Expand All @@ -177,15 +189,28 @@ public static DSLName of(String name, NameFeature feature) {
}

/**
* 创建SQLName 实例
* 创建{@link DSLName} 实例
*
* @param name name
* @param feature feature
* @return {@link DSLName}
*/
public static DSLName of(String name, NameFeature... feature) {
DSLName newName = new DSLName(name);
newName.setFeature(feature);
return newName;
}

/**
* 创建{@link DSLName} 实例
*
* @param sqlName sqlName
* @param dslName sqlName
* @param feature feature
* @return SQLName
* @return {@link DSLName}
*/
public static DSLName of(DSLName sqlName, NameFeature... feature) {
public static DSLName of(DSLName dslName, NameFeature... feature) {
DSLName newName = new DSLName();
newName.name = sqlName.name;
newName.name = dslName.name;
newName.setFeature(feature);
return newName;
}
Expand Down Expand Up @@ -323,4 +348,15 @@ public String format(String o) {
return o.toUpperCase();
}
}

static class FirstCharUpperCaseFeature implements NameFeature {

@Override
public String format(String o) {
if (StringUtils.isBlank(o) || o.length() < 2) {
return o;
}
return o.substring(0, 1).toUpperCase() + o.substring(1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface ShowColumnsOperator<T extends ShowColumnsOperator<T>> extends P
String TABLE_SCHEMA_FILED = "TABLE_SCHEMA";
String TABLE_NAME_FILED = "TABLE_NAME";
String COLUMN_NAME_FIELD = "COLUMN_NAME";
String COLUMN_COMMENT_FIELD = "COLUMN_COMMENT";
String ORDINAL_POSITION_FIELD = "ORDINAL_POSITION";
String COLUMN_DEFAULT_FIELD = "COLUMN_DEFAULT";
String IS_NULLABLE_FIELD = "IS_NULLABLE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface ShowTablesOperator<T extends ShowTablesOperator<T>> extends Tab
String TABLE_SCHEMA_FILED = "TABLE_SCHEMA";
String TABLE_NAME_FILED = "TABLE_NAME";
String TABLE_TYPE_FILED = "TABLE_TYPE";
String TABLE_COMMENT_FILED = "TABLE_COMMENT";

/**
* 转换为{@link QueryOperator}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@
* @since 1.1.4
*/
public class BooleanJavaType extends JavaTypeImpl<Boolean> {

@Override
public Class<Boolean> getJavaType() {
return Types.BOOLEAN;
}

@Override
public boolean equalsTo(Class<?> otherJavaType) {
return Boolean.class.isAssignableFrom(otherJavaType)
|| boolean.class.isAssignableFrom(otherJavaType);
if (otherJavaType == null) {
return false;
}
if (otherJavaType.isPrimitive()) {
return boolean.class.isAssignableFrom(otherJavaType);
}
return Boolean.class.isAssignableFrom(otherJavaType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@
* @since 1.1.4
*/
public class ByteJavaType extends JavaTypeImpl<Byte> {

@Override
public Class<Byte> getJavaType() {
return Types.BYTE;
}

@Override
public boolean equalsTo(Class<?> otherJavaType) {
return Byte.class.isAssignableFrom(otherJavaType)
|| byte.class.isAssignableFrom(otherJavaType);
if (otherJavaType == null) {
return false;
}
if (otherJavaType.isPrimitive()) {
return byte.class.isAssignableFrom(otherJavaType);
}
return Byte.class.isAssignableFrom(otherJavaType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface DSLType extends EqualsTo<DSLType> {

DSLType BIGINT = DefaultDSLType.BIGINT;
DSLType SMALLINT = DefaultDSLType.SMALLINT;
DSLType INT = DefaultDSLType.INT;
DSLType INTEGER = DefaultDSLType.INTEGER;
DSLType BIT = DefaultDSLType.BIT;
DSLType TINYINT = DefaultDSLType.TINYINT;
Expand All @@ -44,6 +45,9 @@ public interface DSLType extends EqualsTo<DSLType> {
DSLType VARBINARY = DefaultDSLType.VARBINARY;
DSLType LONGVARBINARY = DefaultDSLType.LONGVARBINARY;

// ====================== 其他类型 ======================
DSLType BOOLEAN = DefaultDSLType.BOOLEAN;

// ====================== 高级类型 ======================
DSLType OBJECT = DefaultDSLType.OBJECT;
DSLType ARRAY = DefaultDSLType.ARRAY;
Expand Down Expand Up @@ -102,7 +106,7 @@ static DSLType getByJdbcCode(int jdbcCode) {
*/
@Override
default boolean equalsTo(DSLType other) {
return java.util.Objects.equals(this.getName(), other.getName());
return other != null && this.getJdbcType() == other.getJdbcType();
}

/**
Expand Down Expand Up @@ -167,7 +171,8 @@ enum DefaultDSLType implements DSLType {
// ====================== 数字型 ======================
BIGINT("bigint", Types.BIGINT, 64, null),
SMALLINT("smallint", Types.SMALLINT, 32, null),
INTEGER("int", Types.INTEGER, 64, null),
INT("int", Types.INTEGER, 64, null),
INTEGER("integer", Types.INTEGER, 64, null),
BIT("bit", Types.BIT, 4, null),
TINYINT("tinyint", Types.TINYINT, 16, null),
NUMBER("number", Types.NUMERIC, 12, 2),
Expand All @@ -190,6 +195,9 @@ enum DefaultDSLType implements DSLType {
VARBINARY("varbinary", Types.VARBINARY, 1024, null),
LONGVARBINARY("longvarchar", Types.LONGVARBINARY, 2048, null),

// ====================== 其他类型 ======================
BOOLEAN("char", Types.BOOLEAN, 0, null),

// ====================== 高级类型 ======================
OBJECT("object", Types.JAVA_OBJECT, null, null),
ARRAY("array", Types.ARRAY, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @since 1.1.4
*/
public class EnumJavaType extends JavaTypeImpl<Enum> {

@Override
public Class<Enum> getJavaType() {
return Enum.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public Class<Float> getJavaType() {

@Override
public boolean equalsTo(Class<?> otherJavaType) {
return Float.class.isAssignableFrom(otherJavaType)
|| float.class.isAssignableFrom(otherJavaType);
if (otherJavaType == null) {
return false;
}
if (otherJavaType.isPrimitive()) {
return float.class.isAssignableFrom(otherJavaType);
}
return Float.class.isAssignableFrom(otherJavaType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public Class<Integer> getJavaType() {

@Override
public boolean equalsTo(Class<?> otherJavaType) {
return Integer.class.isAssignableFrom(otherJavaType)
|| int.class.isAssignableFrom(otherJavaType);
if (otherJavaType == null) {
return false;
}
if (otherJavaType.isPrimitive()) {
return int.class.isAssignableFrom(otherJavaType);
}
return Integer.class.isAssignableFrom(otherJavaType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public Class<Long> getJavaType() {

@Override
public boolean equalsTo(Class<?> otherJavaType) {
return Long.class.isAssignableFrom(otherJavaType)
|| long.class.isAssignableFrom(otherJavaType);
if (otherJavaType == null) {
return false;
}
if (otherJavaType.isPrimitive()) {
return long.class.isAssignableFrom(otherJavaType);
}
return Long.class.isAssignableFrom(otherJavaType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public Class<Short> getJavaType() {

@Override
public boolean equalsTo(Class<?> otherJavaType) {
return Short.class.isAssignableFrom(otherJavaType)
|| short.class.isAssignableFrom(otherJavaType);
if (otherJavaType == null) {
return false;
}
if (otherJavaType.isPrimitive()) {
return short.class.isAssignableFrom(otherJavaType);
}
return Short.class.isAssignableFrom(otherJavaType);
}
}
Loading

0 comments on commit c9996a4

Please sign in to comment.