This commit is contained in:
Niklas Birk 2020-02-07 18:59:35 +01:00
parent f88cec6ab2
commit c696d83ef8
17 changed files with 325 additions and 74 deletions

View File

@ -2,7 +2,6 @@ package data.source;
import data.SourceDataset;
import java.sql.Clob;
import java.sql.SQLException;
import java.util.Objects;
@ -10,10 +9,10 @@ public class QuestSource implements SourceDataset
{
private final int questId;
private final String name;
private final Clob dialogue;
private final String dialogue;
private final int personId;
public QuestSource(final int questId, final String name, final Clob dialogue, final int personId)
public QuestSource(final int questId, final String name, final String dialogue, final int personId)
{
this.questId = questId;
this.name = name;
@ -31,7 +30,7 @@ public class QuestSource implements SourceDataset
return name;
}
public Clob getDialogue()
public String getDialogue()
{
return dialogue;
}
@ -65,15 +64,6 @@ public class QuestSource implements SourceDataset
@Override
public String toString()
{
try
{
return String.format("Quest { %d, %s, %s..., %d }", this.questId, this.name, this.dialogue.getSubString(1, 10), this.personId);
}
catch (final SQLException e)
{
e.printStackTrace();
}
return null;
return String.format("Quest { %d, %s, %s..., %d }", this.questId, this.name, this.dialogue.substring(0, 10), this.personId);
}
}

View File

@ -6,21 +6,26 @@ public class ActiveQuestsTarget implements TargetDataset
{
private final int playerId;
private final int questId;
private final int questProgress;
private final float questProgress;
public ActiveQuestsTarget(final int playerId, final int questId, final int questProgress)
public ActiveQuestsTarget(final int playerId, final int questId, final float questProgress)
{
this.playerId = playerId;
this.questId = questId;
this.questProgress = questProgress;
}
public int getPlayerId()
{
return playerId;
}
public int getQuestId()
{
return questId;
}
public int getQuestProgress()
public float getQuestProgress()
{
return questProgress;
}
@ -28,6 +33,6 @@ public class ActiveQuestsTarget implements TargetDataset
@Override
public String toString()
{
return String.format("ActiveQuest [ %d, %d, %d ]", this.playerId, this.questId, this.questProgress);
return String.format("ActiveQuest [ %d, %d, %f ]", this.playerId, this.questId, this.questProgress);
}
}

View File

@ -8,6 +8,11 @@ public class InventoryTarget implements TargetDataset
private final int objectId;
private final boolean stolen;
public InventoryTarget(int playerId, int objectId)
{
this(playerId, objectId, false);
}
public InventoryTarget(final int playerId, final int objectId, final boolean stolen)
{
this.playerId = playerId;

View File

@ -2,7 +2,6 @@ package data.target;
import data.TargetDataset;
import java.sql.Clob;
import java.sql.SQLException;
public class QuestTarget implements TargetDataset
@ -10,9 +9,9 @@ public class QuestTarget implements TargetDataset
private final int questId;
private final String name;
private final String involvedCharacters;
private final Clob dialogue;
private final String dialogue;
public QuestTarget(final int questId, final String name, final String involvedCharacters, final Clob dialogue)
public QuestTarget(final int questId, final String name, final String involvedCharacters, final String dialogue)
{
this.questId = questId;
this.name = name;
@ -35,7 +34,7 @@ public class QuestTarget implements TargetDataset
return involvedCharacters;
}
public Clob getDialogue()
public String getDialogue()
{
return dialogue;
}
@ -43,15 +42,6 @@ public class QuestTarget implements TargetDataset
@Override
public String toString()
{
try
{
return String.format("Quest [ %d, %s, { %s }, %s... ]", this.questId, this.name, this.involvedCharacters, this.dialogue.getSubString(1, 10));
}
catch (final SQLException e)
{
e.printStackTrace();
}
return null;
return String.format("Quest [ %d, %s, { %s }, %s... ]", this.questId, this.name, this.involvedCharacters, this.dialogue.substring(0, 10));
}
}

View File

@ -6,9 +6,9 @@ public class RelationshipTarget implements TargetDataset
{
private final int playerId;
private final int personId;
private final int relationshipLevel;
private final float relationshipLevel;
public RelationshipTarget(final int playerId, final int personId, final int relationshipLevel)
public RelationshipTarget(final int playerId, final int personId, final float relationshipLevel)
{
this.playerId = playerId;
this.personId = personId;
@ -25,7 +25,7 @@ public class RelationshipTarget implements TargetDataset
return personId;
}
public int getRelationshipLevel()
public float getRelationshipLevel()
{
return relationshipLevel;
}
@ -33,7 +33,7 @@ public class RelationshipTarget implements TargetDataset
@Override
public String toString()
{
return String.format("Relationship [ %d, %d, %d ]", this.playerId, this.personId, this.relationshipLevel);
return String.format("Relationship [ %d, %d, %f ]", this.playerId, this.personId, this.relationshipLevel);
}
}

View File

@ -0,0 +1,74 @@
package migration;
import com.mysql.cj.exceptions.NumberOutOfRange;
import data.source.ActiveQuestsSource;
import data.target.ActiveQuestsTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.*;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
public class ActiveQuestsMigration extends ETL<ActiveQuestsSource, ActiveQuestsTarget>
{
public ActiveQuestsMigration(Connection source, Connection target)
{
super(source, target);
}
@Override
protected List<ActiveQuestsSource> extract()
{
final DataStorer<ActiveQuestsSource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<ActiveQuestsSource>();
while (resultSet.next())
{
extractedData.add(new ActiveQuestsSource(
resultSet.getInt("questId"),
resultSet.getInt("progress")
));
}
return extractedData;
};
final var sql = "select * from activeQuests;";
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
}
@Override
protected List<ActiveQuestsTarget> transform(List<ActiveQuestsSource> extractedData)
{
final DataTransformer<ActiveQuestsSource, ActiveQuestsTarget> transformer = (dataset) -> {
if (dataset.getProgress() < 0 || dataset.getProgress() > 100)
log.error("level-value out of range",
new NumberOutOfRange("level must be within 0 an 100 (both inclusive)"));
final var levelCorrection = 100f;
return new ActiveQuestsTarget(
0,
dataset.getQuestId(),
dataset.getProgress() / levelCorrection
);
};
return new Transformer<>(transformer, extractedData).doTransform();
}
@Override
protected void load(List<ActiveQuestsTarget> transformedData)
{
final StatementPreparerLoader<ActiveQuestsTarget> statementPreparerLoader = (preparedStatement, data) -> {
preparedStatement.setInt(1, data.getPlayerId());
preparedStatement.setInt(2, data.getQuestId());
preparedStatement.setFloat(3, data.getQuestProgress());
};
final var sql = "insert into activeQuests values (?, ?, ?)";
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
}
}

View File

@ -0,0 +1,66 @@
package migration;
import data.source.PersonInventorySource;
import data.target.CharacterInventoryTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.*;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
public class CharacterInventoryMigration extends ETL<PersonInventorySource, CharacterInventoryTarget>
{
public CharacterInventoryMigration(Connection source, Connection target)
{
super(source, target);
}
@Override
protected List<PersonInventorySource> extract()
{
final DataStorer<PersonInventorySource > dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<PersonInventorySource>();
while (resultSet.next())
{
extractedData.add(new PersonInventorySource(
resultSet.getInt("personId"),
resultSet.getInt("objectId")
));
}
return extractedData;
};
final var sql = "select * from personInventory;";
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
}
@Override
protected List<CharacterInventoryTarget> transform(List<PersonInventorySource> extractedData)
{
final DataTransformer<PersonInventorySource, CharacterInventoryTarget> transformer = (dataset) ->
new CharacterInventoryTarget(
dataset.getPersonId(),
dataset.getObjectId()
);
return new Transformer<>(transformer, extractedData).doTransform();
}
@Override
protected void load(List<CharacterInventoryTarget> transformedData)
{
final StatementPreparerLoader<CharacterInventoryTarget> statementPreparerLoader = (preparedStatement, data) -> {
preparedStatement.setInt(1, data.getPersonId());
preparedStatement.setInt(2, data.getObjectId());
};
final var sql = "insert into characterInventory values (?, ?)";
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
}
}

View File

@ -5,10 +5,7 @@ import data.target.CharacterTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.DataStorer;
import utils.DataTransformer;
import utils.StatementPreparerExtractor;
import utils.StatementPreparerLoader;
import utils.*;
import java.sql.Connection;
import java.util.ArrayList;

View File

@ -5,10 +5,7 @@ import data.target.GameobjectTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.DataStorer;
import utils.DataTransformer;
import utils.StatementPreparerExtractor;
import utils.StatementPreparerLoader;
import utils.*;
import java.sql.Connection;
import java.util.ArrayList;

View File

@ -0,0 +1,66 @@
package migration;
import data.source.InventorySource;
import data.target.InventoryTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.*;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
public class InventoryMigration extends ETL<InventorySource, InventoryTarget>
{
public InventoryMigration(Connection source, Connection target)
{
super(source, target);
}
@Override
protected List<InventorySource> extract()
{
final DataStorer<InventorySource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<InventorySource>();
while (resultSet.next())
{
extractedData.add(new InventorySource(
resultSet.getInt("objectId")
));
}
return extractedData;
};
final var sql = "select * from inventory;";
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
}
@Override
protected List<InventoryTarget> transform(List<InventorySource> extractedData)
{
final DataTransformer<InventorySource, InventoryTarget> transformer = (dataset) ->
new InventoryTarget(
0,
dataset.getObjectId()
);
return new Transformer<>(transformer, extractedData).doTransform();
}
@Override
protected void load(List<InventoryTarget> transformedData)
{
final StatementPreparerLoader<InventoryTarget> statementPreparerLoader = (preparedStatement, data) -> {
preparedStatement.setInt(1, data.getPlayerId());
preparedStatement.setInt(2, data.getObjectId());
preparedStatement.setBoolean(3, data.isStolen());
};
final var sql = "insert into inventory values (?, ?, ?)";
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
}
}

View File

@ -5,10 +5,7 @@ import data.target.ModTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.DataStorer;
import utils.DataTransformer;
import utils.StatementPreparerExtractor;
import utils.StatementPreparerLoader;
import utils.*;
import java.sql.Connection;
import java.sql.Date;

View File

@ -5,10 +5,7 @@ import data.target.PlayerAbilitiesTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.DataStorer;
import utils.DataTransformer;
import utils.StatementPreparerExtractor;
import utils.StatementPreparerLoader;
import utils.*;
import java.sql.Connection;
import java.util.ArrayList;

View File

@ -3,6 +3,7 @@ package migration;
import data.SourceDataset;
import data.target.PlayerTarget;
import etl.Loader;
import utils.ETL;
import utils.StatementPreparerLoader;
import java.sql.Connection;
@ -15,12 +16,6 @@ public class PlayerMigration extends ETL<SourceDataset, PlayerTarget>
super(source, target);
}
@Override
public void migrate()
{
this.createPlayer();
}
@Override
protected List<SourceDataset> extract()
{
@ -36,19 +31,15 @@ public class PlayerMigration extends ETL<SourceDataset, PlayerTarget>
@Override
protected void load(final List<PlayerTarget> transformedData)
{
}
private void createPlayer()
{
final var sql = "insert into player values (?, ?)";
final StatementPreparerLoader<PlayerTarget> statementPreparerLoader = (preparedStatement, data) -> {
preparedStatement.setInt(1, data.getPlayerId());
preparedStatement.setString(2, data.getPlayerName());
};
final var transformedData = List.of(new PlayerTarget(0, "Dummy Name"));
final var createdData = List.of(new PlayerTarget(0, "Dummy Name"));
new Loader<>(this.target, statementPreparerLoader, transformedData, sql).doLoad();
final var sql = "insert into player values (?, ?)";
new Loader<>(this.target, statementPreparerLoader, createdData, sql).doLoad();
}
}

View File

@ -1,14 +1,12 @@
package migration;
import com.mysql.cj.jdbc.Clob;
import data.source.QuestSource;
import data.target.QuestTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.DataStorer;
import utils.DataTransformer;
import utils.StatementPreparerExtractor;
import utils.StatementPreparerLoader;
import utils.*;
import java.sql.Connection;
import java.util.ArrayList;
@ -33,7 +31,7 @@ public class QuestMigration extends ETL<QuestSource, QuestTarget>
extractedData.add(new QuestSource(
resultSet.getInt("questId"),
resultSet.getString("name"),
resultSet.getClob("dialogue"),
resultSet.getString("dialogue"),
resultSet.getInt("personId")));
}
return extractedData;
@ -83,7 +81,7 @@ public class QuestMigration extends ETL<QuestSource, QuestTarget>
preparedStatement.setInt(1, data.getQuestId());
preparedStatement.setString(2, data.getName());
preparedStatement.setString(3, data.getInvolvedCharacters());
preparedStatement.setClob(4, data.getDialogue());
preparedStatement.setString(4, data.getDialogue());
};
final var sql = "insert into quest values (?, ?, ?, ?)";

View File

@ -0,0 +1,74 @@
package migration;
import com.mysql.cj.exceptions.NumberOutOfRange;
import data.source.RelationshipsSource;
import data.target.RelationshipTarget;
import etl.Extractor;
import etl.Loader;
import etl.Transformer;
import utils.*;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
public class RelationshipMigration extends ETL<RelationshipsSource, RelationshipTarget>
{
public RelationshipMigration(Connection source, Connection target)
{
super(source, target);
}
@Override
protected List<RelationshipsSource> extract()
{
final DataStorer<RelationshipsSource> dataStorer = (resultSet) -> {
final var extractedData = new ArrayList<RelationshipsSource>();
while (resultSet.next())
{
extractedData.add(new RelationshipsSource(
resultSet.getInt("personId"),
resultSet.getInt("relationshipLevel")
));
}
return extractedData;
};
final var sql = "select * from relationships;";
final StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
}
@Override
protected List<RelationshipTarget> transform(List<RelationshipsSource> extractedData)
{
final DataTransformer<RelationshipsSource, RelationshipTarget> transformer = (dataset) -> {
if (dataset.getRelationshipLevel() < 0 || dataset.getRelationshipLevel() > 100)
log.error("level-value out of range",
new NumberOutOfRange("level must be within 0 an 100 (both inclusive)"));
final var levelCorrection = 100f;
return new RelationshipTarget(
0,
dataset.getPersonId(),
dataset.getRelationshipLevel() / levelCorrection
);
};
return new Transformer<>(transformer, extractedData).doTransform();
}
@Override
protected void load(List<RelationshipTarget> transformedData)
{
final StatementPreparerLoader<RelationshipTarget> statementPreparerLoader = (preparedStatement, data) -> {
preparedStatement.setInt(1, data.getPlayerId());
preparedStatement.setInt(2, data.getPersonId());
preparedStatement.setFloat(3, data.getRelationshipLevel());
};
final var sql = "insert into relationship values (?, ?, ?)";
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
}
}

View File

@ -4,13 +4,13 @@ import org.apache.log4j.Logger;
import utils.ConnectionHelper;
import utils.DatabaseInformation;
import utils.DatabaseType;
import utils.ETL;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("ALL")
public class ThesisMigration
{
private static final Logger log = Logger.getLogger(ThesisMigration.class.getName());
@ -52,6 +52,10 @@ public class ThesisMigration
this.migrations.add(new GameobjectMigration(this.mariadb, this.postgresql));
this.migrations.add(new QuestMigration(this.mariadb, this.postgresql));
this.migrations.add(new ModMigration(this.mariadb, this.postgresql));
this.migrations.add(new CharacterInventoryMigration(this.mariadb, this.postgresql));
this.migrations.add(new RelationshipMigration(this.mysql, this.postgresql));
this.migrations.add(new ActiveQuestsMigration(this.mysql, this.postgresql));
this.migrations.add(new InventoryMigration(this.mysql, this.postgresql));
}
public void executeMigrations()

View File

@ -1,4 +1,4 @@
package migration;
package utils;
import data.SourceDataset;
import data.TargetDataset;