Rename ...Dao -> ...Repository
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
package database;
|
||||
|
||||
import org.jdbi.v3.core.JdbiException;
|
||||
|
||||
public class DaoException extends JdbiException {
|
||||
|
||||
public DaoException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
10
src/main/java/database/DatabaseException.java
Normal file
10
src/main/java/database/DatabaseException.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package database;
|
||||
|
||||
import org.jdbi.v3.core.JdbiException;
|
||||
|
||||
public class DatabaseException extends JdbiException {
|
||||
|
||||
public DatabaseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package database.character;
|
||||
import client.Character;
|
||||
import client.Client;
|
||||
import client.MonsterBook;
|
||||
import database.monsterbook.MonsterCardDao;
|
||||
import database.monsterbook.MonsterCardRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -12,10 +12,10 @@ import java.util.Optional;
|
||||
|
||||
public class CharacterLoader {
|
||||
private static final Logger log = LoggerFactory.getLogger(CharacterLoader.class);
|
||||
private final MonsterCardDao monsterCardDao;
|
||||
private final MonsterCardRepository monsterCardRepository;
|
||||
|
||||
public CharacterLoader(MonsterCardDao monsterCardDao) {
|
||||
this.monsterCardDao = monsterCardDao;
|
||||
public CharacterLoader(MonsterCardRepository monsterCardRepository) {
|
||||
this.monsterCardRepository = monsterCardRepository;
|
||||
}
|
||||
|
||||
public Optional<Character> loadForChannel(int chrId, Client client) {
|
||||
@@ -33,7 +33,7 @@ public class CharacterLoader {
|
||||
}
|
||||
|
||||
private MonsterBook loadMonsterBook(int chrId) {
|
||||
var monsterCards = monsterCardDao.load(chrId);
|
||||
var monsterCards = monsterCardRepository.load(chrId);
|
||||
return new MonsterBook(monsterCards);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package database.character;
|
||||
|
||||
import client.Character;
|
||||
import database.monsterbook.MonsterCardDao;
|
||||
import database.monsterbook.MonsterCardRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tools.DatabaseConnection;
|
||||
@@ -11,10 +11,10 @@ import java.sql.SQLException;
|
||||
|
||||
public class CharacterSaver {
|
||||
private static final Logger log = LoggerFactory.getLogger(CharacterSaver.class);
|
||||
private final MonsterCardDao monsterCardDao;
|
||||
private final MonsterCardRepository monsterCardRepository;
|
||||
|
||||
public CharacterSaver(MonsterCardDao monsterCardDao) {
|
||||
this.monsterCardDao = monsterCardDao;
|
||||
public CharacterSaver(MonsterCardRepository monsterCardRepository) {
|
||||
this.monsterCardRepository = monsterCardRepository;
|
||||
}
|
||||
|
||||
public void save(Character chr) {
|
||||
@@ -42,7 +42,7 @@ public class CharacterSaver {
|
||||
}
|
||||
|
||||
// Saving monster cards to both MySQL and Postgres for now
|
||||
monsterCardDao.save(chr.getId(), chr.getMonsterBook().getCards());
|
||||
monsterCardRepository.save(chr.getId(), chr.getMonsterBook().getCards());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,20 +10,20 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class DropProvider {
|
||||
private final DropDao dropDao;
|
||||
private final DropRepository dropRepository;
|
||||
private final Cache<Integer, List<MonsterDrop>> monsterDropCache = Caffeine.newBuilder().build();
|
||||
private final Cache<Integer, List<MonsterGlobalDropEntry>> globalContinentDropCache = Caffeine.newBuilder().build();
|
||||
private volatile List<GlobalMonsterDrop> globalMonsterDrops = null;
|
||||
|
||||
public DropProvider(DropDao dropDao) {
|
||||
if (dropDao == null) {
|
||||
public DropProvider(DropRepository dropRepository) {
|
||||
if (dropRepository == null) {
|
||||
throw new IllegalArgumentException("DropDao must not be null");
|
||||
}
|
||||
this.dropDao = dropDao;
|
||||
this.dropRepository = dropRepository;
|
||||
}
|
||||
|
||||
private List<MonsterDrop> getMonsterDrops(int monsterId) {
|
||||
return monsterDropCache.get(monsterId, dropDao::getMonsterDrops);
|
||||
return monsterDropCache.get(monsterId, dropRepository::getMonsterDrops);
|
||||
}
|
||||
|
||||
public List<MonsterDropEntry> getMonsterDropEntries(int monsterId) {
|
||||
@@ -61,7 +61,7 @@ public class DropProvider {
|
||||
}
|
||||
|
||||
private void loadGlobalDrops() {
|
||||
this.globalMonsterDrops = dropDao.getGlobalMonsterDrops();
|
||||
this.globalMonsterDrops = dropRepository.getGlobalMonsterDrops();
|
||||
}
|
||||
|
||||
// TODO: Temporary. MonsterDropEntry should be removed.
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package database.drop;
|
||||
|
||||
import database.DaoException;
|
||||
import database.DatabaseException;
|
||||
import database.PgDatabaseConnection;
|
||||
import org.jdbi.v3.core.Handle;
|
||||
import org.jdbi.v3.core.JdbiException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DropDao {
|
||||
public class DropRepository {
|
||||
private final PgDatabaseConnection connection;
|
||||
|
||||
public DropDao(PgDatabaseConnection connection) {
|
||||
public DropRepository(PgDatabaseConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class DropDao {
|
||||
.mapTo(MonsterDrop.class)
|
||||
.list();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to get monster drops for id %d".formatted(monsterId), e);
|
||||
throw new DatabaseException("Failed to get monster drops for id %d".formatted(monsterId), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class DropDao {
|
||||
.mapTo(GlobalMonsterDrop.class)
|
||||
.list();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to get global monster drops", e);
|
||||
throw new DatabaseException("Failed to get global monster drops", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,24 +11,24 @@ import java.util.Optional;
|
||||
|
||||
@ThreadSafe
|
||||
public class MakerInfoProvider {
|
||||
private final MakerDao makerDao;
|
||||
private final MakerRepository makerRepository;
|
||||
private final Cache<Integer, Optional<MakerReagent>> reagentCache = Caffeine.newBuilder().build();
|
||||
private final Cache<Integer, Optional<MakerRecipe>> recipeCache = Caffeine.newBuilder().build();
|
||||
private final Cache<Integer, List<MakerIngredient>> ingredientsCache = Caffeine.newBuilder().build();
|
||||
|
||||
public MakerInfoProvider(MakerDao makerDao) {
|
||||
if (makerDao == null) {
|
||||
public MakerInfoProvider(MakerRepository makerRepository) {
|
||||
if (makerRepository == null) {
|
||||
throw new IllegalArgumentException("MakerDao must not be null");
|
||||
}
|
||||
this.makerDao = makerDao;
|
||||
this.makerRepository = makerRepository;
|
||||
}
|
||||
|
||||
public Optional<MakerReagent> getMakerReagent(int itemId) {
|
||||
return reagentCache.get(itemId, makerDao::getReagent);
|
||||
return reagentCache.get(itemId, makerRepository::getReagent);
|
||||
}
|
||||
|
||||
public Optional<MakerRecipe> getMakerRecipe(int itemId) {
|
||||
return recipeCache.get(itemId, makerDao::getRecipe);
|
||||
return recipeCache.get(itemId, makerRepository::getRecipe);
|
||||
}
|
||||
|
||||
public Optional<Integer> getStimulant(int itemId) {
|
||||
@@ -36,7 +36,7 @@ public class MakerInfoProvider {
|
||||
}
|
||||
|
||||
public List<MakerIngredient> getIngredients(int recipeItemId) {
|
||||
return ingredientsCache.get(recipeItemId, makerDao::getIngredients);
|
||||
return ingredientsCache.get(recipeItemId, makerRepository::getIngredients);
|
||||
}
|
||||
|
||||
public Optional<MakerDisassemblyInfo> getDisassemblyInfo(int itemId) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package database.maker;
|
||||
|
||||
import database.DaoException;
|
||||
import database.DatabaseException;
|
||||
import database.PgDatabaseConnection;
|
||||
import org.jdbi.v3.core.Handle;
|
||||
import org.jdbi.v3.core.JdbiException;
|
||||
@@ -8,10 +8,10 @@ import org.jdbi.v3.core.JdbiException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MakerDao {
|
||||
public class MakerRepository {
|
||||
private final PgDatabaseConnection connection;
|
||||
|
||||
public MakerDao(PgDatabaseConnection connection) {
|
||||
public MakerRepository(PgDatabaseConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MakerDao {
|
||||
.mapTo(MakerReagent.class)
|
||||
.findOne();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to get maker reagent with item id: %d".formatted(itemId), e);
|
||||
throw new DatabaseException("Failed to get maker reagent with item id: %d".formatted(itemId), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class MakerDao {
|
||||
.mapTo(MakerRecipe.class)
|
||||
.findOne();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to get maker recipe with item id: %d".formatted(itemId), e);
|
||||
throw new DatabaseException("Failed to get maker recipe with item id: %d".formatted(itemId), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MakerDao {
|
||||
.mapTo(MakerIngredient.class)
|
||||
.list();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to get maker ingredients for recipe item id %d".formatted(recipeItemId), e);
|
||||
throw new DatabaseException("Failed to get maker ingredients for recipe item id %d".formatted(recipeItemId), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package database.monsterbook;
|
||||
|
||||
import database.DaoException;
|
||||
import database.DatabaseException;
|
||||
import database.PgDatabaseConnection;
|
||||
import org.jdbi.v3.core.Handle;
|
||||
import org.jdbi.v3.core.JdbiException;
|
||||
@@ -8,10 +8,10 @@ import org.jdbi.v3.core.statement.PreparedBatch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MonsterCardDao {
|
||||
public class MonsterCardRepository {
|
||||
private final PgDatabaseConnection connection;
|
||||
|
||||
public MonsterCardDao(PgDatabaseConnection connection) {
|
||||
public MonsterCardRepository(PgDatabaseConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MonsterCardDao {
|
||||
.mapTo(MonsterCard.class)
|
||||
.list();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to find monster cards (chrId %d)".formatted(chrId), e);
|
||||
throw new DatabaseException("Failed to find monster cards (chrId %d)".formatted(chrId), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class MonsterCardDao {
|
||||
});
|
||||
batch.execute();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to save monster cards (chrId %d)".formatted(chrId), e);
|
||||
throw new DatabaseException("Failed to save monster cards (chrId %d)".formatted(chrId), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package database.note;
|
||||
|
||||
import database.DaoException;
|
||||
import database.DatabaseException;
|
||||
import database.PgDatabaseConnection;
|
||||
import model.Note;
|
||||
import org.jdbi.v3.core.Handle;
|
||||
@@ -29,7 +29,7 @@ public class NoteDao {
|
||||
.bind(5, 0)
|
||||
.execute();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to save note: %s".formatted(note.toString()), e);
|
||||
throw new DatabaseException("Failed to save note: %s".formatted(note.toString()), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class NoteDao {
|
||||
.mapTo(Note.class)
|
||||
.list();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to find notes sent to: %s".formatted(receiver), e);
|
||||
throw new DatabaseException("Failed to find notes sent to: %s".formatted(receiver), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class NoteDao {
|
||||
|
||||
return note;
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to delete note with id: %d".formatted(id), e);
|
||||
throw new DatabaseException("Failed to delete note with id: %d".formatted(id), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class NoteDao {
|
||||
.mapTo(Note.class)
|
||||
.findOne();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed find note with id %s".formatted(id), e);
|
||||
throw new DatabaseException("Failed find note with id %s".formatted(id), e);
|
||||
}
|
||||
return note;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class NoteDao {
|
||||
.bind(0, id)
|
||||
.execute();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to delete note with id %d".formatted(id), e);
|
||||
throw new DatabaseException("Failed to delete note with id %d".formatted(id), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package database.shop;
|
||||
|
||||
import database.DaoException;
|
||||
import database.DatabaseException;
|
||||
import database.PgDatabaseConnection;
|
||||
import org.jdbi.v3.core.Handle;
|
||||
import org.jdbi.v3.core.JdbiException;
|
||||
@@ -25,7 +25,7 @@ public class ShopDao {
|
||||
.mapTo(Shop.class)
|
||||
.findOne();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to get shop with id %d".formatted(shopId), e);
|
||||
throw new DatabaseException("Failed to get shop with id %d".formatted(shopId), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ShopDao {
|
||||
.mapTo(ShopItem.class)
|
||||
.list();
|
||||
} catch (JdbiException e) {
|
||||
throw new DaoException("Failed to get shop items for shop %d".formatted(shopId), e);
|
||||
throw new DatabaseException("Failed to get shop items for shop %d".formatted(shopId), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user