Browse Source

fixed sp generation

develop
Robin Thoni 7 years ago
parent
commit
095f45dd09

+ 2
- 3
TODO View File

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

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

71
         if (type == null) {
71
         if (type == null) {
72
             return;
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
         if (isSetOf)
77
         if (isSetOf)
78
         {
78
         {
79
             sqlTypeName = sqlTypeName.substring(6);
79
             sqlTypeName = sqlTypeName.substring(6);
96
                 typeName = types.get("*").get("*");
96
                 typeName = types.get("*").get("*");
97
             }
97
             }
98
             else {
98
             else {
99
+                type.setLanguageType(table);
99
                 typeName = table.getName();
100
                 typeName = table.getName();
100
             }
101
             }
101
         }
102
         }
103
+        type.setLanguageBaseTypeName(typeName);
102
         if (isArray) {
104
         if (isArray) {
103
             typeName = options.getArrayTemplate().replace("%t", typeName);
105
             typeName = options.getArrayTemplate().replace("%t", typeName);
104
         }
106
         }
105
         if (isSetOf) {
107
         if (isSetOf) {
106
             typeName = options.getSetOfTemplate().replace("%t", typeName);
108
             typeName = options.getSetOfTemplate().replace("%t", typeName);
107
         }
109
         }
108
-        type.setLanguageType(typeName);
110
+        type.setLanguageTypeName(typeName);
109
         type.setLanguageTypeNotNull(options.getNonNullableTypes().contains(typeName));
111
         type.setLanguageTypeNotNull(options.getNonNullableTypes().contains(typeName));
110
     }
112
     }
111
 
113
 
132
         {
134
         {
133
             for (ColumnDataSourceDbo column : table.getColumns())
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
         for (StoredProcedureDbo spDbo : options.getDataSource().getStoredProcedures())
141
         for (StoredProcedureDbo spDbo : options.getDataSource().getStoredProcedures())
140
         {
142
         {
141
-            convertSqlType(spDbo.getSqlType(), types, options.getDataSource());
143
+            convertSqlType(spDbo.getType(), types, options.getDataSource());
142
             for (StoredProcedureArgDbo arg : spDbo.getArguments()) {
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
 
11
 
12
     private boolean _isSelected;
12
     private boolean _isSelected;
13
 
13
 
14
-    private SqlTypeDbo _sqlType;
14
+    private SqlTypeDbo _type;
15
 
15
 
16
     private boolean _notNull;
16
     private boolean _notNull;
17
 
17
 
41
         _isSelected = selected;
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
     public boolean isNotNull() {
52
     public boolean isNotNull() {
62
     }
58
     }
63
 
59
 
64
     public boolean isTypeNotNull() {
60
     public boolean isTypeNotNull() {
65
-        return _sqlType != null && _sqlType.isLanguageTypeNotNull();
61
+        return _type != null && _type.isLanguageTypeNotNull();
66
     }
62
     }
67
 
63
 
68
     public String getDefaultValue() {
64
     public String getDefaultValue() {

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

5
  */
5
  */
6
 public class SqlTypeDbo {
6
 public class SqlTypeDbo {
7
 
7
 
8
-    private String _type;
8
+    private String _name;
9
 
9
 
10
     private String vagueArg;
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
     private boolean _languageTypeNotNull;
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
     public String getVagueArg() {
54
     public String getVagueArg() {
29
         this.vagueArg = vagueArg;
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
         return _languageType;
71
         return _languageType;
34
     }
72
     }
35
 
73
 
36
-    public void setLanguageType(String languageType) {
74
+    public void setLanguageType(TableDataSourceDbo languageType) {
37
         _languageType = languageType;
75
         _languageType = languageType;
38
     }
76
     }
39
 
77
 
44
     public void setLanguageTypeNotNull(boolean languageTypeNotNull) {
82
     public void setLanguageTypeNotNull(boolean languageTypeNotNull) {
45
         _languageTypeNotNull = languageTypeNotNull;
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
 
8
     private String name;
8
     private String name;
9
 
9
 
10
-    private SqlTypeDbo _sqlType;
10
+    private SqlTypeDbo _type;
11
 
11
 
12
     public String getName() {
12
     public String getName() {
13
         return name;
13
         return name;
17
         this.name = name;
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
 
12
 
13
     private List<StoredProcedureArgDbo> _arguments = new Vector<>();
13
     private List<StoredProcedureArgDbo> _arguments = new Vector<>();
14
 
14
 
15
-    private SqlTypeDbo _sqlType;
15
+    private SqlTypeDbo _type;
16
 
16
 
17
     private boolean _isSelected;
17
     private boolean _isSelected;
18
 
18
 
34
         _arguments.add(arguments);
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
     public boolean isSelected() {
45
     public boolean isSelected() {

Loading…
Cancel
Save