소스 검색

added custom types for sp

develop
Robin Thoni 7 년 전
부모
커밋
36f11430f8

+ 25
- 6
src/com/rthoni/intellij/codefromds/DataAccess/DataSourcesDataAccess.java 파일 보기

108
                 dataSourceDbo.addStoredProcedure(spDbo);
108
                 dataSourceDbo.addStoredProcedure(spDbo);
109
                 DataHolder<Integer> position = new DataHolder<>();
109
                 DataHolder<Integer> position = new DataHolder<>();
110
                 position.data = 0;
110
                 position.data = 0;
111
+                TableDataSourceDbo returnType = new TableDataSourceDbo();
112
+                returnType.setName(spDbo.getName());
111
                 sp.getArguments().forEach(o ->
113
                 sp.getArguments().forEach(o ->
112
                 {
114
                 {
113
                     SqlTypeDbo sqlTypeDbo = new SqlTypeDbo();
115
                     SqlTypeDbo sqlTypeDbo = new SqlTypeDbo();
116
 
118
 
117
                     DasArgument.Direction dir = o.getArgumentDirection();
119
                     DasArgument.Direction dir = o.getArgumentDirection();
118
 
120
 
119
-
120
-
121
                     if (dir.isReturnOrResult()) {
121
                     if (dir.isReturnOrResult()) {
122
                         spDbo.setSqlType(sqlTypeDbo);
122
                         spDbo.setSqlType(sqlTypeDbo);
123
                     }
123
                     }
125
                         StoredProcedureArgDbo argDbo = new StoredProcedureArgDbo();
125
                         StoredProcedureArgDbo argDbo = new StoredProcedureArgDbo();
126
                         argDbo.setName(o.getName().isEmpty() ? "arg" + position.data : o.getName());
126
                         argDbo.setName(o.getName().isEmpty() ? "arg" + position.data : o.getName());
127
                         argDbo.setSqlType(sqlTypeDbo);
127
                         argDbo.setSqlType(sqlTypeDbo);
128
-                        argDbo.setOut(o.getArgumentDirection().isOut());
129
                         spDbo.addArgument(argDbo);
128
                         spDbo.addArgument(argDbo);
130
                         ++position.data;
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
         return dataSourceDbo;
157
         return dataSourceDbo;

+ 3
- 3
src/com/rthoni/intellij/codefromds/business/Generator.java 파일 보기

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

+ 36
- 0
src/com/rthoni/intellij/codefromds/dbo/template/DataSourceDbo.java 파일 보기

12
 
12
 
13
     private List<TableDataSourceDbo> _tables = new Vector<>();
13
     private List<TableDataSourceDbo> _tables = new Vector<>();
14
 
14
 
15
+    private List<TableDataSourceDbo> _types = new Vector<>();
16
+
15
     private List<StoredProcedureDbo> _storedProcedures = new Vector<>();
17
     private List<StoredProcedureDbo> _storedProcedures = new Vector<>();
16
 
18
 
17
     public List<StoredProcedureDbo> getStoredProcedures() {
19
     public List<StoredProcedureDbo> getStoredProcedures() {
38
         _tables.add(table);
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
     public TableDataSourceDbo findTable(String name)
58
     public TableDataSourceDbo findTable(String name)
42
     {
59
     {
43
         for (TableDataSourceDbo table : _tables) {
60
         for (TableDataSourceDbo table : _tables) {
48
         return null;
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
     public StoredProcedureDbo findStoredProcedure(String name)
87
     public StoredProcedureDbo findStoredProcedure(String name)
52
     {
88
     {
53
         for (StoredProcedureDbo sp : _storedProcedures) {
89
         for (StoredProcedureDbo sp : _storedProcedures) {

+ 0
- 10
src/com/rthoni/intellij/codefromds/dbo/template/StoredProcedureArgDbo.java 파일 보기

9
 
9
 
10
     private SqlTypeDbo _sqlType;
10
     private SqlTypeDbo _sqlType;
11
 
11
 
12
-    private boolean _isOut;
13
-
14
     public String getName() {
12
     public String getName() {
15
         return name;
13
         return name;
16
     }
14
     }
30
     public void setSqlType(SqlTypeDbo sqlType) {
28
     public void setSqlType(SqlTypeDbo sqlType) {
31
         _sqlType = sqlType;
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…
취소
저장