Browse Source

refactor dbo build

develop
Robin Thoni 7 years ago
parent
commit
60469ec8c5

+ 7
- 0
.idea/kotlinc.xml View File

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="KotlinCommonCompilerArguments">
4
+    <option name="languageVersion" value="1.1" />
5
+    <option name="apiVersion" value="1.1" />
6
+  </component>
7
+</project>

+ 1
- 11
.idea/misc.xml View File

@@ -3,17 +3,7 @@
3 3
   <component name="EntryPointsManager">
4 4
     <entry_points version="2.0" />
5 5
   </component>
6
-  <component name="ProjectLevelVcsManager" settingsEditedManually="false">
7
-    <OptionsSetting value="true" id="Add" />
8
-    <OptionsSetting value="true" id="Remove" />
9
-    <OptionsSetting value="true" id="Checkout" />
10
-    <OptionsSetting value="true" id="Update" />
11
-    <OptionsSetting value="true" id="Status" />
12
-    <OptionsSetting value="true" id="Edit" />
13
-    <ConfirmationsSetting value="0" id="Add" />
14
-    <ConfirmationsSetting value="0" id="Remove" />
15
-  </component>
16
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="IntelliJ IDEA IU-162.2032.8" project-jdk-type="IDEA JDK">
6
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="IntelliJ IDEA IU-162.2032.8" project-jdk-type="IDEA JDK">
17 7
     <output url="file://$PROJECT_DIR$/out" />
18 8
   </component>
19 9
 </project>

+ 119
- 0
src/com/rthoni/intellij/codefromds/DataAccess/DataSourcesDataAccess.java View File

@@ -0,0 +1,119 @@
1
+package com.rthoni.intellij.codefromds.DataAccess;
2
+
3
+import com.intellij.database.psi.*;
4
+import com.intellij.database.util.DasUtil;
5
+import com.rthoni.intellij.codefromds.business.Helper;
6
+import com.rthoni.intellij.codefromds.dbo.template.*;
7
+
8
+import java.util.List;
9
+import java.util.stream.Collectors;
10
+
11
+/**
12
+ * Created by robin on 4/13/17.
13
+ */
14
+public class DataSourcesDataAccess {
15
+
16
+    public static List<DataSourceDbo> getDataSourcesDbo()
17
+    {
18
+        return Helper.getDataSources().stream()
19
+                .map(DataSourcesDataAccess::dataSourceToDbo)
20
+                .collect(Collectors.toList());
21
+    }
22
+
23
+    public static DataSourceDbo getDataSourceDbo(String name)
24
+    {
25
+        return Helper.getDataSources().stream()
26
+                .filter(dataSource -> dataSource.getName().equals(name))
27
+                .map(DataSourcesDataAccess::dataSourceToDbo)
28
+                .findFirst().orElse(null);
29
+    }
30
+
31
+    private static DataSourceDbo dataSourceToDbo(DbDataSource dataSource)
32
+    {
33
+        DataSourceDbo dataSourceDbo = new DataSourceDbo();
34
+        dataSourceDbo.setName(dataSource.getName());
35
+
36
+        final DataHolder<TableDataSourceDbo> tableDataSourceDbo = new DataHolder<>();
37
+        final DataHolder<ColumnDataSourceDbo> columnDataSourceDbo = new DataHolder<>();
38
+
39
+        dataSource.getModel().traverser().forEach(dasObject ->
40
+        {
41
+            if (dasObject instanceof DbTable) {
42
+                DbTable table = (DbTable) dasObject;
43
+                tableDataSourceDbo.data = new TableDataSourceDbo();
44
+                tableDataSourceDbo.data.setName(table.getName());
45
+                dataSourceDbo.addTable(tableDataSourceDbo.data);
46
+            }
47
+            else if (dasObject instanceof DbColumn) {
48
+                DbColumn column = (DbColumn) dasObject;
49
+                columnDataSourceDbo.data = new ColumnDataSourceDbo();
50
+                columnDataSourceDbo.data.setName(column.getName());
51
+                columnDataSourceDbo.data.setNotNull(column.isNotNull());
52
+                SqlTypeDbo type = new SqlTypeDbo();
53
+                type.setType(column.getDataType().typeName);
54
+                type.setVagueArg(column.getDataType().vagueArg);
55
+                columnDataSourceDbo.data.setSqlType(type);
56
+                columnDataSourceDbo.data.setDefaultValue(column.getDefault());
57
+                columnDataSourceDbo.data.setPrimary(DasUtil.isPrimary(column));
58
+                columnDataSourceDbo.data.setSelected(false);
59
+                columnDataSourceDbo.data.setTypeNotNull(false);
60
+                columnDataSourceDbo.data.setType(null);
61
+                tableDataSourceDbo.data.addColumn(columnDataSourceDbo.data);
62
+            }
63
+        });
64
+
65
+        dataSource.getModel().traverser().forEach(dasObject ->
66
+        {
67
+            if (dasObject instanceof DbTable) {
68
+                DbTable table = (DbTable) dasObject;
69
+                tableDataSourceDbo.data = dataSourceDbo.findTable(table.getName());
70
+                System.out.println("Table: " + tableDataSourceDbo.data.getName());
71
+                DasUtil.getForeignKeys(table).forEach(fk ->
72
+                {
73
+                    if (fk.getRefTable() == null) {
74
+                        return;
75
+                    }
76
+
77
+                    TableDataSourceDbo srcTable = dataSourceDbo.findTable(fk.getTable().getName());
78
+                    TableDataSourceDbo targetTable = dataSourceDbo.findTable(fk.getRefTable().getName());
79
+
80
+                    ForeignKeyDbo fkDbo = new ForeignKeyDbo();
81
+                    fkDbo.setName(fk.getName());
82
+                    fkDbo.setSourceTable(srcTable);
83
+                    fkDbo.setSourceForeignKeyName("fk_" + targetTable.getName());//TODO find if it already exists
84
+                    fkDbo.setTargetTable(targetTable);
85
+                    fkDbo.setTargetForeignKeyName(srcTable.getName() + "_fk");//TODO find if it already exists
86
+
87
+                    fk.getColumnsRef().names().forEach(s -> fkDbo.addSourceColumn(srcTable.findColumn(s)));
88
+                    fk.getRefColumns().names().forEach(s -> fkDbo.addTargetColumn(targetTable.findColumn(s)));
89
+
90
+                    srcTable.addSourceForeignKey(fkDbo);
91
+                    targetTable.addTargetForeignKey(fkDbo);
92
+
93
+                    System.out.println("FK: " + fkDbo.getName());
94
+                });
95
+            }
96
+            else if (dasObject instanceof DbColumn) {
97
+                DbColumn column = (DbColumn) dasObject;
98
+                columnDataSourceDbo.data = tableDataSourceDbo.data.findColumn(column.getName());
99
+                System.out.println("Column: " + columnDataSourceDbo.data.getName());
100
+            }
101
+            else if (dasObject instanceof DbIndex) {
102
+                DbIndex index = (DbIndex) dasObject;
103
+                System.out.println("Index: " + index.getName());
104
+            }
105
+            else if (dasObject instanceof DbConstraint) {
106
+                DbConstraint constraint = (DbConstraint) dasObject;
107
+                System.out.println("Constraint: " + constraint.getName());
108
+            }
109
+            else if (dasObject instanceof DbRoutine) {
110
+                DbRoutine sp = (DbRoutine) dasObject;
111
+                System.out.println("SP: " + sp.getName());
112
+            }
113
+            else {
114
+                System.out.println(dasObject.getClass().getName());
115
+            }
116
+        });
117
+        return dataSourceDbo;
118
+    }
119
+}

+ 23
- 0
src/com/rthoni/intellij/codefromds/business/DataSourcesBusiness.java View File

@@ -0,0 +1,23 @@
1
+package com.rthoni.intellij.codefromds.business;
2
+
3
+import com.rthoni.intellij.codefromds.DataAccess.DataSourcesDataAccess;
4
+import com.rthoni.intellij.codefromds.dbo.template.DataSourceDbo;
5
+
6
+import java.util.List;
7
+
8
+/**
9
+ * Created by robin on 4/12/17.
10
+ */
11
+public class DataSourcesBusiness {
12
+
13
+    public static List<DataSourceDbo> getDataSourcesDbo()
14
+    {
15
+        return DataSourcesDataAccess.getDataSourcesDbo();
16
+    }
17
+
18
+    public static DataSourceDbo getDataSourceDbo(String name)
19
+    {
20
+        return DataSourcesDataAccess.getDataSourceDbo(name);
21
+    }
22
+
23
+}

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

@@ -1,10 +1,6 @@
1 1
 package com.rthoni.intellij.codefromds.business;
2 2
 
3
-import com.intellij.database.model.DasForeignKey;
4
-import com.intellij.database.model.DataType;
5
-import com.intellij.database.model.MultiRef;
6 3
 import com.intellij.database.psi.DbDataSource;
7
-import com.intellij.database.util.DasUtil;
8 4
 import com.intellij.openapi.project.Project;
9 5
 import com.rthoni.intellij.codefromds.dbo.options.ColumnSelection;
10 6
 import com.rthoni.intellij.codefromds.dbo.options.GenerateOptions;
@@ -12,7 +8,7 @@ import com.rthoni.intellij.codefromds.dbo.options.TableSelection;
12 8
 import com.rthoni.intellij.codefromds.dbo.options.TypesCastOptions;
13 9
 import com.rthoni.intellij.codefromds.dbo.template.ColumnDataSourceDbo;
14 10
 import com.rthoni.intellij.codefromds.dbo.template.DataSourceDbo;
15
-import com.rthoni.intellij.codefromds.dbo.template.ForeignKeyDbo;
11
+import com.rthoni.intellij.codefromds.dbo.template.SqlTypeDbo;
16 12
 import com.rthoni.intellij.codefromds.dbo.template.TableDataSourceDbo;
17 13
 import org.json.JSONArray;
18 14
 import org.json.JSONObject;
@@ -25,8 +21,6 @@ import java.io.IOException;
25 21
 import java.util.HashMap;
26 22
 import java.util.List;
27 23
 import java.util.Vector;
28
-import java.util.stream.Collectors;
29
-import java.util.stream.StreamSupport;
30 24
 
31 25
 /**
32 26
  * Created by robin on 11/15/16.
@@ -60,38 +54,17 @@ public abstract class Generator {
60 54
         return options;
61 55
     }
62 56
 
63
-    public static ForeignKeyDbo convertForeignKey(DasForeignKey fk, DataSourceDbo source)
57
+    public static String convertSqlType(SqlTypeDbo type, TypesCastOptions options)
64 58
     {
65
-        ForeignKeyDbo dbo = new ForeignKeyDbo();
66
-
67
-        dbo.setName(fk.getName());
68
-
69
-        dbo.setSourceForeignKeyName("fk_" + fk.getRefTable().getName());
70
-        dbo.setSourceTable(source.getTables().stream().filter(t -> t.getName().equals(fk.getTable().getName())).findFirst().get());
71
-        MultiRef columnsRef = fk.getColumnsRef();
72
-        dbo.setSourceColumns(dbo.getSourceTable().getColumns().stream().filter(c -> StreamSupport.stream(columnsRef.names().spliterator(), false).anyMatch(cc -> cc.equals(c.getName()))).collect(Collectors.toList()));
73
-
74
-        dbo.setTargetForeignKeyName(fk.getTable().getName() + "_fk");
75
-        dbo.setTargetTable(source.getTables().stream().filter(t -> t.getName().equals(fk.getRefTable().getName())).findFirst().get());
76
-        MultiRef refColumns = fk.getRefColumns();
77
-        dbo.setTargetColumns(dbo.getTargetTable().getColumns().stream().filter(c -> StreamSupport.stream(refColumns.names().spliterator(), false).anyMatch(cc -> cc.equals(c.getName()))).collect(Collectors.toList()));
78
-
79
-        dbo.getTargetTable().getTargetForeignKeys().add(dbo);
80
-
81
-        return dbo;
82
-    }
83
-
84
-    public static String convertSqlType(DataType type, TypesCastOptions options)
85
-    {
86
-        boolean isArray = type.typeName.endsWith("[]");
87
-        String sqlTypeName = isArray ? type.typeName.substring(0, type.typeName.length() - 2) : type.typeName;
88
-        String typeName = type.typeName;
59
+        boolean isArray = type.getType().endsWith("[]");
60
+        String sqlTypeName = isArray ? type.getType().substring(0, type.getType().length() - 2) : type.getType();
61
+        String typeName = type.getType();
89 62
         HashMap<String, HashMap<String, String>> types = options.getTypes();
90 63
 
91 64
         if (types.containsKey(sqlTypeName)) {
92 65
             HashMap<String, String> subtype = types.get(sqlTypeName);
93
-            if (subtype.containsKey(type.vagueArg)) {
94
-                typeName = subtype.get(type.vagueArg);
66
+            if (subtype.containsKey(type.getVagueArg())) {
67
+                typeName = subtype.get(type.getVagueArg());
95 68
             }
96 69
             else if (subtype.containsKey("*")) {
97 70
                 typeName = subtype.get("*");
@@ -102,48 +75,45 @@ public abstract class Generator {
102 75
         }
103 76
         return typeName;
104 77
     }
105
-
106
-    public static ColumnDataSourceDbo convertColumn(ColumnSelection columnSelection, TypesCastOptions options)
107
-    {
108
-        ColumnDataSourceDbo dbo = new ColumnDataSourceDbo();
109
-        dbo.setName(columnSelection.getColumn().getName());
110
-        dbo.setPrimary(DasUtil.isPrimary(columnSelection.getColumn()));
111
-        dbo.setSelected(columnSelection.isSelected());
112
-        dbo.setNotNull(columnSelection.getColumn().isNotNull());
113
-        dbo.setType(convertSqlType(columnSelection.getColumn().getDataType(), options));
114
-        dbo.setTypeNotNull(options.getNonNullableTypes().contains(dbo.getType()));
115
-        dbo.setDefaultValue(columnSelection.getColumn().getDefault());
116
-
117
-        return dbo;
118
-    }
119
-
120
-    public static TableDataSourceDbo convertTable(TableSelection tableSelection, TypesCastOptions types)
121
-    {
122
-        TableDataSourceDbo dbo = new TableDataSourceDbo();
123
-        dbo.setName(tableSelection.getTable().getName());
124
-        dbo.setColumns(tableSelection.getColumns().stream().map(c -> convertColumn(c, types)).collect(Collectors.toList()));
125
-        dbo.setPrimaryKeys(dbo.getColumns().stream().filter(ColumnDataSourceDbo::isPrimary).collect(Collectors.toList()));
126
-        dbo.setHasAny(!tableSelection.hasNone());
127
-        dbo.setTargetForeignKeys(new Vector<>());
128
-        return dbo;
129
-    }
78
+//
79
+//    public static boolean isUnionSame(List<ColumnDataSourceDbo> part1, List<ColumnDataSourceDbo> part2, List<ColumnDataSourceDbo> list2)
80
+//    {
81
+//        List<ColumnDataSourceDbo> list1 = new Vector<>(part1);
82
+//        for (ColumnDataSourceDbo col : part2) {
83
+//            if (!list1.contains(col)) {
84
+//                list1.add(col);
85
+//            }
86
+//        }
87
+//        if (list1.size() != list2.size()) {
88
+//            return false;
89
+//        }
90
+//        list1.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
91
+//        list2.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
92
+//        return list1.equals(list2);
93
+//    }
130 94
 
131 95
     public static DataSourceDbo convertOptions(GenerateOptions options, TypesCastOptions types)
132 96
     {
133
-        DataSourceDbo dbo = new DataSourceDbo();
134
-
135
-        dbo.setName(options.getSelection().getSource().getName());
136
-        dbo.setTables(options.getSelection().getTables().stream().map(t -> convertTable(t, types)).collect(Collectors.toList()));
137
-
138
-        List<TableDataSourceDbo> tables = dbo.getTables();
139
-        List<TableSelection> tableSelections = options.getSelection().getTables();
140
-        for (int i = 0; i < tables.size(); ++i) {
141
-            TableDataSourceDbo table = tables.get(i);
142
-            TableSelection tableSelection = tableSelections.get(i);
143
-            table.setSourceForeignKeys(DasUtil.getForeignKeys(tableSelection.getTable()).toList().stream().map(t -> convertForeignKey(t, dbo)).collect(Collectors.toList()));
97
+        String dataSourceName = options.getSelection().getSource().getName();
98
+        DataSourceDbo dataSourceDbo = DataSourcesBusiness.getDataSourceDbo(dataSourceName);
99
+
100
+        for (TableDataSourceDbo table : dataSourceDbo.getTables())
101
+        {
102
+            TableSelection tableSelection = options.getSelection().getTables().stream()
103
+                    .filter(t -> t.getTable().getName().equals(table.getName()))
104
+                    .findFirst().orElse(null);
105
+            for (ColumnDataSourceDbo column : table.getColumns())
106
+            {
107
+                ColumnSelection columnSelection = tableSelection.getColumns().stream()
108
+                        .filter(c -> c.getColumn().getName().equals(column.getName()))
109
+                        .findFirst().orElse(null);
110
+                column.setType(convertSqlType(column.getSqlType(), types));
111
+                column.setTypeNotNull(types.getNonNullableTypes().contains(column.getType()));
112
+                column.setSelected(columnSelection.isSelected());
113
+            }
144 114
         }
145 115
 
146
-        return dbo;
116
+        return dataSourceDbo;
147 117
     }
148 118
 
149 119
     public static TypesCastOptions loadTypesCast(String file) throws IOException
@@ -199,20 +169,22 @@ public abstract class Generator {
199 169
 
200 170
     public static void generate(GenerateOptions options, Project project) throws IOException
201 171
     {
172
+        DataSourcesBusiness.getDataSourcesDbo();
202 173
         String modelsAbsolutePath = Helper.getAbsolutePath(project, options.getModelsRelativePath());
203 174
         String dataSourceTemplateAbsolutePath = Helper.getAbsolutePath(project, options.getDataSourceTemplateRelativePath());
204 175
         String modelsTemplateAbsolutePath = Helper.getAbsolutePath(project, options.getModelsTemplateRelativePath());
205 176
         String typesCastAbsolutePath = Helper.getAbsolutePath(project, options.getCastFileRelativePath());
177
+        String dataSourceAbsolutePath = Helper.getAbsolutePath(project, options.getDataSourceRelativePath());
206 178
 
207 179
         TypesCastOptions types = loadTypesCast(typesCastAbsolutePath);
208 180
 
209 181
         DataSourceDbo dbo = convertOptions(options, types);
210 182
 
211
-        generateFile(dataSourceTemplateAbsolutePath, Helper.getAbsolutePath(project, options.getDataSourceRelativePath()), dbo, null);
183
+        generateFile(dataSourceTemplateAbsolutePath, dataSourceAbsolutePath, dbo, null);
212 184
         for (TableDataSourceDbo table : dbo.getTables()) {
213 185
             if (table.hasAny()) {
214
-                generateFile(modelsTemplateAbsolutePath, modelsAbsolutePath + File.separator +
215
-                        table.getName() + "." + options.getFilesExtension(), dbo, table);
186
+                String filename = modelsAbsolutePath + File.separator + table.getName() + "." + options.getFilesExtension();
187
+                generateFile(modelsTemplateAbsolutePath, filename, dbo, table);
216 188
             }
217 189
         }
218 190
     }

+ 1
- 6
src/com/rthoni/intellij/codefromds/business/Helper.java View File

@@ -15,7 +15,6 @@ import java.nio.file.Paths;
15 15
 import java.util.Arrays;
16 16
 import java.util.Collection;
17 17
 import java.util.List;
18
-import java.util.Optional;
19 18
 import java.util.stream.Collectors;
20 19
 
21 20
 /**
@@ -33,11 +32,7 @@ public abstract class Helper {
33 32
 
34 33
     public static DbDataSource findDataSource(String name)
35 34
     {
36
-        Optional<DbDataSource> opt = getDataSources().stream().filter(d -> d.getName().equals(name)).findFirst();
37
-        if (opt.isPresent()) {
38
-            return opt.get();
39
-        }
40
-        return null;
35
+        return getDataSources().stream().filter(d -> d.getName().equals(name)).findFirst().orElse(null);
41 36
     }
42 37
 
43 38
     public static JSONObject findTableInJson(JSONArray tables, String name)

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

@@ -15,6 +15,8 @@ public class ColumnDataSourceDbo {
15 15
 
16 16
     private String _type;
17 17
 
18
+    private SqlTypeDbo _sqlType;
19
+
18 20
     private boolean _notNull;
19 21
 
20 22
     private boolean _typeNotNull;
@@ -53,6 +55,14 @@ public class ColumnDataSourceDbo {
53 55
         _type = type;
54 56
     }
55 57
 
58
+    public SqlTypeDbo getSqlType() {
59
+        return _sqlType;
60
+    }
61
+
62
+    public void setSqlType(SqlTypeDbo sqlType) {
63
+        _sqlType = sqlType;
64
+    }
65
+
56 66
     public boolean isNotNull() {
57 67
         return _notNull;
58 68
     }

+ 8
- 0
src/com/rthoni/intellij/codefromds/dbo/template/DataHolder.java View File

@@ -0,0 +1,8 @@
1
+package com.rthoni.intellij.codefromds.dbo.template;
2
+
3
+/**
4
+ * Created by robin on 4/13/17.
5
+ */
6
+public class DataHolder<T> {
7
+    public T data;
8
+}

+ 14
- 3
src/com/rthoni/intellij/codefromds/dbo/template/DataSourceDbo.java View File

@@ -1,6 +1,7 @@
1 1
 package com.rthoni.intellij.codefromds.dbo.template;
2 2
 
3 3
 import java.util.List;
4
+import java.util.Vector;
4 5
 
5 6
 /**
6 7
  * Created by robin on 11/18/16.
@@ -9,7 +10,7 @@ public class DataSourceDbo {
9 10
 
10 11
     private String _name;
11 12
 
12
-    private List<TableDataSourceDbo> _tables;
13
+    private List<TableDataSourceDbo> _tables = new Vector<>();
13 14
 
14 15
     public String getName() {
15 16
         return _name;
@@ -23,7 +24,17 @@ public class DataSourceDbo {
23 24
         return _tables;
24 25
     }
25 26
 
26
-    public void setTables(List<TableDataSourceDbo> tables) {
27
-        _tables = tables;
27
+    public void addTable(TableDataSourceDbo table) {
28
+        _tables.add(table);
29
+    }
30
+
31
+    public TableDataSourceDbo findTable(String name)
32
+    {
33
+        for (TableDataSourceDbo table : _tables) {
34
+            if (table.getName().equals(name)) {
35
+                return table;
36
+            }
37
+        }
38
+        return null;
28 39
     }
29 40
 }

+ 59
- 6
src/com/rthoni/intellij/codefromds/dbo/template/ForeignKeyDbo.java View File

@@ -1,6 +1,7 @@
1 1
 package com.rthoni.intellij.codefromds.dbo.template;
2 2
 
3 3
 import java.util.List;
4
+import java.util.Vector;
4 5
 
5 6
 /**
6 7
  * Created by robin on 11/18/16.
@@ -9,17 +10,25 @@ public class ForeignKeyDbo {
9 10
 
10 11
     private TableDataSourceDbo _sourceTable;
11 12
 
12
-    private List<ColumnDataSourceDbo> _sourceColumns;
13
+    private List<ColumnDataSourceDbo> _sourceColumns = new Vector<>();
13 14
 
14 15
     private TableDataSourceDbo _targetTable;
15 16
 
16
-    private List<ColumnDataSourceDbo> _targetColumns;
17
+    private List<ColumnDataSourceDbo> _targetColumns = new Vector<>();
17 18
 
18 19
     private String _sourceForeignKeyName;
19 20
 
20 21
     private String _targetForeignKeyName;
21 22
 
22 23
     private String _name;
24
+//
25
+//    private ForeignKeyDbo _other;
26
+//
27
+//    private boolean _isOneToOne;
28
+//
29
+//    private boolean _isOneToMany;
30
+//
31
+//    private boolean _isManyToMany;
23 32
 
24 33
     public TableDataSourceDbo getSourceTable() {
25 34
         return _sourceTable;
@@ -39,8 +48,8 @@ public class ForeignKeyDbo {
39 48
         return _sourceColumns;
40 49
     }
41 50
 
42
-    public void setSourceColumns(List<ColumnDataSourceDbo> sourceColumns) {
43
-        _sourceColumns = sourceColumns;
51
+    public void addSourceColumn(ColumnDataSourceDbo sourceColumns) {
52
+        _sourceColumns.add(sourceColumns);
44 53
     }
45 54
 
46 55
     public TableDataSourceDbo getTargetTable() {
@@ -55,8 +64,8 @@ public class ForeignKeyDbo {
55 64
         return _targetColumns;
56 65
     }
57 66
 
58
-    public void setTargetColumns(List<ColumnDataSourceDbo> targetColumns) {
59
-        _targetColumns = targetColumns;
67
+    public void addTargetColumn(ColumnDataSourceDbo targetColumns) {
68
+        _targetColumns.add(targetColumns);
60 69
     }
61 70
 
62 71
     public String getSourceForeignKeyName() {
@@ -82,4 +91,48 @@ public class ForeignKeyDbo {
82 91
     public void setName(String name) {
83 92
         _name = name;
84 93
     }
94
+
95
+//    public boolean isOneToOne() {
96
+//        return _isOneToOne;
97
+//    }
98
+//
99
+//    public void setOneToOne(boolean oneToOne) {
100
+//        _isOneToOne = oneToOne;
101
+//        if (_isOneToOne) {
102
+//            _isOneToMany = true;
103
+//            _isManyToMany = false;
104
+//        }
105
+//    }
106
+//
107
+//    public boolean isOneToMany() {
108
+//        return _isOneToMany;
109
+//    }
110
+//
111
+//    public void setOneToMany(boolean oneToMany) {
112
+//        _isOneToMany = oneToMany;
113
+//        if (_isOneToMany) {
114
+//            _isOneToOne = true;
115
+//            _isManyToMany = false;
116
+//        }
117
+//    }
118
+//
119
+//    public boolean isManyToMany() {
120
+//        return _isManyToMany;
121
+//    }
122
+//
123
+//    public void setManyToMany(boolean manyToMany) {
124
+//        _isManyToMany = manyToMany;
125
+//        if (_isManyToMany) {
126
+//            _isOneToOne = true;
127
+//            _isOneToMany = false;
128
+//        }
129
+//    }
130
+//
131
+//    public ForeignKeyDbo getOther() {
132
+//        return _other;
133
+//    }
134
+//
135
+//    public void setOther(ForeignKeyDbo other) {
136
+//        _other = other;
137
+//    }
85 138
 }

+ 27
- 0
src/com/rthoni/intellij/codefromds/dbo/template/SqlTypeDbo.java View File

@@ -0,0 +1,27 @@
1
+package com.rthoni.intellij.codefromds.dbo.template;
2
+
3
+/**
4
+ * Created by robin on 4/13/17.
5
+ */
6
+public class SqlTypeDbo {
7
+
8
+    private String _type;
9
+
10
+    private String vagueArg;
11
+
12
+    public String getType() {
13
+        return _type;
14
+    }
15
+
16
+    public void setType(String type) {
17
+        _type = type;
18
+    }
19
+
20
+    public String getVagueArg() {
21
+        return vagueArg;
22
+    }
23
+
24
+    public void setVagueArg(String vagueArg) {
25
+        this.vagueArg = vagueArg;
26
+    }
27
+}

+ 28
- 22
src/com/rthoni/intellij/codefromds/dbo/template/TableDataSourceDbo.java View File

@@ -1,22 +1,21 @@
1 1
 package com.rthoni.intellij.codefromds.dbo.template;
2 2
 
3 3
 import java.util.List;
4
+import java.util.Vector;
5
+import java.util.stream.Collectors;
4 6
 
5 7
 /**
6 8
  * Created by robin on 11/18/16.
7 9
  */
8 10
 public class TableDataSourceDbo {
9
-    private String _name;
10
-
11
-    private List<ColumnDataSourceDbo> _columns;
12 11
 
13
-    private List<ColumnDataSourceDbo> _primaryKeys;
12
+    private String _name;
14 13
 
15
-    private List<ForeignKeyDbo> _sourceForeignKeys;
14
+    private List<ColumnDataSourceDbo> _columns = new Vector<>();
16 15
 
17
-    private List<ForeignKeyDbo> _targetForeignKeys;
16
+    private List<ForeignKeyDbo> _sourceForeignKeys = new Vector<>();
18 17
 
19
-    private boolean _hasAny;
18
+    private List<ForeignKeyDbo> _targetForeignKeys = new Vector<>();
20 19
 
21 20
     public String getName() {
22 21
         return _name;
@@ -30,39 +29,46 @@ public class TableDataSourceDbo {
30 29
         return _columns;
31 30
     }
32 31
 
33
-    public void setColumns(List<ColumnDataSourceDbo> columns) {
34
-        _columns = columns;
32
+    public void addColumn(ColumnDataSourceDbo column) {
33
+        _columns.add(column);
35 34
     }
36 35
 
37
-    public List<ColumnDataSourceDbo> getPrimaryKeys() {
38
-        return _primaryKeys;
36
+    public ColumnDataSourceDbo findColumn(String name)
37
+    {
38
+        for (ColumnDataSourceDbo column : _columns) {
39
+            if (column.getName().equals(name)) {
40
+                return column;
41
+            }
42
+        }
43
+        return null;
39 44
     }
40 45
 
41
-    public void setPrimaryKeys(List<ColumnDataSourceDbo> primaryKeys) {
42
-        _primaryKeys = primaryKeys;
46
+    public List<ColumnDataSourceDbo> getPrimaryKeys() {
47
+        return _columns.stream().filter(ColumnDataSourceDbo::isPrimary).collect(Collectors.toList());
43 48
     }
44 49
 
45 50
     public boolean hasAny() {
46
-        return _hasAny;
47
-    }
48
-
49
-    public void setHasAny(boolean hasAny) {
50
-        _hasAny = hasAny;
51
+        for (ColumnDataSourceDbo column : _columns) {
52
+            if (column.isSelected()) {
53
+                return true;
54
+            }
55
+        }
56
+        return false;
51 57
     }
52 58
 
53 59
     public List<ForeignKeyDbo> getSourceForeignKeys() {
54 60
         return _sourceForeignKeys;
55 61
     }
56 62
 
57
-    public void setSourceForeignKeys(List<ForeignKeyDbo> sourceForeignKeys) {
58
-        _sourceForeignKeys = sourceForeignKeys;
63
+    public void addSourceForeignKey(ForeignKeyDbo sourceForeignKeys) {
64
+        _sourceForeignKeys.add(sourceForeignKeys);
59 65
     }
60 66
 
61 67
     public List<ForeignKeyDbo> getTargetForeignKeys() {
62 68
         return _targetForeignKeys;
63 69
     }
64 70
 
65
-    public void setTargetForeignKeys(List<ForeignKeyDbo> targetForeignKeys) {
66
-        _targetForeignKeys = targetForeignKeys;
71
+    public void addTargetForeignKey(ForeignKeyDbo targetForeignKeys) {
72
+        _targetForeignKeys.add(targetForeignKeys);
67 73
     }
68 74
 }

Loading…
Cancel
Save