|
@@ -14,7 +14,6 @@ import com.rthoni.intellij.codefromds.dbo.template.ColumnDataSourceDbo;
|
14
|
14
|
import com.rthoni.intellij.codefromds.dbo.template.DataSourceDbo;
|
15
|
15
|
import com.rthoni.intellij.codefromds.dbo.template.ForeignKeyDbo;
|
16
|
16
|
import com.rthoni.intellij.codefromds.dbo.template.TableDataSourceDbo;
|
17
|
|
-import org.json.JSONArray;
|
18
|
17
|
import org.json.JSONObject;
|
19
|
18
|
import org.jtwig.JtwigModel;
|
20
|
19
|
import org.jtwig.JtwigTemplate;
|
|
@@ -22,9 +21,6 @@ import org.jtwig.JtwigTemplate;
|
22
|
21
|
import java.io.File;
|
23
|
22
|
import java.io.FileOutputStream;
|
24
|
23
|
import java.io.IOException;
|
25
|
|
-import java.nio.charset.StandardCharsets;
|
26
|
|
-import java.nio.file.Files;
|
27
|
|
-import java.nio.file.Paths;
|
28
|
24
|
import java.util.HashMap;
|
29
|
25
|
import java.util.List;
|
30
|
26
|
import java.util.Vector;
|
|
@@ -83,15 +79,9 @@ public abstract class Generator {
|
83
|
79
|
|
84
|
80
|
return dbo;
|
85
|
81
|
}
|
86
|
|
-
|
87
|
|
- public static ColumnDataSourceDbo convertColumn(ColumnSelection columnSelection, TypesCastOptions options)
|
|
82
|
+
|
|
83
|
+ public static String convertSqlType(DataType type, TypesCastOptions options)
|
88
|
84
|
{
|
89
|
|
- ColumnDataSourceDbo dbo = new ColumnDataSourceDbo();
|
90
|
|
- dbo.setName(columnSelection.getColumn().getName());
|
91
|
|
- dbo.setPrimary(DasUtil.isPrimary(columnSelection.getColumn()));
|
92
|
|
- dbo.setSelected(columnSelection.isSelected());
|
93
|
|
-
|
94
|
|
- DataType type = columnSelection.getColumn().getDataType();
|
95
|
85
|
boolean isArray = type.typeName.endsWith("[]");
|
96
|
86
|
String sqlTypeName = isArray ? type.typeName.substring(0, type.typeName.length() - 2) : type.typeName;
|
97
|
87
|
String typeName = type.typeName;
|
|
@@ -109,7 +99,16 @@ public abstract class Generator {
|
109
|
99
|
if (isArray) {
|
110
|
100
|
typeName = options.getArrayTemplate().replace("%t", typeName);
|
111
|
101
|
}
|
112
|
|
- dbo.setType(typeName);
|
|
102
|
+ return typeName;
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ public static ColumnDataSourceDbo convertColumn(ColumnSelection columnSelection, TypesCastOptions options)
|
|
106
|
+ {
|
|
107
|
+ ColumnDataSourceDbo dbo = new ColumnDataSourceDbo();
|
|
108
|
+ dbo.setName(columnSelection.getColumn().getName());
|
|
109
|
+ dbo.setPrimary(DasUtil.isPrimary(columnSelection.getColumn()));
|
|
110
|
+ dbo.setSelected(columnSelection.isSelected());
|
|
111
|
+ dbo.setType(convertSqlType(columnSelection.getColumn().getDataType(), options));
|
113
|
112
|
|
114
|
113
|
return dbo;
|
115
|
114
|
}
|
|
@@ -156,14 +155,14 @@ public abstract class Generator {
|
156
|
155
|
HashMap<String, String> typeMap = new HashMap<>();
|
157
|
156
|
String type = objTypes.optString(key);
|
158
|
157
|
JSONObject typeObject = objTypes.optJSONObject(key);
|
159
|
|
- if (type != null) {
|
160
|
|
- typeMap.put("*", type);
|
161
|
|
- }
|
162
|
|
- else if (typeObject != null) {
|
|
158
|
+ if (typeObject != null) {
|
163
|
159
|
for (String subtype : typeObject.keySet()) {
|
164
|
160
|
typeMap.put(subtype, typeObject.getString(subtype));
|
165
|
161
|
}
|
166
|
162
|
}
|
|
163
|
+ else if (type != null) {
|
|
164
|
+ typeMap.put("*", type);
|
|
165
|
+ }
|
167
|
166
|
map.put(key, typeMap);
|
168
|
167
|
}
|
169
|
168
|
dbo.setTypes(map);
|