Class JKNoSqlDataSource

java.lang.Object
com.jk.data.datasource.JKNoSqlDataSource

public class JKNoSqlDataSource extends Object
This class is designed to manage connections to a NoSQL database, specifically MongoDB.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Summary

    Constructors
    Constructor
    Description
    This method constructs a new with default values and sets up the MongoClient.
    JKNoSqlDataSource(String url, String dbName, String username, String password)
    This method constructs a new with the provided values and sets up the MongoClient.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method closes a MongoClient when its no longer needed.
    com.mongodb.client.MongoClient
    This method returns the MongoClient instance.
    com.mongodb.client.MongoDatabase
    This method returns the MongoDatabase instance.
    protected void
    This method initializes the MongoClient by configuring a PojoCodecProvider to handle object mapping, creating MongoClientSettings with connection details and credentials, and then creating the MongoClient.

    Methods inherited from class java.lang.Object

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

    • JKNoSqlDataSource

      public JKNoSqlDataSource()
      This method constructs a new with default values and sets up the MongoClient.
    • JKNoSqlDataSource

      public JKNoSqlDataSource(String url, String dbName, String username, String password)
      This method constructs a new with the provided values and sets up the MongoClient.
      Parameters:
      url - Specifies the MongoDB connection URL.
      dbName - Specifies the name of the MongoDB database.
      username - Specifies the user name.
      password - Specifies the password.
  • Method Details

    • init

      protected void init()
      This method initializes the MongoClient by configuring a PojoCodecProvider to handle object mapping, creating MongoClientSettings with connection details and credentials, and then creating the MongoClient.
    • getClient

      public com.mongodb.client.MongoClient getClient()
      This method returns the MongoClient instance.
      Returns:
      the MongoClient instance.
    • getDatabase

      public com.mongodb.client.MongoDatabase getDatabase()
      This method returns the MongoDatabase instance.
      Returns:
      the MongoDatabase instance.
    • close

      public void close()
      This method closes a MongoClient when its no longer needed.