Class Database

java.lang.Object
com.github.darksoulq.abyssallib.common.database.nosql.mongodb.Database

public class Database extends Object
Manages the connection lifecycle for a MongoDB NoSQL database.

This class handles the initialization of the MongoClient, provides access to specific MongoDatabase instances, and maintains an asynchronous thread pool for non-blocking operations.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Database(String uri, String databaseName)
    Constructs a new MongoDB Database handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Establishes a connection to the MongoDB server and initializes the database instance.
    void
    Closes the MongoDB client connection and shuts down the asynchronous thread pool.
    Creates a new QueryExecutor to perform operations on collections.
    Gets the thread pool used for asynchronous operations.
    com.mongodb.client.MongoDatabase
    Retrieves the active MongoDatabase instance.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Database

      public Database(String uri, String databaseName)
      Constructs a new MongoDB Database handler.
      Parameters:
      uri - The connection string.
      databaseName - The target database name.
  • Method Details

    • connect

      public void connect()
      Establishes a connection to the MongoDB server and initializes the database instance.
    • disconnect

      public void disconnect()
      Closes the MongoDB client connection and shuts down the asynchronous thread pool.
    • getDatabase

      public com.mongodb.client.MongoDatabase getDatabase()
      Retrieves the active MongoDatabase instance.
      Returns:
      The MongoDatabase instance.
    • getAsyncPool

      public ExecutorService getAsyncPool()
      Gets the thread pool used for asynchronous operations.
      Returns:
      The ExecutorService instance.
    • executor

      public QueryExecutor executor()
      Creates a new QueryExecutor to perform operations on collections.
      Returns:
      A new QueryExecutor.