From 70c738c97efa2a9921717bf2e9656c72b2d697be Mon Sep 17 00:00:00 2001 From: Niklas Birk Date: Wed, 26 Feb 2020 23:28:58 +0100 Subject: [PATCH] Refactoring --- src/main/java/Main.java | 59 ------------------- .../java/{migration => }/ThesisMigration.java | 5 +- src/main/java/{utils => etl}/ETL.java | 2 +- src/main/java/migration/AbilityMigration.java | 1 + .../java/migration/ActiveQuestsMigration.java | 1 + .../CharacterInventoryMigration.java | 1 + .../java/migration/CharacterMigration.java | 1 + .../java/migration/GameobjectMigration.java | 1 + .../java/migration/InventoryMigration.java | 1 + src/main/java/migration/ModMigration.java | 1 + .../migration/PlayerAbilitiesMigration.java | 2 +- src/main/java/migration/PlayerMigration.java | 2 +- src/main/java/migration/QuestMigration.java | 2 +- .../java/migration/RelationshipMigration.java | 1 + 14 files changed, 14 insertions(+), 66 deletions(-) rename src/main/java/{migration => }/ThesisMigration.java (98%) rename src/main/java/{utils => etl}/ETL.java (98%) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 1741553..7246d11 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,11 +1,4 @@ -import data.source.PersonSource; -import data.target.CharacterTarget; -import etl.*; -import migration.ThesisMigration; import org.apache.log4j.Logger; -import utils.*; - -import java.util.*; public class Main { @@ -17,56 +10,4 @@ public class Main new ThesisMigration().executeMigrations(); log.info("------------- Migration Finished -------------"); } - - private static List testExtract() - { - final var dbInfo = new DatabaseInformation("localhost", "sourcedb1", "test", "test", 25003); - final var connection = new ConnectionHelper(DatabaseType.MARIADB, dbInfo).createConnection(); - - final DataStorer personSourceDataStorer = (rs) -> { - final var persons = new ArrayList(); - while (rs.next()) - { - persons.add(new PersonSource( - rs.getInt("personId"), - rs.getString("name"), - rs.getBoolean("mortal")) - ); - } - return persons; - }; - - final StatementPreparerExtractor statementPreparer = (preparedStatement) -> { - }; - - final var sql = "select * from person;"; - - return new Extractor<>(connection, personSourceDataStorer, statementPreparer, sql).doExtract(); - } - - private static List testTransform(final List persons) - { - final DataTransformer personTransformer = - (personSource) -> new CharacterTarget(personSource.getPersonId(), - personSource.getName(), - personSource.isMortal()); - - return new Transformer<>(personTransformer, persons).doTransform(); - } - - private static void testLoad(final List transformedData) - { - final var dbInfo = new DatabaseInformation("localhost", "targetdb", "test", "test", 25001); - final var connection = new ConnectionHelper(DatabaseType.POSTGRESQL, dbInfo).createConnection(); - - final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { - preparedStatement.setInt(1, data.getPersonId()); - preparedStatement.setString(2, data.getName()); - preparedStatement.setBoolean(3, data.isMortal()); - }; - - final var sql = "insert into person values (?, ?, ?)"; - - new Loader<>(connection, statementPreparerLoader, transformedData, sql).doLoad(); - } } diff --git a/src/main/java/migration/ThesisMigration.java b/src/main/java/ThesisMigration.java similarity index 98% rename from src/main/java/migration/ThesisMigration.java rename to src/main/java/ThesisMigration.java index 6bdab46..3cd85db 100644 --- a/src/main/java/migration/ThesisMigration.java +++ b/src/main/java/ThesisMigration.java @@ -1,10 +1,9 @@ -package migration; - +import migration.*; import org.apache.log4j.Logger; import utils.ConnectionHelper; import utils.DatabaseInformation; import utils.DatabaseType; -import utils.ETL; +import etl.ETL; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/utils/ETL.java b/src/main/java/etl/ETL.java similarity index 98% rename from src/main/java/utils/ETL.java rename to src/main/java/etl/ETL.java index 3d74542..13fcad8 100644 --- a/src/main/java/utils/ETL.java +++ b/src/main/java/etl/ETL.java @@ -1,4 +1,4 @@ -package utils; +package etl; import data.SourceDataset; import data.TargetDataset; diff --git a/src/main/java/migration/AbilityMigration.java b/src/main/java/migration/AbilityMigration.java index 7797ab8..be0685e 100644 --- a/src/main/java/migration/AbilityMigration.java +++ b/src/main/java/migration/AbilityMigration.java @@ -3,6 +3,7 @@ package migration; import com.mysql.cj.exceptions.NumberOutOfRange; import data.source.AbilitiesSource; import data.target.AbilityTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; diff --git a/src/main/java/migration/ActiveQuestsMigration.java b/src/main/java/migration/ActiveQuestsMigration.java index fd6e29d..054de46 100644 --- a/src/main/java/migration/ActiveQuestsMigration.java +++ b/src/main/java/migration/ActiveQuestsMigration.java @@ -3,6 +3,7 @@ package migration; import com.mysql.cj.exceptions.NumberOutOfRange; import data.source.ActiveQuestsSource; import data.target.ActiveQuestsTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; diff --git a/src/main/java/migration/CharacterInventoryMigration.java b/src/main/java/migration/CharacterInventoryMigration.java index 33edb4b..9685873 100644 --- a/src/main/java/migration/CharacterInventoryMigration.java +++ b/src/main/java/migration/CharacterInventoryMigration.java @@ -2,6 +2,7 @@ package migration; import data.source.PersonInventorySource; import data.target.CharacterInventoryTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; diff --git a/src/main/java/migration/CharacterMigration.java b/src/main/java/migration/CharacterMigration.java index 284f74c..aae6be7 100644 --- a/src/main/java/migration/CharacterMigration.java +++ b/src/main/java/migration/CharacterMigration.java @@ -2,6 +2,7 @@ package migration; import data.source.PersonSource; import data.target.CharacterTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; diff --git a/src/main/java/migration/GameobjectMigration.java b/src/main/java/migration/GameobjectMigration.java index 314c88e..5169749 100644 --- a/src/main/java/migration/GameobjectMigration.java +++ b/src/main/java/migration/GameobjectMigration.java @@ -2,6 +2,7 @@ package migration; import data.source.GameobjectSource; import data.target.GameobjectTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; diff --git a/src/main/java/migration/InventoryMigration.java b/src/main/java/migration/InventoryMigration.java index 75751a9..87e19aa 100644 --- a/src/main/java/migration/InventoryMigration.java +++ b/src/main/java/migration/InventoryMigration.java @@ -2,6 +2,7 @@ package migration; import data.source.InventorySource; import data.target.InventoryTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; diff --git a/src/main/java/migration/ModMigration.java b/src/main/java/migration/ModMigration.java index 2d20141..a63ad45 100644 --- a/src/main/java/migration/ModMigration.java +++ b/src/main/java/migration/ModMigration.java @@ -2,6 +2,7 @@ package migration; import data.source.ModSource; import data.target.ModTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; diff --git a/src/main/java/migration/PlayerAbilitiesMigration.java b/src/main/java/migration/PlayerAbilitiesMigration.java index d8bb0c1..6fadefe 100644 --- a/src/main/java/migration/PlayerAbilitiesMigration.java +++ b/src/main/java/migration/PlayerAbilitiesMigration.java @@ -2,6 +2,7 @@ package migration; import data.source.PlayerAbilitiesSource; import data.target.PlayerAbilitiesTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; @@ -51,7 +52,6 @@ public class PlayerAbilitiesMigration extends ETL transformedData) { - final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getPlayerId()); preparedStatement.setInt(2, data.getAbilityId()); diff --git a/src/main/java/migration/PlayerMigration.java b/src/main/java/migration/PlayerMigration.java index 8417577..0112a13 100644 --- a/src/main/java/migration/PlayerMigration.java +++ b/src/main/java/migration/PlayerMigration.java @@ -3,7 +3,7 @@ package migration; import data.SourceDataset; import data.target.PlayerTarget; import etl.Loader; -import utils.ETL; +import etl.ETL; import utils.StatementPreparerLoader; import java.sql.Connection; diff --git a/src/main/java/migration/QuestMigration.java b/src/main/java/migration/QuestMigration.java index 821ee17..3b909d2 100644 --- a/src/main/java/migration/QuestMigration.java +++ b/src/main/java/migration/QuestMigration.java @@ -1,8 +1,8 @@ package migration; -import com.mysql.cj.jdbc.Clob; import data.source.QuestSource; import data.target.QuestTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer; diff --git a/src/main/java/migration/RelationshipMigration.java b/src/main/java/migration/RelationshipMigration.java index b0a6eb1..1c4dc01 100644 --- a/src/main/java/migration/RelationshipMigration.java +++ b/src/main/java/migration/RelationshipMigration.java @@ -3,6 +3,7 @@ package migration; import com.mysql.cj.exceptions.NumberOutOfRange; import data.source.RelationshipsSource; import data.target.RelationshipTarget; +import etl.ETL; import etl.Extractor; import etl.Loader; import etl.Transformer;