Browse Source

added support for non nullable language types

tags/v1.1.0
Robin Thoni 7 years ago
parent
commit
22b4dcd63c

+ 11
- 1
src/com/rthoni/intellij/codefromds/business/Generator.java View File

14
 import com.rthoni.intellij.codefromds.dbo.template.DataSourceDbo;
14
 import com.rthoni.intellij.codefromds.dbo.template.DataSourceDbo;
15
 import com.rthoni.intellij.codefromds.dbo.template.ForeignKeyDbo;
15
 import com.rthoni.intellij.codefromds.dbo.template.ForeignKeyDbo;
16
 import com.rthoni.intellij.codefromds.dbo.template.TableDataSourceDbo;
16
 import com.rthoni.intellij.codefromds.dbo.template.TableDataSourceDbo;
17
+import org.json.JSONArray;
17
 import org.json.JSONObject;
18
 import org.json.JSONObject;
18
 import org.jtwig.JtwigModel;
19
 import org.jtwig.JtwigModel;
19
 import org.jtwig.JtwigTemplate;
20
 import org.jtwig.JtwigTemplate;
79
 
80
 
80
         return dbo;
81
         return dbo;
81
     }
82
     }
82
-    
83
+
83
     public static String convertSqlType(DataType type, TypesCastOptions options)
84
     public static String convertSqlType(DataType type, TypesCastOptions options)
84
     {
85
     {
85
         boolean isArray = type.typeName.endsWith("[]");
86
         boolean isArray = type.typeName.endsWith("[]");
108
         dbo.setName(columnSelection.getColumn().getName());
109
         dbo.setName(columnSelection.getColumn().getName());
109
         dbo.setPrimary(DasUtil.isPrimary(columnSelection.getColumn()));
110
         dbo.setPrimary(DasUtil.isPrimary(columnSelection.getColumn()));
110
         dbo.setSelected(columnSelection.isSelected());
111
         dbo.setSelected(columnSelection.isSelected());
112
+        dbo.setNotNull(columnSelection.getColumn().isNotNull());
111
         dbo.setType(convertSqlType(columnSelection.getColumn().getDataType(), options));
113
         dbo.setType(convertSqlType(columnSelection.getColumn().getDataType(), options));
114
+        dbo.setTypeNotNull(options.getNonNullableTypes().contains(dbo.getType()));
112
 
115
 
113
         return dbo;
116
         return dbo;
114
     }
117
     }
167
         }
170
         }
168
         dbo.setTypes(map);
171
         dbo.setTypes(map);
169
 
172
 
173
+        List<String> nonNullableTypes = new Vector<>();
174
+        JSONArray array = obj.getJSONArray("non-nullable-types");
175
+        for (int i = 0; i < array.length(); ++i) {
176
+            nonNullableTypes.add(array.getString(i));
177
+        }
178
+        dbo.setNonNullableTypes(nonNullableTypes);
179
+
170
         dbo.setArrayTemplate(obj.getString("arrayTemplate"));
180
         dbo.setArrayTemplate(obj.getString("arrayTemplate"));
171
 
181
 
172
         return dbo;
182
         return dbo;

+ 11
- 0
src/com/rthoni/intellij/codefromds/dbo/options/TypesCastOptions.java View File

1
 package com.rthoni.intellij.codefromds.dbo.options;
1
 package com.rthoni.intellij.codefromds.dbo.options;
2
 
2
 
3
 import java.util.HashMap;
3
 import java.util.HashMap;
4
+import java.util.List;
4
 
5
 
5
 /**
6
 /**
6
  * Created by robin on 11/19/16.
7
  * Created by robin on 11/19/16.
11
 
12
 
12
     private HashMap<String, HashMap<String, String>> _types;
13
     private HashMap<String, HashMap<String, String>> _types;
13
 
14
 
15
+    private List<String> _nonNullableTypes;
16
+
14
     public String getArrayTemplate() {
17
     public String getArrayTemplate() {
15
         return _arrayTemplate;
18
         return _arrayTemplate;
16
     }
19
     }
26
     public void setTypes(HashMap<String, HashMap<String, String>> types) {
29
     public void setTypes(HashMap<String, HashMap<String, String>> types) {
27
         _types = types;
30
         _types = types;
28
     }
31
     }
32
+
33
+    public List<String> getNonNullableTypes() {
34
+        return _nonNullableTypes;
35
+    }
36
+
37
+    public void setNonNullableTypes(List<String> nonNullableTypes) {
38
+        _nonNullableTypes = nonNullableTypes;
39
+    }
29
 }
40
 }

+ 20
- 0
src/com/rthoni/intellij/codefromds/dbo/template/ColumnDataSourceDbo.java View File

13
 
13
 
14
     private String _type;
14
     private String _type;
15
 
15
 
16
+    private boolean _notNull;
17
+
18
+    private boolean _typeNotNull;
19
+
16
     public String getName() {
20
     public String getName() {
17
         return _name;
21
         return _name;
18
     }
22
     }
44
     public void setType(String type) {
48
     public void setType(String type) {
45
         _type = type;
49
         _type = type;
46
     }
50
     }
51
+
52
+    public boolean isNotNull() {
53
+        return _notNull;
54
+    }
55
+
56
+    public void setNotNull(boolean notNull) {
57
+        _notNull = notNull;
58
+    }
59
+
60
+    public boolean isTypeNotNull() {
61
+        return _typeNotNull;
62
+    }
63
+
64
+    public void setTypeNotNull(boolean typeNotNull) {
65
+        _typeNotNull = typeNotNull;
66
+    }
47
 }
67
 }

Loading…
Cancel
Save