Skip to content

Commit

Permalink
Removed code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
suarezgpablo committed Oct 4, 2024
1 parent dd86a16 commit 88ebeec
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@Getter @Setter
public class ColumnValue {
private Column column;
private Select selectOrigin;
private String[] key;
private String value; //String generic type, actual type in DB could be different
private String variableName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Insert(Table table, For insideFor) {
public ColumnValue addColumnValue(Column columnSelect, Select s, String[] key, Column target) {
ColumnValue cv = new ColumnValue ();
cv.setColumn(target);
cv.setSelectOrigin(s);
s.getValuesExtracted().add(cv);
cv.setKey(key);
cv.setColumnSelectOrigin(columnSelect);
this.getColumnValue().add(cv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class Script {
private List<For> fors;
private List<For> forsHigherLevel; //These are the For loops that are not inside other For loops
private List<Insert> inserts;
private ScriptText scriptText;
private boolean executable;
private List<For> forsSplit;
public Script () {
Expand All @@ -44,7 +43,6 @@ public Script () {
inserts = new ArrayList<>();
forsSplit = new ArrayList<>();
setForsHigherLevel(new ArrayList<>());
scriptText = new ScriptText();
}
public boolean isExecutable() {
return executable;
Expand Down Expand Up @@ -103,7 +101,7 @@ private Script migrationSplitColumn(Schema schema, SchemaEvolution se, Migration
for (Column c: t.getKey()) {
ColumnValue cv=insert.addColumnValue (c, s, null, c);
Column copyTarget = new Column (c);
cv.getSelectOrigin().getSearch().add(copyTarget);
s.getSearch().add(copyTarget);
cv.setColumn(copyTarget);

}
Expand Down Expand Up @@ -322,4 +320,12 @@ public boolean inList(Column c, List<ColumnValue> columnValues) {
}
return false;
}
public Select findSelect(ColumnValue cv) {
for (Select s: selects) {
if (s.getValuesExtracted().contains(cv)) {
return s;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ private void writeSyntaxInsert(StringBuilder sb, Script s) {
initializeVariableName (cv);

String nameColumn = cv.getColumn().getName();
String nameVariable=cv.getSelectOrigin().findNameVariable (cv.getColumn().getNameAttribute(), cv.getColumn().getNameEntity());
Select selectOrigin = s.findSelect (cv);
String nameVariable=selectOrigin.findNameVariable (cv.getColumn().getNameAttribute(), cv.getColumn().getNameEntity());
if (nameVariable == null) {
Column columnOrigin = cv.getSelectOrigin().getSplitColumn();
Column columnOrigin = selectOrigin.getSplitColumn();
nameVariable=columnOrigin.getVariableName();
}
namesColumns.append(nameColumn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public class Select {
private String criteriaOperator;
private String criteriaValue;
private Column splitColumn;
private List<ColumnValue> valuesExtracted;

public Select () {
where = new ArrayList<>();
search = new ArrayList<>();
whereValue = new ArrayList<>();
valuesExtracted = new ArrayList<>();
}

public Select(Table table, Column c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ private MigrationColumn storeInfoMigrationColumn(Node nodeColumn, SchemaEvolutio
if (!elementMigCol.getAttribute("Description").isEmpty()) {
return null;
}
c.setTable(migrationTable);
NodeList toFrom = nodeColumn.getChildNodes();
// Right now it's only for one from table and one to table
ColFrom colfrom = new ColFrom();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class MigrationColumn {
private String name;
private ColTo colTo; // Contains the required information to migrate data to a column
private ColFrom colFrom; // Contains the required information to migrate data from a column
private MigrationTable table;
private String description; //when it is not possible to proceed with the migration

public MigrationColumn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ public class Column {
private boolean ck;
private String dataType;
private String nameEntity;
private Table table;
private String variableName;

private String nameTable;
public Column() {
super();
}

public Column(String name, String nameAttribute, boolean pk, boolean ck, String nameEntity, Table table) {
public Column(String name, String nameAttribute, boolean pk, boolean ck, String nameEntity, String nameTable) {
super();
this.name = name;
this.pk = pk;
this.ck = ck;
this.setNameAttribute(nameAttribute);
this.nameEntity = nameEntity;
this.table = table;
this.nameTable = nameTable;

}

public Column(Column c) {
Expand All @@ -42,19 +42,18 @@ public Column(Column c) {
this.pk = c.pk;
this.ck = c.ck;
this.setNameAttribute(c.nameAttribute);
this.table = c.table;
this.dataType = c.dataType;
this.nameEntity = c.nameEntity;
this.variableName = c.variableName;

this.nameTable = c.nameTable;
}

public Column(String nameTable) {
this.name = nameTable;
public Column(String name) {
this.name = name;
}

public boolean equalsValues (Column c) {
return c.getName().equals(this.getName()) && c.getTable().equals(this.getTable()) && c.getNameAttribute().equals(this.getNameAttribute()) && c.getNameEntity().equals(this.getNameEntity());
return c.getName().equals(this.getName()) && c.getNameTable().equals(this.getNameTable()) && c.getNameAttribute().equals(this.getNameAttribute()) && c.getNameEntity().equals(this.getNameEntity());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private Column readColumn(Node nodeColumn, Table table) {
String nameEntity = element.getAttribute("nameEntity");
boolean pk = pkString.equalsIgnoreCase("True");
boolean ck = ckString.equalsIgnoreCase("True");
return new Column(column, attribute, pk, ck, nameEntity, table);
return new Column(column, attribute, pk, ck, nameEntity, table.getName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Table(String name, List<Column> columns) {
this.setName(name);
this.columns = columns;
for (Column c: columns) {
c.setTable(this);
c.setNameTable(name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected Column columnFromModelToObject(Element column, Table t) {
String nameEntity = column.getAttribute("nameEntity");
columnObject.setNameAttribute(nameAttribute);
columnObject.setNameEntity(nameEntity);
columnObject.setTable(t);
columnObject.setNameTable(t.getName());
return columnObject;
}

Expand Down

0 comments on commit 88ebeec

Please sign in to comment.