diff --git a/src/main/java/com/dre/brewery/storage/DataManager.java b/src/main/java/com/dre/brewery/storage/DataManager.java index 92dc8030..3bc21f57 100644 --- a/src/main/java/com/dre/brewery/storage/DataManager.java +++ b/src/main/java/com/dre/brewery/storage/DataManager.java @@ -10,7 +10,6 @@ import com.dre.brewery.filedata.BConfig; import com.dre.brewery.integration.bstats.Stats; import com.dre.brewery.storage.impls.FlatFileStorage; -import com.dre.brewery.storage.impls.MongoDBStorage; import com.dre.brewery.storage.impls.MySQLStorage; import com.dre.brewery.storage.impls.SQLiteStorage; import com.dre.brewery.storage.records.BreweryMiscData; @@ -139,7 +138,6 @@ public static DataManager createDataManager(ConfiguredDataManager record) throws case FLATFILE -> new FlatFileStorage(record); case MYSQL -> new MySQLStorage(record); case SQLITE -> new SQLiteStorage(record); - case MONGODB -> new MongoDBStorage(record); }; // Legacy data migration diff --git a/src/main/java/com/dre/brewery/storage/DataManagerType.java b/src/main/java/com/dre/brewery/storage/DataManagerType.java index b3472b96..406b919e 100644 --- a/src/main/java/com/dre/brewery/storage/DataManagerType.java +++ b/src/main/java/com/dre/brewery/storage/DataManagerType.java @@ -5,8 +5,7 @@ public enum DataManagerType { // Maybe add: h2, mongodb, sqlite? FLATFILE("FlatFile"), MYSQL("MySQL"), - SQLITE("SQLite"), - MONGODB("MongoDB"),; + SQLITE("SQLite"); private final String formattedName; diff --git a/src/main/java/com/dre/brewery/storage/impls/MongoDBStorage.java b/src/main/java/com/dre/brewery/storage/impls/MongoDBStorage.java deleted file mode 100644 index d5edd290..00000000 --- a/src/main/java/com/dre/brewery/storage/impls/MongoDBStorage.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.dre.brewery.storage.impls; - -import com.dre.brewery.BCauldron; -import com.dre.brewery.BPlayer; -import com.dre.brewery.Barrel; -import com.dre.brewery.Wakeup; -import com.dre.brewery.storage.DataManager; -import com.dre.brewery.storage.StorageInitException; -import com.dre.brewery.storage.records.BreweryMiscData; -import com.dre.brewery.storage.records.ConfiguredDataManager; -import com.dre.brewery.storage.records.SerializableBPlayer; -import com.dre.brewery.storage.records.SerializableBarrel; -import com.dre.brewery.storage.records.SerializableCauldron; -import com.dre.brewery.storage.records.SerializableThing; -import com.dre.brewery.storage.records.SerializableWakeup; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.model.Filters; -import com.mongodb.client.model.ReplaceOptions; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; - -public class MongoDBStorage extends DataManager { - - private static final String URL = "mongodb+srv://%s:%s@%s/?retryWrites=true&w=majority&appName=BreweryX#%d"; - private static final String[] COLLECTIONS = { - "misc", "barrels", "cauldrons", "players", "wakeups" - }; - - private final MongoClient mongoClient; - private final MongoDatabase mongoDatabase; - private final String collectionPrefix; - - public MongoDBStorage(ConfiguredDataManager record) throws StorageInitException { - String fullurl = String.format(URL, record.username(), record.password(), record.address(), this.getClass().hashCode()); - System.out.println(fullurl); - this.mongoClient = MongoClients.create(fullurl); - this.mongoClient.startSession(); - this.mongoDatabase = mongoClient.getDatabase(record.database()); - this.collectionPrefix = record.tablePrefix(); - - for (String collection : COLLECTIONS) { - mongoDatabase.createCollection(collectionPrefix + collection); // Create the collection if it doesn't exist - } - try { - System.out.println("ttttt"); - } catch (Exception e) { - throw new StorageInitException("Failed to start MongoDB client or get database!", e); - } - } - - @Override - protected void closeConnection() { - mongoClient.close(); - } - - private T getGeneric(UUID id, String collection, Class type) { - MongoCollection mongoCollection = mongoDatabase.getCollection(collectionPrefix + collection, type); - return mongoCollection.find(Filters.eq("_id", id)).first(); - } - - private T getGeneric(String id, String collection, Class type) { - MongoCollection mongoCollection = mongoDatabase.getCollection(collectionPrefix + collection, type); - return mongoCollection.find(Filters.eq("_id", id)).first(); - } - - private List getAllGeneric(String collection, Class type) { - MongoCollection mongoCollection = mongoDatabase.getCollection(collectionPrefix + collection, type); - return mongoCollection.find().into(new ArrayList<>()); - } - - - private void saveGeneric(T thing, String collection) { - MongoCollection mongoCollection = (MongoCollection) mongoDatabase.getCollection(collectionPrefix + collection, thing.getClass()); - mongoCollection.replaceOne(Filters.eq("_id", thing.getId()), thing, new ReplaceOptions().upsert(true)); - } - - private void saveAllGeneric(List things, String collection) { - MongoCollection mongoCollection = (MongoCollection) mongoDatabase.getCollection(collectionPrefix + collection, things.iterator().next().getClass()); - for (T thing : things) { - mongoCollection.replaceOne(Filters.eq("_id", thing.getId()), thing, new ReplaceOptions().upsert(true)); - } - } - - private void deleteGeneric(UUID id, String collection) { - MongoCollection mongoCollection = mongoDatabase.getCollection(collectionPrefix + collection, SerializableThing.class); - mongoCollection.deleteOne(Filters.eq("_id", id)); - } - - - @Override - public Barrel getBarrel(UUID id) { - SerializableBarrel serializableBarrel = getGeneric(id, "barrels", SerializableBarrel.class); - if (serializableBarrel != null) { - return serializableBarrel.toBarrel(); - } - return null; - } - - @Override - public Collection getAllBarrels() { - return getAllGeneric("barrels", SerializableBarrel.class).stream() - .map(SerializableBarrel::toBarrel) - .toList(); - } - - @Override - public void saveAllBarrels(Collection barrels, boolean overwrite) { - List serializableBarrels = barrels.stream() - .map(SerializableBarrel::new) - .toList(); - saveAllGeneric(serializableBarrels, "barrels"); - } - - @Override - public void saveBarrel(Barrel barrel) { - saveGeneric(new SerializableBarrel(barrel), "barrels"); - } - - @Override - public void deleteBarrel(UUID id) { - deleteGeneric(id, "barrels"); - } - - @Override - public BCauldron getCauldron(UUID id) { - SerializableCauldron serializableCauldron = getGeneric(id, "cauldrons", SerializableCauldron.class); - if (serializableCauldron != null) { - return serializableCauldron.toCauldron(); - } - return null; - } - - @Override - public Collection getAllCauldrons() { - return getAllGeneric("cauldrons", SerializableCauldron.class).stream() - .map(SerializableCauldron::toCauldron) - .toList(); - } - - @Override - public void saveAllCauldrons(Collection cauldrons, boolean overwrite) { - List serializableCauldrons = cauldrons.stream() - .map(SerializableCauldron::new) - .toList(); - saveAllGeneric(serializableCauldrons, "cauldrons"); - } - - @Override - public void saveCauldron(BCauldron cauldron) { - saveGeneric(new SerializableCauldron(cauldron), "cauldrons"); - } - - @Override - public void deleteCauldron(UUID id) { - deleteGeneric(id, "cauldrons"); - } - - @Override - public BPlayer getPlayer(UUID playerUUID) { - SerializableBPlayer serializableBPlayer = getGeneric(playerUUID, "players", SerializableBPlayer.class); - if (serializableBPlayer != null) { - return serializableBPlayer.toBPlayer(); - } - return null; - } - - @Override - public Collection getAllPlayers() { - return getAllGeneric("players", SerializableBPlayer.class).stream() - .map(SerializableBPlayer::toBPlayer) - .toList(); - } - - @Override - public void saveAllPlayers(Collection players, boolean overwrite) { - List serializableBPlayers = players.stream() - .map(SerializableBPlayer::new) - .toList(); - saveAllGeneric(serializableBPlayers, "players"); - } - - @Override - public void savePlayer(BPlayer player) { - saveGeneric(new SerializableBPlayer(player), "players"); - } - - @Override - public void deletePlayer(UUID playerUUID) { - deleteGeneric(playerUUID, "players"); - } - - @Override - public Wakeup getWakeup(UUID id) { - SerializableWakeup serializableWakeup = getGeneric(id, "wakeups", SerializableWakeup.class); - if (serializableWakeup != null) { - return serializableWakeup.toWakeup(); - } - return null; - } - - @Override - public Collection getAllWakeups() { - return getAllGeneric("wakeups", SerializableWakeup.class).stream() - .map(SerializableWakeup::toWakeup) - .toList(); - } - - @Override - public void saveAllWakeups(Collection wakeups, boolean overwrite) { - List serializableWakeups = wakeups.stream() - .map(SerializableWakeup::new) - .toList(); - saveAllGeneric(serializableWakeups, "wakeups"); - } - - @Override - public void saveWakeup(Wakeup wakeup) { - saveGeneric(new SerializableWakeup(wakeup), "wakeups"); - } - - @Override - public void deleteWakeup(UUID id) { - deleteGeneric(id, "wakeups"); - } - - @Override - public BreweryMiscData getBreweryMiscData() { - BreweryMiscData data = getGeneric("misc", "misc", BreweryMiscData.class); - if (data != null) { - return data; - } - return new BreweryMiscData(System.currentTimeMillis(), 0, new ArrayList<>(), new ArrayList<>(), 0); - } - - @Override - public void saveBreweryMiscData(BreweryMiscData data) { - saveGeneric(data, "misc"); - } -} diff --git a/src/main/resources/config/v13/de/config.yml b/src/main/resources/config/v13/de/config.yml index 38859d9b..a5c75fea 100644 --- a/src/main/resources/config/v13/de/config.yml +++ b/src/main/resources/config/v13/de/config.yml @@ -7,7 +7,7 @@ version: '3.1' # -- Storage Settings -- storage: # What type of storage to use [FLATFILE] - # Available types: FlatFile, MySQL, SQLite, MongoDB + # Available types: FlatFile, MySQL, SQLite type: FlatFile # The name of the database. When the database is a file, this will be the name of the file. [brewery-data] database: brewery-data diff --git a/src/main/resources/config/v13/en/config.yml b/src/main/resources/config/v13/en/config.yml index ba4ccf35..6aa4d7f3 100644 --- a/src/main/resources/config/v13/en/config.yml +++ b/src/main/resources/config/v13/en/config.yml @@ -8,7 +8,7 @@ version: '3.1' # -- Storage Settings -- storage: # What type of storage to use [FLATFILE] - # Available types: FlatFile, MySQL, SQLite, MongoDB + # Available types: FlatFile, MySQL, SQLite type: FlatFile # The name of the database. When the database is a file, this will be the name of the file. [brewery-data] database: brewery-data diff --git a/src/main/resources/config/v13/es/config.yml b/src/main/resources/config/v13/es/config.yml index cde8868c..322271fe 100644 --- a/src/main/resources/config/v13/es/config.yml +++ b/src/main/resources/config/v13/es/config.yml @@ -9,7 +9,7 @@ version: '3.1' # -- Storage Settings -- storage: # What type of storage to use [FLATFILE] - # Available types: FlatFile, MySQL, SQLite, MongoDB + # Available types: FlatFile, MySQL, SQLite type: FlatFile # The name of the database. When the database is a file, this will be the name of the file. [brewery-data] database: brewery-data diff --git a/src/main/resources/config/v13/fr/config.yml b/src/main/resources/config/v13/fr/config.yml index 6e66d0b6..c5b0bb15 100644 --- a/src/main/resources/config/v13/fr/config.yml +++ b/src/main/resources/config/v13/fr/config.yml @@ -9,7 +9,7 @@ version: '3.1' # -- Storage Settings -- storage: # What type of storage to use [FLATFILE] - # Available types: FlatFile, MySQL, SQLite, MongoDB + # Available types: FlatFile, MySQL, SQLite type: FlatFile # The name of the database. When the database is a file, this will be the name of the file. [brewery-data] database: brewery-data diff --git a/src/main/resources/config/v13/it/config.yml b/src/main/resources/config/v13/it/config.yml index e27ec297..0b571ffa 100644 --- a/src/main/resources/config/v13/it/config.yml +++ b/src/main/resources/config/v13/it/config.yml @@ -8,7 +8,7 @@ version: '3.1' # -- Storage Settings -- storage: # What type of storage to use [FLATFILE] - # Available types: FlatFile, MySQL, SQLite, MongoDB + # Available types: FlatFile, MySQL, SQLite type: FlatFile # The name of the database. When the database is a file, this will be the name of the file. [brewery-data] database: brewery-data