parent
608341ae2e
commit
36d29de268
@ -1,69 +0,0 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.core.generator.strategy.sync.mysql.enums;
|
||||
|
||||
|
||||
|
||||
import org.opsli.core.generator.strategy.sync.mysql.entity.FieldTypeAttribute;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* MySQL 字段类型 判断
|
||||
*
|
||||
* @author parker
|
||||
* @date 2020-11-18 13:21
|
||||
*/
|
||||
public enum MySQLSyncColumnType {
|
||||
|
||||
/** 实例对象 */
|
||||
INSTANCE;
|
||||
|
||||
private static final Map<String, FieldTypeAttribute> FIELD_TYPE_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
FIELD_TYPE_MAP.put("tinyint", new FieldTypeAttribute(true, false));
|
||||
FIELD_TYPE_MAP.put("smallint", new FieldTypeAttribute(true, false));
|
||||
FIELD_TYPE_MAP.put("mediumint", new FieldTypeAttribute(true, false));
|
||||
FIELD_TYPE_MAP.put("int", new FieldTypeAttribute(true, false));
|
||||
FIELD_TYPE_MAP.put("integer", new FieldTypeAttribute(true, false));
|
||||
FIELD_TYPE_MAP.put("bigint", new FieldTypeAttribute(true, false));
|
||||
FIELD_TYPE_MAP.put("real", new FieldTypeAttribute(true, true));
|
||||
FIELD_TYPE_MAP.put("float", new FieldTypeAttribute(true, true));
|
||||
FIELD_TYPE_MAP.put("double", new FieldTypeAttribute(true, true));
|
||||
FIELD_TYPE_MAP.put("decimal", new FieldTypeAttribute(true, true));
|
||||
FIELD_TYPE_MAP.put("numeric", new FieldTypeAttribute(true, true));
|
||||
FIELD_TYPE_MAP.put("char", new FieldTypeAttribute(true, false));
|
||||
FIELD_TYPE_MAP.put("varchar", new FieldTypeAttribute(true, false));
|
||||
FIELD_TYPE_MAP.put("date", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("time", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("timestamp", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("datetime", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("blob", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("mediumblob", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("longblob", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("tinytext", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("text", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("mediumtext", new FieldTypeAttribute(false, false));
|
||||
FIELD_TYPE_MAP.put("longtext", new FieldTypeAttribute(false, false));
|
||||
}
|
||||
|
||||
public FieldTypeAttribute getAttr(String fieldType){
|
||||
return FIELD_TYPE_MAP.get(fieldType);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.plugins.generator.enums.TypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 将各数据库类型格式化成统一的类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2021年5月26日14:45:15
|
||||
*/
|
||||
public interface TypeFormatter {
|
||||
|
||||
/**
|
||||
* 转化格式
|
||||
* @param columnType 字段类型
|
||||
* @return String
|
||||
*/
|
||||
default TypeEnum format(String columnType) {
|
||||
if (isBit(columnType)) {
|
||||
return TypeEnum.BIT;
|
||||
}
|
||||
if (isBoolean(columnType)) {
|
||||
return TypeEnum.BOOLEAN;
|
||||
}
|
||||
if (isTinyint(columnType)) {
|
||||
return TypeEnum.TINYINT;
|
||||
}
|
||||
if (isSmallint(columnType)) {
|
||||
return TypeEnum.SMALLINT;
|
||||
}
|
||||
if (isInt(columnType)) {
|
||||
return TypeEnum.INT;
|
||||
}
|
||||
if (isLong(columnType)) {
|
||||
return TypeEnum.BIGINT;
|
||||
}
|
||||
if (isFloat(columnType)) {
|
||||
return TypeEnum.FLOAT;
|
||||
}
|
||||
if (isDouble(columnType)) {
|
||||
return TypeEnum.DOUBLE;
|
||||
}
|
||||
if (isDecimal(columnType)) {
|
||||
return TypeEnum.DECIMAL;
|
||||
}
|
||||
if(isJsonb(columnType)){
|
||||
return TypeEnum.JSONB;
|
||||
}
|
||||
if (isVarchar(columnType)) {
|
||||
return TypeEnum.VARCHAR;
|
||||
}
|
||||
if (isDatetime(columnType)) {
|
||||
return TypeEnum.DATETIME;
|
||||
}
|
||||
if (isBlob(columnType)) {
|
||||
return TypeEnum.BLOB;
|
||||
}
|
||||
|
||||
return TypeEnum.VARCHAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较 是否包含
|
||||
* @param columnTypes 类型集合
|
||||
* @param type 当前类型
|
||||
* @return boolean
|
||||
*/
|
||||
default boolean isContains(List<String> columnTypes, String type) {
|
||||
if(CollUtil.isEmpty(columnTypes)){
|
||||
return false;
|
||||
}
|
||||
for (String columnType : columnTypes) {
|
||||
if(StringUtils.equalsIgnoreCase(columnType, type)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否二进制
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isBit(String columnType);
|
||||
/**
|
||||
* 是否布尔类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isBoolean(String columnType);
|
||||
/**
|
||||
* 是否微小整数类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isTinyint(String columnType);
|
||||
/**
|
||||
* 是否小整数类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isSmallint(String columnType);
|
||||
/**
|
||||
* 是否整数类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isInt(String columnType);
|
||||
/**
|
||||
* 是否长整数类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isLong(String columnType);
|
||||
/**
|
||||
* 是否单浮点类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isFloat(String columnType);
|
||||
/**
|
||||
* 是否双浮点类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isDouble(String columnType);
|
||||
/**
|
||||
* 是否小数精度类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isDecimal(String columnType);
|
||||
/**
|
||||
* 是否字符串类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isVarchar(String columnType);
|
||||
/**
|
||||
* 是否时间类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isDatetime(String columnType);
|
||||
/**
|
||||
* 是否对象类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isBlob(String columnType);
|
||||
/**
|
||||
* 是否JSON类型
|
||||
* @param columnType 字段类型
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isJsonb(String columnType);
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.converter;
|
||||
|
||||
import org.opsli.plugins.generator.enums.TypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 将数据库类型转换成各语言对应的类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2021年5月26日14:22:31
|
||||
*/
|
||||
public interface ColumnTypeConverter {
|
||||
|
||||
/**
|
||||
* 将数据库类型转成基本类型
|
||||
* @param type 数据库类型
|
||||
* @return 基本类型
|
||||
*/
|
||||
String convertType(TypeEnum type);
|
||||
|
||||
/**
|
||||
* 将数据库类型转成基本类型 (会多返 一个String 兜底类型)
|
||||
* @param type 数据库类型
|
||||
* @return List 基本类型
|
||||
*/
|
||||
List<String> convertTypeBySafety(TypeEnum type);
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.converter;
|
||||
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.opsli.common.utils.ListDistinctUtil;
|
||||
import org.opsli.plugins.generator.enums.JavaType;
|
||||
import org.opsli.plugins.generator.enums.TypeEnum;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Java 字段类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2021年5月26日14:25:47
|
||||
*/
|
||||
public class JavaColumnTypeConverter implements ColumnTypeConverter {
|
||||
|
||||
private static final Map<TypeEnum, JavaType> TYPE_MAP = new HashMap<>(64);
|
||||
static {
|
||||
TYPE_MAP.put(TypeEnum.BIT, JavaType.BOOLEAN);
|
||||
TYPE_MAP.put(TypeEnum.BOOLEAN, JavaType.BOOLEAN);
|
||||
TYPE_MAP.put(TypeEnum.TINYINT, JavaType.BYTE);
|
||||
TYPE_MAP.put(TypeEnum.SMALLINT, JavaType.SHORT);
|
||||
TYPE_MAP.put(TypeEnum.INT, JavaType.INTEGER);
|
||||
TYPE_MAP.put(TypeEnum.BIGINT, JavaType.LONG);
|
||||
TYPE_MAP.put(TypeEnum.FLOAT, JavaType.FLOAT);
|
||||
TYPE_MAP.put(TypeEnum.DOUBLE, JavaType.DOUBLE);
|
||||
TYPE_MAP.put(TypeEnum.DECIMAL, JavaType.BIG_DECIMAL);
|
||||
TYPE_MAP.put(TypeEnum.VARCHAR, JavaType.STRING);
|
||||
TYPE_MAP.put(TypeEnum.DATETIME, JavaType.DATE);
|
||||
TYPE_MAP.put(TypeEnum.BLOB, JavaType.BYTE_ARRAY);
|
||||
TYPE_MAP.put(TypeEnum.JSONB, JavaType.MAP_OBJECT) ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertType(TypeEnum type) {
|
||||
return TYPE_MAP.getOrDefault(type, TYPE_MAP.get(TypeEnum.VARCHAR)).getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> convertTypeBySafety(TypeEnum type) {
|
||||
String currType = TYPE_MAP.getOrDefault(type, TYPE_MAP.get(TypeEnum.VARCHAR)).getType();
|
||||
String defType = TYPE_MAP.get(TypeEnum.VARCHAR).getType();
|
||||
List<String> typeList = Lists.newArrayListWithCapacity(2);
|
||||
typeList.add(currType);
|
||||
typeList.add(defType);
|
||||
return ListDistinctUtil.distinct(typeList);
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.database.mysql;
|
||||
|
||||
|
||||
import org.opsli.plugins.generator.TypeFormatter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* MySQL 字段格式化判断
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2021年5月26日14:51:50
|
||||
*/
|
||||
public class MySqlTypeFormatter implements TypeFormatter {
|
||||
|
||||
@Override
|
||||
public boolean isBit(String columnType) {
|
||||
return isContains(Collections.singletonList("bit"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String columnType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTinyint(String columnType) {
|
||||
return isContains(Collections.singletonList("tinyint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSmallint(String columnType) {
|
||||
return isContains(Collections.singletonList("smallint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInt(String columnType) {
|
||||
return !isLong(columnType) && isContains(Arrays.asList("int", "integer"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLong(String columnType) {
|
||||
return !isVarchar(columnType) && isContains(Collections.singletonList("bigint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFloat(String columnType) {
|
||||
return isContains(Collections.singletonList("float"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDouble(String columnType) {
|
||||
return isContains(Collections.singletonList("double"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDecimal(String columnType) {
|
||||
return isContains(Collections.singletonList("decimal"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVarchar(String columnType) {
|
||||
return isContains(Arrays.asList("CHAR", "VARCHAR", "TEXT"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDatetime(String columnType) {
|
||||
return isContains(Arrays.asList("DATE", "TIME", "DATETIME", "TIMESTAMP"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlob(String columnType) {
|
||||
return isContains(Collections.singletonList("blob"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonb(String columnType) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.database.oracle;
|
||||
|
||||
|
||||
import org.opsli.plugins.generator.TypeFormatter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Oracle 字段格式化判断
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2021年5月26日14:51:50
|
||||
*/
|
||||
public class OracleTypeFormatter implements TypeFormatter {
|
||||
|
||||
@Override
|
||||
public boolean isBit(String columnType) {
|
||||
return isContains(Collections.singletonList("bit"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String columnType) {
|
||||
return isContains(Collections.singletonList("boolean"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTinyint(String columnType) {
|
||||
return isContains(Collections.singletonList("tinyint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSmallint(String columnType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInt(String columnType) {
|
||||
return isContains(Arrays.asList("int", "integer"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLong(String columnType) {
|
||||
return !isVarchar(columnType) && isContains(Collections.singletonList("long"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFloat(String columnType) {
|
||||
return isContains(Collections.singletonList("float"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDouble(String columnType) {
|
||||
return isContains(Collections.singletonList("double"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDecimal(String columnType) {
|
||||
return isContains(Collections.singletonList("decimal"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVarchar(String columnType) {
|
||||
return isContains(Arrays.asList("CHAR", "VARCHAR", "VARCHAR2", "NVARCHAR2", "TEXT", "NCHAR"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDatetime(String columnType) {
|
||||
return isContains(Arrays.asList("DATE", "TIME", "DATETIME", "TIMESTAMP"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlob(String columnType) {
|
||||
return isContains(Collections.singletonList("blob"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonb(String columnType) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.database.postgresql;
|
||||
|
||||
|
||||
import org.opsli.plugins.generator.TypeFormatter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* PostgreSql 字段格式化判断
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2021年5月26日14:51:50
|
||||
*/
|
||||
public class PostgreSqlTypeFormatter implements TypeFormatter {
|
||||
|
||||
@Override
|
||||
public boolean isBit(String columnType) {
|
||||
return isContains(Collections.singletonList("bit"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String columnType) {
|
||||
return isContains(Collections.singletonList("boolean"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTinyint(String columnType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSmallint(String columnType) {
|
||||
return isContains(Arrays.asList("int2", "serial2", "smallint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInt(String columnType) {
|
||||
return isContains(Arrays.asList("int4", "serial4", "integer"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLong(String columnType) {
|
||||
return !isVarchar(columnType) && isContains(Arrays.asList("int8", "serial8", "bigint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFloat(String columnType) {
|
||||
return isContains(Arrays.asList("float", "real"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDouble(String columnType) {
|
||||
return isContains(Collections.singletonList("double"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDecimal(String columnType) {
|
||||
return isContains(Arrays.asList("decimal","numeric"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVarchar(String columnType) {
|
||||
return isContains(Arrays.asList("CHAR", "VARCHAR", "TEXT", "character", "json"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDatetime(String columnType) {
|
||||
return isContains(Arrays.asList("DATE", "TIME", "DATETIME", "TIMESTAMP"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlob(String columnType) {
|
||||
return isContains(Collections.singletonList("blob"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonb(String columnType) {
|
||||
return isContains(Collections.singletonList("jsonb"), columnType);
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.database.sqlserver;
|
||||
|
||||
|
||||
import org.opsli.plugins.generator.TypeFormatter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* SqlServer 字段格式化判断
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2021年5月26日14:51:50
|
||||
*/
|
||||
public class SqlServerTypeFormatter implements TypeFormatter {
|
||||
|
||||
@Override
|
||||
public boolean isBit(String columnType) {
|
||||
return isContains(Collections.singletonList("bit"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBoolean(String columnType) {
|
||||
return isContains(Collections.singletonList("boolean"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTinyint(String columnType) {
|
||||
return isContains(Collections.singletonList("tinyint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSmallint(String columnType) {
|
||||
return isContains(Collections.singletonList("smallint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInt(String columnType) {
|
||||
return !isLong(columnType) && isContains(Arrays.asList("int", "integer"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLong(String columnType) {
|
||||
return !isVarchar(columnType) && isContains(Collections.singletonList("bigint"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFloat(String columnType) {
|
||||
return isContains(Arrays.asList("float", "real"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDouble(String columnType) {
|
||||
return isContains(Collections.singletonList("double"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDecimal(String columnType) {
|
||||
return isContains(Arrays.asList("decimal", "numeric", "money", "smallmoney"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVarchar(String columnType) {
|
||||
return isContains(Arrays.asList("CHAR", "VARCHAR", "TEXT", "nchar", "nvarchar", "ntext"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDatetime(String columnType) {
|
||||
return isContains(Arrays.asList("DATE", "TIME", "DATETIME", "TIMESTAMP", "datetime2", "smalldatetime", "datetimeoffset"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlob(String columnType) {
|
||||
return isContains(Arrays.asList("blob", "binary", "varbinary"), columnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonb(String columnType) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,4 +1,19 @@
|
||||
package org.opsli.core.generator.enums;
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.enums;
|
||||
|
||||
/**
|
||||
* 数据库类型
|
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.enums;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opsli.common.utils.ListDistinctUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Java 类型
|
||||
*
|
||||
* @author Parker
|
||||
* @date 2021年5月26日16:31:08
|
||||
*/
|
||||
public enum JavaType {
|
||||
|
||||
/** 包装类型 */
|
||||
BYTE("Byte", null),
|
||||
SHORT("Short", null),
|
||||
CHARACTER("Character", null),
|
||||
INTEGER("Integer", null),
|
||||
LONG("Long", null),
|
||||
FLOAT("Float", null),
|
||||
DOUBLE("Double", null),
|
||||
BOOLEAN("Boolean", null),
|
||||
STRING("String", null),
|
||||
|
||||
/** Big类 */
|
||||
BIG_INTEGER("BigInteger", "java.math.BigInteger"),
|
||||
BIG_DECIMAL("BigDecimal", "java.math.BigDecimal"),
|
||||
|
||||
/** 时间类 */
|
||||
DATE("Date", "java.util.Date"),
|
||||
LOCAL_DATE("LocalDate", "java.time.LocalDate"),
|
||||
LOCAL_TIME("LocalTime", "java.time.LocalTime"),
|
||||
YEAR("Year", "java.time.Year"),
|
||||
YEAR_MONTH("YearMonth", "java.time.YearMonth"),
|
||||
LOCAL_DATE_TIME("LocalDateTime", "java.time.LocalDateTime"),
|
||||
INSTANT("Instant", "java.time.Instant"),
|
||||
|
||||
/** 其他 */
|
||||
BYTE_ARRAY("Byte[]",null),
|
||||
MAP_OBJECT("Map<String, Object>", "java.util.Map"),
|
||||
|
||||
;
|
||||
|
||||
/** 类型 */
|
||||
private final String type;
|
||||
/** 包路径 */
|
||||
private final String pkg;
|
||||
|
||||
JavaType(final String type, final String pkg) {
|
||||
this.type = type;
|
||||
this.pkg = pkg;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getPkg() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 包地址
|
||||
* @param typeList 类型集合
|
||||
* @return 包集合
|
||||
*/
|
||||
public static List<String> getPkgList(List<String> typeList) {
|
||||
if(typeList == null || typeList.size() == 0){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<String> pkgList = new ArrayList<>();
|
||||
JavaType[] types = values();
|
||||
for (JavaType javaType : types) {
|
||||
if(typeList.contains(javaType.type)){
|
||||
pkgList.add(javaType.pkg);
|
||||
}
|
||||
}
|
||||
pkgList.removeIf(StringUtils::isBlank);
|
||||
// 去重复
|
||||
return ListDistinctUtil.distinct(pkgList);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package org.opsli.plugins.generator.enums;
|
||||
|
||||
/**
|
||||
* 统一类型枚举
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
public enum TypeEnum {
|
||||
|
||||
/** 统一类型 */
|
||||
BIT("bit"),
|
||||
|
||||
BOOLEAN("boolean"),
|
||||
|
||||
TINYINT("tinyint"),
|
||||
|
||||
SMALLINT("smallint"),
|
||||
|
||||
INT("int"),
|
||||
|
||||
BIGINT("bigint"),
|
||||
|
||||
FLOAT("float"),
|
||||
|
||||
DOUBLE("double"),
|
||||
|
||||
DECIMAL("decimal"),
|
||||
|
||||
VARCHAR("varchar"),
|
||||
|
||||
DATETIME("datetime"),
|
||||
|
||||
BLOB("blob"),
|
||||
|
||||
JSONB("jsonb")
|
||||
|
||||
;
|
||||
|
||||
private final String type;
|
||||
|
||||
TypeEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static TypeEnum getType(String type) {
|
||||
TypeEnum[] types = values();
|
||||
for (TypeEnum typeEnum : types) {
|
||||
if (typeEnum.type.equalsIgnoreCase(type)) {
|
||||
return typeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue