diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 7b5c09a..1741553 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -9,7 +9,7 @@ import java.util.*; public class Main { - private static Logger log = Logger.getLogger(Main.class.getName()); + private static final Logger log = Logger.getLogger(Main.class.getName()); public static void main(final String[] args) { @@ -23,8 +23,8 @@ public class Main final var dbInfo = new DatabaseInformation("localhost", "sourcedb1", "test", "test", 25003); final var connection = new ConnectionHelper(DatabaseType.MARIADB, dbInfo).createConnection(); - DataStorer personSourceDataStorer = (rs) -> { - var persons = new ArrayList(); + final DataStorer personSourceDataStorer = (rs) -> { + final var persons = new ArrayList(); while (rs.next()) { persons.add(new PersonSource( @@ -36,17 +36,17 @@ public class Main return persons; }; - StatementPreparerExtractor statementPreparer = (preparedStatement) -> { + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> { }; - var sql = "select * from person;"; + final var sql = "select * from person;"; return new Extractor<>(connection, personSourceDataStorer, statementPreparer, sql).doExtract(); } - private static List testTransform(List persons) + private static List testTransform(final List persons) { - DataTransformer personTransformer = + final DataTransformer personTransformer = (personSource) -> new CharacterTarget(personSource.getPersonId(), personSource.getName(), personSource.isMortal()); @@ -54,18 +54,18 @@ public class Main return new Transformer<>(personTransformer, persons).doTransform(); } - private static void testLoad(List transformedData) + 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(); - StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getPersonId()); preparedStatement.setString(2, data.getName()); preparedStatement.setBoolean(3, data.isMortal()); }; - var sql = "insert into person values (?, ?, ?)"; + final var sql = "insert into person values (?, ?, ?)"; new Loader<>(connection, statementPreparerLoader, transformedData, sql).doLoad(); } diff --git a/src/main/java/data/source/AbilitiesSource.java b/src/main/java/data/source/AbilitiesSource.java index 65f07be..8a3d755 100644 --- a/src/main/java/data/source/AbilitiesSource.java +++ b/src/main/java/data/source/AbilitiesSource.java @@ -4,11 +4,11 @@ import data.SourceDataset; public class AbilitiesSource implements SourceDataset { - private String name; - private String description; - private int level; + private final String name; + private final String description; + private final int level; - public AbilitiesSource(String name, String description, int level) + public AbilitiesSource(final String name, final String description, final int level) { this.name = name; this.description = description; diff --git a/src/main/java/data/source/ActiveQuestsSource.java b/src/main/java/data/source/ActiveQuestsSource.java index da4224c..e4caaad 100644 --- a/src/main/java/data/source/ActiveQuestsSource.java +++ b/src/main/java/data/source/ActiveQuestsSource.java @@ -4,10 +4,10 @@ import data.SourceDataset; public class ActiveQuestsSource implements SourceDataset { - private int questId; - private int progress; + private final int questId; + private final int progress; - public ActiveQuestsSource(int questId, int progress) + public ActiveQuestsSource(final int questId, final int progress) { this.questId = questId; this.progress = progress; diff --git a/src/main/java/data/source/GameobjectSource.java b/src/main/java/data/source/GameobjectSource.java index a8668da..7da9f03 100644 --- a/src/main/java/data/source/GameobjectSource.java +++ b/src/main/java/data/source/GameobjectSource.java @@ -4,11 +4,11 @@ import data.SourceDataset; public class GameobjectSource implements SourceDataset { - private int objectId; - private String name; - private String description; + private final int objectId; + private final String name; + private final String description; - public GameobjectSource(int objectId, String name, String description) + public GameobjectSource(final int objectId, final String name, final String description) { this.objectId = objectId; this.name = name; diff --git a/src/main/java/data/source/InventorySource.java b/src/main/java/data/source/InventorySource.java index 9376da0..b773642 100644 --- a/src/main/java/data/source/InventorySource.java +++ b/src/main/java/data/source/InventorySource.java @@ -4,9 +4,9 @@ import data.SourceDataset; public class InventorySource implements SourceDataset { - private int objectId; + private final int objectId; - public InventorySource(int objectId) + public InventorySource(final int objectId) { this.objectId = objectId; } diff --git a/src/main/java/data/source/ModSource.java b/src/main/java/data/source/ModSource.java index c65cef5..a44c43c 100644 --- a/src/main/java/data/source/ModSource.java +++ b/src/main/java/data/source/ModSource.java @@ -7,12 +7,12 @@ import java.time.LocalDate; public class ModSource implements SourceDataset { - private int modId; - private String name; - private LocalDate installationDate; - private Blob binary; + private final int modId; + private final String name; + private final LocalDate installationDate; + private final Blob binary; - public ModSource(int modId, String name, LocalDate installationDate, Blob binary) + public ModSource(final int modId, final String name, final LocalDate installationDate, final Blob binary) { this.modId = modId; this.name = name; diff --git a/src/main/java/data/source/PersonInventorySource.java b/src/main/java/data/source/PersonInventorySource.java index 7c87468..55d23ec 100644 --- a/src/main/java/data/source/PersonInventorySource.java +++ b/src/main/java/data/source/PersonInventorySource.java @@ -4,10 +4,10 @@ import data.SourceDataset; public class PersonInventorySource implements SourceDataset { - private int personId; - private int objectId; + private final int personId; + private final int objectId; - public PersonInventorySource(int personId, int objectId) + public PersonInventorySource(final int personId, final int objectId) { this.personId = personId; this.objectId = objectId; diff --git a/src/main/java/data/source/PersonSource.java b/src/main/java/data/source/PersonSource.java index 3df6ead..0f4f093 100644 --- a/src/main/java/data/source/PersonSource.java +++ b/src/main/java/data/source/PersonSource.java @@ -4,11 +4,11 @@ import data.SourceDataset; public class PersonSource implements SourceDataset { - private int personId; - private String name; - private boolean mortal; + private final int personId; + private final String name; + private final boolean mortal; - public PersonSource(int personId, String name, boolean mortal) + public PersonSource(final int personId, final String name, final boolean mortal) { this.personId = personId; this.name = name; diff --git a/src/main/java/data/source/PlayerAbilitiesSource.java b/src/main/java/data/source/PlayerAbilitiesSource.java index 04287e0..e4f3b04 100644 --- a/src/main/java/data/source/PlayerAbilitiesSource.java +++ b/src/main/java/data/source/PlayerAbilitiesSource.java @@ -4,10 +4,10 @@ import data.SourceDataset; public class PlayerAbilitiesSource implements SourceDataset { - private int playerId; - private int abilityId; + private final int playerId; + private final int abilityId; - public PlayerAbilitiesSource(int playerId, int abilityId) + public PlayerAbilitiesSource(final int playerId, final int abilityId) { this.playerId = playerId; this.abilityId = abilityId; diff --git a/src/main/java/data/source/QuestSource.java b/src/main/java/data/source/QuestSource.java index 826f27e..643c763 100644 --- a/src/main/java/data/source/QuestSource.java +++ b/src/main/java/data/source/QuestSource.java @@ -8,12 +8,12 @@ import java.util.Objects; public class QuestSource implements SourceDataset { - private int questId; - private String name; - private Clob dialogue; - private int personId; + private final int questId; + private final String name; + private final Clob dialogue; + private final int personId; - public QuestSource(int questId, String name, Clob dialogue, int personId) + public QuestSource(final int questId, final String name, final Clob dialogue, final int personId) { this.questId = questId; this.name = name; @@ -42,7 +42,7 @@ public class QuestSource implements SourceDataset } @Override - public boolean equals(Object o) + public boolean equals(final Object o) { if (this == o) { @@ -52,7 +52,7 @@ public class QuestSource implements SourceDataset { return false; } - QuestSource that = (QuestSource) o; + final QuestSource that = (QuestSource) o; return questId == that.questId; } @@ -69,7 +69,7 @@ public class QuestSource implements SourceDataset { return String.format("Quest { %d, %s, %s..., %d }", this.questId, this.name, this.dialogue.getSubString(1, 10), this.personId); } - catch (SQLException e) + catch (final SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/data/source/RelationshipsSource.java b/src/main/java/data/source/RelationshipsSource.java index f2a6e9d..93563c6 100644 --- a/src/main/java/data/source/RelationshipsSource.java +++ b/src/main/java/data/source/RelationshipsSource.java @@ -4,10 +4,10 @@ import data.SourceDataset; public class RelationshipsSource implements SourceDataset { - private int personId; - private int relationshipLevel; + private final int personId; + private final int relationshipLevel; - public RelationshipsSource(int personId, int relationshipLevel) + public RelationshipsSource(final int personId, final int relationshipLevel) { this.personId = personId; this.relationshipLevel = relationshipLevel; diff --git a/src/main/java/data/target/AbilityTarget.java b/src/main/java/data/target/AbilityTarget.java index 0ee02fe..2eec3ae 100644 --- a/src/main/java/data/target/AbilityTarget.java +++ b/src/main/java/data/target/AbilityTarget.java @@ -4,12 +4,12 @@ import data.TargetDataset; public class AbilityTarget implements TargetDataset { - private int abilityId; - private String abilityName; - private String abilityDescription; - private float abilityLevel; + private final int abilityId; + private final String abilityName; + private final String abilityDescription; + private final float abilityLevel; - public AbilityTarget(int abilityId, String abilityName, String abilityDescription, float abilityLevel) + public AbilityTarget(final int abilityId, final String abilityName, final String abilityDescription, final float abilityLevel) { this.abilityId = abilityId; this.abilityName = abilityName; diff --git a/src/main/java/data/target/ActiveQuestsTarget.java b/src/main/java/data/target/ActiveQuestsTarget.java index 37048a3..4691fc1 100644 --- a/src/main/java/data/target/ActiveQuestsTarget.java +++ b/src/main/java/data/target/ActiveQuestsTarget.java @@ -4,11 +4,11 @@ import data.TargetDataset; public class ActiveQuestsTarget implements TargetDataset { - private int playerId; - private int questId; - private int questProgress; + private final int playerId; + private final int questId; + private final int questProgress; - public ActiveQuestsTarget(int playerId, int questId, int questProgress) + public ActiveQuestsTarget(final int playerId, final int questId, final int questProgress) { this.playerId = playerId; this.questId = questId; diff --git a/src/main/java/data/target/CharacterInventoryTarget.java b/src/main/java/data/target/CharacterInventoryTarget.java index 57dcc34..6e5c86d 100644 --- a/src/main/java/data/target/CharacterInventoryTarget.java +++ b/src/main/java/data/target/CharacterInventoryTarget.java @@ -4,10 +4,10 @@ import data.TargetDataset; public class CharacterInventoryTarget implements TargetDataset { - private int personId; - private int objectId; + private final int personId; + private final int objectId; - public CharacterInventoryTarget(int personId, int objectId) + public CharacterInventoryTarget(final int personId, final int objectId) { this.personId = personId; this.objectId = objectId; diff --git a/src/main/java/data/target/CharacterTarget.java b/src/main/java/data/target/CharacterTarget.java index bc7c8fa..3c9b2dd 100644 --- a/src/main/java/data/target/CharacterTarget.java +++ b/src/main/java/data/target/CharacterTarget.java @@ -1,15 +1,14 @@ package data.target; -import data.SourceDataset; import data.TargetDataset; public class CharacterTarget implements TargetDataset { - private int personId; - private String name; - private boolean mortal; + private final int personId; + private final String name; + private final boolean mortal; - public CharacterTarget(int personId, String name, boolean mortal) + public CharacterTarget(final int personId, final String name, final boolean mortal) { this.personId = personId; this.name = name; diff --git a/src/main/java/data/target/GameobjectTarget.java b/src/main/java/data/target/GameobjectTarget.java index 13813d3..c4e3b65 100644 --- a/src/main/java/data/target/GameobjectTarget.java +++ b/src/main/java/data/target/GameobjectTarget.java @@ -4,11 +4,11 @@ import data.TargetDataset; public class GameobjectTarget implements TargetDataset { - private int objectId; - private String name; - private String description; + private final int objectId; + private final String name; + private final String description; - public GameobjectTarget(int objectId, String name, String description) + public GameobjectTarget(final int objectId, final String name, final String description) { this.objectId = objectId; this.name = name; diff --git a/src/main/java/data/target/InventoryTarget.java b/src/main/java/data/target/InventoryTarget.java index 3a4fe0b..6a126d7 100644 --- a/src/main/java/data/target/InventoryTarget.java +++ b/src/main/java/data/target/InventoryTarget.java @@ -4,11 +4,11 @@ import data.TargetDataset; public class InventoryTarget implements TargetDataset { - private int playerId; - private int objectId; - private boolean stolen; + private final int playerId; + private final int objectId; + private final boolean stolen; - public InventoryTarget(int playerId, int objectId, boolean stolen) + public InventoryTarget(final int playerId, final int objectId, final boolean stolen) { this.playerId = playerId; this.objectId = objectId; diff --git a/src/main/java/data/target/ModTarget.java b/src/main/java/data/target/ModTarget.java index 5446599..a867b31 100644 --- a/src/main/java/data/target/ModTarget.java +++ b/src/main/java/data/target/ModTarget.java @@ -7,12 +7,12 @@ import java.time.LocalDate; public class ModTarget implements TargetDataset { - private int modId; - private String modName; - private LocalDate modInstallationDate; - private Blob modBinary; + private final int modId; + private final String modName; + private final LocalDate modInstallationDate; + private final Blob modBinary; - public ModTarget(int modId, String modName, LocalDate modInstallationDate, Blob modBinary) + public ModTarget(final int modId, final String modName, final LocalDate modInstallationDate, final Blob modBinary) { this.modId = modId; this.modName = modName; diff --git a/src/main/java/data/target/PlayerAbilitiesTarget.java b/src/main/java/data/target/PlayerAbilitiesTarget.java index 367fa15..5227850 100644 --- a/src/main/java/data/target/PlayerAbilitiesTarget.java +++ b/src/main/java/data/target/PlayerAbilitiesTarget.java @@ -4,10 +4,10 @@ import data.TargetDataset; public class PlayerAbilitiesTarget implements TargetDataset { - private int playerId; - private int abilityId; + private final int playerId; + private final int abilityId; - public PlayerAbilitiesTarget(int playerId, int abilityId) + public PlayerAbilitiesTarget(final int playerId, final int abilityId) { this.playerId = playerId; this.abilityId = abilityId; diff --git a/src/main/java/data/target/PlayerTarget.java b/src/main/java/data/target/PlayerTarget.java index ef1e4cd..c2f646c 100644 --- a/src/main/java/data/target/PlayerTarget.java +++ b/src/main/java/data/target/PlayerTarget.java @@ -4,10 +4,10 @@ import data.TargetDataset; public class PlayerTarget implements TargetDataset { - private int playerId; - private String playerName; + private final int playerId; + private final String playerName; - public PlayerTarget(int playerId, String playerName) + public PlayerTarget(final int playerId, final String playerName) { this.playerId = playerId; this.playerName = playerName; diff --git a/src/main/java/data/target/QuestTarget.java b/src/main/java/data/target/QuestTarget.java index d0bcacb..408c4af 100644 --- a/src/main/java/data/target/QuestTarget.java +++ b/src/main/java/data/target/QuestTarget.java @@ -7,12 +7,12 @@ import java.sql.SQLException; public class QuestTarget implements TargetDataset { - private int questId; - private String name; - private String involvedCharacters; - private Clob dialogue; + private final int questId; + private final String name; + private final String involvedCharacters; + private final Clob dialogue; - public QuestTarget(int questId, String name, String involvedCharacters, Clob dialogue) + public QuestTarget(final int questId, final String name, final String involvedCharacters, final Clob dialogue) { this.questId = questId; this.name = name; @@ -47,7 +47,7 @@ public class QuestTarget implements TargetDataset { return String.format("Quest [ %d, %s, { %s }, %s... ]", this.questId, this.name, this.involvedCharacters, this.dialogue.getSubString(1, 10)); } - catch (SQLException e) + catch (final SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/data/target/RelationshipTarget.java b/src/main/java/data/target/RelationshipTarget.java index e0450cb..2182f03 100644 --- a/src/main/java/data/target/RelationshipTarget.java +++ b/src/main/java/data/target/RelationshipTarget.java @@ -4,11 +4,11 @@ import data.TargetDataset; public class RelationshipTarget implements TargetDataset { - private int playerId; - private int personId; - private int relationshipLevel; + private final int playerId; + private final int personId; + private final int relationshipLevel; - public RelationshipTarget(int playerId, int personId, int relationshipLevel) + public RelationshipTarget(final int playerId, final int personId, final int relationshipLevel) { this.playerId = playerId; this.personId = personId; diff --git a/src/main/java/etl/Extractor.java b/src/main/java/etl/Extractor.java index dcb4a7d..14feeec 100644 --- a/src/main/java/etl/Extractor.java +++ b/src/main/java/etl/Extractor.java @@ -11,15 +11,15 @@ import java.util.List; public class Extractor { - private static Logger log = Logger.getLogger(Extractor.class.getName()); + private static final Logger log = Logger.getLogger(Extractor.class.getName()); - private Connection sourceDatabase; - private DataStorer dataStorer; - private StatementPreparerExtractor statementPreparer; - private String sql; + private final Connection sourceDatabase; + private final DataStorer dataStorer; + private final StatementPreparerExtractor statementPreparer; + private final String sql; - public Extractor(Connection sourceDatabase, DataStorer dataStorer, - StatementPreparerExtractor statementPreparer, String sql) + public Extractor(final Connection sourceDatabase, final DataStorer dataStorer, + final StatementPreparerExtractor statementPreparer, final String sql) { this.sourceDatabase = sourceDatabase; this.dataStorer = dataStorer; @@ -31,13 +31,13 @@ public class Extractor { try { - var preparedStatement = this.sourceDatabase.prepareStatement(sql); + final var preparedStatement = this.sourceDatabase.prepareStatement(sql); this.statementPreparer.doPrepare(preparedStatement); - var resultSet = preparedStatement.executeQuery(); + final var resultSet = preparedStatement.executeQuery(); log.info(String.format("--- Data extracted with '%s' ---", this.sql)); return this.dataStorer.doStore(resultSet); } - catch (SQLException e) + catch (final SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/etl/Loader.java b/src/main/java/etl/Loader.java index 65c449d..aad1769 100644 --- a/src/main/java/etl/Loader.java +++ b/src/main/java/etl/Loader.java @@ -1,6 +1,5 @@ package etl; -import data.SourceDataset; import data.TargetDataset; import org.apache.log4j.Logger; import utils.StatementPreparerLoader; @@ -11,15 +10,15 @@ import java.util.List; public class Loader { - private static Logger log = Logger.getLogger(Loader.class.getName()); + private static final Logger log = Logger.getLogger(Loader.class.getName()); - private Connection targetDatabase; - private StatementPreparerLoader statementPreparerLoader; - private List transformedData; - private String sql; + private final Connection targetDatabase; + private final StatementPreparerLoader statementPreparerLoader; + private final List transformedData; + private final String sql; - public Loader(Connection targetDatabase, StatementPreparerLoader statementPreparerLoader, List transformedData, - String sql) + public Loader(final Connection targetDatabase, final StatementPreparerLoader statementPreparerLoader, final List transformedData, + final String sql) { this.targetDatabase = targetDatabase; this.statementPreparerLoader = statementPreparerLoader; @@ -31,16 +30,16 @@ public class Loader { try { - for (T transformedDatum : this.transformedData) + for (final T transformedDatum : this.transformedData) { log.info(String.format("Load data into target: %s", transformedDatum)); - var preparedStatement = this.targetDatabase.prepareStatement(this.sql); + final var preparedStatement = this.targetDatabase.prepareStatement(this.sql); this.statementPreparerLoader.doPrepare(preparedStatement, transformedDatum); preparedStatement.executeUpdate(); } log.info(String.format("--- Data loaded into target with '%s' ---", this.sql)); } - catch (SQLException e) + catch (final SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/etl/Transformer.java b/src/main/java/etl/Transformer.java index fef0322..0c13acb 100644 --- a/src/main/java/etl/Transformer.java +++ b/src/main/java/etl/Transformer.java @@ -10,12 +10,12 @@ import java.util.List; public class Transformer { - private static Logger log = Logger.getLogger(Transformer.class.getName()); + private static final Logger log = Logger.getLogger(Transformer.class.getName()); - private DataTransformer transformer; - private List extractedData; + private final DataTransformer transformer; + private final List extractedData; - public Transformer(DataTransformer transformer, List extractedData) + public Transformer(final DataTransformer transformer, final List extractedData) { this.transformer = transformer; this.extractedData = extractedData; @@ -23,8 +23,8 @@ public class Transformer public List doTransform() { - var transformed = new ArrayList(); - for (T dataset : this.extractedData) + final var transformed = new ArrayList(); + for (final T dataset : this.extractedData) { log.info(String.format("Transform data: %s", dataset)); transformed.add(this.transformer.transform(dataset)); diff --git a/src/main/java/migration/AbilityMigration.java b/src/main/java/migration/AbilityMigration.java index 96ce99d..7797ab8 100644 --- a/src/main/java/migration/AbilityMigration.java +++ b/src/main/java/migration/AbilityMigration.java @@ -2,9 +2,7 @@ package migration; import com.mysql.cj.exceptions.NumberOutOfRange; import data.source.AbilitiesSource; -import data.source.PersonSource; import data.target.AbilityTarget; -import data.target.CharacterTarget; import etl.Extractor; import etl.Loader; import etl.Transformer; @@ -18,7 +16,7 @@ public class AbilityMigration extends ETL { private int abilityId; - public AbilityMigration(Connection source, Connection target) + public AbilityMigration(final Connection source, final Connection target) { super(source, target); this.abilityId = 0; @@ -27,8 +25,8 @@ public class AbilityMigration extends ETL @Override protected List extract() { - DataStorer dataStorer = (resultSet) -> { - var extractedData = new ArrayList(); + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); while (resultSet.next()) { extractedData.add(new AbilitiesSource( @@ -40,20 +38,20 @@ public class AbilityMigration extends ETL return extractedData; }; - var sql = "select * from abilities;"; - StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + final var sql = "select * from abilities;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); } @Override - protected List transform(List extractedData) + protected List transform(final List extractedData) { - DataTransformer transformer = (dataset) -> { + final DataTransformer transformer = (dataset) -> { if (dataset.getLevel() < 0 || dataset.getLevel() > 100) log.error("level-value out of range", new NumberOutOfRange("level must be within 0 an 100 (both inclusive)")); - var levelCorrection = 100f; + final var levelCorrection = 100f; return new AbilityTarget( abilityId++, dataset.getName(), @@ -66,16 +64,16 @@ public class AbilityMigration extends ETL } @Override - protected void load(List transformedData) + protected void load(final List transformedData) { - StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getAbilityId()); preparedStatement.setString(2, data.getAbilityName()); preparedStatement.setString(3, data.getAbilityDescription()); preparedStatement.setFloat(4, data.getAbilityLevel()); }; - var sql = "insert into ability values (?, ?, ?, ?)"; + final var sql = "insert into ability 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 bc11304..1a71caf 100644 --- a/src/main/java/migration/CharacterMigration.java +++ b/src/main/java/migration/CharacterMigration.java @@ -1,8 +1,6 @@ package migration; -import data.source.AbilitiesSource; import data.source.PersonSource; -import data.target.AbilityTarget; import data.target.CharacterTarget; import etl.Extractor; import etl.Loader; @@ -18,7 +16,7 @@ import java.util.List; public class CharacterMigration extends ETL { - public CharacterMigration(Connection source, Connection target) + public CharacterMigration(final Connection source, final Connection target) { super(source, target); } @@ -26,8 +24,8 @@ public class CharacterMigration extends ETL @Override protected List extract() { - DataStorer dataStorer = (resultSet) -> { - var extractedData = new ArrayList(); + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); while (resultSet.next()) { extractedData.add(new PersonSource( @@ -39,16 +37,16 @@ public class CharacterMigration extends ETL return extractedData; }; - var sql = "select * from person;"; - StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + final var sql = "select * from person;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); } @Override - protected List transform(List extractedData) + protected List transform(final List extractedData) { - DataTransformer transformer = + final DataTransformer transformer = (dataset) -> new CharacterTarget( dataset.getPersonId(), dataset.getName(), @@ -59,15 +57,15 @@ public class CharacterMigration extends ETL } @Override - protected void load(List transformedData) + protected void load(final List transformedData) { - StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getPersonId()); preparedStatement.setString(2, data.getName()); preparedStatement.setBoolean(3, data.isMortal()); }; - var sql = "insert into character values (?, ?, ?)"; + final var sql = "insert into character values (?, ?, ?)"; new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad(); } diff --git a/src/main/java/migration/ETL.java b/src/main/java/migration/ETL.java index bd7fce1..88933e6 100644 --- a/src/main/java/migration/ETL.java +++ b/src/main/java/migration/ETL.java @@ -2,7 +2,6 @@ package migration; import data.SourceDataset; import data.TargetDataset; -import data.source.PersonSource; import org.apache.log4j.Logger; import java.sql.Connection; @@ -11,12 +10,12 @@ import java.util.List; public abstract class ETL { - protected static Logger log = Logger.getLogger(ETL.class.getName()); + protected static final Logger log = Logger.getLogger(ETL.class.getName()); - protected Connection source; - protected Connection target; + protected final Connection source; + protected final Connection target; - public ETL(Connection source, Connection target) + public ETL(final Connection source, final Connection target) { this.source = source; this.target = target; @@ -25,15 +24,15 @@ public abstract class ETL public void migrate() { log.info(String.format("--- Migration: %s ---", this.getClass().getName())); - var extractedData = this.extract(); - var transformedData = this.transform(extractedData); + final var extractedData = this.extract(); + final var transformedData = this.transform(extractedData); this.load(transformedData); try { this.target.commit(); } - catch (SQLException e) + catch (final SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/migration/GameobjectMigration.java b/src/main/java/migration/GameobjectMigration.java index f225381..2100a96 100644 --- a/src/main/java/migration/GameobjectMigration.java +++ b/src/main/java/migration/GameobjectMigration.java @@ -1,9 +1,6 @@ package migration; -import com.mysql.cj.exceptions.NumberOutOfRange; -import data.source.AbilitiesSource; import data.source.GameobjectSource; -import data.target.AbilityTarget; import data.target.GameobjectTarget; import etl.Extractor; import etl.Loader; @@ -19,7 +16,7 @@ import java.util.List; public class GameobjectMigration extends ETL { - public GameobjectMigration(Connection source, Connection target) + public GameobjectMigration(final Connection source, final Connection target) { super(source, target); } @@ -27,8 +24,8 @@ public class GameobjectMigration extends ETL @Override protected List extract() { - DataStorer dataStorer = (resultSet) -> { - var extractedData = new ArrayList(); + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); while (resultSet.next()) { extractedData.add(new GameobjectSource( @@ -40,16 +37,16 @@ public class GameobjectMigration extends ETL return extractedData; }; - var sql = "select * from gameobject;"; - StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + final var sql = "select * from gameobject;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); } @Override - protected List transform(List extractedData) + protected List transform(final List extractedData) { - DataTransformer transformer = (dataset) -> new GameobjectTarget( + final DataTransformer transformer = (dataset) -> new GameobjectTarget( dataset.getObjectId(), dataset.getName(), dataset.getDescription() @@ -59,15 +56,15 @@ public class GameobjectMigration extends ETL } @Override - protected void load(List transformedData) + protected void load(final List transformedData) { - StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getObjectId()); preparedStatement.setString(2, data.getName()); preparedStatement.setString(3, data.getDescription()); }; - var sql = "insert into gameobject values (?, ?, ?)"; + final var sql = "insert into gameobject 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 e37d789..de062d5 100644 --- a/src/main/java/migration/ModMigration.java +++ b/src/main/java/migration/ModMigration.java @@ -1,8 +1,6 @@ package migration; -import data.source.GameobjectSource; import data.source.ModSource; -import data.target.GameobjectTarget; import data.target.ModTarget; import etl.Extractor; import etl.Loader; @@ -19,7 +17,7 @@ import java.util.List; public class ModMigration extends ETL { - public ModMigration(Connection source, Connection target) + public ModMigration(final Connection source, final Connection target) { super(source, target); } @@ -27,8 +25,8 @@ public class ModMigration extends ETL @Override protected List extract() { - DataStorer dataStorer = (resultSet) -> { - var extractedData = new ArrayList(); + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); while (resultSet.next()) { extractedData.add(new ModSource( @@ -41,16 +39,16 @@ public class ModMigration extends ETL return extractedData; }; - var sql = "select * from `mod`;"; - StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + final var sql = "select * from `mod`;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); } @Override - protected List transform(List extractedData) + protected List transform(final List extractedData) { - DataTransformer transformer = (dataset) -> new ModTarget( + final DataTransformer transformer = (dataset) -> new ModTarget( dataset.getModId(), dataset.getName(), dataset.getInstallationDate(), @@ -61,16 +59,16 @@ public class ModMigration extends ETL } @Override - protected void load(List transformedData) + protected void load(final List transformedData) { - StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + final 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 (?, ?, ?, ?)"; + final var sql = "insert into \"mod\" values (?, ?, ?, ?)"; new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad(); } diff --git a/src/main/java/migration/PlayerAbilitiesMigration.java b/src/main/java/migration/PlayerAbilitiesMigration.java index 8337d1e..525e95a 100644 --- a/src/main/java/migration/PlayerAbilitiesMigration.java +++ b/src/main/java/migration/PlayerAbilitiesMigration.java @@ -1,9 +1,6 @@ package migration; -import data.SourceDataset; -import data.source.AbilitiesSource; import data.source.PlayerAbilitiesSource; -import data.target.AbilityTarget; import data.target.PlayerAbilitiesTarget; import etl.Extractor; import etl.Loader; @@ -19,7 +16,7 @@ import java.util.List; public class PlayerAbilitiesMigration extends ETL { - public PlayerAbilitiesMigration(Connection source, Connection target) + public PlayerAbilitiesMigration(final Connection source, final Connection target) { super(source, target); } @@ -27,8 +24,8 @@ public class PlayerAbilitiesMigration extends ETL extract() { - DataStorer dataStorer = (resultSet) -> { - var extractedData = new ArrayList(); + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); while (resultSet.next()) { extractedData.add(new PlayerAbilitiesSource( @@ -39,33 +36,31 @@ public class PlayerAbilitiesMigration extends ETL { - preparedStatement.setInt(1, 0); - }; + final var sql = "select * from player p join ability a on p.playerId = ?;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> preparedStatement.setInt(1, 0); return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); } @Override - protected List transform(List extractedData) + protected List transform(final List extractedData) { - DataTransformer transformer = + final DataTransformer transformer = (dataset) -> new PlayerAbilitiesTarget(dataset.getPlayerId(), dataset.getAbilityId()); return new Transformer<>(transformer, extractedData).doTransform(); } @Override - protected void load(List transformedData) + protected void load(final List transformedData) { - StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getPlayerId()); preparedStatement.setInt(2, data.getAbilityId()); }; - var sql = "insert into playerAbilities values (?, ?)"; + final var sql = "insert into playerAbilities values (?, ?)"; new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad(); } diff --git a/src/main/java/migration/PlayerMigration.java b/src/main/java/migration/PlayerMigration.java index 708eb48..9a3e843 100644 --- a/src/main/java/migration/PlayerMigration.java +++ b/src/main/java/migration/PlayerMigration.java @@ -3,9 +3,6 @@ package migration; import data.SourceDataset; import data.target.PlayerTarget; import etl.Loader; -import utils.ConnectionHelper; -import utils.DatabaseInformation; -import utils.DatabaseType; import utils.StatementPreparerLoader; import java.sql.Connection; @@ -13,7 +10,7 @@ import java.util.List; public class PlayerMigration extends ETL { - public PlayerMigration(Connection source, Connection target) + public PlayerMigration(final Connection source, final Connection target) { super(source, target); } @@ -31,26 +28,26 @@ public class PlayerMigration extends ETL } @Override - protected List transform(List extractedData) + protected List transform(final List extractedData) { return null; } @Override - protected void load(List transformedData) + protected void load(final List transformedData) { } private void createPlayer() { - var sql = "insert into player values (?, ?)"; + final var sql = "insert into player values (?, ?)"; - StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getPlayerId()); preparedStatement.setString(2, data.getPlayerName()); }; - var transformedData = List.of(new PlayerTarget(0, "Dummy Name")); + final var transformedData = List.of(new PlayerTarget(0, "Dummy Name")); new Loader<>(this.target, statementPreparerLoader, transformedData, sql).doLoad(); } diff --git a/src/main/java/migration/QuestMigration.java b/src/main/java/migration/QuestMigration.java index 9afc279..6235f14 100644 --- a/src/main/java/migration/QuestMigration.java +++ b/src/main/java/migration/QuestMigration.java @@ -18,7 +18,7 @@ import java.util.stream.Collectors; public class QuestMigration extends ETL { - public QuestMigration(Connection source, Connection target) + public QuestMigration(final Connection source, final Connection target) { super(source, target); } @@ -26,8 +26,8 @@ public class QuestMigration extends ETL @Override protected List extract() { - DataStorer dataStorer = (resultSet) -> { - var extractedData = new ArrayList(); + final DataStorer dataStorer = (resultSet) -> { + final var extractedData = new ArrayList(); while (resultSet.next()) { extractedData.add(new QuestSource( @@ -39,8 +39,8 @@ public class QuestMigration extends ETL return extractedData; }; - var sql = "select * from quest q join questParticipation qp on q.questId = qp.questId;"; - StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; + final var sql = "select * from quest q join questParticipation qp on q.questId = qp.questId;"; + final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {}; return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract(); } @@ -48,25 +48,25 @@ public class QuestMigration extends ETL @Override protected List transform(List extractedData) { - var map = new HashMap(); + final var map = new HashMap(); - for (QuestSource extractedDatum : extractedData) + for (final QuestSource extractedDatum : extractedData) { - var key = extractedDatum.getQuestId(); + final var key = extractedDatum.getQuestId(); if (!map.containsKey(key)) { map.put(key, String.valueOf(extractedDatum.getPersonId())); } else { - var involvedPersons = String.format("%s, %s", map.get(key), extractedDatum.getPersonId()); + final var involvedPersons = String.format("%s, %s", map.get(key), extractedDatum.getPersonId()); map.replace(key, involvedPersons); } } extractedData = extractedData.stream().distinct().collect(Collectors.toList()); - DataTransformer transformer = (dataset) -> new QuestTarget( + final DataTransformer transformer = (dataset) -> new QuestTarget( dataset.getQuestId(), dataset.getName(), map.get(dataset.getQuestId()), @@ -77,16 +77,16 @@ public class QuestMigration extends ETL } @Override - protected void load(List transformedData) + protected void load(final List transformedData) { - StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { + final StatementPreparerLoader statementPreparerLoader = (preparedStatement, data) -> { preparedStatement.setInt(1, data.getQuestId()); preparedStatement.setString(2, data.getName()); preparedStatement.setString(3, data.getInvolvedCharacters()); preparedStatement.setClob(4, data.getDialogue()); }; - var sql = "insert into quest values (?, ?, ?, ?)"; + final var sql = "insert into quest 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 d87923c..6d0a6c5 100644 --- a/src/main/java/migration/ThesisMigration.java +++ b/src/main/java/migration/ThesisMigration.java @@ -10,15 +10,16 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +@SuppressWarnings("ALL") public class ThesisMigration { - private static Logger log = Logger.getLogger(ThesisMigration.class.getName()); + private static final Logger log = Logger.getLogger(ThesisMigration.class.getName()); - private List migrations; + private final List migrations; - private Connection mariadb; - private Connection mysql; - private Connection postgresql; + private final Connection mariadb; + private final Connection mysql; + private final Connection postgresql; public ThesisMigration() { @@ -38,7 +39,7 @@ public class ThesisMigration this.mysql.setAutoCommit(false); this.postgresql.setAutoCommit(false); } - catch (SQLException e) + catch (final SQLException e) { e.printStackTrace(); } @@ -55,17 +56,23 @@ public class ThesisMigration public void executeMigrations() { - log.info("\n----- Starting migrations for each migration step -----\n"); + log.info(""" + + ----- Starting migrations for each migration step ----- + """); this.migrations.forEach(ETL::migrate); try { - log.info("\n--- Closing connections ---\n"); + log.info(""" + + --- Closing connections --- + """); this.mariadb.close(); this.mysql.close(); this.postgresql.close(); } - catch (SQLException e) + catch (final SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/utils/ConnectionHelper.java b/src/main/java/utils/ConnectionHelper.java index 81155d0..74edf00 100644 --- a/src/main/java/utils/ConnectionHelper.java +++ b/src/main/java/utils/ConnectionHelper.java @@ -1,6 +1,5 @@ package utils; -import migration.ThesisMigration; import org.apache.log4j.Logger; import java.net.URI; @@ -9,7 +8,7 @@ import java.sql.*; public class ConnectionHelper { - private static Logger log = Logger.getLogger(ConnectionHelper.class.getName()); + private static final Logger log = Logger.getLogger(ConnectionHelper.class.getName()); private final DatabaseType databaseType; private final String user; diff --git a/src/main/java/utils/DatabaseHelper.java b/src/main/java/utils/DatabaseHelper.java deleted file mode 100644 index 80debfa..0000000 --- a/src/main/java/utils/DatabaseHelper.java +++ /dev/null @@ -1,5 +0,0 @@ -package utils; - -public class DatabaseHelper -{ -} diff --git a/src/main/java/utils/StatementPreparerLoader.java b/src/main/java/utils/StatementPreparerLoader.java index b00e992..705827a 100644 --- a/src/main/java/utils/StatementPreparerLoader.java +++ b/src/main/java/utils/StatementPreparerLoader.java @@ -1,6 +1,5 @@ package utils; -import data.SourceDataset; import data.TargetDataset; import java.sql.PreparedStatement;