ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.vci.client.omd.linktype.util;
 
import java.util.ArrayList;
 
import com.vci.corba.omd.atm.AttribItem;
/**
* 提供一些常用的功能
* @author Administrator
*
*/
public class Tool {
    private static Tool tool = null;
    private Tool(){
        
    }
    public static Tool getInstance(){
        if(tool == null){
            tool = new Tool();
        }
        return tool;
    }
 
    /**
     * 获取属性字段的sql语句
     * @param array
     * @return
     */
    public ArrayList<String> convertArrayToList(String[] array){
        ArrayList<String> list = new ArrayList<String>();
        for(int i = 0; i < array.length; i++){
            list.add(array[i]);
        }
        return list;
    }
    
    public String getAbSql(AttribItem abItem){
        String sql = "";
        if(abItem == null){
            return sql;
        }
        String abName = abItem.name;
        String vtType = abItem.vtDataType;
        String other = abItem.other;
        String defValue = abItem.defValue;
        
        if(vtType.equals("VTString")){
            int length = 50;
            String lengthStr = getOtherValueByType(other, "length");
            if(lengthStr != null && !lengthStr.equals("")){
                length = Integer.valueOf(lengthStr);
            }
            sql += abName.toUpperCase() + " VARCHAR2(" + length + ")";
            if(!defValue.equals("")){
                sql += " default '" + defValue + "'";
            }
            sql += ",\n\t";
        }else if(vtType.equals("VTInteger")){
            sql += abName.toUpperCase() + " NUMBER";
            if(!defValue.equals("")){
                sql += " default " + defValue;
            }
            sql += ",\n\t";
        }else if(vtType.equals("VTDouble")){
            int length = 20;
            String lengthStr = getOtherValueByType(other, "length");
            if(lengthStr != null && !lengthStr.equals("")){
                length = Integer.valueOf(lengthStr);
            }
            
            int accuracy = 2;
            String accuracyStr = getOtherValueByType(other, "accuracy");
            if(accuracyStr != null && !accuracyStr.equals("")){
                accuracy = Integer.valueOf(accuracyStr);
            }
            sql += abName.toUpperCase() + " NUMBER(" + length + ", " + accuracy +")";
            if(!defValue.equals("")){
                sql += " default " + defValue;
            }
            sql += ",\n\t";
        }else if(vtType.equals("VTBoolean")){
            sql += abName.toUpperCase() + " VARCHAR2(8)";
            if(!defValue.equals("")){
                sql += " default '" + defValue + "'";
            }
            sql += ",\n\t";
        }else if(vtType.equals("VTImage")){
            sql += abName.toUpperCase() + " VARCHAR2(255)";
            sql += ",\n\t";
        }else if(vtType.equals("VTDate")){
            sql += abName.toUpperCase() + " DATE";
            sql += ",\n\t";
        }else if(vtType.equals("VTTime")){
            sql += abName.toUpperCase() + " TIMESTAMP";
            sql += ",\n\t";
        }else if(vtType.equals("VTDateTime")){
            sql += abName.toUpperCase() + " TIMESTAMP";
            sql += ",\n\t";
        }else if(vtType.equals("VTNote")){
            sql += abName.toUpperCase() + " VARCHAR2(255)";
            sql += ",\n\t";
        }else if(vtType.equals("VTFilePath")){
            sql += abName.toUpperCase() + " VARCHAR2(255)";
            sql += ",\n\t";
        }else if(vtType.equals("VTClob")){
            sql += abName.toUpperCase() + " CLOB";
            sql += ",\n\t";
        }
        
        return sql;
    }
    
    /**
     * 获取属性other中type的值
     * @param other
     * @param type
     * @return
     */
    public String getOtherValueByType(String other, String type){
        String[] otherArray = other.split(";");
        for(int i = 0; i < otherArray.length; i++){
            String otherValue = otherArray[i];
            if(otherValue.contains(type)){
                return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length());
            }
        }
        return null;
        
    }
}