Browse Source

added custom types for sp

develop
Robin Thoni 7 years ago
parent
commit
36f11430f8

+ 25
- 6
src/com/rthoni/intellij/codefromds/DataAccess/DataSourcesDataAccess.java View File

@@ -108,6 +108,8 @@ public class DataSourcesDataAccess {
108 108
                 dataSourceDbo.addStoredProcedure(spDbo);
109 109
                 DataHolder<Integer> position = new DataHolder<>();
110 110
                 position.data = 0;
111
+                TableDataSourceDbo returnType = new TableDataSourceDbo();
112
+                returnType.setName(spDbo.getName());
111 113
                 sp.getArguments().forEach(o ->
112 114
                 {
113 115
                     SqlTypeDbo sqlTypeDbo = new SqlTypeDbo();
@@ -116,8 +118,6 @@ public class DataSourcesDataAccess {
116 118
 
117 119
                     DasArgument.Direction dir = o.getArgumentDirection();
118 120
 
119
-
120
-
121 121
                     if (dir.isReturnOrResult()) {
122 122
                         spDbo.setSqlType(sqlTypeDbo);
123 123
                     }
@@ -125,14 +125,33 @@ public class DataSourcesDataAccess {
125 125
                         StoredProcedureArgDbo argDbo = new StoredProcedureArgDbo();
126 126
                         argDbo.setName(o.getName().isEmpty() ? "arg" + position.data : o.getName());
127 127
                         argDbo.setSqlType(sqlTypeDbo);
128
-                        argDbo.setOut(o.getArgumentDirection().isOut());
129 128
                         spDbo.addArgument(argDbo);
130 129
                         ++position.data;
131 130
                     }
131
+                    if (dir.isOut()) {
132
+                        ColumnDataSourceDbo field = new ColumnDataSourceDbo();
133
+                        field.setSelected(true);
134
+                        field.setPrimary(false);
135
+                        field.setDefaultValue(null);
136
+                        field.setNotNull(false);
137
+                        field.setName(o.getName());
138
+                        field.setSqlType(sqlTypeDbo);
139
+                        returnType.addColumn(field);
140
+                    }
132 141
                 });
133
-//                DasArgument arg = sp.getReturnArgument();
134
-//                if (arg != null)
135
-//                    arg.toString();
142
+                if (returnType.getColumns().size() > 1) {
143
+                    boolean isSetOf = sp.getReturnArgument().getDataType().typeName.startsWith("setof ");
144
+                    SqlTypeDbo sqlTypeDbo = new SqlTypeDbo();
145
+                    sqlTypeDbo.setType((isSetOf ? "setof " : "" ) + returnType.getName());
146
+                    sqlTypeDbo.setVagueArg(null);
147
+                    spDbo.setSqlType(sqlTypeDbo);
148
+                    dataSourceDbo.addType(returnType);
149
+                }
150
+                else {
151
+                    DasArgument returnArg = sp.getReturnArgument();
152
+                    if (returnArg != null) {
153
+                    }
154
+                }
136 155
             }
137 156
         });
138 157
         return dataSourceDbo;

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

@@ -91,7 +91,7 @@ public abstract class Generator {
91 91
             }
92 92
         }
93 93
         if (typeName == null) {
94
-            TableDataSourceDbo table = dataSourceDbo.findTable(sqlTypeName);
94
+            TableDataSourceDbo table = dataSourceDbo.findTypeOrTable(sqlTypeName);
95 95
             if (table == null) {
96 96
                 typeName = types.get("*").get("*");
97 97
             }
@@ -128,7 +128,7 @@ public abstract class Generator {
128 128
     public static void convertOptions(GenerateOptions options, TypesCastOptions types)
129 129
     {
130 130
 
131
-        for (TableDataSourceDbo table : options.getDataSource().getTables())
131
+        for (TableDataSourceDbo table : options.getDataSource().getTablesAndTypes())
132 132
         {
133 133
             for (ColumnDataSourceDbo column : table.getColumns())
134 134
             {
@@ -267,7 +267,7 @@ public abstract class Generator {
267 267
         convertOptions(options, types);
268 268
 
269 269
         generateFile(dataSourceTemplateAbsolutePath, dataSourceAbsolutePath, options.getDataSource(), null, types);
270
-        for (TableDataSourceDbo table : options.getDataSource().getTables()) {
270
+        for (TableDataSourceDbo table : options.getDataSource().getTablesAndTypes()) {
271 271
             if (table.hasAny()) {
272 272
                 String filename = modelsAbsolutePath + File.separator + table.getName() + "." + options.getFilesExtension();
273 273
                 generateFile(modelsTemplateAbsolutePath, filename, options.getDataSource(), table, types);

+ 36
- 0
src/com/rthoni/intellij/codefromds/dbo/template/DataSourceDbo.java View File

@@ -12,6 +12,8 @@ public class DataSourceDbo {
12 12
 
13 13
     private List<TableDataSourceDbo> _tables = new Vector<>();
14 14
 
15
+    private List<TableDataSourceDbo> _types = new Vector<>();
16
+
15 17
     private List<StoredProcedureDbo> _storedProcedures = new Vector<>();
16 18
 
17 19
     public List<StoredProcedureDbo> getStoredProcedures() {
@@ -38,6 +40,21 @@ public class DataSourceDbo {
38 40
         _tables.add(table);
39 41
     }
40 42
 
43
+    public List<TableDataSourceDbo> getTypes() {
44
+        return _types;
45
+    }
46
+
47
+    public List<TableDataSourceDbo> getTablesAndTypes() {
48
+        List<TableDataSourceDbo> all = new Vector<>();
49
+        all.addAll(_tables);
50
+        all.addAll(_types);
51
+        return all;
52
+    }
53
+
54
+    public void addType(TableDataSourceDbo types) {
55
+        _types.add(types);
56
+    }
57
+
41 58
     public TableDataSourceDbo findTable(String name)
42 59
     {
43 60
         for (TableDataSourceDbo table : _tables) {
@@ -48,6 +65,25 @@ public class DataSourceDbo {
48 65
         return null;
49 66
     }
50 67
 
68
+    public TableDataSourceDbo findType(String name)
69
+    {
70
+        for (TableDataSourceDbo table : _types) {
71
+            if (table.getName().equals(name)) {
72
+                return table;
73
+            }
74
+        }
75
+        return null;
76
+    }
77
+
78
+    public TableDataSourceDbo findTypeOrTable(String name)
79
+    {
80
+        TableDataSourceDbo type = findType(name);
81
+        if (type == null) {
82
+            return findTable(name);
83
+        }
84
+        return type;
85
+    }
86
+
51 87
     public StoredProcedureDbo findStoredProcedure(String name)
52 88
     {
53 89
         for (StoredProcedureDbo sp : _storedProcedures) {

+ 0
- 10
src/com/rthoni/intellij/codefromds/dbo/template/StoredProcedureArgDbo.java View File

@@ -9,8 +9,6 @@ public class StoredProcedureArgDbo {
9 9
 
10 10
     private SqlTypeDbo _sqlType;
11 11
 
12
-    private boolean _isOut;
13
-
14 12
     public String getName() {
15 13
         return name;
16 14
     }
@@ -30,12 +28,4 @@ public class StoredProcedureArgDbo {
30 28
     public void setSqlType(SqlTypeDbo sqlType) {
31 29
         _sqlType = sqlType;
32 30
     }
33
-
34
-    public boolean isOut() {
35
-        return _isOut;
36
-    }
37
-
38
-    public void setOut(boolean out) {
39
-        _isOut = out;
40
-    }
41 31
 }

Loading…
Cancel
Save