Package com.jk.data.datasource
Class JKNoSqlDataSource
java.lang.Object
com.jk.data.datasource.JKNoSqlDataSource
This class is designed to manage connections to a NoSQL
database, specifically MongoDB.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Constructor Summary
ConstructorsConstructorDescriptionThis method constructs a new with default values and sets up theMongoClient
.JKNoSqlDataSource
(String url, String dbName, String username, String password) This method constructs a new with the provided values and sets up theMongoClient
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
This method closes aMongoClient
when its no longer needed.com.mongodb.client.MongoClient
This method returns theMongoClient
instance.com.mongodb.client.MongoDatabase
This method returns theMongoDatabase
instance.protected void
init()
This method initializes theMongoClient
by configuring aPojoCodecProvider
to handle object mapping, creatingMongoClientSettings
with connection details and credentials, and then creating theMongoClient
.
-
Constructor Details
-
JKNoSqlDataSource
public JKNoSqlDataSource()This method constructs a new with default values and sets up theMongoClient
. -
JKNoSqlDataSource
This method constructs a new with the provided values and sets up theMongoClient
.- 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 theMongoClient
by configuring aPojoCodecProvider
to handle object mapping, creatingMongoClientSettings
with connection details and credentials, and then creating theMongoClient
. -
getClient
public com.mongodb.client.MongoClient getClient()This method returns theMongoClient
instance.- Returns:
- the
MongoClient
instance.
-
getDatabase
public com.mongodb.client.MongoDatabase getDatabase()This method returns theMongoDatabase
instance.- Returns:
- the
MongoDatabase
instance.
-
close
public void close()This method closes aMongoClient
when its no longer needed.
-