Skip to content

Commit c1f3306

Browse files
committed
Changing access level of tablesmap
1 parent 9fa1004 commit c1f3306

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

src/main/java/io/github/ngbsn/generator/AssociationMappingsGenerator.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
import java.util.Map;
1010
import java.util.Optional;
1111

12-
import static io.github.ngbsn.generator.ModelGenerator.tablesMap;
1312
import static io.github.ngbsn.generator.UniDirectionalMappingsGenerator.addBothSideUniDirectionalMappings;
1413

1514
/**
16-
* This class contains logic for generating all the association mappings
15+
* Generate both UniDirectional and BiDirectional association mappings for all tables
1716
*/
18-
public class AssociationMappingsGenerator {
17+
class AssociationMappingsGenerator {
1918

2019

2120
private AssociationMappingsGenerator() {
@@ -24,8 +23,8 @@ private AssociationMappingsGenerator() {
2423
/**
2524
* Generate both UniDirectional and BiDirectional association mappings for all tables
2625
*/
27-
public static void generateMappings() {
28-
Iterator<Map.Entry<String, Table>> it = tablesMap.entrySet().iterator();
26+
static void generateMappings() {
27+
Iterator<Map.Entry<String, Table>> it = ModelGenerator.getTablesMap().entrySet().iterator();
2928
while (it.hasNext()) {
3029
Map.Entry<String, Table> item = it.next();
3130
Table table = item.getValue();

src/main/java/io/github/ngbsn/generator/BiDirectionalMappingsGenerator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import java.util.List;
1313
import java.util.Set;
1414

15-
import static io.github.ngbsn.generator.ModelGenerator.tablesMap;
16-
17-
public class BiDirectionalMappingsGenerator {
15+
/**
16+
* Generate BiDirectional Mappings (many-to-many) for a specific table
17+
*/
18+
class BiDirectionalMappingsGenerator {
1819

1920
private BiDirectionalMappingsGenerator() {
2021
}
@@ -25,8 +26,8 @@ private BiDirectionalMappingsGenerator() {
2526
* @param foreignKeyConstraintList List of generated foreignKeyConstraintList models
2627
*/
2728
static void addBiDirectionalMappings(Table table, List<ForeignKeyConstraint> foreignKeyConstraintList) {
28-
Table table1 = tablesMap.get(foreignKeyConstraintList.get(0).getReferencedTableName().replaceAll("[\"']", ""));
29-
Table table2 = tablesMap.get(foreignKeyConstraintList.get(1).getReferencedTableName().replaceAll("[\"']", ""));
29+
Table table1 = ModelGenerator.getTablesMap().get(foreignKeyConstraintList.get(0).getReferencedTableName().replaceAll("[\"']", ""));
30+
Table table2 = ModelGenerator.getTablesMap().get(foreignKeyConstraintList.get(1).getReferencedTableName().replaceAll("[\"']", ""));
3031

3132
//Adding @ManyToMany and @JoinTable to table1
3233
Column column1 = new Column();

src/main/java/io/github/ngbsn/generator/ModelGenerator.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,29 @@ private ModelGenerator() {
3434
}
3535

3636
private static final Logger logger = LoggerFactory.getLogger(ModelGenerator.class);
37-
protected static Map<String, Table> tablesMap = new HashMap<>();
37+
private static final Map<String, Table> tablesMap = new HashMap<>();
38+
39+
/**
40+
* Clears the tables map. This is needed to have a clean start between JUnits
41+
*/
42+
public static void clearTablesMap() {
43+
tablesMap.clear();
44+
}
45+
46+
/**
47+
* Returns the tables map.
48+
*/
49+
public static Map<String, Table> getTablesMap() {
50+
return tablesMap;
51+
}
52+
3853

3954
/**
4055
* Parse the DDL statements using JSQL parser
4156
* @param sqlScript The input DDL commands used for generating the models
4257
* @return List of Tables models
4358
*/
44-
public static List<Table> parse(final String sqlScript) {
59+
static List<Table> parse(final String sqlScript) {
4560
try {
4661
Statements statements = CCJSqlParserUtil.parseStatements(sqlScript);
4762
processCreateTableStatements(statements);
@@ -54,13 +69,6 @@ public static List<Table> parse(final String sqlScript) {
5469
return new ArrayList<>();
5570
}
5671

57-
/**
58-
* Clears the tables map. This is needed to have a clean start between junits
59-
*/
60-
public static void clearTablesMap() {
61-
tablesMap.clear();
62-
}
63-
6472
/**
6573
* Iterate over all the JSQL Create Table statements and prepare the list of Table Model
6674
* @param statements Set of JSQL statements
@@ -149,7 +157,6 @@ private static void extractForeignKeys(final List<Index> foreignKeyIndexes, fina
149157

150158
/**
151159
* Extracting primary key information from the JSQL parsed data and setting them into the Table model
152-
*
153160
* @param primaryKeyIndex JSQL primaryKeyIndex
154161
* @param table Table model
155162
*/

src/main/java/io/github/ngbsn/generator/UniDirectionalMappingsGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
import java.util.stream.Collectors;
1515
import java.util.stream.Stream;
1616

17-
import static io.github.ngbsn.generator.ModelGenerator.tablesMap;
18-
17+
/**
18+
* Generate UniDirectional Mappings (one-to-many and many-to-one) for a specific table
19+
*/
1920
public class UniDirectionalMappingsGenerator {
2021

2122
private UniDirectionalMappingsGenerator() {
@@ -27,7 +28,7 @@ private UniDirectionalMappingsGenerator() {
2728
* @param foreignKeyConstraint ForeignKeyConstraint model
2829
*/
2930
static void addBothSideUniDirectionalMappings(Table table, ForeignKeyConstraint foreignKeyConstraint) {
30-
Table referencedTable = tablesMap.get(foreignKeyConstraint.getReferencedTableName().replaceAll("[\"']", ""));
31+
Table referencedTable = ModelGenerator.getTablesMap().get(foreignKeyConstraint.getReferencedTableName().replaceAll("[\"']", ""));
3132

3233
//In the Child table, create a new column having field name as Parent(Referenced) Table.
3334
Column parentTableField = new Column();

src/test/java/io/github/ngbsn/maven/CodeGenTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import static io.github.ngbsn.generator.JPACodeGenerator.generateCode;
1717

18+
//TODO write assertions
1819
public class CodeGenTest {
1920
private static final Logger logger = LoggerFactory.getLogger(CodeGenTest.class);
2021

0 commit comments

Comments
 (0)