Browse Source

added sp support

develop
Robin Thoni 7 years ago
parent
commit
fbe8dc59a0

+ 3
- 1
TODO View File

1
 proc stock
1
 proc stock
2
 many to many
2
 many to many
3
-table inheritance
3
+table inheritance
4
+generate custom types (sp return)
5
+UI for sp selection

+ 14
- 16
src/com/rthoni/intellij/codefromds/DataAccess/DataSourcesDataAccess.java View File

1
 package com.rthoni.intellij.codefromds.DataAccess;
1
 package com.rthoni.intellij.codefromds.DataAccess;
2
 
2
 
3
+import com.intellij.database.model.DasArgument;
3
 import com.intellij.database.psi.*;
4
 import com.intellij.database.psi.*;
4
 import com.intellij.database.util.DasUtil;
5
 import com.intellij.database.util.DasUtil;
5
 import com.rthoni.intellij.codefromds.business.Helper;
6
 import com.rthoni.intellij.codefromds.business.Helper;
64
             if (dasObject instanceof DbTable) {
65
             if (dasObject instanceof DbTable) {
65
                 DbTable table = (DbTable) dasObject;
66
                 DbTable table = (DbTable) dasObject;
66
                 tableDataSourceDbo.data = dataSourceDbo.findTable(table.getName());
67
                 tableDataSourceDbo.data = dataSourceDbo.findTable(table.getName());
67
-//                System.out.println("Table: " + tableDataSourceDbo.data.getName());
68
                 DasUtil.getForeignKeys(table).forEach(fk ->
68
                 DasUtil.getForeignKeys(table).forEach(fk ->
69
                 {
69
                 {
70
                     if (fk.getRefTable() == null) {
70
                     if (fk.getRefTable() == null) {
77
                     ForeignKeyDbo fkDbo = new ForeignKeyDbo();
77
                     ForeignKeyDbo fkDbo = new ForeignKeyDbo();
78
                     fkDbo.setName(fk.getName());
78
                     fkDbo.setName(fk.getName());
79
                     fkDbo.setSourceTable(srcTable);
79
                     fkDbo.setSourceTable(srcTable);
80
-                    fkDbo.setSourceForeignKeyName("fk_" + targetTable.getName());//TODO find if it already exists
80
+                    fkDbo.setSourceForeignKeyName(fkDbo.getName());//TODO find if it already exists
81
                     fkDbo.setTargetTable(targetTable);
81
                     fkDbo.setTargetTable(targetTable);
82
-                    fkDbo.setTargetForeignKeyName(srcTable.getName() + "_fk");//TODO find if it already exists
82
+                    fkDbo.setTargetForeignKeyName(fkDbo.getName());//TODO find if it already exists
83
 
83
 
84
                     fk.getColumnsRef().names().forEach(s -> fkDbo.addSourceColumn(srcTable.findColumn(s)));
84
                     fk.getColumnsRef().names().forEach(s -> fkDbo.addSourceColumn(srcTable.findColumn(s)));
85
                     fk.getRefColumns().names().forEach(s -> fkDbo.addTargetColumn(targetTable.findColumn(s)));
85
                     fk.getRefColumns().names().forEach(s -> fkDbo.addTargetColumn(targetTable.findColumn(s)));
87
                     srcTable.addSourceForeignKey(fkDbo);
87
                     srcTable.addSourceForeignKey(fkDbo);
88
                     targetTable.addTargetForeignKey(fkDbo);
88
                     targetTable.addTargetForeignKey(fkDbo);
89
 
89
 
90
-//                    System.out.println("FK: " + fkDbo.getName());
91
                 });
90
                 });
92
             }
91
             }
93
             else if (dasObject instanceof DbColumn) {
92
             else if (dasObject instanceof DbColumn) {
94
                 DbColumn column = (DbColumn) dasObject;
93
                 DbColumn column = (DbColumn) dasObject;
95
                 columnDataSourceDbo.data = tableDataSourceDbo.data.findColumn(column.getName());
94
                 columnDataSourceDbo.data = tableDataSourceDbo.data.findColumn(column.getName());
96
-//                System.out.println("Column: " + columnDataSourceDbo.data.getName());
97
             }
95
             }
98
             else if (dasObject instanceof DbIndex) {
96
             else if (dasObject instanceof DbIndex) {
99
                 DbIndex index = (DbIndex) dasObject;
97
                 DbIndex index = (DbIndex) dasObject;
100
-//                System.out.println("Index: " + index.getName());
101
             }
98
             }
102
             else if (dasObject instanceof DbConstraint) {
99
             else if (dasObject instanceof DbConstraint) {
103
                 DbConstraint constraint = (DbConstraint) dasObject;
100
                 DbConstraint constraint = (DbConstraint) dasObject;
104
-//                System.out.println("Constraint: " + constraint.getName());
105
             }
101
             }
106
             else if (dasObject instanceof DbRoutine) {
102
             else if (dasObject instanceof DbRoutine) {
107
                 DbRoutine sp = (DbRoutine) dasObject;
103
                 DbRoutine sp = (DbRoutine) dasObject;
108
                 StoredProcedureDbo spDbo = new StoredProcedureDbo();
104
                 StoredProcedureDbo spDbo = new StoredProcedureDbo();
109
                 spDbo.setSelected(true);
105
                 spDbo.setSelected(true);
110
-                dataSourceDbo.addStoredProcedure(spDbo);
111
                 spDbo.setName(sp.getName());
106
                 spDbo.setName(sp.getName());
112
-//                System.out.println("SP: " + spDbo.getName());
107
+                spDbo.setFullName(sp.getText());
108
+                dataSourceDbo.addStoredProcedure(spDbo);
113
                 DataHolder<Integer> position = new DataHolder<>();
109
                 DataHolder<Integer> position = new DataHolder<>();
114
                 position.data = 0;
110
                 position.data = 0;
115
                 sp.getArguments().forEach(o ->
111
                 sp.getArguments().forEach(o ->
118
                     sqlTypeDbo.setType(o.getDataType().typeName);
114
                     sqlTypeDbo.setType(o.getDataType().typeName);
119
                     sqlTypeDbo.setVagueArg(o.getDataType().vagueArg);
115
                     sqlTypeDbo.setVagueArg(o.getDataType().vagueArg);
120
 
116
 
121
-                    if (o.getArgumentDirection().isReturnOrResult()) {
117
+                    DasArgument.Direction dir = o.getArgumentDirection();
118
+
119
+
120
+
121
+                    if (dir.isReturnOrResult()) {
122
                         spDbo.setSqlType(sqlTypeDbo);
122
                         spDbo.setSqlType(sqlTypeDbo);
123
-//                        System.out.println("SP return: " + sqlTypeDbo.getType());
124
                     }
123
                     }
125
-                    else {
124
+                    if (dir.isIn()) {
126
                         StoredProcedureArgDbo argDbo = new StoredProcedureArgDbo();
125
                         StoredProcedureArgDbo argDbo = new StoredProcedureArgDbo();
127
                         argDbo.setName(o.getName().isEmpty() ? "arg" + position.data : o.getName());
126
                         argDbo.setName(o.getName().isEmpty() ? "arg" + position.data : o.getName());
128
                         argDbo.setSqlType(sqlTypeDbo);
127
                         argDbo.setSqlType(sqlTypeDbo);
129
                         argDbo.setOut(o.getArgumentDirection().isOut());
128
                         argDbo.setOut(o.getArgumentDirection().isOut());
130
                         spDbo.addArgument(argDbo);
129
                         spDbo.addArgument(argDbo);
131
                         ++position.data;
130
                         ++position.data;
132
-//                        System.out.println("SP arg: " + o.getName());
133
                     }
131
                     }
134
                 });
132
                 });
133
+//                DasArgument arg = sp.getReturnArgument();
134
+//                if (arg != null)
135
+//                    arg.toString();
135
             }
136
             }
136
-//            else {
137
-//                System.out.println(dasObject.getClass().getName());
138
-//            }
139
         });
137
         });
140
         return dataSourceDbo;
138
         return dataSourceDbo;
141
     }
139
     }

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

2
 
2
 
3
 import com.intellij.database.psi.DbDataSource;
3
 import com.intellij.database.psi.DbDataSource;
4
 import com.intellij.openapi.project.Project;
4
 import com.intellij.openapi.project.Project;
5
-import com.rthoni.intellij.codefromds.dbo.options.ColumnSelection;
6
-import com.rthoni.intellij.codefromds.dbo.options.GenerateOptions;
7
-import com.rthoni.intellij.codefromds.dbo.options.TableSelection;
8
-import com.rthoni.intellij.codefromds.dbo.options.TypesCastOptions;
5
+import com.rthoni.intellij.codefromds.dbo.options.*;
9
 import com.rthoni.intellij.codefromds.dbo.template.*;
6
 import com.rthoni.intellij.codefromds.dbo.template.*;
10
 import groovy.json.StringEscapeUtils;
7
 import groovy.json.StringEscapeUtils;
11
 import org.json.JSONArray;
8
 import org.json.JSONArray;
70
         return StringEscapeUtils.escapeJava(str);
67
         return StringEscapeUtils.escapeJava(str);
71
     }
68
     }
72
 
69
 
73
-    public static void convertSqlType(SqlTypeDbo type, TypesCastOptions options)
70
+    public static void convertSqlType(SqlTypeDbo type, TypesCastOptions options, DataSourceDbo dataSourceDbo)
74
     {
71
     {
75
         if (type == null) {
72
         if (type == null) {
76
             return;
73
             return;
77
         }
74
         }
78
         boolean isArray = type.getType().endsWith("[]");
75
         boolean isArray = type.getType().endsWith("[]");
76
+        boolean isSetOf = type.getType().startsWith("setof ");
79
         String sqlTypeName = isArray ? type.getType().substring(0, type.getType().length() - 2) : type.getType();
77
         String sqlTypeName = isArray ? type.getType().substring(0, type.getType().length() - 2) : type.getType();
78
+        if (isSetOf)
79
+        {
80
+            sqlTypeName = sqlTypeName.substring(6);
81
+        }
80
         String typeName = null;
82
         String typeName = null;
81
         HashMap<String, HashMap<String, String>> types = options.getTypes();
83
         HashMap<String, HashMap<String, String>> types = options.getTypes();
82
 
84
 
90
             }
92
             }
91
         }
93
         }
92
         if (typeName == null) {
94
         if (typeName == null) {
93
-            typeName = types.get("*").get("*");
95
+            TableDataSourceDbo table = dataSourceDbo.findTable(sqlTypeName);
96
+            if (table == null) {
97
+                typeName = types.get("*").get("*");
98
+            }
99
+            else {
100
+                typeName = table.getName();
101
+            }
94
         }
102
         }
95
         if (isArray) {
103
         if (isArray) {
96
             typeName = options.getArrayTemplate().replace("%t", typeName);
104
             typeName = options.getArrayTemplate().replace("%t", typeName);
97
         }
105
         }
106
+        if (isSetOf) {
107
+            typeName = options.getSetOfTemplate().replace("%t", typeName);
108
+        }
98
         type.setLanguageType(typeName);
109
         type.setLanguageType(typeName);
99
         type.setLanguageTypeNotNull(options.getNonNullableTypes().contains(typeName));
110
         type.setLanguageTypeNotNull(options.getNonNullableTypes().contains(typeName));
100
     }
111
     }
130
                 ColumnSelection columnSelection = tableSelection.getColumns().stream()
141
                 ColumnSelection columnSelection = tableSelection.getColumns().stream()
131
                         .filter(c -> c.getColumn().getName().equals(column.getName()))
142
                         .filter(c -> c.getColumn().getName().equals(column.getName()))
132
                         .findFirst().orElse(null);
143
                         .findFirst().orElse(null);
133
-                convertSqlType(column.getSqlType(), types);
144
+                convertSqlType(column.getSqlType(), types, dataSourceDbo);
134
                 column.setSelected(columnSelection.isSelected());
145
                 column.setSelected(columnSelection.isSelected());
135
             }
146
             }
136
         }
147
         }
137
 
148
 
138
         for (StoredProcedureDbo spDbo : dataSourceDbo.getStoredProcedures())
149
         for (StoredProcedureDbo spDbo : dataSourceDbo.getStoredProcedures())
139
         {
150
         {
140
-            convertSqlType(spDbo.getSqlType(), types);
151
+            StoredProcedureSelection sp = options.getSelection().getStoredProcedures().stream()
152
+                    .filter(s -> s.getStoredProcedure().getText().equals(spDbo.getFullName()))
153
+                    .findFirst().orElse(null);
154
+            convertSqlType(spDbo.getSqlType(), types, dataSourceDbo);
155
+            spDbo.setSelected(sp.isSelected());
141
             for (StoredProcedureArgDbo arg : spDbo.getArguments()) {
156
             for (StoredProcedureArgDbo arg : spDbo.getArguments()) {
142
-                convertSqlType(arg.getSqlType(), types);
157
+                convertSqlType(arg.getSqlType(), types, dataSourceDbo);
143
             }
158
             }
144
         }
159
         }
145
 
160
 
186
         dbo.setReservedWords(reservedWords);
201
         dbo.setReservedWords(reservedWords);
187
 
202
 
188
         dbo.setArrayTemplate(obj.getString("arrayTemplate"));
203
         dbo.setArrayTemplate(obj.getString("arrayTemplate"));
204
+        dbo.setSetOfTemplate(obj.getString("setOfTemplate"));
189
 
205
 
190
         return dbo;
206
         return dbo;
191
     }
207
     }
205
 
221
 
206
             @Override
222
             @Override
207
             public Object execute(FunctionRequest functionRequest) {
223
             public Object execute(FunctionRequest functionRequest) {
208
-                String arg = (String) functionRequest.get(0);
224
+                Object obj = functionRequest.get(0);
225
+                if (obj == null)
226
+                {
227
+                    return null;
228
+                }
229
+                String arg = (String) obj;
209
                 String v = escapeReservedWords(arg, options);
230
                 String v = escapeReservedWords(arg, options);
210
                 return v;
231
                 return v;
211
             }
232
             }

+ 27
- 11
src/com/rthoni/intellij/codefromds/business/Helper.java View File

1
 package com.rthoni.intellij.codefromds.business;
1
 package com.rthoni.intellij.codefromds.business;
2
 
2
 
3
+import com.intellij.database.model.DasRoutine;
3
 import com.intellij.database.psi.DbDataSource;
4
 import com.intellij.database.psi.DbDataSource;
4
 import com.intellij.database.psi.DbPsiFacade;
5
 import com.intellij.database.psi.DbPsiFacade;
6
+import com.intellij.database.psi.DbRoutine;
5
 import com.intellij.openapi.project.Project;
7
 import com.intellij.openapi.project.Project;
6
 import com.intellij.openapi.project.ProjectManager;
8
 import com.intellij.openapi.project.ProjectManager;
7
 import org.json.JSONArray;
9
 import org.json.JSONArray;
8
 import org.json.JSONObject;
10
 import org.json.JSONObject;
9
 
11
 
12
+import javax.sql.DataSource;
10
 import java.io.IOException;
13
 import java.io.IOException;
11
 import java.nio.charset.StandardCharsets;
14
 import java.nio.charset.StandardCharsets;
12
 import java.nio.file.Files;
15
 import java.nio.file.Files;
15
 import java.util.Arrays;
18
 import java.util.Arrays;
16
 import java.util.Collection;
19
 import java.util.Collection;
17
 import java.util.List;
20
 import java.util.List;
21
+import java.util.Vector;
18
 import java.util.stream.Collectors;
22
 import java.util.stream.Collectors;
19
 
23
 
20
 /**
24
 /**
22
  */
26
  */
23
 public abstract class Helper {
27
 public abstract class Helper {
24
 
28
 
29
+    public static List<DbRoutine> getRoutines(DbDataSource dataSource)
30
+    {
31
+        List<DbRoutine> routines = new Vector<>();
32
+        dataSource.getModel().traverser().forEach(dasObject ->
33
+        {
34
+            if (dasObject instanceof DbRoutine) {
35
+                routines.add((DbRoutine) dasObject);
36
+            }
37
+        });
38
+        return routines;
39
+    }
40
+
25
     public static List<DbDataSource> getDataSources()
41
     public static List<DbDataSource> getDataSources()
26
     {
42
     {
27
         ProjectManager pm = ProjectManager.getInstance();
43
         ProjectManager pm = ProjectManager.getInstance();
35
         return getDataSources().stream().filter(d -> d.getName().equals(name)).findFirst().orElse(null);
51
         return getDataSources().stream().filter(d -> d.getName().equals(name)).findFirst().orElse(null);
36
     }
52
     }
37
 
53
 
38
-    public static JSONObject findTableInJson(JSONArray tables, String name)
54
+    public static JSONObject findInJson(JSONArray tables, String key, String name)
39
     {
55
     {
40
         for (int i = 0; i < tables.length(); ++i) {
56
         for (int i = 0; i < tables.length(); ++i) {
41
-            if (tables.getJSONObject(i).getString("table").equals(name)) {
57
+            if (tables.getJSONObject(i).getString(key).equals(name)) {
42
                 return tables.getJSONObject(i);
58
                 return tables.getJSONObject(i);
43
             }
59
             }
44
         }
60
         }
45
         return null;
61
         return null;
46
     }
62
     }
47
 
63
 
48
-    public static JSONObject findColumnInJson(JSONArray tables, String name)
49
-    {
50
-        for (int i = 0; i < tables.length(); ++i) {
51
-            if (tables.getJSONObject(i).getString("column").equals(name)) {
52
-                return tables.getJSONObject(i);
53
-            }
54
-        }
55
-        return null;
56
-    }
64
+//    public static JSONObject findColumnInJson(JSONArray tables, String name)
65
+//    {
66
+//        for (int i = 0; i < tables.length(); ++i) {
67
+//            if (tables.getJSONObject(i).getString("column").equals(name)) {
68
+//                return tables.getJSONObject(i);
69
+//            }
70
+//        }
71
+//        return null;
72
+//    }
57
 
73
 
58
     public static String readFile(String path) throws IOException {
74
     public static String readFile(String path) throws IOException {
59
         String data = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8)
75
         String data = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8)

+ 27
- 1
src/com/rthoni/intellij/codefromds/dbo/options/DataSourceSelection.java View File

20
 
20
 
21
     private List<TableSelection> _tables;
21
     private List<TableSelection> _tables;
22
 
22
 
23
+    private List<StoredProcedureSelection> _storedProcedures;
24
+
23
     public DataSourceSelection(DbDataSource source) {
25
     public DataSourceSelection(DbDataSource source) {
24
         _source = source;
26
         _source = source;
25
         _tables = DasUtil.getTables(source).toList().stream().map(TableSelection::new).collect(Collectors.toList());
27
         _tables = DasUtil.getTables(source).toList().stream().map(TableSelection::new).collect(Collectors.toList());
28
+        _storedProcedures = Helper.getRoutines(source).stream().map(StoredProcedureSelection::new).collect(Collectors.toList());
26
     }
29
     }
27
 
30
 
28
     public HashMap<String, Object> toMap()
31
     public HashMap<String, Object> toMap()
30
         HashMap<String, Object> map = new HashMap<>();
33
         HashMap<String, Object> map = new HashMap<>();
31
 
34
 
32
         map.put("source", _source == null ? null : _source.getName());
35
         map.put("source", _source == null ? null : _source.getName());
36
+
33
         List<Object> tables = new Vector<>();
37
         List<Object> tables = new Vector<>();
34
         for (TableSelection table : _tables) {
38
         for (TableSelection table : _tables) {
35
             tables.add(table.toMap());
39
             tables.add(table.toMap());
36
         }
40
         }
37
         map.put("tables", tables);
41
         map.put("tables", tables);
38
 
42
 
43
+        List<Object> sps = new Vector<>();
44
+        for (StoredProcedureSelection sp : _storedProcedures) {
45
+            sps.add(sp.toMap());
46
+        }
47
+        map.put("storedProcedures", sps);
48
+
39
         return map;
49
         return map;
40
     }
50
     }
41
 
51
 
43
     {
53
     {
44
         JSONArray array = json.getJSONArray("tables");
54
         JSONArray array = json.getJSONArray("tables");
45
         for (TableSelection table : _tables) {
55
         for (TableSelection table : _tables) {
46
-            JSONObject obj = Helper.findTableInJson(array, table.getTable().getName());
56
+            JSONObject obj = Helper.findInJson(array, "table", table.getTable().getName());
47
             if (obj != null) {
57
             if (obj != null) {
48
                 table.fromJson(obj);
58
                 table.fromJson(obj);
49
             } else {
59
             } else {
52
                 }
62
                 }
53
             }
63
             }
54
         }
64
         }
65
+
66
+        array = json.getJSONArray("storedProcedures");
67
+        for (StoredProcedureSelection sp : _storedProcedures) {
68
+            JSONObject obj = Helper.findInJson(array, "name", sp.getStoredProcedure().getText());
69
+            if (obj != null) {
70
+                sp.fromJson(obj);
71
+            }
72
+        }
55
     }
73
     }
56
 
74
 
57
     public DbDataSource getSource() {
75
     public DbDataSource getSource() {
69
     public void setTables(List<TableSelection> tables) {
87
     public void setTables(List<TableSelection> tables) {
70
         _tables = tables;
88
         _tables = tables;
71
     }
89
     }
90
+
91
+    public List<StoredProcedureSelection> getStoredProcedures() {
92
+        return _storedProcedures;
93
+    }
94
+
95
+    public void setStoredProcedures(List<StoredProcedureSelection> storedProcedures) {
96
+        _storedProcedures = storedProcedures;
97
+    }
72
 }
98
 }

+ 52
- 0
src/com/rthoni/intellij/codefromds/dbo/options/StoredProcedureSelection.java View File

1
+package com.rthoni.intellij.codefromds.dbo.options;
2
+
3
+import com.intellij.database.psi.DbRoutine;
4
+import org.json.JSONObject;
5
+
6
+import java.util.HashMap;
7
+
8
+/**
9
+ * Created by robin on 4/14/17.
10
+ */
11
+public class StoredProcedureSelection {
12
+
13
+    private DbRoutine _storedProcedure;
14
+
15
+    private boolean _isSelected;
16
+
17
+    public StoredProcedureSelection(DbRoutine storedProcedure) {
18
+        _storedProcedure = storedProcedure;
19
+        _isSelected = true;
20
+    }
21
+
22
+    public DbRoutine getStoredProcedure() {
23
+        return _storedProcedure;
24
+    }
25
+
26
+    public void setStoredProcedure(DbRoutine storedProcedure) {
27
+        _storedProcedure = storedProcedure;
28
+    }
29
+
30
+    public boolean isSelected() {
31
+        return _isSelected;
32
+    }
33
+
34
+    public void setSelected(boolean selected) {
35
+        _isSelected = selected;
36
+    }
37
+
38
+    public HashMap<String, Object> toMap()
39
+    {
40
+        HashMap<String, Object> map = new HashMap<>();
41
+
42
+        map.put("name", _storedProcedure == null ? null : _storedProcedure.getText());
43
+        map.put("selected", _isSelected);
44
+
45
+        return map;
46
+    }
47
+
48
+    public void fromJson(JSONObject json)
49
+    {
50
+        _isSelected = json.getBoolean("selected");
51
+    }
52
+}

+ 1
- 1
src/com/rthoni/intellij/codefromds/dbo/options/TableSelection.java View File

44
     {
44
     {
45
         JSONArray array = json.getJSONArray("columns");
45
         JSONArray array = json.getJSONArray("columns");
46
         for (ColumnSelection column : _columns) {
46
         for (ColumnSelection column : _columns) {
47
-            JSONObject obj = Helper.findColumnInJson(array, column.getColumn().getName());
47
+            JSONObject obj = Helper.findInJson(array, "column", column.getColumn().getName());
48
             if (obj != null) {
48
             if (obj != null) {
49
                 column.fromJson(obj);
49
                 column.fromJson(obj);
50
             } else {
50
             } else {

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

10
 
10
 
11
     private String _arrayTemplate;
11
     private String _arrayTemplate;
12
 
12
 
13
+    private String _setOfTemplate;
14
+
13
     private HashMap<String, HashMap<String, String>> _types;
15
     private HashMap<String, HashMap<String, String>> _types;
14
 
16
 
15
     private List<String> _nonNullableTypes;
17
     private List<String> _nonNullableTypes;
47
     public void setReservedWords(List<String> reservedWords) {
49
     public void setReservedWords(List<String> reservedWords) {
48
         _reservedWords = reservedWords;
50
         _reservedWords = reservedWords;
49
     }
51
     }
52
+
53
+    public String getSetOfTemplate() {
54
+        return _setOfTemplate;
55
+    }
56
+
57
+    public void setSetOfTemplate(String setOfTemplate) {
58
+        _setOfTemplate = setOfTemplate;
59
+    }
50
 }
60
 }

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

16
 
16
 
17
     private boolean _isSelected;
17
     private boolean _isSelected;
18
 
18
 
19
+    private String _fullName;
20
+
19
     public String getName() {
21
     public String getName() {
20
         return _name;
22
         return _name;
21
     }
23
     }
51
     public void setSelected(boolean selected) {
53
     public void setSelected(boolean selected) {
52
         _isSelected = selected;
54
         _isSelected = selected;
53
     }
55
     }
56
+
57
+    public String getFullName() {
58
+        return _fullName;
59
+    }
60
+
61
+    public void setFullName(String fullName) {
62
+        _fullName = fullName;
63
+    }
54
 }
64
 }

+ 35
- 6
src/com/rthoni/intellij/codefromds/ui/dialogs/GenerateDialog.java View File

11
 import com.intellij.ui.JBColor;
11
 import com.intellij.ui.JBColor;
12
 import com.intellij.ui.components.JBList;
12
 import com.intellij.ui.components.JBList;
13
 import com.rthoni.intellij.codefromds.business.Helper;
13
 import com.rthoni.intellij.codefromds.business.Helper;
14
-import com.rthoni.intellij.codefromds.dbo.options.ColumnSelection;
15
-import com.rthoni.intellij.codefromds.dbo.options.DataSourceSelection;
16
-import com.rthoni.intellij.codefromds.dbo.options.GenerateOptions;
17
-import com.rthoni.intellij.codefromds.dbo.options.TableSelection;
14
+import com.rthoni.intellij.codefromds.dbo.options.*;
18
 import org.jetbrains.annotations.NotNull;
15
 import org.jetbrains.annotations.NotNull;
19
 import org.jetbrains.annotations.Nullable;
16
 import org.jetbrains.annotations.Nullable;
20
 
17
 
50
     private JLabel _lblModelsTemplatePath;
47
     private JLabel _lblModelsTemplatePath;
51
     private TextFieldWithBrowseButton _textCastFile;
48
     private TextFieldWithBrowseButton _textCastFile;
52
     private JLabel _lblCastFile;
49
     private JLabel _lblCastFile;
50
+    private JBList _listStoredProcedure;
53
 
51
 
54
     private GenerateOptions _options;
52
     private GenerateOptions _options;
55
 
53
 
165
             }
163
             }
166
         });
164
         });
167
 
165
 
166
+        _listStoredProcedure.addListSelectionListener(e -> {
167
+            if (!e.getValueIsAdjusting()) {
168
+                updateSpSelection();
169
+            }
170
+        });
171
+
168
         setupTextField(_textModels, null, true, "Models");
172
         setupTextField(_textModels, null, true, "Models");
169
         setupTextField(_textDataSource, null, false, "Data Source");
173
         setupTextField(_textDataSource, null, false, "Data Source");
170
         setupTextField(_textDataSourceTemplate, null, false, "Data Source Template");
174
         setupTextField(_textDataSourceTemplate, null, false, "Data Source Template");
213
             }
217
             }
214
         });
218
         });
215
 
219
 
220
+        _listStoredProcedure.setCellRenderer(new ColoredListCellRenderer() {
221
+            @Override
222
+            protected void customizeCellRenderer(@NotNull JList jList, Object o, int i, boolean b, boolean b1) {
223
+                StoredProcedureSelection spSelection = _options.getSelection().getStoredProcedures().get(i);
224
+                if (spSelection.isSelected()) {
225
+                    setBackground(JBColor.GREEN);
226
+                }
227
+                else {
228
+                    setBackground(JBColor.RED);
229
+                }
230
+                append(spSelection.getStoredProcedure().getText());
231
+            }
232
+        });
233
+
216
         if (dataSources.size() > 0) {
234
         if (dataSources.size() > 0) {
217
             _listDatasources.setSelectedIndices(new int[]{0});
235
             _listDatasources.setSelectedIndices(new int[]{0});
218
         }
236
         }
264
             else {
282
             else {
265
                 showTable(null);
283
                 showTable(null);
266
             }
284
             }
285
+            List<String> sps = source.getStoredProcedures().stream().map(t -> t.getStoredProcedure().getText()).collect(Collectors.toList());
286
+            _listStoredProcedure.setListData(sps.toArray(new String[sps.size()]));
267
         }
287
         }
268
         else {
288
         else {
269
             _listTables.setListData(new String[]{});
289
             _listTables.setListData(new String[]{});
290
+            _listStoredProcedure.setListData(new String[]{});
270
             showTable(null);
291
             showTable(null);
271
         }
292
         }
272
     }
293
     }
283
         return indices.stream().mapToInt(Integer::intValue).toArray();
304
         return indices.stream().mapToInt(Integer::intValue).toArray();
284
     }
305
     }
285
 
306
 
286
-    private void updateSelection(final TableSelection table)
307
+    private void updateColumnSelection(final TableSelection table)
287
     {
308
     {
288
         List<ColumnSelection> columns = table.getColumns();
309
         List<ColumnSelection> columns = table.getColumns();
289
         for (int i = 0; i < columns.size(); ++i) {
310
         for (int i = 0; i < columns.size(); ++i) {
291
         }
312
         }
292
     }
313
     }
293
 
314
 
315
+    private void updateSpSelection()
316
+    {
317
+        List<StoredProcedureSelection> sps = _options.getSelection().getStoredProcedures();
318
+        for (int i = 0; i < sps.size(); ++i) {
319
+            sps.get(i).setSelected(_listStoredProcedure.isSelectedIndex(i));
320
+        }
321
+    }
322
+
294
     private void showTable(TableSelection table)
323
     private void showTable(TableSelection table)
295
     {
324
     {
296
         for (ListSelectionListener e : _listColumns.getListSelectionListeners()) {
325
         for (ListSelectionListener e : _listColumns.getListSelectionListeners()) {
303
             _listColumns.addListSelectionListener(e -> {
332
             _listColumns.addListSelectionListener(e -> {
304
                 if (!e.getValueIsAdjusting()) {
333
                 if (!e.getValueIsAdjusting()) {
305
                     _listTables.updateUI();
334
                     _listTables.updateUI();
306
-                    updateSelection(table);
335
+                    updateColumnSelection(table);
307
                 }
336
                 }
308
             });
337
             });
309
         }
338
         }

+ 27
- 4
src/com/rthoni/intellij/codefromds/ui/forms/GenerateForm.form View File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.rthoni.intellij.codefromds.ui.dialogs.GenerateDialog">
2
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.rthoni.intellij.codefromds.ui.dialogs.GenerateDialog">
3
-  <grid id="27dc6" binding="_panel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3
+  <grid id="27dc6" binding="_panel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4
     <margin top="0" left="0" bottom="0" right="0"/>
4
     <margin top="0" left="0" bottom="0" right="0"/>
5
     <constraints>
5
     <constraints>
6
-      <xy x="20" y="20" width="934" height="526"/>
6
+      <xy x="20" y="20" width="934" height="652"/>
7
     </constraints>
7
     </constraints>
8
     <properties/>
8
     <properties/>
9
     <border type="none"/>
9
     <border type="none"/>
10
     <children>
10
     <children>
11
       <vspacer id="cffbd">
11
       <vspacer id="cffbd">
12
         <constraints>
12
         <constraints>
13
-          <grid row="3" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
13
+          <grid row="4" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
14
         </constraints>
14
         </constraints>
15
       </vspacer>
15
       </vspacer>
16
       <grid id="6946b" layout-manager="GridLayoutManager" row-count="12" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
16
       <grid id="6946b" layout-manager="GridLayoutManager" row-count="12" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
17
         <margin top="0" left="0" bottom="0" right="0"/>
17
         <margin top="0" left="0" bottom="0" right="0"/>
18
         <constraints>
18
         <constraints>
19
-          <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
19
+          <grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
20
         </constraints>
20
         </constraints>
21
         <properties/>
21
         <properties/>
22
         <border type="none"/>
22
         <border type="none"/>
237
           </scrollpane>
237
           </scrollpane>
238
         </children>
238
         </children>
239
       </grid>
239
       </grid>
240
+      <grid id="484d8" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
241
+        <margin top="0" left="0" bottom="0" right="0"/>
242
+        <constraints>
243
+          <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
244
+        </constraints>
245
+        <properties/>
246
+        <border type="none" title="Select Stored Procedures To Map"/>
247
+        <children>
248
+          <scrollpane id="705ec">
249
+            <constraints>
250
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
251
+            </constraints>
252
+            <properties/>
253
+            <border type="none"/>
254
+            <children>
255
+              <component id="77e75" class="com.intellij.ui.components.JBList" binding="_listStoredProcedure">
256
+                <constraints/>
257
+                <properties/>
258
+              </component>
259
+            </children>
260
+          </scrollpane>
261
+        </children>
262
+      </grid>
240
     </children>
263
     </children>
241
   </grid>
264
   </grid>
242
 </form>
265
 </form>

Loading…
Cancel
Save