diff --git a/src/main/java/data/source/QuestSource.java b/src/main/java/data/source/QuestSource.java index 643c763..ad593df 100644 --- a/src/main/java/data/source/QuestSource.java +++ b/src/main/java/data/source/QuestSource.java @@ -2,7 +2,6 @@ package data.source; import data.SourceDataset; -import java.sql.Clob; import java.sql.SQLException; import java.util.Objects; @@ -10,10 +9,10 @@ public class QuestSource implements SourceDataset { private final int questId; private final String name; - private final Clob dialogue; + private final String dialogue; private final int personId; - public QuestSource(final int questId, final String name, final Clob dialogue, final int personId) + public QuestSource(final int questId, final String name, final String dialogue, final int personId) { this.questId = questId; this.name = name; @@ -31,7 +30,7 @@ public class QuestSource implements SourceDataset return name; } - public Clob getDialogue() + public String getDialogue() { return dialogue; } @@ -65,15 +64,6 @@ public class QuestSource implements SourceDataset @Override public String toString() { - try - { - return String.format("Quest { %d, %s, %s..., %d }", this.questId, this.name, this.dialogue.getSubString(1, 10), this.personId); - } - catch (final SQLException e) - { - e.printStackTrace(); - } - - return null; + return String.format("Quest { %d, %s, %s..., %d }", this.questId, this.name, this.dialogue.substring(0, 10), this.personId); } } diff --git a/src/main/java/data/target/ActiveQuestsTarget.java b/src/main/java/data/target/ActiveQuestsTarget.java index 4691fc1..06d4616 100644 --- a/src/main/java/data/target/ActiveQuestsTarget.java +++ b/src/main/java/data/target/ActiveQuestsTarget.java @@ -6,21 +6,26 @@ public class ActiveQuestsTarget implements TargetDataset { private final int playerId; private final int questId; - private final int questProgress; + private final float questProgress; - public ActiveQuestsTarget(final int playerId, final int questId, final int questProgress) + public ActiveQuestsTarget(final int playerId, final int questId, final float questProgress) { this.playerId = playerId; this.questId = questId; this.questProgress = questProgress; } + public int getPlayerId() + { + return playerId; + } + public int getQuestId() { return questId; } - public int getQuestProgress() + public float getQuestProgress() { return questProgress; } @@ -28,6 +33,6 @@ public class ActiveQuestsTarget implements TargetDataset @Override public String toString() { - return String.format("ActiveQuest [ %d, %d, %d ]", this.playerId, this.questId, this.questProgress); + return String.format("ActiveQuest [ %d, %d, %f ]", this.playerId, this.questId, this.questProgress); } } diff --git a/src/main/java/data/target/InventoryTarget.java b/src/main/java/data/target/InventoryTarget.java index 6a126d7..77f2ea8 100644 --- a/src/main/java/data/target/InventoryTarget.java +++ b/src/main/java/data/target/InventoryTarget.java @@ -8,6 +8,11 @@ public class InventoryTarget implements TargetDataset private final int objectId; private final boolean stolen; + public InventoryTarget(int playerId, int objectId) + { + this(playerId, objectId, false); + } + public InventoryTarget(final int playerId, final int objectId, final boolean stolen) { this.playerId = playerId; diff --git a/src/main/java/data/target/QuestTarget.java b/src/main/java/data/target/QuestTarget.java index 408c4af..d4a60e3 100644 --- a/src/main/java/data/target/QuestTarget.java +++ b/src/main/java/data/target/QuestTarget.java @@ -2,7 +2,6 @@ package data.target; import data.TargetDataset; -import java.sql.Clob; import java.sql.SQLException; public class QuestTarget implements TargetDataset @@ -10,9 +9,9 @@ public class QuestTarget implements TargetDataset private final int questId; private final String name; private final String involvedCharacters; - private final Clob dialogue; + private final String dialogue; - public QuestTarget(final int questId, final String name, final String involvedCharacters, final Clob dialogue) + public QuestTarget(final int questId, final String name, final String involvedCharacters, final String dialogue) { this.questId = questId; this.name = name; @@ -35,7 +34,7 @@ public class QuestTarget implements TargetDataset return involvedCharacters; } - public Clob getDialogue() + public String getDialogue() { return dialogue; } @@ -43,15 +42,6 @@ public class QuestTarget implements TargetDataset @Override public String toString() { - try - { - return String.format("Quest [ %d, %s, { %s }, %s... ]", this.questId, this.name, this.involvedCharacters, this.dialogue.getSubString(1, 10)); - } - catch (final SQLException e) - { - e.printStackTrace(); - } - - return null; + return String.format("Quest [ %d, %s, { %s }, %s... ]", this.questId, this.name, this.involvedCharacters, this.dialogue.substring(0, 10)); } } diff --git a/src/main/java/data/target/RelationshipTarget.java b/src/main/java/data/target/RelationshipTarget.java index 2182f03..e1ec72c 100644 --- a/src/main/java/data/target/RelationshipTarget.java +++ b/src/main/java/data/target/RelationshipTarget.java @@ -6,9 +6,9 @@ public class RelationshipTarget implements TargetDataset { private final int playerId; private final int personId; - private final int relationshipLevel; + private final float relationshipLevel; - public RelationshipTarget(final int playerId, final int personId, final int relationshipLevel) + public RelationshipTarget(final int playerId, final int personId, final float relationshipLevel) { this.playerId = playerId; this.personId = personId; @@ -25,7 +25,7 @@ public class RelationshipTarget implements TargetDataset return personId; } - public int getRelationshipLevel() + public float getRelationshipLevel() { return relationshipLevel; } @@ -33,7 +33,7 @@ public class RelationshipTarget implements TargetDataset @Override public String toString() { - return String.format("Relationship [ %d, %d, %d ]", this.playerId, this.personId, this.relationshipLevel); + return String.format("Relationship [ %d, %d, %f ]", this.playerId, this.personId, this.relationshipLevel); } } diff --git a/src/main/java/migration/ActiveQuestsMigration.java b/src/main/java/migration/ActiveQuestsMigration.java new file mode 100644 index 0000000..fd6e29d --- /dev/null +++ b/src/main/java/migration/ActiveQuestsMigration.java @@ -0,0 +1,74 @@ +package migration; + +import com.mysql.cj.exceptions.NumberOutOfRange; +import data.source.ActiveQuestsSource; +import data.target.ActiveQuestsTarget; +import etl.Extractor; +import etl.Loader; +import etl.Transformer; +import utils.*; + +import java.sql.Connection; +import java.util.ArrayList; +import java.util.List; + +public class ActiveQuestsMigration extends ETL +{ + public ActiveQuestsMigration(Connection source, Connection target) + { + super(source, target); + } + + @Override + protected List extract() + { + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); + while (resultSet.next()) + { + extractedData.add(new ActiveQuestsSource( + resultSet.getInt("questId"), + resultSet.getInt("progress") + )); + } + return extractedData; + }; + + final var sql = "select * from activeQuests;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + + return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); + } + + @Override + protected List transform(List extractedData) + { + final DataTransformer transformer = (dataset) -> { + if (dataset.getProgress() < 0 || dataset.getProgress() > 100) + log.error("level-value out of range", + new NumberOutOfRange("level must be within 0 an 100 (both inclusive)")); + final var levelCorrection = 100f; + return new ActiveQuestsTarget( + 0, + dataset.getQuestId(), + dataset.getProgress() / levelCorrection + ); + }; + + return new Transformer<>(transformer, extractedData).doTransform(); + } + + @Override + protected void load(List transformedData) + { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + preparedStatement.setInt(1, data.getPlayerId()); + preparedStatement.setInt(2, data.getQuestId()); + preparedStatement.setFloat(3, data.getQuestProgress()); + }; + + final var sql = "insert into activeQuests values (?, ?, ?)"; + + new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad(); + } +} diff --git a/src/main/java/migration/CharacterInventoryMigration.java b/src/main/java/migration/CharacterInventoryMigration.java new file mode 100644 index 0000000..33edb4b --- /dev/null +++ b/src/main/java/migration/CharacterInventoryMigration.java @@ -0,0 +1,66 @@ +package migration; + +import data.source.PersonInventorySource; +import data.target.CharacterInventoryTarget; +import etl.Extractor; +import etl.Loader; +import etl.Transformer; +import utils.*; + +import java.sql.Connection; +import java.util.ArrayList; +import java.util.List; + +public class CharacterInventoryMigration extends ETL +{ + public CharacterInventoryMigration(Connection source, Connection target) + { + super(source, target); + } + + @Override + protected List extract() + { + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); + while (resultSet.next()) + { + extractedData.add(new PersonInventorySource( + resultSet.getInt("personId"), + resultSet.getInt("objectId") + )); + } + return extractedData; + }; + + final var sql = "select * from personInventory;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + + return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); + } + + @Override + protected List transform(List extractedData) + { + final DataTransformer transformer = (dataset) -> + new CharacterInventoryTarget( + dataset.getPersonId(), + dataset.getObjectId() + ); + + return new Transformer<>(transformer, extractedData).doTransform(); + } + + @Override + protected void load(List transformedData) + { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + preparedStatement.setInt(1, data.getPersonId()); + preparedStatement.setInt(2, data.getObjectId()); + }; + + final var sql = "insert into characterInventory values (?, ?)"; + + new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad(); + } +} diff --git a/src/main/java/migration/CharacterMigration.java b/src/main/java/migration/CharacterMigration.java index 1a71caf..284f74c 100644 --- a/src/main/java/migration/CharacterMigration.java +++ b/src/main/java/migration/CharacterMigration.java @@ -5,10 +5,7 @@ import data.target.CharacterTarget; import etl.Extractor; import etl.Loader; import etl.Transformer; -import utils.DataStorer; -import utils.DataTransformer; -import utils.StatementPreparerExtractor; -import utils.StatementPreparerLoader; +import utils.*; import java.sql.Connection; import java.util.ArrayList; diff --git a/src/main/java/migration/GameobjectMigration.java b/src/main/java/migration/GameobjectMigration.java index 2100a96..314c88e 100644 --- a/src/main/java/migration/GameobjectMigration.java +++ b/src/main/java/migration/GameobjectMigration.java @@ -5,10 +5,7 @@ import data.target.GameobjectTarget; import etl.Extractor; import etl.Loader; import etl.Transformer; -import utils.DataStorer; -import utils.DataTransformer; -import utils.StatementPreparerExtractor; -import utils.StatementPreparerLoader; +import utils.*; import java.sql.Connection; import java.util.ArrayList; diff --git a/src/main/java/migration/InventoryMigration.java b/src/main/java/migration/InventoryMigration.java new file mode 100644 index 0000000..75751a9 --- /dev/null +++ b/src/main/java/migration/InventoryMigration.java @@ -0,0 +1,66 @@ +package migration; + +import data.source.InventorySource; +import data.target.InventoryTarget; +import etl.Extractor; +import etl.Loader; +import etl.Transformer; +import utils.*; + +import java.sql.Connection; +import java.util.ArrayList; +import java.util.List; + +public class InventoryMigration extends ETL +{ + public InventoryMigration(Connection source, Connection target) + { + super(source, target); + } + + @Override + protected List extract() + { + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); + while (resultSet.next()) + { + extractedData.add(new InventorySource( + resultSet.getInt("objectId") + )); + } + return extractedData; + }; + + final var sql = "select * from inventory;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + + return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); + } + + @Override + protected List transform(List extractedData) + { + final DataTransformer transformer = (dataset) -> + new InventoryTarget( + 0, + dataset.getObjectId() + ); + + return new Transformer<>(transformer, extractedData).doTransform(); + } + + @Override + protected void load(List transformedData) + { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + preparedStatement.setInt(1, data.getPlayerId()); + preparedStatement.setInt(2, data.getObjectId()); + preparedStatement.setBoolean(3, data.isStolen()); + }; + + final var sql = "insert into inventory values (?, ?, ?)"; + + new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad(); + } +} diff --git a/src/main/java/migration/ModMigration.java b/src/main/java/migration/ModMigration.java index de062d5..2d20141 100644 --- a/src/main/java/migration/ModMigration.java +++ b/src/main/java/migration/ModMigration.java @@ -5,10 +5,7 @@ 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 utils.*; import java.sql.Connection; import java.sql.Date; diff --git a/src/main/java/migration/PlayerAbilitiesMigration.java b/src/main/java/migration/PlayerAbilitiesMigration.java index 525e95a..d8bb0c1 100644 --- a/src/main/java/migration/PlayerAbilitiesMigration.java +++ b/src/main/java/migration/PlayerAbilitiesMigration.java @@ -5,10 +5,7 @@ import data.target.PlayerAbilitiesTarget; import etl.Extractor; import etl.Loader; import etl.Transformer; -import utils.DataStorer; -import utils.DataTransformer; -import utils.StatementPreparerExtractor; -import utils.StatementPreparerLoader; +import utils.*; import java.sql.Connection; import java.util.ArrayList; diff --git a/src/main/java/migration/PlayerMigration.java b/src/main/java/migration/PlayerMigration.java index 9a3e843..8417577 100644 --- a/src/main/java/migration/PlayerMigration.java +++ b/src/main/java/migration/PlayerMigration.java @@ -3,6 +3,7 @@ package migration; import data.SourceDataset; import data.target.PlayerTarget; import etl.Loader; +import utils.ETL; import utils.StatementPreparerLoader; import java.sql.Connection; @@ -15,12 +16,6 @@ public class PlayerMigration extends ETL super(source, target); } - @Override - public void migrate() - { - this.createPlayer(); - } - @Override protected List extract() { @@ -36,19 +31,15 @@ public class PlayerMigration extends ETL @Override protected void load(final List transformedData) { - } - - private void createPlayer() - { - final var sql = "insert into player values (?, ?)"; - final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getPlayerId()); preparedStatement.setString(2, data.getPlayerName()); }; - final var transformedData = List.of(new PlayerTarget(0, "Dummy Name")); + final var createdData = List.of(new PlayerTarget(0, "Dummy Name")); - new Loader<>(this.target, statementPreparerLoader, transformedData, sql).doLoad(); + final var sql = "insert into player values (?, ?)"; + + new Loader<>(this.target, statementPreparerLoader, createdData, sql).doLoad(); } } diff --git a/src/main/java/migration/QuestMigration.java b/src/main/java/migration/QuestMigration.java index 6235f14..821ee17 100644 --- a/src/main/java/migration/QuestMigration.java +++ b/src/main/java/migration/QuestMigration.java @@ -1,14 +1,12 @@ package migration; +import com.mysql.cj.jdbc.Clob; import data.source.QuestSource; import data.target.QuestTarget; import etl.Extractor; import etl.Loader; import etl.Transformer; -import utils.DataStorer; -import utils.DataTransformer; -import utils.StatementPreparerExtractor; -import utils.StatementPreparerLoader; +import utils.*; import java.sql.Connection; import java.util.ArrayList; @@ -33,7 +31,7 @@ public class QuestMigration extends ETL extractedData.add(new QuestSource( resultSet.getInt("questId"), resultSet.getString("name"), - resultSet.getClob("dialogue"), + resultSet.getString("dialogue"), resultSet.getInt("personId"))); } return extractedData; @@ -83,7 +81,7 @@ public class QuestMigration extends ETL preparedStatement.setInt(1, data.getQuestId()); preparedStatement.setString(2, data.getName()); preparedStatement.setString(3, data.getInvolvedCharacters()); - preparedStatement.setClob(4, data.getDialogue()); + preparedStatement.setString(4, data.getDialogue()); }; final var sql = "insert into quest values (?, ?, ?, ?)"; diff --git a/src/main/java/migration/RelationshipMigration.java b/src/main/java/migration/RelationshipMigration.java new file mode 100644 index 0000000..b0a6eb1 --- /dev/null +++ b/src/main/java/migration/RelationshipMigration.java @@ -0,0 +1,74 @@ +package migration; + +import com.mysql.cj.exceptions.NumberOutOfRange; +import data.source.RelationshipsSource; +import data.target.RelationshipTarget; +import etl.Extractor; +import etl.Loader; +import etl.Transformer; +import utils.*; + +import java.sql.Connection; +import java.util.ArrayList; +import java.util.List; + +public class RelationshipMigration extends ETL +{ + public RelationshipMigration(Connection source, Connection target) + { + super(source, target); + } + + @Override + protected List extract() + { + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); + while (resultSet.next()) + { + extractedData.add(new RelationshipsSource( + resultSet.getInt("personId"), + resultSet.getInt("relationshipLevel") + )); + } + return extractedData; + }; + + final var sql = "select * from relationships;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + + return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); + } + + @Override + protected List transform(List extractedData) + { + final DataTransformer transformer = (dataset) -> { + if (dataset.getRelationshipLevel() < 0 || dataset.getRelationshipLevel() > 100) + log.error("level-value out of range", + new NumberOutOfRange("level must be within 0 an 100 (both inclusive)")); + final var levelCorrection = 100f; + return new RelationshipTarget( + 0, + dataset.getPersonId(), + dataset.getRelationshipLevel() / levelCorrection + ); + }; + + return new Transformer<>(transformer, extractedData).doTransform(); + } + + @Override + protected void load(List transformedData) + { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + preparedStatement.setInt(1, data.getPlayerId()); + preparedStatement.setInt(2, data.getPersonId()); + preparedStatement.setFloat(3, data.getRelationshipLevel()); + }; + + final var sql = "insert into relationship 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 6d0a6c5..6bdab46 100644 --- a/src/main/java/migration/ThesisMigration.java +++ b/src/main/java/migration/ThesisMigration.java @@ -4,13 +4,13 @@ import org.apache.log4j.Logger; import utils.ConnectionHelper; import utils.DatabaseInformation; import utils.DatabaseType; +import utils.ETL; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -@SuppressWarnings("ALL") public class ThesisMigration { private static final Logger log = Logger.getLogger(ThesisMigration.class.getName()); @@ -52,6 +52,10 @@ public class ThesisMigration 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)); + this.migrations.add(new CharacterInventoryMigration(this.mariadb, this.postgresql)); + this.migrations.add(new RelationshipMigration(this.mysql, this.postgresql)); + this.migrations.add(new ActiveQuestsMigration(this.mysql, this.postgresql)); + this.migrations.add(new InventoryMigration(this.mysql, this.postgresql)); } public void executeMigrations() diff --git a/src/main/java/migration/ETL.java b/src/main/java/utils/ETL.java similarity index 98% rename from src/main/java/migration/ETL.java rename to src/main/java/utils/ETL.java index 88933e6..3d74542 100644 --- a/src/main/java/migration/ETL.java +++ b/src/main/java/utils/ETL.java @@ -1,4 +1,4 @@ -package migration; +package utils; import data.SourceDataset; import data.TargetDataset;