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,6 +14,7 @@ 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;
17 18
 import org.json.JSONObject;
18 19
 import org.jtwig.JtwigModel;
19 20
 import org.jtwig.JtwigTemplate;
@@ -79,7 +80,7 @@ public abstract class Generator {
79 80
 
80 81
         return dbo;
81 82
     }
82
-    
83
+
83 84
     public static String convertSqlType(DataType type, TypesCastOptions options)
84 85
     {
85 86
         boolean isArray = type.typeName.endsWith("[]");
@@ -108,7 +109,9 @@ public abstract class Generator {
108 109
         dbo.setName(columnSelection.getColumn().getName());
109 110
         dbo.setPrimary(DasUtil.isPrimary(columnSelection.getColumn()));
110 111
         dbo.setSelected(columnSelection.isSelected());
112
+        dbo.setNotNull(columnSelection.getColumn().isNotNull());
111 113
         dbo.setType(convertSqlType(columnSelection.getColumn().getDataType(), options));
114
+        dbo.setTypeNotNull(options.getNonNullableTypes().contains(dbo.getType()));
112 115
 
113 116
         return dbo;
114 117
     }
@@ -167,6 +170,13 @@ public abstract class Generator {
167 170
         }
168 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 180
         dbo.setArrayTemplate(obj.getString("arrayTemplate"));
171 181
 
172 182
         return dbo;

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

@@ -1,6 +1,7 @@
1 1
 package com.rthoni.intellij.codefromds.dbo.options;
2 2
 
3 3
 import java.util.HashMap;
4
+import java.util.List;
4 5
 
5 6
 /**
6 7
  * Created by robin on 11/19/16.
@@ -11,6 +12,8 @@ public class TypesCastOptions {
11 12
 
12 13
     private HashMap<String, HashMap<String, String>> _types;
13 14
 
15
+    private List<String> _nonNullableTypes;
16
+
14 17
     public String getArrayTemplate() {
15 18
         return _arrayTemplate;
16 19
     }
@@ -26,4 +29,12 @@ public class TypesCastOptions {
26 29
     public void setTypes(HashMap<String, HashMap<String, String>> types) {
27 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,6 +13,10 @@ public class ColumnDataSourceDbo {
13 13
 
14 14
     private String _type;
15 15
 
16
+    private boolean _notNull;
17
+
18
+    private boolean _typeNotNull;
19
+
16 20
     public String getName() {
17 21
         return _name;
18 22
     }
@@ -44,4 +48,20 @@ public class ColumnDataSourceDbo {
44 48
     public void setType(String type) {
45 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