Made finals

This commit is contained in:
Niklas Birk 2020-02-06 21:14:08 +01:00
parent 6e8eec3ffa
commit f88cec6ab2
37 changed files with 214 additions and 234 deletions

View File

@ -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<PersonSource> personSourceDataStorer = (rs) -> {
var persons = new ArrayList<PersonSource>();
final DataStorer<PersonSource> personSourceDataStorer = (rs) -> {
final var persons = new ArrayList<PersonSource>();
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<CharacterTarget> testTransform(List<PersonSource> persons)
private static List<CharacterTarget> testTransform(final List<PersonSource> persons)
{
DataTransformer<PersonSource, CharacterTarget> personTransformer =
final DataTransformer<PersonSource, CharacterTarget> 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<CharacterTarget> transformedData)
private static void testLoad(final List<CharacterTarget> transformedData)
{
final var dbInfo = new DatabaseInformation("localhost", "targetdb", "test", "test", 25001);
final var connection = new ConnectionHelper(DatabaseType.POSTGRESQL, dbInfo).createConnection();
StatementPreparerLoader<CharacterTarget> statementPreparerLoader = (preparedStatement, data) -> {
final StatementPreparerLoader<CharacterTarget> 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();
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();
}

View File

@ -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;

View File

@ -11,15 +11,15 @@ import java.util.List;
public class Extractor<T extends SourceDataset>
{
private static Logger log = Logger.getLogger(Extractor.class.getName());
private static final Logger log = Logger.getLogger(Extractor.class.getName());
private Connection sourceDatabase;
private DataStorer<T> dataStorer;
private StatementPreparerExtractor statementPreparer;
private String sql;
private final Connection sourceDatabase;
private final DataStorer<T> dataStorer;
private final StatementPreparerExtractor statementPreparer;
private final String sql;
public Extractor(Connection sourceDatabase, DataStorer<T> dataStorer,
StatementPreparerExtractor statementPreparer, String sql)
public Extractor(final Connection sourceDatabase, final DataStorer<T> dataStorer,
final StatementPreparerExtractor statementPreparer, final String sql)
{
this.sourceDatabase = sourceDatabase;
this.dataStorer = dataStorer;
@ -31,13 +31,13 @@ public class Extractor<T extends SourceDataset>
{
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();
}

View File

@ -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<T extends TargetDataset>
{
private static Logger log = Logger.getLogger(Loader.class.getName());
private static final Logger log = Logger.getLogger(Loader.class.getName());
private Connection targetDatabase;
private StatementPreparerLoader<T> statementPreparerLoader;
private List<T> transformedData;
private String sql;
private final Connection targetDatabase;
private final StatementPreparerLoader<T> statementPreparerLoader;
private final List<T> transformedData;
private final String sql;
public Loader(Connection targetDatabase, StatementPreparerLoader<T> statementPreparerLoader, List<T> transformedData,
String sql)
public Loader(final Connection targetDatabase, final StatementPreparerLoader<T> statementPreparerLoader, final List<T> transformedData,
final String sql)
{
this.targetDatabase = targetDatabase;
this.statementPreparerLoader = statementPreparerLoader;
@ -31,16 +30,16 @@ public class Loader<T extends TargetDataset>
{
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();
}

View File

@ -10,12 +10,12 @@ import java.util.List;
public class Transformer<T extends SourceDataset, E extends TargetDataset>
{
private static Logger log = Logger.getLogger(Transformer.class.getName());
private static final Logger log = Logger.getLogger(Transformer.class.getName());
private DataTransformer<T, E> transformer;
private List<T> extractedData;
private final DataTransformer<T, E> transformer;
private final List<T> extractedData;
public Transformer(DataTransformer<T, E> transformer, List<T> extractedData)
public Transformer(final DataTransformer<T, E> transformer, final List<T> extractedData)
{
this.transformer = transformer;
this.extractedData = extractedData;
@ -23,8 +23,8 @@ public class Transformer<T extends SourceDataset, E extends TargetDataset>
public List<E> doTransform()
{
var transformed = new ArrayList<E>();
for (T dataset : this.extractedData)
final var transformed = new ArrayList<E>();
for (final T dataset : this.extractedData)
{
log.info(String.format("Transform data: %s", dataset));
transformed.add(this.transformer.transform(dataset));

View File

@ -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<AbilitiesSource, AbilityTarget>
{
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<AbilitiesSource, AbilityTarget>
@Override
protected List<AbilitiesSource> extract()
{
DataStorer<AbilitiesSource> dataStorer = (resultSet) -> {
var extractedData = new ArrayList<AbilitiesSource>();
final DataStorer<AbilitiesSource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<AbilitiesSource>();
while (resultSet.next())
{
extractedData.add(new AbilitiesSource(
@ -40,20 +38,20 @@ public class AbilityMigration extends ETL<AbilitiesSource, AbilityTarget>
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<AbilityTarget> transform(List<AbilitiesSource> extractedData)
protected List<AbilityTarget> transform(final List<AbilitiesSource> extractedData)
{
DataTransformer<AbilitiesSource, AbilityTarget> transformer = (dataset) -> {
final DataTransformer<AbilitiesSource, AbilityTarget> 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<AbilitiesSource, AbilityTarget>
}
@Override
protected void load(List<AbilityTarget> transformedData)
protected void load(final List<AbilityTarget> transformedData)
{
StatementPreparerLoader<AbilityTarget> statementPreparerLoader = (preparedStatement, data) -> {
final StatementPreparerLoader<AbilityTarget> 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();
}

View File

@ -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<PersonSource, CharacterTarget>
{
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<PersonSource, CharacterTarget>
@Override
protected List<PersonSource> extract()
{
DataStorer<PersonSource> dataStorer = (resultSet) -> {
var extractedData = new ArrayList<PersonSource>();
final DataStorer<PersonSource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<PersonSource>();
while (resultSet.next())
{
extractedData.add(new PersonSource(
@ -39,16 +37,16 @@ public class CharacterMigration extends ETL<PersonSource, CharacterTarget>
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<CharacterTarget> transform(List<PersonSource> extractedData)
protected List<CharacterTarget> transform(final List<PersonSource> extractedData)
{
DataTransformer<PersonSource, CharacterTarget> transformer =
final DataTransformer<PersonSource, CharacterTarget> transformer =
(dataset) -> new CharacterTarget(
dataset.getPersonId(),
dataset.getName(),
@ -59,15 +57,15 @@ public class CharacterMigration extends ETL<PersonSource, CharacterTarget>
}
@Override
protected void load(List<CharacterTarget> transformedData)
protected void load(final List<CharacterTarget> transformedData)
{
StatementPreparerLoader<CharacterTarget> statementPreparerLoader = (preparedStatement, data) -> {
final StatementPreparerLoader<CharacterTarget> 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();
}

View File

@ -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<T extends SourceDataset, E extends TargetDataset>
{
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<T extends SourceDataset, E extends TargetDataset>
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();
}

View File

@ -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<GameobjectSource, GameobjectTarget>
{
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<GameobjectSource, GameobjectTarget>
@Override
protected List<GameobjectSource> extract()
{
DataStorer<GameobjectSource> dataStorer = (resultSet) -> {
var extractedData = new ArrayList<GameobjectSource>();
final DataStorer<GameobjectSource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<GameobjectSource>();
while (resultSet.next())
{
extractedData.add(new GameobjectSource(
@ -40,16 +37,16 @@ public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
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<GameobjectTarget> transform(List<GameobjectSource> extractedData)
protected List<GameobjectTarget> transform(final List<GameobjectSource> extractedData)
{
DataTransformer<GameobjectSource, GameobjectTarget> transformer = (dataset) -> new GameobjectTarget(
final DataTransformer<GameobjectSource, GameobjectTarget> transformer = (dataset) -> new GameobjectTarget(
dataset.getObjectId(),
dataset.getName(),
dataset.getDescription()
@ -59,15 +56,15 @@ public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
}
@Override
protected void load(List<GameobjectTarget> transformedData)
protected void load(final List<GameobjectTarget> transformedData)
{
StatementPreparerLoader<GameobjectTarget> statementPreparerLoader = (preparedStatement, data) -> {
final StatementPreparerLoader<GameobjectTarget> 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();
}

View File

@ -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<ModSource, ModTarget>
{
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<ModSource, ModTarget>
@Override
protected List<ModSource> extract()
{
DataStorer<ModSource> dataStorer = (resultSet) -> {
var extractedData = new ArrayList<ModSource>();
final DataStorer<ModSource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<ModSource>();
while (resultSet.next())
{
extractedData.add(new ModSource(
@ -41,16 +39,16 @@ public class ModMigration extends ETL<ModSource, ModTarget>
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<ModTarget> transform(List<ModSource> extractedData)
protected List<ModTarget> transform(final List<ModSource> extractedData)
{
DataTransformer<ModSource, ModTarget> transformer = (dataset) -> new ModTarget(
final DataTransformer<ModSource, ModTarget> transformer = (dataset) -> new ModTarget(
dataset.getModId(),
dataset.getName(),
dataset.getInstallationDate(),
@ -61,16 +59,16 @@ public class ModMigration extends ETL<ModSource, ModTarget>
}
@Override
protected void load(List<ModTarget> transformedData)
protected void load(final List<ModTarget> transformedData)
{
StatementPreparerLoader<ModTarget> statementPreparerLoader = (preparedStatement, data) -> {
final StatementPreparerLoader<ModTarget> 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();
}

View File

@ -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<PlayerAbilitiesSource, PlayerAbilitiesTarget>
{
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<PlayerAbilitiesSource, PlayerA
@Override
protected List<PlayerAbilitiesSource> extract()
{
DataStorer<PlayerAbilitiesSource> dataStorer = (resultSet) -> {
var extractedData = new ArrayList<PlayerAbilitiesSource>();
final DataStorer<PlayerAbilitiesSource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<PlayerAbilitiesSource>();
while (resultSet.next())
{
extractedData.add(new PlayerAbilitiesSource(
@ -39,33 +36,31 @@ public class PlayerAbilitiesMigration extends ETL<PlayerAbilitiesSource, PlayerA
return extractedData;
};
var sql = "select * from player p join ability a on p.playerId = ?;";
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {
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<PlayerAbilitiesTarget> transform(List<PlayerAbilitiesSource> extractedData)
protected List<PlayerAbilitiesTarget> transform(final List<PlayerAbilitiesSource> extractedData)
{
DataTransformer<PlayerAbilitiesSource, PlayerAbilitiesTarget> transformer =
final DataTransformer<PlayerAbilitiesSource, PlayerAbilitiesTarget> transformer =
(dataset) -> new PlayerAbilitiesTarget(dataset.getPlayerId(), dataset.getAbilityId());
return new Transformer<>(transformer, extractedData).doTransform();
}
@Override
protected void load(List<PlayerAbilitiesTarget> transformedData)
protected void load(final List<PlayerAbilitiesTarget> transformedData)
{
StatementPreparerLoader<PlayerAbilitiesTarget> statementPreparerLoader = (preparedStatement, data) -> {
final StatementPreparerLoader<PlayerAbilitiesTarget> 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();
}

View File

@ -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<SourceDataset, PlayerTarget>
{
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<SourceDataset, PlayerTarget>
}
@Override
protected List<PlayerTarget> transform(List<SourceDataset> extractedData)
protected List<PlayerTarget> transform(final List<SourceDataset> extractedData)
{
return null;
}
@Override
protected void load(List<PlayerTarget> transformedData)
protected void load(final List<PlayerTarget> transformedData)
{
}
private void createPlayer()
{
var sql = "insert into player values (?, ?)";
final var sql = "insert into player values (?, ?)";
StatementPreparerLoader<PlayerTarget> statementPreparerLoader = (preparedStatement, data) -> {
final StatementPreparerLoader<PlayerTarget> 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();
}

View File

@ -18,7 +18,7 @@ import java.util.stream.Collectors;
public class QuestMigration extends ETL<QuestSource, QuestTarget>
{
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<QuestSource, QuestTarget>
@Override
protected List<QuestSource> extract()
{
DataStorer<QuestSource> dataStorer = (resultSet) -> {
var extractedData = new ArrayList<QuestSource>();
final DataStorer<QuestSource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<QuestSource>();
while (resultSet.next())
{
extractedData.add(new QuestSource(
@ -39,8 +39,8 @@ public class QuestMigration extends ETL<QuestSource, QuestTarget>
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<QuestSource, QuestTarget>
@Override
protected List<QuestTarget> transform(List<QuestSource> extractedData)
{
var map = new HashMap<Integer, String>();
final var map = new HashMap<Integer, String>();
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<QuestSource, QuestTarget> transformer = (dataset) -> new QuestTarget(
final DataTransformer<QuestSource, QuestTarget> transformer = (dataset) -> new QuestTarget(
dataset.getQuestId(),
dataset.getName(),
map.get(dataset.getQuestId()),
@ -77,16 +77,16 @@ public class QuestMigration extends ETL<QuestSource, QuestTarget>
}
@Override
protected void load(List<QuestTarget> transformedData)
protected void load(final List<QuestTarget> transformedData)
{
StatementPreparerLoader<QuestTarget> statementPreparerLoader = (preparedStatement, data) -> {
final StatementPreparerLoader<QuestTarget> 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();
}

View File

@ -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<ETL> migrations;
private final List<ETL> 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();
}

View File

@ -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;

View File

@ -1,5 +0,0 @@
package utils;
public class DatabaseHelper
{
}

View File

@ -1,6 +1,5 @@
package utils;
import data.SourceDataset;
import data.TargetDataset;
import java.sql.PreparedStatement;