Added few Migrations
This commit is contained in:
parent
f6bb596455
commit
780bad6dbd
@ -1,31 +0,0 @@
|
|||||||
package data.source;
|
|
||||||
|
|
||||||
import data.SourceDataset;
|
|
||||||
|
|
||||||
public class QuestParticipationSource implements SourceDataset
|
|
||||||
{
|
|
||||||
private int questId;
|
|
||||||
private int personId;
|
|
||||||
|
|
||||||
public QuestParticipationSource(int questId, int personId)
|
|
||||||
{
|
|
||||||
this.questId = questId;
|
|
||||||
this.personId = personId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPersonId()
|
|
||||||
{
|
|
||||||
return personId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getQuestId()
|
|
||||||
{
|
|
||||||
return questId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return String.format("QuestParticipation { %d, %d }", this.questId, this.personId);
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,17 +2,23 @@ package data.source;
|
|||||||
|
|
||||||
import data.SourceDataset;
|
import data.SourceDataset;
|
||||||
|
|
||||||
|
import java.sql.Clob;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class QuestSource implements SourceDataset
|
public class QuestSource implements SourceDataset
|
||||||
{
|
{
|
||||||
private int questId;
|
private int questId;
|
||||||
private String name;
|
private String name;
|
||||||
private String dialogue;
|
private Clob dialogue;
|
||||||
|
private int personId;
|
||||||
|
|
||||||
public QuestSource(int questId, String name, String dialogue)
|
public QuestSource(int questId, String name, Clob dialogue, int personId)
|
||||||
{
|
{
|
||||||
this.questId = questId;
|
this.questId = questId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.dialogue = dialogue;
|
this.dialogue = dialogue;
|
||||||
|
this.personId = personId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getQuestId()
|
public int getQuestId()
|
||||||
@ -25,14 +31,49 @@ public class QuestSource implements SourceDataset
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDialogue()
|
public Clob getDialogue()
|
||||||
{
|
{
|
||||||
return dialogue;
|
return dialogue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPersonId()
|
||||||
|
{
|
||||||
|
return personId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (this == o)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QuestSource that = (QuestSource) o;
|
||||||
|
return questId == that.questId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return Objects.hash(questId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("Quest { %d, %s, %s... }", this.questId, this.name, this.dialogue.substring(0, 10));
|
try
|
||||||
|
{
|
||||||
|
return String.format("Quest { %d, %s, %s..., %d }", this.questId, this.name, this.dialogue.getSubString(1, 10), this.personId);
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@ public class AbilityTarget implements TargetDataset
|
|||||||
private int abilityId;
|
private int abilityId;
|
||||||
private String abilityName;
|
private String abilityName;
|
||||||
private String abilityDescription;
|
private String abilityDescription;
|
||||||
private int abilityLevel;
|
private float abilityLevel;
|
||||||
|
|
||||||
public AbilityTarget(int abilityId, String abilityName, String abilityDescription, int abilityLevel)
|
public AbilityTarget(int abilityId, String abilityName, String abilityDescription, float abilityLevel)
|
||||||
{
|
{
|
||||||
this.abilityId = abilityId;
|
this.abilityId = abilityId;
|
||||||
this.abilityName = abilityName;
|
this.abilityName = abilityName;
|
||||||
@ -32,7 +32,7 @@ public class AbilityTarget implements TargetDataset
|
|||||||
return abilityDescription;
|
return abilityDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAbilityLevel()
|
public float getAbilityLevel()
|
||||||
{
|
{
|
||||||
return abilityLevel;
|
return abilityLevel;
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ public class AbilityTarget implements TargetDataset
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("Ability [ %d, %s, %s, %d ]", this.abilityId, this.abilityName, this.abilityDescription, this.abilityLevel);
|
return String.format("Ability [ %d, %s, %s, %f ]", this.abilityId, this.abilityName, this.abilityDescription, this.abilityLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,17 @@ package data.target;
|
|||||||
|
|
||||||
import data.TargetDataset;
|
import data.TargetDataset;
|
||||||
|
|
||||||
|
import java.sql.Clob;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class QuestTarget implements TargetDataset
|
public class QuestTarget implements TargetDataset
|
||||||
{
|
{
|
||||||
private int questId;
|
private int questId;
|
||||||
private String name;
|
private String name;
|
||||||
private String involvedCharacters;
|
private String involvedCharacters;
|
||||||
private String dialogue;
|
private Clob dialogue;
|
||||||
|
|
||||||
public QuestTarget(int questId, String name, String involvedCharacters, String dialogue)
|
public QuestTarget(int questId, String name, String involvedCharacters, Clob dialogue)
|
||||||
{
|
{
|
||||||
this.questId = questId;
|
this.questId = questId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -32,7 +35,7 @@ public class QuestTarget implements TargetDataset
|
|||||||
return involvedCharacters;
|
return involvedCharacters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDialogue()
|
public Clob getDialogue()
|
||||||
{
|
{
|
||||||
return dialogue;
|
return dialogue;
|
||||||
}
|
}
|
||||||
@ -40,6 +43,15 @@ public class QuestTarget implements TargetDataset
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("Quest [ %d, %s, %s, %s... ]", this.questId, this.name, this.involvedCharacters, this.dialogue.substring(0, 10));
|
try
|
||||||
|
{
|
||||||
|
return String.format("Quest [ %d, %s, { %s }, %s... ]", this.questId, this.name, this.involvedCharacters, this.dialogue.getSubString(1, 10));
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package migration;
|
package migration;
|
||||||
|
|
||||||
|
import com.mysql.cj.exceptions.NumberOutOfRange;
|
||||||
import data.source.AbilitiesSource;
|
import data.source.AbilitiesSource;
|
||||||
import data.source.PersonSource;
|
import data.source.PersonSource;
|
||||||
import data.target.AbilityTarget;
|
import data.target.AbilityTarget;
|
||||||
@ -48,13 +49,18 @@ public class AbilityMigration extends ETL<AbilitiesSource, AbilityTarget>
|
|||||||
@Override
|
@Override
|
||||||
protected List<AbilityTarget> transform(List<AbilitiesSource> extractedData)
|
protected List<AbilityTarget> transform(List<AbilitiesSource> extractedData)
|
||||||
{
|
{
|
||||||
DataTransformer<AbilitiesSource, AbilityTarget> transformer =
|
DataTransformer<AbilitiesSource, AbilityTarget> transformer = (dataset) -> {
|
||||||
(dataset) -> new AbilityTarget(
|
if (dataset.getLevel() < 0 || dataset.getLevel() > 100)
|
||||||
abilityId++,
|
log.error("level-value out of range",
|
||||||
dataset.getName(),
|
new NumberOutOfRange("level must be within 0 an 100 (both inclusive)"));
|
||||||
dataset.getDescription(),
|
var levelCorrection = 100f;
|
||||||
dataset.getLevel()
|
return new AbilityTarget(
|
||||||
);
|
abilityId++,
|
||||||
|
dataset.getName(),
|
||||||
|
dataset.getDescription(),
|
||||||
|
dataset.getLevel() / levelCorrection
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return new Transformer<>(transformer, extractedData).doTransform();
|
return new Transformer<>(transformer, extractedData).doTransform();
|
||||||
}
|
}
|
||||||
@ -66,7 +72,7 @@ public class AbilityMigration extends ETL<AbilitiesSource, AbilityTarget>
|
|||||||
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.setInt(4, data.getAbilityLevel());
|
preparedStatement.setFloat(4, data.getAbilityLevel());
|
||||||
};
|
};
|
||||||
|
|
||||||
var sql = "insert into ability values (?, ?, ?, ?)";
|
var sql = "insert into ability values (?, ?, ?, ?)";
|
||||||
|
@ -6,6 +6,7 @@ import data.source.PersonSource;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class ETL<T extends SourceDataset, E extends TargetDataset>
|
public abstract class ETL<T extends SourceDataset, E extends TargetDataset>
|
||||||
@ -27,6 +28,15 @@ public abstract class ETL<T extends SourceDataset, E extends TargetDataset>
|
|||||||
var extractedData = this.extract();
|
var extractedData = this.extract();
|
||||||
var transformedData = this.transform(extractedData);
|
var transformedData = this.transform(extractedData);
|
||||||
this.load(transformedData);
|
this.load(transformedData);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.target.commit();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract List<T> extract();
|
protected abstract List<T> extract();
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
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.Loader;
|
||||||
|
import etl.Transformer;
|
||||||
|
import utils.DataStorer;
|
||||||
|
import utils.DataTransformer;
|
||||||
|
import utils.StatementPreparerExtractor;
|
||||||
|
import utils.StatementPreparerLoader;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
|
public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
|
||||||
@ -16,18 +27,48 @@ public class GameobjectMigration extends ETL<GameobjectSource, GameobjectTarget>
|
|||||||
@Override
|
@Override
|
||||||
protected List<GameobjectSource> extract()
|
protected List<GameobjectSource> extract()
|
||||||
{
|
{
|
||||||
return null;
|
DataStorer<GameobjectSource> dataStorer = (resultSet) -> {
|
||||||
|
var extractedData = new ArrayList<GameobjectSource>();
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
extractedData.add(new GameobjectSource(
|
||||||
|
resultSet.getInt("objectId"),
|
||||||
|
resultSet.getString("name"),
|
||||||
|
resultSet.getString("description")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return extractedData;
|
||||||
|
};
|
||||||
|
|
||||||
|
var sql = "select * from gameobject;";
|
||||||
|
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
||||||
|
|
||||||
|
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<GameobjectTarget> transform(List<GameobjectSource> extractedData)
|
protected List<GameobjectTarget> transform(List<GameobjectSource> extractedData)
|
||||||
{
|
{
|
||||||
return null;
|
DataTransformer<GameobjectSource, GameobjectTarget> transformer = (dataset) -> new GameobjectTarget(
|
||||||
|
dataset.getObjectId(),
|
||||||
|
dataset.getName(),
|
||||||
|
dataset.getDescription()
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Transformer<>(transformer, extractedData).doTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void load(List<GameobjectTarget> transformedData)
|
protected void load(List<GameobjectTarget> transformedData)
|
||||||
{
|
{
|
||||||
|
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 (?, ?, ?)";
|
||||||
|
|
||||||
|
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
src/main/java/migration/ModMigration.java
Normal file
33
src/main/java/migration/ModMigration.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package migration;
|
||||||
|
|
||||||
|
import data.source.ModSource;
|
||||||
|
import data.target.ModTarget;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ModMigration extends ETL<ModSource, ModTarget>
|
||||||
|
{
|
||||||
|
public ModMigration(Connection source, Connection target)
|
||||||
|
{
|
||||||
|
super(source, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<ModSource> extract()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<ModTarget> transform(List<ModSource> extractedData)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void load(List<ModTarget> transformedData)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
93
src/main/java/migration/QuestMigration.java
Normal file
93
src/main/java/migration/QuestMigration.java
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
package migration;
|
||||||
|
|
||||||
|
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 java.sql.Connection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class QuestMigration extends ETL<QuestSource, QuestTarget>
|
||||||
|
{
|
||||||
|
public QuestMigration(Connection source, Connection target)
|
||||||
|
{
|
||||||
|
super(source, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<QuestSource> extract()
|
||||||
|
{
|
||||||
|
DataStorer<QuestSource> dataStorer = (resultSet) -> {
|
||||||
|
var extractedData = new ArrayList<QuestSource>();
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
extractedData.add(new QuestSource(
|
||||||
|
resultSet.getInt("questId"),
|
||||||
|
resultSet.getString("name"),
|
||||||
|
resultSet.getClob("dialogue"),
|
||||||
|
resultSet.getInt("personId")));
|
||||||
|
}
|
||||||
|
return extractedData;
|
||||||
|
};
|
||||||
|
|
||||||
|
var sql = "select * from quest q join questParticipation qp on q.questId = qp.questId;";
|
||||||
|
StatementPreparerExtractor statementPreparer = (preparedStatement) -> {};
|
||||||
|
|
||||||
|
return new Extractor<>(super.source, dataStorer, statementPreparer, sql).doExtract();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<QuestTarget> transform(List<QuestSource> extractedData)
|
||||||
|
{
|
||||||
|
var map = new HashMap<Integer, String>();
|
||||||
|
|
||||||
|
for (QuestSource extractedDatum : extractedData)
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
map.replace(key, involvedPersons);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extractedData = extractedData.stream().distinct().collect(Collectors.toList());
|
||||||
|
|
||||||
|
DataTransformer<QuestSource, QuestTarget> transformer = (dataset) -> new QuestTarget(
|
||||||
|
dataset.getQuestId(),
|
||||||
|
dataset.getName(),
|
||||||
|
map.get(dataset.getQuestId()),
|
||||||
|
dataset.getDialogue()
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Transformer<>(transformer, extractedData).doTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void load(List<QuestTarget> transformedData)
|
||||||
|
{
|
||||||
|
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 (?, ?, ?, ?)";
|
||||||
|
|
||||||
|
new Loader<>(super.target, statementPreparerLoader, transformedData, sql).doLoad();
|
||||||
|
}
|
||||||
|
}
|
@ -32,11 +32,24 @@ public class ThesisMigration
|
|||||||
final var postgresInfo = new DatabaseInformation("localhost", "targetdb", "test", "test", 25001);
|
final var postgresInfo = new DatabaseInformation("localhost", "targetdb", "test", "test", 25001);
|
||||||
this.postgresql= new ConnectionHelper(DatabaseType.POSTGRESQL, postgresInfo).createConnection();
|
this.postgresql= new ConnectionHelper(DatabaseType.POSTGRESQL, postgresInfo).createConnection();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.mariadb.setAutoCommit(false);
|
||||||
|
this.mysql.setAutoCommit(false);
|
||||||
|
this.postgresql.setAutoCommit(false);
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
this.migrations = new ArrayList<>();
|
this.migrations = new ArrayList<>();
|
||||||
this.migrations.add(new PlayerMigration(null, this.postgresql));
|
this.migrations.add(new PlayerMigration(null, this.postgresql));
|
||||||
this.migrations.add(new AbilityMigration(this.mysql, this.postgresql));
|
this.migrations.add(new AbilityMigration(this.mysql, this.postgresql));
|
||||||
this.migrations.add(new PlayerAbilitiesMigration(this.postgresql, this.postgresql));
|
this.migrations.add(new PlayerAbilitiesMigration(this.postgresql, this.postgresql));
|
||||||
this.migrations.add(new CharacterMigration(this.mariadb, this.postgresql));
|
this.migrations.add(new CharacterMigration(this.mariadb, this.postgresql));
|
||||||
|
this.migrations.add(new GameobjectMigration(this.mariadb, this.postgresql));
|
||||||
|
this.migrations.add(new QuestMigration(this.mariadb, this.postgresql));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeMigrations()
|
public void executeMigrations()
|
||||||
|
@ -64,7 +64,6 @@ public class ConnectionHelper
|
|||||||
SQLState: %s;
|
SQLState: %s;
|
||||||
VendorError:%s""",
|
VendorError:%s""",
|
||||||
e.getMessage(), e.getSQLState(), e.getErrorCode()));
|
e.getMessage(), e.getSQLState(), e.getErrorCode()));
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user