diff --git a/modevo-script/pom.xml b/modevo-script/pom.xml index dcd593e..2382e17 100644 --- a/modevo-script/pom.xml +++ b/modevo-script/pom.xml @@ -32,6 +32,15 @@ junit junit + + org.projectlombok + lombok + + + com.datastax.cassandra + cassandra-driver-core + 3.11.5 + @@ -54,7 +63,8 @@ org.apache.maven.plugins maven-javadoc-plugin - + + \ No newline at end of file diff --git a/modevo-script/src/main/java/giis/modevo/migration/script/ColumnValue.java b/modevo-script/src/main/java/giis/modevo/migration/script/ColumnValue.java new file mode 100644 index 0000000..2df2a03 --- /dev/null +++ b/modevo-script/src/main/java/giis/modevo/migration/script/ColumnValue.java @@ -0,0 +1,15 @@ +package giis.modevo.migration.script; + +import giis.modevo.model.schema.Column; +import lombok.Getter; +import lombok.Setter; +@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; + private Column columnSelectOrigin; + +} diff --git a/modevo-script/src/main/java/giis/modevo/migration/script/For.java b/modevo-script/src/main/java/giis/modevo/migration/script/For.java new file mode 100644 index 0000000..f4bb5cf --- /dev/null +++ b/modevo-script/src/main/java/giis/modevo/migration/script/For.java @@ -0,0 +1,29 @@ +package giis.modevo.migration.script; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class For { + private List selectsInsideFor; + + private For nestedFor; + public For () { + selectsFor = new ArrayList<>(); + selectsInsideFor = new ArrayList<>(); + } + /** + * Class that creates a For object to loop a SELECT statement. + */ + public void newForSelect (Select s) { + this.getSelectsFor().add(s); + For oldFor = s.getInsideFor(); + oldFor.setNestedFor(this); //might change to a list + s.setLoopFor(this); + s.setInsideFor(null); + } +} diff --git a/modevo-script/src/main/java/giis/modevo/migration/script/Insert.java b/modevo-script/src/main/java/giis/modevo/migration/script/Insert.java new file mode 100644 index 0000000..40df6b2 --- /dev/null +++ b/modevo-script/src/main/java/giis/modevo/migration/script/Insert.java @@ -0,0 +1,56 @@ +package giis.modevo.migration.script; + +import java.util.ArrayList; +import java.util.List; + +import giis.modevo.model.schema.Column; +import giis.modevo.model.schema.Table; +import lombok.Getter; +import lombok.Setter; +@Getter @Setter +public class Insert { + private List columnValue; + private Table table; + private For insideFor; + private String insertStatement; + private String nameNewTable; //Only used when a new table is required when adding a new column + public Insert() { + columnValue = new ArrayList<>(); + } + public Insert(Table table) { + this(); + this.table = table; + } + public Insert(Table table, For insideFor) { + this(table); + this.insideFor = insideFor; + } + /** + * Adds in a ColumnValue object the information of the column to insert, the source of the data and, optionally, + * the columns used to synchronize the migration + * @param key If there is no key, value is null + * @param target + */ + public void addColumnValue(Column columnSelect, Select s, String[] key, Column target) { + ColumnValue cv = new ColumnValue (); + cv.setColumn(target); + cv.setSelectOrigin(s); + cv.setKey(key); + cv.setColumnSelectOrigin(columnSelect); + this.getColumnValue().add(cv); + } + public String getNameNewTable() { + return nameNewTable; + } + public void setNameNewTable(String nameNewTable) { + this.nameNewTable = nameNewTable; + } + public String getNameTable() { + String name = this.getTable().getName(); + if (!this.getNameNewTable().isEmpty()) { + name = this.getNameNewTable(); + } + return name; + } + +} diff --git a/modevo-script/src/main/java/giis/modevo/migration/script/MainScript.java b/modevo-script/src/main/java/giis/modevo/migration/script/MainScript.java new file mode 100644 index 0000000..3d65a8f --- /dev/null +++ b/modevo-script/src/main/java/giis/modevo/migration/script/MainScript.java @@ -0,0 +1,33 @@ +package giis.modevo.migration.script; + +import java.util.List; + +import giis.modevo.migration.script.execution.CassandraConnection; +import giis.modevo.migration.script.execution.ScriptExecution; +import giis.modevo.model.ModelObjects; +import lombok.extern.slf4j.Slf4j; + +/** + * + * Main Class to call for the creation of scripts. It receives the models as objects and calls first the method to create + * the script object and then, the method to create the textual script. + */ +@Slf4j +public class MainScript { + + public String createScriptAndText (ModelObjects models, CassandraConnection c, String nameKeyspace) { + List