Browse Source

fixed sp generation

develop
Robin Thoni 7 years ago
parent
commit
095f45dd09

+ 2
- 3
TODO View File

@@ -1,5 +1,4 @@
1
-proc stock
2 1
 many to many
3 2
 table inheritance
4
-generate custom types (sp return)
5
-UI for sp dataSource
3
+variadic sp
4
+inout sp arguments

+ 11
- 13
src/com/rthoni/intellij/codefromds/DataAccess/DataSourcesDataAccess.java View File

@@ -51,9 +51,10 @@ public class DataSourcesDataAccess {
51 51
                 columnDataSourceDbo.data.setName(column.getName());
52 52
                 columnDataSourceDbo.data.setNotNull(column.isNotNull());
53 53
                 SqlTypeDbo type = new SqlTypeDbo();
54
-                type.setType(column.getDataType().typeName);
54
+                type.setName(column.getDataType().typeName);
55
+                type.guessArrayAndSetOf();
55 56
                 type.setVagueArg(column.getDataType().vagueArg);
56
-                columnDataSourceDbo.data.setSqlType(type);
57
+                columnDataSourceDbo.data.setType(type);
57 58
                 columnDataSourceDbo.data.setDefaultValue(column.getDefault());
58 59
                 columnDataSourceDbo.data.setPrimary(DasUtil.isPrimary(column));
59 60
                 tableDataSourceDbo.data.addColumn(columnDataSourceDbo.data);
@@ -113,18 +114,19 @@ public class DataSourcesDataAccess {
113 114
                 sp.getArguments().forEach(o ->
114 115
                 {
115 116
                     SqlTypeDbo sqlTypeDbo = new SqlTypeDbo();
116
-                    sqlTypeDbo.setType(o.getDataType().typeName);
117
+                    sqlTypeDbo.setName(o.getDataType().typeName);
118
+                    sqlTypeDbo.guessArrayAndSetOf();
117 119
                     sqlTypeDbo.setVagueArg(o.getDataType().vagueArg);
118 120
 
119 121
                     DasArgument.Direction dir = o.getArgumentDirection();
120 122
 
121 123
                     if (dir.isReturnOrResult()) {
122
-                        spDbo.setSqlType(sqlTypeDbo);
124
+                        spDbo.setType(sqlTypeDbo);
123 125
                     }
124 126
                     if (dir.isIn()) {
125 127
                         StoredProcedureArgDbo argDbo = new StoredProcedureArgDbo();
126 128
                         argDbo.setName(o.getName().isEmpty() ? "arg" + position.data : o.getName());
127
-                        argDbo.setSqlType(sqlTypeDbo);
129
+                        argDbo.setType(sqlTypeDbo);
128 130
                         spDbo.addArgument(argDbo);
129 131
                         ++position.data;
130 132
                     }
@@ -135,23 +137,19 @@ public class DataSourcesDataAccess {
135 137
                         field.setDefaultValue(null);
136 138
                         field.setNotNull(false);
137 139
                         field.setName(o.getName());
138
-                        field.setSqlType(sqlTypeDbo);
140
+                        field.setType(sqlTypeDbo);
139 141
                         returnType.addColumn(field);
140 142
                     }
141 143
                 });
142 144
                 if (returnType.getColumns().size() > 1) {
143 145
                     boolean isSetOf = sp.getReturnArgument().getDataType().typeName.startsWith("setof ");
144 146
                     SqlTypeDbo sqlTypeDbo = new SqlTypeDbo();
145
-                    sqlTypeDbo.setType((isSetOf ? "setof " : "" ) + returnType.getName());
147
+                    sqlTypeDbo.setName((isSetOf ? "setof " : "" ) + returnType.getName());
148
+                    sqlTypeDbo.guessArrayAndSetOf();
146 149
                     sqlTypeDbo.setVagueArg(null);
147
-                    spDbo.setSqlType(sqlTypeDbo);
150
+                    spDbo.setType(sqlTypeDbo);
148 151
                     dataSourceDbo.addType(returnType);
149 152
                 }
150
-                else {
151
-                    DasArgument returnArg = sp.getReturnArgument();
152
-                    if (returnArg != null) {
153
-                    }
154
-                }
155 153
             }
156 154
         });
157 155
         return dataSourceDbo;

+ 9
- 7
src/com/rthoni/intellij/codefromds/business/Generator.java View File

@@ -71,9 +71,9 @@ public abstract class Generator {
71 71
         if (type == null) {
72 72
             return;
73 73
         }
74
-        boolean isArray = type.getType().endsWith("[]");
75
-        boolean isSetOf = type.getType().startsWith("setof ");
76
-        String sqlTypeName = isArray ? type.getType().substring(0, type.getType().length() - 2) : type.getType();
74
+        boolean isArray = type.isArray();
75
+        boolean isSetOf = type.isSetOf();
76
+        String sqlTypeName = isArray ? type.getName().substring(0, type.getName().length() - 2) : type.getName();
77 77
         if (isSetOf)
78 78
         {
79 79
             sqlTypeName = sqlTypeName.substring(6);
@@ -96,16 +96,18 @@ public abstract class Generator {
96 96
                 typeName = types.get("*").get("*");
97 97
             }
98 98
             else {
99
+                type.setLanguageType(table);
99 100
                 typeName = table.getName();
100 101
             }
101 102
         }
103
+        type.setLanguageBaseTypeName(typeName);
102 104
         if (isArray) {
103 105
             typeName = options.getArrayTemplate().replace("%t", typeName);
104 106
         }
105 107
         if (isSetOf) {
106 108
             typeName = options.getSetOfTemplate().replace("%t", typeName);
107 109
         }
108
-        type.setLanguageType(typeName);
110
+        type.setLanguageTypeName(typeName);
109 111
         type.setLanguageTypeNotNull(options.getNonNullableTypes().contains(typeName));
110 112
     }
111 113
 
@@ -132,15 +134,15 @@ public abstract class Generator {
132 134
         {
133 135
             for (ColumnDataSourceDbo column : table.getColumns())
134 136
             {
135
-                convertSqlType(column.getSqlType(), types, options.getDataSource());
137
+                convertSqlType(column.getType(), types, options.getDataSource());
136 138
             }
137 139
         }
138 140
 
139 141
         for (StoredProcedureDbo spDbo : options.getDataSource().getStoredProcedures())
140 142
         {
141
-            convertSqlType(spDbo.getSqlType(), types, options.getDataSource());
143
+            convertSqlType(spDbo.getType(), types, options.getDataSource());
142 144
             for (StoredProcedureArgDbo arg : spDbo.getArguments()) {
143
-                convertSqlType(arg.getSqlType(), types, options.getDataSource());
145
+                convertSqlType(arg.getType(), types, options.getDataSource());
144 146
             }
145 147
         }
146 148
     }

+ 6
- 10
src/com/rthoni/intellij/codefromds/dbo/template/ColumnDataSourceDbo.java View File

@@ -11,7 +11,7 @@ public class ColumnDataSourceDbo {
11 11
 
12 12
     private boolean _isSelected;
13 13
 
14
-    private SqlTypeDbo _sqlType;
14
+    private SqlTypeDbo _type;
15 15
 
16 16
     private boolean _notNull;
17 17
 
@@ -41,16 +41,12 @@ public class ColumnDataSourceDbo {
41 41
         _isSelected = selected;
42 42
     }
43 43
 
44
-    public String getType() {
45
-        return _sqlType != null ? _sqlType.getLanguageType() : null;
44
+    public SqlTypeDbo getType() {
45
+        return _type;
46 46
     }
47 47
 
48
-    public SqlTypeDbo getSqlType() {
49
-        return _sqlType;
50
-    }
51
-
52
-    public void setSqlType(SqlTypeDbo sqlType) {
53
-        _sqlType = sqlType;
48
+    public void setType(SqlTypeDbo type) {
49
+        _type = type;
54 50
     }
55 51
 
56 52
     public boolean isNotNull() {
@@ -62,7 +58,7 @@ public class ColumnDataSourceDbo {
62 58
     }
63 59
 
64 60
     public boolean isTypeNotNull() {
65
-        return _sqlType != null && _sqlType.isLanguageTypeNotNull();
61
+        return _type != null && _type.isLanguageTypeNotNull();
66 62
     }
67 63
 
68 64
     public String getDefaultValue() {

+ 54
- 8
src/com/rthoni/intellij/codefromds/dbo/template/SqlTypeDbo.java View File

@@ -5,20 +5,50 @@ package com.rthoni.intellij.codefromds.dbo.template;
5 5
  */
6 6
 public class SqlTypeDbo {
7 7
 
8
-    private String _type;
8
+    private String _name;
9 9
 
10 10
     private String vagueArg;
11 11
 
12
-    private String _languageType;
12
+    private boolean _isArray;
13
+
14
+    private boolean _isSetOf;
15
+
16
+    private String _languageTypeName;
17
+
18
+    private String _languageBaseTypeName;
19
+
20
+    private TableDataSourceDbo _languageType;
13 21
 
14 22
     private boolean _languageTypeNotNull;
15 23
 
16
-    public String getType() {
17
-        return _type;
24
+    public String getName() {
25
+        return _name;
26
+    }
27
+
28
+    public void setName(String name) {
29
+        _name = name;
30
+    }
31
+
32
+    public boolean isArray() {
33
+        return _isArray;
34
+    }
35
+
36
+    public void setArray(boolean array) {
37
+        _isArray = array;
38
+    }
39
+
40
+    public boolean isSetOf() {
41
+        return _isSetOf;
42
+    }
43
+
44
+    public void setSetOf(boolean setOf) {
45
+        _isSetOf = setOf;
18 46
     }
19 47
 
20
-    public void setType(String type) {
21
-        _type = type;
48
+    public void guessArrayAndSetOf()
49
+    {
50
+        setArray(_name.endsWith("[]"));
51
+        setSetOf(_name.startsWith("setof "));
22 52
     }
23 53
 
24 54
     public String getVagueArg() {
@@ -29,11 +59,19 @@ public class SqlTypeDbo {
29 59
         this.vagueArg = vagueArg;
30 60
     }
31 61
 
32
-    public String getLanguageType() {
62
+    public String getLanguageTypeName() {
63
+        return _languageTypeName;
64
+    }
65
+
66
+    public void setLanguageTypeName(String languageTypeName) {
67
+        _languageTypeName = languageTypeName;
68
+    }
69
+
70
+    public TableDataSourceDbo getLanguageType() {
33 71
         return _languageType;
34 72
     }
35 73
 
36
-    public void setLanguageType(String languageType) {
74
+    public void setLanguageType(TableDataSourceDbo languageType) {
37 75
         _languageType = languageType;
38 76
     }
39 77
 
@@ -44,4 +82,12 @@ public class SqlTypeDbo {
44 82
     public void setLanguageTypeNotNull(boolean languageTypeNotNull) {
45 83
         _languageTypeNotNull = languageTypeNotNull;
46 84
     }
85
+
86
+    public String getLanguageBaseTypeName() {
87
+        return _languageBaseTypeName;
88
+    }
89
+
90
+    public void setLanguageBaseTypeName(String languageBaseTypeName) {
91
+        _languageBaseTypeName = languageBaseTypeName;
92
+    }
47 93
 }

+ 5
- 9
src/com/rthoni/intellij/codefromds/dbo/template/StoredProcedureArgDbo.java View File

@@ -7,7 +7,7 @@ public class StoredProcedureArgDbo {
7 7
 
8 8
     private String name;
9 9
 
10
-    private SqlTypeDbo _sqlType;
10
+    private SqlTypeDbo _type;
11 11
 
12 12
     public String getName() {
13 13
         return name;
@@ -17,15 +17,11 @@ public class StoredProcedureArgDbo {
17 17
         this.name = name;
18 18
     }
19 19
 
20
-    public String getType() {
21
-        return _sqlType != null ? _sqlType.getLanguageType() : null;
20
+    public SqlTypeDbo getType() {
21
+        return _type;
22 22
     }
23 23
 
24
-    public SqlTypeDbo getSqlType() {
25
-        return _sqlType;
26
-    }
27
-
28
-    public void setSqlType(SqlTypeDbo sqlType) {
29
-        _sqlType = sqlType;
24
+    public void setType(SqlTypeDbo type) {
25
+        _type = type;
30 26
     }
31 27
 }

+ 5
- 9
src/com/rthoni/intellij/codefromds/dbo/template/StoredProcedureDbo.java View File

@@ -12,7 +12,7 @@ public class StoredProcedureDbo {
12 12
 
13 13
     private List<StoredProcedureArgDbo> _arguments = new Vector<>();
14 14
 
15
-    private SqlTypeDbo _sqlType;
15
+    private SqlTypeDbo _type;
16 16
 
17 17
     private boolean _isSelected;
18 18
 
@@ -34,16 +34,12 @@ public class StoredProcedureDbo {
34 34
         _arguments.add(arguments);
35 35
     }
36 36
 
37
-    public String getType() {
38
-        return _sqlType != null ? _sqlType.getLanguageType() : null;
37
+    public SqlTypeDbo getType() {
38
+        return _type;
39 39
     }
40 40
 
41
-    public SqlTypeDbo getSqlType() {
42
-        return _sqlType;
43
-    }
44
-
45
-    public void setSqlType(SqlTypeDbo sqlType) {
46
-        _sqlType = sqlType;
41
+    public void setType(SqlTypeDbo type) {
42
+        _type = type;
47 43
     }
48 44
 
49 45
     public boolean isSelected() {

Loading…
Cancel
Save