Skip to content

Commit

Permalink
First commit to script module. Expected to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo committed Apr 10, 2024
1 parent af8215a commit 31847e1
Show file tree
Hide file tree
Showing 15 changed files with 1,078 additions and 30 deletions.
12 changes: 11 additions & 1 deletion modevo-script/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.11.5</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -54,7 +63,8 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugin>

</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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;

}
29 changes: 29 additions & 0 deletions modevo-script/src/main/java/giis/modevo/migration/script/For.java
Original file line number Diff line number Diff line change
@@ -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<Select> selectsFor;
private List<Select> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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<Script> scripts = new Script().createScript(models.getSchema(), models.getSchemaEvolution(), models.getDataMigration());
if (scripts.isEmpty()) {
log.info("Scenario not implemented yet");
return null;
}
StringBuilder sb = new StringBuilder();
for (Script script : scripts) {
log.info("Execution script");
sb.append(new ScriptText().writeScript(script));
new ScriptExecution().execute (script, c, nameKeyspace);
}

return sb.toString();
}
}
Loading

0 comments on commit 31847e1

Please sign in to comment.