diff --git a/src/main/java/migration/ModMigration.java b/src/main/java/migration/ModMigration.java index 3394dfc..e37d789 100644 --- a/src/main/java/migration/ModMigration.java +++ b/src/main/java/migration/ModMigration.java @@ -1,9 +1,20 @@ package migration; +import data.source.GameobjectSource; import data.source.ModSource; +import data.target.GameobjectTarget; import data.target.ModTarget; +import etl.Extractor; +import etl.Loader; +import etl.Transformer; +import utils.DataStorer; +import utils.DataTransformer; +import utils.StatementPreparerExtractor; +import utils.StatementPreparerLoader; import java.sql.Connection; +import java.sql.Date; +import java.util.ArrayList; import java.util.List; public class ModMigration extends ETL @@ -16,18 +27,51 @@ public class ModMigration extends ETL @Override protected List extract() { - return null; + DataStorer dataStorer = (resultSet) -> { + var extractedData = new ArrayList(); + while (resultSet.next()) + { + extractedData.add(new ModSource( + resultSet.getInt("modId"), + resultSet.getString("name"), + resultSet.getDate("installationDate").toLocalDate(), + resultSet.getBlob("binary") + )); + } + return extractedData; + }; + + var sql = "select * from `mod`;"; + StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + + return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); } @Override protected List transform(List extractedData) { - return null; + DataTransformer transformer = (dataset) -> new ModTarget( + dataset.getModId(), + dataset.getName(), + dataset.getInstallationDate(), + dataset.getBinary() + ); + + return new Transformer<>(transformer, extractedData).doTransform(); } @Override protected void load(List transformedData) { + StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + preparedStatement.setInt(1, data.getModId()); + preparedStatement.setString(2, data.getName()); + preparedStatement.setDate(3, Date.valueOf(data.getModInstallationDate())); + preparedStatement.setBinaryStream(4, data.getModBinary().getBinaryStream()); + }; + var sql = "insert into \"mod\" values (?, ?, ?, ?)"; + + new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad(); } } diff --git a/src/main/java/migration/ThesisMigration.java b/src/main/java/migration/ThesisMigration.java index d2adaf1..d87923c 100644 --- a/src/main/java/migration/ThesisMigration.java +++ b/src/main/java/migration/ThesisMigration.java @@ -50,6 +50,7 @@ public class ThesisMigration this.migrations.add(new CharacterMigration(this.mariadb, this.postgresql)); this.migrations.add(new GameobjectMigration(this.mariadb, this.postgresql)); this.migrations.add(new QuestMigration(this.mariadb, this.postgresql)); + this.migrations.add(new ModMigration(this.mariadb, this.postgresql)); } public void executeMigrations()