shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.walker.jdbc.generator.db;
 
import com.walker.jdbc.generator.util.StringUtils;
 
import java.util.Map;
 
/**
 * 数据库列定义。
 * @author 时克英
 * @date 2022-08-16
 */
public class Column {
    private String name;
    private String type;
    private String not_null;
    private Integer length;
    private Integer digits;
    private String comment;
 
    public Column(Map columnMap)
    {
        this.name = StringUtils.safeToString(columnMap.get("COLUMN_NAME"));
        this.type = getType(StringUtils.safeToString(columnMap.get("TYPE_NAME")), StringUtils.intValue(columnMap.get("COLUMN_SIZE")), StringUtils.intValue(columnMap.get("DECIMAL_DIGITS")));
        this.length = Integer.valueOf(StringUtils.intValue(columnMap.get("COLUMN_SIZE")));
        String isNullable = StringUtils.safeToString(columnMap.get("IS_NULLABLE"));
        this.comment = StringUtils.safeToString(columnMap.get("REMARKS"));
        this.digits = Integer.valueOf(StringUtils.intValue(columnMap.get("DECIMAL_DIGITS")));
        if (isNullable.equals("NO"))
            this.not_null = "true";
        else
            this.not_null = "";
    }
 
    public Integer getLength()
    {
        return this.length;
    }
 
    public String getName() {
        return this.name;
    }
 
    public String getNot_null() {
        return this.not_null;
    }
 
    public String getType() {
        return this.type;
    }
 
    private String getType(String type_name, int column_size, int decimal_digits) {
        if (type_name.contains("CHAR"))
            return "string";
        if (("NUMBER".equals(type_name)) || ("DECIMAL".equals(type_name))) {
            if (decimal_digits == 0) {
                if (column_size <= 8) {
                    return "int";
                }
                return "long";
            }
 
            if (column_size < 14) {
                return "double";
            }
            return "big_decimal";
        }
 
        if (("DATE".equals(type_name)) || ("DATETIME".equals(type_name)) || (type_name.startsWith("TIMESTAMP")))
            return "date";
        if ("INT".equals(type_name))
            return "int";
        if (("Long".equals(type_name)) || ("BIGINT".equals(type_name)))
            return "long";
        if ("FLOAT".equals(type_name))
            return "float";
        if ("SMALLINT".equals(type_name))
            return "int";
        if ("TINYINT".equals(type_name))
            return "byte";
        if ("DOUBLE".equals(type_name))
            return "double";
        if (("CLOB".equals(type_name)) || ("TEXT".equals(type_name)) || ("MEDIUMTEXT".equals(type_name)) || ("LONGTEXT".equals(type_name)))
            return "materialized_clob";
        if (type_name.contains("BLOB")) {
            return "materialized_blob";
        }
        throw new RuntimeException("类型 " + type_name + " 不支持! ");
    }
 
    public String getComment()
    {
        return this.comment;
    }
 
    public Integer getDigits() {
        return this.digits;
    }
 
    public void setDigits(Integer digits) {
        this.digits = digits;
    }
}