Made finals
This commit is contained in:
parent
6e8eec3ffa
commit
f88cec6ab2
@ -9,7 +9,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class Main
|
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)
|
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 dbInfo = new DatabaseInformation("localhost", "sourcedb1", "test", "test", 25003);
|
||||||
final var connection = new ConnectionHelper(DatabaseType.MARIADB, dbInfo).createConnection();
|
final var connection = new ConnectionHelper(DatabaseType.MARIADB, dbInfo).createConnection();
|
||||||
|
|
||||||
DataStorer<PersonSource> personSourceDataStorer = (rs) -> {
|
final DataStorer<PersonSource> personSourceDataStorer = (rs) -> {
|
||||||
var persons = new ArrayList<PersonSource>();
|
final var persons = new ArrayList<PersonSource>();
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
persons.add(new PersonSource(
|
persons.add(new PersonSource(
|
||||||
@ -36,17 +36,17 @@ public class Main
|
|||||||
return persons;
|
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();
|
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) -> new CharacterTarget(personSource.getPersonId(),
|
||||||
personSource.getName(),
|
personSource.getName(),
|
||||||
personSource.isMortal());
|
personSource.isMortal());
|
||||||
@ -54,18 +54,18 @@ public class Main
|
|||||||
return new Transformer<>(personTransformer, persons).doTransform();
|
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 dbInfo = new DatabaseInformation("localhost", "targetdb", "test", "test", 25001);
|
||||||
final var connection = new ConnectionHelper(DatabaseType.POSTGRESQL, dbInfo).createConnection();
|
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.setInt(1, data.getPersonId());
|
||||||
preparedStatement.setString(2, data.getName());
|
preparedStatement.setString(2, data.getName());
|
||||||
preparedStatement.setBoolean(3, data.isMortal());
|
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();
|
new Loader<>(connection, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ import data.SourceDataset;
|
|||||||
|
|
||||||
public class AbilitiesSource implements SourceDataset
|
public class AbilitiesSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private String name;
|
private final String name;
|
||||||
private String description;
|
private final String description;
|
||||||
private int level;
|
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.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
@ -4,10 +4,10 @@ import data.SourceDataset;
|
|||||||
|
|
||||||
public class ActiveQuestsSource implements SourceDataset
|
public class ActiveQuestsSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int questId;
|
private final int questId;
|
||||||
private int progress;
|
private final int progress;
|
||||||
|
|
||||||
public ActiveQuestsSource(int questId, int progress)
|
public ActiveQuestsSource(final int questId, final int progress)
|
||||||
{
|
{
|
||||||
this.questId = questId;
|
this.questId = questId;
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
|
@ -4,11 +4,11 @@ import data.SourceDataset;
|
|||||||
|
|
||||||
public class GameobjectSource implements SourceDataset
|
public class GameobjectSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int objectId;
|
private final int objectId;
|
||||||
private String name;
|
private final String name;
|
||||||
private String description;
|
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.objectId = objectId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -4,9 +4,9 @@ import data.SourceDataset;
|
|||||||
|
|
||||||
public class InventorySource implements 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;
|
this.objectId = objectId;
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ import java.time.LocalDate;
|
|||||||
|
|
||||||
public class ModSource implements SourceDataset
|
public class ModSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int modId;
|
private final int modId;
|
||||||
private String name;
|
private final String name;
|
||||||
private LocalDate installationDate;
|
private final LocalDate installationDate;
|
||||||
private Blob binary;
|
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.modId = modId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -4,10 +4,10 @@ import data.SourceDataset;
|
|||||||
|
|
||||||
public class PersonInventorySource implements SourceDataset
|
public class PersonInventorySource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int personId;
|
private final int personId;
|
||||||
private int objectId;
|
private final int objectId;
|
||||||
|
|
||||||
public PersonInventorySource(int personId, int objectId)
|
public PersonInventorySource(final int personId, final int objectId)
|
||||||
{
|
{
|
||||||
this.personId = personId;
|
this.personId = personId;
|
||||||
this.objectId = objectId;
|
this.objectId = objectId;
|
||||||
|
@ -4,11 +4,11 @@ import data.SourceDataset;
|
|||||||
|
|
||||||
public class PersonSource implements SourceDataset
|
public class PersonSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int personId;
|
private final int personId;
|
||||||
private String name;
|
private final String name;
|
||||||
private boolean mortal;
|
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.personId = personId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -4,10 +4,10 @@ import data.SourceDataset;
|
|||||||
|
|
||||||
public class PlayerAbilitiesSource implements SourceDataset
|
public class PlayerAbilitiesSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int playerId;
|
private final int playerId;
|
||||||
private int abilityId;
|
private final int abilityId;
|
||||||
|
|
||||||
public PlayerAbilitiesSource(int playerId, int abilityId)
|
public PlayerAbilitiesSource(final int playerId, final int abilityId)
|
||||||
{
|
{
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
this.abilityId = abilityId;
|
this.abilityId = abilityId;
|
||||||
|
@ -8,12 +8,12 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class QuestSource implements SourceDataset
|
public class QuestSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int questId;
|
private final int questId;
|
||||||
private String name;
|
private final String name;
|
||||||
private Clob dialogue;
|
private final Clob dialogue;
|
||||||
private int personId;
|
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.questId = questId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -42,7 +42,7 @@ public class QuestSource implements SourceDataset
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(final Object o)
|
||||||
{
|
{
|
||||||
if (this == o)
|
if (this == o)
|
||||||
{
|
{
|
||||||
@ -52,7 +52,7 @@ public class QuestSource implements SourceDataset
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QuestSource that = (QuestSource) o;
|
final QuestSource that = (QuestSource) o;
|
||||||
return questId == that.questId;
|
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);
|
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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ import data.SourceDataset;
|
|||||||
|
|
||||||
public class RelationshipsSource implements SourceDataset
|
public class RelationshipsSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int personId;
|
private final int personId;
|
||||||
private int relationshipLevel;
|
private final int relationshipLevel;
|
||||||
|
|
||||||
public RelationshipsSource(int personId, int relationshipLevel)
|
public RelationshipsSource(final int personId, final int relationshipLevel)
|
||||||
{
|
{
|
||||||
this.personId = personId;
|
this.personId = personId;
|
||||||
this.relationshipLevel = relationshipLevel;
|
this.relationshipLevel = relationshipLevel;
|
||||||
|
@ -4,12 +4,12 @@ import data.TargetDataset;
|
|||||||
|
|
||||||
public class AbilityTarget implements TargetDataset
|
public class AbilityTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int abilityId;
|
private final int abilityId;
|
||||||
private String abilityName;
|
private final String abilityName;
|
||||||
private String abilityDescription;
|
private final String abilityDescription;
|
||||||
private float abilityLevel;
|
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.abilityId = abilityId;
|
||||||
this.abilityName = abilityName;
|
this.abilityName = abilityName;
|
||||||
|
@ -4,11 +4,11 @@ import data.TargetDataset;
|
|||||||
|
|
||||||
public class ActiveQuestsTarget implements TargetDataset
|
public class ActiveQuestsTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int playerId;
|
private final int playerId;
|
||||||
private int questId;
|
private final int questId;
|
||||||
private int questProgress;
|
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.playerId = playerId;
|
||||||
this.questId = questId;
|
this.questId = questId;
|
||||||
|
@ -4,10 +4,10 @@ import data.TargetDataset;
|
|||||||
|
|
||||||
public class CharacterInventoryTarget implements TargetDataset
|
public class CharacterInventoryTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int personId;
|
private final int personId;
|
||||||
private int objectId;
|
private final int objectId;
|
||||||
|
|
||||||
public CharacterInventoryTarget(int personId, int objectId)
|
public CharacterInventoryTarget(final int personId, final int objectId)
|
||||||
{
|
{
|
||||||
this.personId = personId;
|
this.personId = personId;
|
||||||
this.objectId = objectId;
|
this.objectId = objectId;
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package data.target;
|
package data.target;
|
||||||
|
|
||||||
import data.SourceDataset;
|
|
||||||
import data.TargetDataset;
|
import data.TargetDataset;
|
||||||
|
|
||||||
public class CharacterTarget implements TargetDataset
|
public class CharacterTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int personId;
|
private final int personId;
|
||||||
private String name;
|
private final String name;
|
||||||
private boolean mortal;
|
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.personId = personId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -4,11 +4,11 @@ import data.TargetDataset;
|
|||||||
|
|
||||||
public class GameobjectTarget implements TargetDataset
|
public class GameobjectTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int objectId;
|
private final int objectId;
|
||||||
private String name;
|
private final String name;
|
||||||
private String description;
|
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.objectId = objectId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -4,11 +4,11 @@ import data.TargetDataset;
|
|||||||
|
|
||||||
public class InventoryTarget implements TargetDataset
|
public class InventoryTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int playerId;
|
private final int playerId;
|
||||||
private int objectId;
|
private final int objectId;
|
||||||
private boolean stolen;
|
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.playerId = playerId;
|
||||||
this.objectId = objectId;
|
this.objectId = objectId;
|
||||||
|
@ -7,12 +7,12 @@ import java.time.LocalDate;
|
|||||||
|
|
||||||
public class ModTarget implements TargetDataset
|
public class ModTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int modId;
|
private final int modId;
|
||||||
private String modName;
|
private final String modName;
|
||||||
private LocalDate modInstallationDate;
|
private final LocalDate modInstallationDate;
|
||||||
private Blob modBinary;
|
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.modId = modId;
|
||||||
this.modName = modName;
|
this.modName = modName;
|
||||||
|
@ -4,10 +4,10 @@ import data.TargetDataset;
|
|||||||
|
|
||||||
public class PlayerAbilitiesTarget implements TargetDataset
|
public class PlayerAbilitiesTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int playerId;
|
private final int playerId;
|
||||||
private int abilityId;
|
private final int abilityId;
|
||||||
|
|
||||||
public PlayerAbilitiesTarget(int playerId, int abilityId)
|
public PlayerAbilitiesTarget(final int playerId, final int abilityId)
|
||||||
{
|
{
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
this.abilityId = abilityId;
|
this.abilityId = abilityId;
|
||||||
|
@ -4,10 +4,10 @@ import data.TargetDataset;
|
|||||||
|
|
||||||
public class PlayerTarget implements TargetDataset
|
public class PlayerTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int playerId;
|
private final int playerId;
|
||||||
private String playerName;
|
private final String playerName;
|
||||||
|
|
||||||
public PlayerTarget(int playerId, String playerName)
|
public PlayerTarget(final int playerId, final String playerName)
|
||||||
{
|
{
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
|
@ -7,12 +7,12 @@ import java.sql.SQLException;
|
|||||||
|
|
||||||
public class QuestTarget implements TargetDataset
|
public class QuestTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int questId;
|
private final int questId;
|
||||||
private String name;
|
private final String name;
|
||||||
private String involvedCharacters;
|
private final String involvedCharacters;
|
||||||
private Clob dialogue;
|
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.questId = questId;
|
||||||
this.name = name;
|
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));
|
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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ import data.TargetDataset;
|
|||||||
|
|
||||||
public class RelationshipTarget implements TargetDataset
|
public class RelationshipTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int playerId;
|
private final int playerId;
|
||||||
private int personId;
|
private final int personId;
|
||||||
private int relationshipLevel;
|
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.playerId = playerId;
|
||||||
this.personId = personId;
|
this.personId = personId;
|
||||||
|
@ -11,15 +11,15 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Extractor<T extends SourceDataset>
|
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 final Connection sourceDatabase;
|
||||||
private DataStorer<T> dataStorer;
|
private final DataStorer<T> dataStorer;
|
||||||
private StatementPreparerExtractor statementPreparer;
|
private final StatementPreparerExtractor statementPreparer;
|
||||||
private String sql;
|
private final String sql;
|
||||||
|
|
||||||
public Extractor(Connection sourceDatabase, DataStorer<T> dataStorer,
|
public Extractor(final Connection sourceDatabase, final DataStorer<T> dataStorer,
|
||||||
StatementPreparerExtractor statementPreparer, String sql)
|
final StatementPreparerExtractor statementPreparer, final String sql)
|
||||||
{
|
{
|
||||||
this.sourceDatabase = sourceDatabase;
|
this.sourceDatabase = sourceDatabase;
|
||||||
this.dataStorer = dataStorer;
|
this.dataStorer = dataStorer;
|
||||||
@ -31,13 +31,13 @@ public class Extractor<T extends SourceDataset>
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var preparedStatement = this.sourceDatabase.prepareStatement(sql);
|
final var preparedStatement = this.sourceDatabase.prepareStatement(sql);
|
||||||
this.statementPreparer.doPrepare(preparedStatement);
|
this.statementPreparer.doPrepare(preparedStatement);
|
||||||
var resultSet = preparedStatement.executeQuery();
|
final var resultSet = preparedStatement.executeQuery();
|
||||||
log.info(String.format("--- Data extracted with '%s' ---", this.sql));
|
log.info(String.format("--- Data extracted with '%s' ---", this.sql));
|
||||||
return this.dataStorer.doStore(resultSet);
|
return this.dataStorer.doStore(resultSet);
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (final SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package etl;
|
package etl;
|
||||||
|
|
||||||
import data.SourceDataset;
|
|
||||||
import data.TargetDataset;
|
import data.TargetDataset;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import utils.StatementPreparerLoader;
|
import utils.StatementPreparerLoader;
|
||||||
@ -11,15 +10,15 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Loader<T extends TargetDataset>
|
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 final Connection targetDatabase;
|
||||||
private StatementPreparerLoader<T> statementPreparerLoader;
|
private final StatementPreparerLoader<T> statementPreparerLoader;
|
||||||
private List<T> transformedData;
|
private final List<T> transformedData;
|
||||||
private String sql;
|
private final String sql;
|
||||||
|
|
||||||
public Loader(Connection targetDatabase, StatementPreparerLoader<T> statementPreparerLoader, List<T> transformedData,
|
public Loader(final Connection targetDatabase, final StatementPreparerLoader<T> statementPreparerLoader, final List<T> transformedData,
|
||||||
String sql)
|
final String sql)
|
||||||
{
|
{
|
||||||
this.targetDatabase = targetDatabase;
|
this.targetDatabase = targetDatabase;
|
||||||
this.statementPreparerLoader = statementPreparerLoader;
|
this.statementPreparerLoader = statementPreparerLoader;
|
||||||
@ -31,16 +30,16 @@ public class Loader<T extends TargetDataset>
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (T transformedDatum : this.transformedData)
|
for (final T transformedDatum : this.transformedData)
|
||||||
{
|
{
|
||||||
log.info(String.format("Load data into target: %s", transformedDatum));
|
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);
|
this.statementPreparerLoader.doPrepare(preparedStatement, transformedDatum);
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
}
|
}
|
||||||
log.info(String.format("--- Data loaded into target with '%s' ---", this.sql));
|
log.info(String.format("--- Data loaded into target with '%s' ---", this.sql));
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (final SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Transformer<T extends SourceDataset, E extends TargetDataset>
|
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 final DataTransformer<T, E> transformer;
|
||||||
private List<T> extractedData;
|
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.transformer = transformer;
|
||||||
this.extractedData = extractedData;
|
this.extractedData = extractedData;
|
||||||
@ -23,8 +23,8 @@ public class Transformer<T extends SourceDataset, E extends TargetDataset>
|
|||||||
|
|
||||||
public List<E> doTransform()
|
public List<E> doTransform()
|
||||||
{
|
{
|
||||||
var transformed = new ArrayList<E>();
|
final var transformed = new ArrayList<E>();
|
||||||
for (T dataset : this.extractedData)
|
for (final T dataset : this.extractedData)
|
||||||
{
|
{
|
||||||
log.info(String.format("Transform data: %s", dataset));
|
log.info(String.format("Transform data: %s", dataset));
|
||||||
transformed.add(this.transformer.transform(dataset));
|
transformed.add(this.transformer.transform(dataset));
|
||||||
|
@ -2,9 +2,7 @@ package migration;
|
|||||||
|
|
||||||
import com.mysql.cj.exceptions.NumberOutOfRange;
|
import com.mysql.cj.exceptions.NumberOutOfRange;
|
||||||
import data.source.AbilitiesSource;
|
import data.source.AbilitiesSource;
|
||||||
import data.source.PersonSource;
|
|
||||||
import data.target.AbilityTarget;
|
import data.target.AbilityTarget;
|
||||||
import data.target.CharacterTarget;
|
|
||||||
import etl.Extractor;
|
import etl.Extractor;
|
||||||
import etl.Loader;
|
import etl.Loader;
|
||||||
import etl.Transformer;
|
import etl.Transformer;
|
||||||
@ -18,7 +16,7 @@ public class AbilityMigration extends ETL<AbilitiesSource, AbilityTarget>
|
|||||||
{
|
{
|
||||||
private int abilityId;
|
private int abilityId;
|
||||||
|
|
||||||
public AbilityMigration(Connection source, Connection target)
|
public AbilityMigration(final Connection source, final Connection target)
|
||||||
{
|
{
|
||||||
super(source, target);
|
super(source, target);
|
||||||
this.abilityId = 0;
|
this.abilityId = 0;
|
||||||
@ -27,8 +25,8 @@ public class AbilityMigration extends ETL<AbilitiesSource, AbilityTarget>
|
|||||||
@Override
|
@Override
|
||||||
protected List<AbilitiesSource> extract()
|
protected List<AbilitiesSource> extract()
|
||||||
{
|
{
|
||||||
DataStorer<AbilitiesSource> dataStorer = (resultSet) -> {
|
final DataStorer<AbilitiesSource> dataStorer = (resultSet) -> {
|
||||||
var extractedData = new ArrayList<AbilitiesSource>();
|
final var extractedData = new ArrayList<AbilitiesSource>();
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
extractedData.add(new AbilitiesSource(
|
extractedData.add(new AbilitiesSource(
|
||||||
@ -40,20 +38,20 @@ public class AbilityMigration extends ETL<AbilitiesSource, AbilityTarget>
|
|||||||
return extractedData;
|
return extractedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
var sql = "select * from abilities;";
|
final var sql = "select * from abilities;";
|
||||||
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
||||||
|
|
||||||
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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)
|
if (dataset.getLevel() < 0 || dataset.getLevel() > 100)
|
||||||
log.error("level-value out of range",
|
log.error("level-value out of range",
|
||||||
new NumberOutOfRange("level must be within 0 an 100 (both inclusive)"));
|
new NumberOutOfRange("level must be within 0 an 100 (both inclusive)"));
|
||||||
var levelCorrection = 100f;
|
final var levelCorrection = 100f;
|
||||||
return new AbilityTarget(
|
return new AbilityTarget(
|
||||||
abilityId++,
|
abilityId++,
|
||||||
dataset.getName(),
|
dataset.getName(),
|
||||||
@ -66,16 +64,16 @@ public class AbilityMigration extends ETL<AbilitiesSource, AbilityTarget>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.setInt(1, data.getAbilityId());
|
||||||
preparedStatement.setString(2, data.getAbilityName());
|
preparedStatement.setString(2, data.getAbilityName());
|
||||||
preparedStatement.setString(3, data.getAbilityDescription());
|
preparedStatement.setString(3, data.getAbilityDescription());
|
||||||
preparedStatement.setFloat(4, data.getAbilityLevel());
|
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();
|
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package migration;
|
package migration;
|
||||||
|
|
||||||
import data.source.AbilitiesSource;
|
|
||||||
import data.source.PersonSource;
|
import data.source.PersonSource;
|
||||||
import data.target.AbilityTarget;
|
|
||||||
import data.target.CharacterTarget;
|
import data.target.CharacterTarget;
|
||||||
import etl.Extractor;
|
import etl.Extractor;
|
||||||
import etl.Loader;
|
import etl.Loader;
|
||||||
@ -18,7 +16,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CharacterMigration extends ETL<PersonSource, CharacterTarget>
|
public class CharacterMigration extends ETL<PersonSource, CharacterTarget>
|
||||||
{
|
{
|
||||||
public CharacterMigration(Connection source, Connection target)
|
public CharacterMigration(final Connection source, final Connection target)
|
||||||
{
|
{
|
||||||
super(source, target);
|
super(source, target);
|
||||||
}
|
}
|
||||||
@ -26,8 +24,8 @@ public class CharacterMigration extends ETL<PersonSource, CharacterTarget>
|
|||||||
@Override
|
@Override
|
||||||
protected List<PersonSource> extract()
|
protected List<PersonSource> extract()
|
||||||
{
|
{
|
||||||
DataStorer<PersonSource> dataStorer = (resultSet) -> {
|
final DataStorer<PersonSource> dataStorer = (resultSet) -> {
|
||||||
var extractedData = new ArrayList<PersonSource>();
|
final var extractedData = new ArrayList<PersonSource>();
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
extractedData.add(new PersonSource(
|
extractedData.add(new PersonSource(
|
||||||
@ -39,16 +37,16 @@ public class CharacterMigration extends ETL<PersonSource, CharacterTarget>
|
|||||||
return extractedData;
|
return extractedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
var sql = "select * from person;";
|
final var sql = "select * from person;";
|
||||||
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
||||||
|
|
||||||
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) -> new CharacterTarget(
|
||||||
dataset.getPersonId(),
|
dataset.getPersonId(),
|
||||||
dataset.getName(),
|
dataset.getName(),
|
||||||
@ -59,15 +57,15 @@ public class CharacterMigration extends ETL<PersonSource, CharacterTarget>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.setInt(1, data.getPersonId());
|
||||||
preparedStatement.setString(2, data.getName());
|
preparedStatement.setString(2, data.getName());
|
||||||
preparedStatement.setBoolean(3, data.isMortal());
|
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();
|
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package migration;
|
|||||||
|
|
||||||
import data.SourceDataset;
|
import data.SourceDataset;
|
||||||
import data.TargetDataset;
|
import data.TargetDataset;
|
||||||
import data.source.PersonSource;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -11,12 +10,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public abstract class ETL<T extends SourceDataset, E extends TargetDataset>
|
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 final Connection source;
|
||||||
protected Connection target;
|
protected final Connection target;
|
||||||
|
|
||||||
public ETL(Connection source, Connection target)
|
public ETL(final Connection source, final Connection target)
|
||||||
{
|
{
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
@ -25,15 +24,15 @@ public abstract class ETL<T extends SourceDataset, E extends TargetDataset>
|
|||||||
public void migrate()
|
public void migrate()
|
||||||
{
|
{
|
||||||
log.info(String.format("--- Migration: %s ---", this.getClass().getName()));
|
log.info(String.format("--- Migration: %s ---", this.getClass().getName()));
|
||||||
var extractedData = this.extract();
|
final var extractedData = this.extract();
|
||||||
var transformedData = this.transform(extractedData);
|
final var transformedData = this.transform(extractedData);
|
||||||
this.load(transformedData);
|
this.load(transformedData);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.target.commit();
|
this.target.commit();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (final SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package migration;
|
package migration;
|
||||||
|
|
||||||
import com.mysql.cj.exceptions.NumberOutOfRange;
|
|
||||||
import data.source.AbilitiesSource;
|
|
||||||
import data.source.GameobjectSource;
|
import data.source.GameobjectSource;
|
||||||
import data.target.AbilityTarget;
|
|
||||||
import data.target.GameobjectTarget;
|
import data.target.GameobjectTarget;
|
||||||
import etl.Extractor;
|
import etl.Extractor;
|
||||||
import etl.Loader;
|
import etl.Loader;
|
||||||
@ -19,7 +16,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
|
public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
|
||||||
{
|
{
|
||||||
public GameobjectMigration(Connection source, Connection target)
|
public GameobjectMigration(final Connection source, final Connection target)
|
||||||
{
|
{
|
||||||
super(source, target);
|
super(source, target);
|
||||||
}
|
}
|
||||||
@ -27,8 +24,8 @@ public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
|
|||||||
@Override
|
@Override
|
||||||
protected List<GameobjectSource> extract()
|
protected List<GameobjectSource> extract()
|
||||||
{
|
{
|
||||||
DataStorer<GameobjectSource> dataStorer = (resultSet) -> {
|
final DataStorer<GameobjectSource> dataStorer = (resultSet) -> {
|
||||||
var extractedData = new ArrayList<GameobjectSource>();
|
final var extractedData = new ArrayList<GameobjectSource>();
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
extractedData.add(new GameobjectSource(
|
extractedData.add(new GameobjectSource(
|
||||||
@ -40,16 +37,16 @@ public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
|
|||||||
return extractedData;
|
return extractedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
var sql = "select * from gameobject;";
|
final var sql = "select * from gameobject;";
|
||||||
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
||||||
|
|
||||||
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.getObjectId(),
|
||||||
dataset.getName(),
|
dataset.getName(),
|
||||||
dataset.getDescription()
|
dataset.getDescription()
|
||||||
@ -59,15 +56,15 @@ public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.setInt(1, data.getObjectId());
|
||||||
preparedStatement.setString(2, data.getName());
|
preparedStatement.setString(2, data.getName());
|
||||||
preparedStatement.setString(3, data.getDescription());
|
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();
|
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package migration;
|
package migration;
|
||||||
|
|
||||||
import data.source.GameobjectSource;
|
|
||||||
import data.source.ModSource;
|
import data.source.ModSource;
|
||||||
import data.target.GameobjectTarget;
|
|
||||||
import data.target.ModTarget;
|
import data.target.ModTarget;
|
||||||
import etl.Extractor;
|
import etl.Extractor;
|
||||||
import etl.Loader;
|
import etl.Loader;
|
||||||
@ -19,7 +17,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ModMigration extends ETL<ModSource, ModTarget>
|
public class ModMigration extends ETL<ModSource, ModTarget>
|
||||||
{
|
{
|
||||||
public ModMigration(Connection source, Connection target)
|
public ModMigration(final Connection source, final Connection target)
|
||||||
{
|
{
|
||||||
super(source, target);
|
super(source, target);
|
||||||
}
|
}
|
||||||
@ -27,8 +25,8 @@ public class ModMigration extends ETL<ModSource, ModTarget>
|
|||||||
@Override
|
@Override
|
||||||
protected List<ModSource> extract()
|
protected List<ModSource> extract()
|
||||||
{
|
{
|
||||||
DataStorer<ModSource> dataStorer = (resultSet) -> {
|
final DataStorer<ModSource> dataStorer = (resultSet) -> {
|
||||||
var extractedData = new ArrayList<ModSource>();
|
final var extractedData = new ArrayList<ModSource>();
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
extractedData.add(new ModSource(
|
extractedData.add(new ModSource(
|
||||||
@ -41,16 +39,16 @@ public class ModMigration extends ETL<ModSource, ModTarget>
|
|||||||
return extractedData;
|
return extractedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
var sql = "select * from `mod`;";
|
final var sql = "select * from `mod`;";
|
||||||
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
||||||
|
|
||||||
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.getModId(),
|
||||||
dataset.getName(),
|
dataset.getName(),
|
||||||
dataset.getInstallationDate(),
|
dataset.getInstallationDate(),
|
||||||
@ -61,16 +59,16 @@ public class ModMigration extends ETL<ModSource, ModTarget>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.setInt(1, data.getModId());
|
||||||
preparedStatement.setString(2, data.getName());
|
preparedStatement.setString(2, data.getName());
|
||||||
preparedStatement.setDate(3, Date.valueOf(data.getModInstallationDate()));
|
preparedStatement.setDate(3, Date.valueOf(data.getModInstallationDate()));
|
||||||
preparedStatement.setBinaryStream(4, data.getModBinary().getBinaryStream());
|
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();
|
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package migration;
|
package migration;
|
||||||
|
|
||||||
import data.SourceDataset;
|
|
||||||
import data.source.AbilitiesSource;
|
|
||||||
import data.source.PlayerAbilitiesSource;
|
import data.source.PlayerAbilitiesSource;
|
||||||
import data.target.AbilityTarget;
|
|
||||||
import data.target.PlayerAbilitiesTarget;
|
import data.target.PlayerAbilitiesTarget;
|
||||||
import etl.Extractor;
|
import etl.Extractor;
|
||||||
import etl.Loader;
|
import etl.Loader;
|
||||||
@ -19,7 +16,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class PlayerAbilitiesMigration extends ETL<PlayerAbilitiesSource, PlayerAbilitiesTarget>
|
public class PlayerAbilitiesMigration extends ETL<PlayerAbilitiesSource, PlayerAbilitiesTarget>
|
||||||
{
|
{
|
||||||
public PlayerAbilitiesMigration(Connection source, Connection target)
|
public PlayerAbilitiesMigration(final Connection source, final Connection target)
|
||||||
{
|
{
|
||||||
super(source, target);
|
super(source, target);
|
||||||
}
|
}
|
||||||
@ -27,8 +24,8 @@ public class PlayerAbilitiesMigration extends ETL<PlayerAbilitiesSource, PlayerA
|
|||||||
@Override
|
@Override
|
||||||
protected List<PlayerAbilitiesSource> extract()
|
protected List<PlayerAbilitiesSource> extract()
|
||||||
{
|
{
|
||||||
DataStorer<PlayerAbilitiesSource> dataStorer = (resultSet) -> {
|
final DataStorer<PlayerAbilitiesSource> dataStorer = (resultSet) -> {
|
||||||
var extractedData = new ArrayList<PlayerAbilitiesSource>();
|
final var extractedData = new ArrayList<PlayerAbilitiesSource>();
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
extractedData.add(new PlayerAbilitiesSource(
|
extractedData.add(new PlayerAbilitiesSource(
|
||||||
@ -39,33 +36,31 @@ public class PlayerAbilitiesMigration extends ETL<PlayerAbilitiesSource, PlayerA
|
|||||||
return extractedData;
|
return extractedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
var sql = "select * from player p join ability a on p.playerId = ?;";
|
final var sql = "select * from player p join ability a on p.playerId = ?;";
|
||||||
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {
|
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> preparedStatement.setInt(1, 0);
|
||||||
preparedStatement.setInt(1, 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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());
|
(dataset) -> new PlayerAbilitiesTarget(dataset.getPlayerId(), dataset.getAbilityId());
|
||||||
|
|
||||||
return new Transformer<>(transformer, extractedData).doTransform();
|
return new Transformer<>(transformer, extractedData).doTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(1, data.getPlayerId());
|
||||||
preparedStatement.setInt(2, data.getAbilityId());
|
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();
|
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,6 @@ package migration;
|
|||||||
import data.SourceDataset;
|
import data.SourceDataset;
|
||||||
import data.target.PlayerTarget;
|
import data.target.PlayerTarget;
|
||||||
import etl.Loader;
|
import etl.Loader;
|
||||||
import utils.ConnectionHelper;
|
|
||||||
import utils.DatabaseInformation;
|
|
||||||
import utils.DatabaseType;
|
|
||||||
import utils.StatementPreparerLoader;
|
import utils.StatementPreparerLoader;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -13,7 +10,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class PlayerMigration extends ETL<SourceDataset, PlayerTarget>
|
public class PlayerMigration extends ETL<SourceDataset, PlayerTarget>
|
||||||
{
|
{
|
||||||
public PlayerMigration(Connection source, Connection target)
|
public PlayerMigration(final Connection source, final Connection target)
|
||||||
{
|
{
|
||||||
super(source, target);
|
super(source, target);
|
||||||
}
|
}
|
||||||
@ -31,26 +28,26 @@ public class PlayerMigration extends ETL<SourceDataset, PlayerTarget>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<PlayerTarget> transform(List<SourceDataset> extractedData)
|
protected List<PlayerTarget> transform(final List<SourceDataset> extractedData)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void load(List<PlayerTarget> transformedData)
|
protected void load(final List<PlayerTarget> transformedData)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createPlayer()
|
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.setInt(1, data.getPlayerId());
|
||||||
preparedStatement.setString(2, data.getPlayerName());
|
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();
|
new Loader<>(this.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class QuestMigration extends ETL<QuestSource, QuestTarget>
|
public class QuestMigration extends ETL<QuestSource, QuestTarget>
|
||||||
{
|
{
|
||||||
public QuestMigration(Connection source, Connection target)
|
public QuestMigration(final Connection source, final Connection target)
|
||||||
{
|
{
|
||||||
super(source, target);
|
super(source, target);
|
||||||
}
|
}
|
||||||
@ -26,8 +26,8 @@ public class QuestMigration extends ETL<QuestSource, QuestTarget>
|
|||||||
@Override
|
@Override
|
||||||
protected List<QuestSource> extract()
|
protected List<QuestSource> extract()
|
||||||
{
|
{
|
||||||
DataStorer<QuestSource> dataStorer = (resultSet) -> {
|
final DataStorer<QuestSource> dataStorer = (resultSet) -> {
|
||||||
var extractedData = new ArrayList<QuestSource>();
|
final var extractedData = new ArrayList<QuestSource>();
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
extractedData.add(new QuestSource(
|
extractedData.add(new QuestSource(
|
||||||
@ -39,8 +39,8 @@ public class QuestMigration extends ETL<QuestSource, QuestTarget>
|
|||||||
return extractedData;
|
return extractedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
var sql = "select * from quest q join questParticipation qp on q.questId = qp.questId;";
|
final var sql = "select * from quest q join questParticipation qp on q.questId = qp.questId;";
|
||||||
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
||||||
|
|
||||||
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
||||||
}
|
}
|
||||||
@ -48,25 +48,25 @@ public class QuestMigration extends ETL<QuestSource, QuestTarget>
|
|||||||
@Override
|
@Override
|
||||||
protected List<QuestTarget> transform(List<QuestSource> extractedData)
|
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))
|
if (!map.containsKey(key))
|
||||||
{
|
{
|
||||||
map.put(key, String.valueOf(extractedDatum.getPersonId()));
|
map.put(key, String.valueOf(extractedDatum.getPersonId()));
|
||||||
}
|
}
|
||||||
else
|
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);
|
map.replace(key, involvedPersons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extractedData = extractedData.stream().distinct().collect(Collectors.toList());
|
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.getQuestId(),
|
||||||
dataset.getName(),
|
dataset.getName(),
|
||||||
map.get(dataset.getQuestId()),
|
map.get(dataset.getQuestId()),
|
||||||
@ -77,16 +77,16 @@ public class QuestMigration extends ETL<QuestSource, QuestTarget>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.setInt(1, data.getQuestId());
|
||||||
preparedStatement.setString(2, data.getName());
|
preparedStatement.setString(2, data.getName());
|
||||||
preparedStatement.setString(3, data.getInvolvedCharacters());
|
preparedStatement.setString(3, data.getInvolvedCharacters());
|
||||||
preparedStatement.setClob(4, data.getDialogue());
|
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();
|
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,16 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("ALL")
|
||||||
public class ThesisMigration
|
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 final Connection mariadb;
|
||||||
private Connection mysql;
|
private final Connection mysql;
|
||||||
private Connection postgresql;
|
private final Connection postgresql;
|
||||||
|
|
||||||
public ThesisMigration()
|
public ThesisMigration()
|
||||||
{
|
{
|
||||||
@ -38,7 +39,7 @@ public class ThesisMigration
|
|||||||
this.mysql.setAutoCommit(false);
|
this.mysql.setAutoCommit(false);
|
||||||
this.postgresql.setAutoCommit(false);
|
this.postgresql.setAutoCommit(false);
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (final SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -55,17 +56,23 @@ public class ThesisMigration
|
|||||||
|
|
||||||
public void executeMigrations()
|
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);
|
this.migrations.forEach(ETL::migrate);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
log.info("\n--- Closing connections ---\n");
|
log.info("""
|
||||||
|
|
||||||
|
--- Closing connections ---
|
||||||
|
""");
|
||||||
this.mariadb.close();
|
this.mariadb.close();
|
||||||
this.mysql.close();
|
this.mysql.close();
|
||||||
this.postgresql.close();
|
this.postgresql.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (final SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package utils;
|
package utils;
|
||||||
|
|
||||||
import migration.ThesisMigration;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@ -9,7 +8,7 @@ import java.sql.*;
|
|||||||
|
|
||||||
public class ConnectionHelper
|
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 DatabaseType databaseType;
|
||||||
private final String user;
|
private final String user;
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package utils;
|
|
||||||
|
|
||||||
public class DatabaseHelper
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,6 +1,5 @@
|
|||||||
package utils;
|
package utils;
|
||||||
|
|
||||||
import data.SourceDataset;
|
|
||||||
import data.TargetDataset;
|
import data.TargetDataset;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user