mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 00:18:02 +00:00
DatabaseManager clean up
This commit is contained in:
parent
77fcce6510
commit
1969d38e06
@ -38,7 +38,8 @@ public final class DatabaseManager {
|
|||||||
return getDatastore().getDatabase();
|
return getDatastore().getDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yes. I very dislike this method also but I'm lazy. Probably replace it by making the game server connect to the dispatch server instead.
|
// Yes. I very dislike this method. However, this will be good for now.
|
||||||
|
// TODO: Add dispatch routes for player account management
|
||||||
public static Datastore getAccountDatastore() {
|
public static Datastore getAccountDatastore() {
|
||||||
if(Grasscutter.getConfig().RunMode.equalsIgnoreCase("GAME_ONLY")) {
|
if(Grasscutter.getConfig().RunMode.equalsIgnoreCase("GAME_ONLY")) {
|
||||||
return dispatchDatastore;
|
return dispatchDatastore;
|
||||||
@ -50,7 +51,6 @@ public final class DatabaseManager {
|
|||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
// Initialize
|
// Initialize
|
||||||
mongoClient = new MongoClient(new MongoClientURI(Grasscutter.getConfig().DatabaseUrl));
|
mongoClient = new MongoClient(new MongoClientURI(Grasscutter.getConfig().DatabaseUrl));
|
||||||
dispatchMongoClient = new MongoClient(new MongoClientURI(Grasscutter.getConfig().getGameServerOptions().DispatchServerDatabaseUrl));
|
|
||||||
Morphia morphia = new Morphia();
|
Morphia morphia = new Morphia();
|
||||||
|
|
||||||
// TODO Update when migrating to Morphia 2.0
|
// TODO Update when migrating to Morphia 2.0
|
||||||
@ -63,7 +63,6 @@ public final class DatabaseManager {
|
|||||||
|
|
||||||
// Build datastore
|
// Build datastore
|
||||||
datastore = morphia.createDatastore(mongoClient, Grasscutter.getConfig().DatabaseCollection);
|
datastore = morphia.createDatastore(mongoClient, Grasscutter.getConfig().DatabaseCollection);
|
||||||
dispatchDatastore = morphia.createDatastore(dispatchMongoClient, Grasscutter.getConfig().getGameServerOptions().DispatchServerDatabaseCollection);
|
|
||||||
|
|
||||||
// Ensure indexes
|
// Ensure indexes
|
||||||
try {
|
try {
|
||||||
@ -82,6 +81,10 @@ public final class DatabaseManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Grasscutter.getConfig().RunMode.equalsIgnoreCase("GAME_ONLY")) {
|
||||||
|
dispatchMongoClient = new MongoClient(new MongoClientURI(Grasscutter.getConfig().getGameServerOptions().DispatchServerDatabaseUrl));
|
||||||
|
dispatchDatastore = morphia.createDatastore(dispatchMongoClient, Grasscutter.getConfig().getGameServerOptions().DispatchServerDatabaseCollection);
|
||||||
|
|
||||||
// Ensure indexes for dispatch server
|
// Ensure indexes for dispatch server
|
||||||
try {
|
try {
|
||||||
dispatchDatastore.ensureIndexes();
|
dispatchDatastore.ensureIndexes();
|
||||||
@ -99,6 +102,7 @@ public final class DatabaseManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized int getNextId(Class<?> c) {
|
public static synchronized int getNextId(Class<?> c) {
|
||||||
DatabaseCounter counter = getDatastore().createQuery(DatabaseCounter.class).field("_id").equal(c.getSimpleName()).find().tryNext();
|
DatabaseCounter counter = getDatastore().createQuery(DatabaseCounter.class).field("_id").equal(c.getSimpleName()).find().tryNext();
|
||||||
|
Loading…
Reference in New Issue
Block a user