generated from giis-uniovi/samples-giis-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit to script module. Expected to fail
- Loading branch information
pablo
committed
Apr 10, 2024
1 parent
af8215a
commit 31847e1
Showing
15 changed files
with
1,078 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
modevo-script/src/main/java/giis/modevo/migration/script/ColumnValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
modevo-script/src/main/java/giis/modevo/migration/script/For.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
modevo-script/src/main/java/giis/modevo/migration/script/Insert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
modevo-script/src/main/java/giis/modevo/migration/script/MainScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.