Class MongoDataConnection

  • All Implemented Interfaces:
    DataConnection

    public class MongoDataConnection
    extends DataConnectionBase
    Creates a MongoDB DataConnection.

    According to MongoClient documentation, the client object is responsible for maintaining connection pool, so this data connection just returns one, cached client.

    Since:
    5.3
    • Field Detail

      • CONNECTION_STRING_PROPERTY

        public static final java.lang.String CONNECTION_STRING_PROPERTY
        Name of a property which holds connection string to the mongodb instance.
        See Also:
        Constant Field Values
      • DATABASE_PROPERTY

        public static final java.lang.String DATABASE_PROPERTY
        Name of a property with a database name hint. This is used as a hint only; listResources() will return only collection from db with this name, but client is not restricted to this database. It can be used to specify database to which SQL Mappings will point.
        See Also:
        Constant Field Values
      • USERNAME_PROPERTY

        public static final java.lang.String USERNAME_PROPERTY
        Name of the property holding username.
        See Also:
        Constant Field Values
      • PASSWORD_PROPERTY

        public static final java.lang.String PASSWORD_PROPERTY
        Name of the property holding user password.
        See Also:
        Constant Field Values
      • HOST_PROPERTY

        public static final java.lang.String HOST_PROPERTY
        Name of a property which holds host:port address of the mongodb instance.
        See Also:
        Constant Field Values
      • AUTH_DB_PROPERTY

        public static final java.lang.String AUTH_DB_PROPERTY
        Name of the property holding the name of the database in which user is created. Default value is admin.
        See Also:
        Constant Field Values
      • CONNECTION_POOL_MIN

        public static final java.lang.String CONNECTION_POOL_MIN
        Name of the property holding the minimum size of Mongo Client connection pool. Default is 10.
        Since:
        5.4
        See Also:
        Constant Field Values
      • CONNECTION_POOL_MAX

        public static final java.lang.String CONNECTION_POOL_MAX
        Name of the property holding the maximum size of Mongo Client connection pool. Default is 10.
        Since:
        5.4
        See Also:
        Constant Field Values
    • Constructor Detail

      • MongoDataConnection

        public MongoDataConnection​(DataConnectionConfig config)
        Creates a new data connection based on given config.
    • Method Detail

      • getClient

        @Nonnull
        public com.mongodb.client.MongoClient getClient()
        Returns an instance of MongoClient. If client is DataConnectionConfig.isShared() and there will be still some usages of given client, the MongoClient.close() method won't take an effect.
      • getDatabaseName

        public java.lang.String getDatabaseName()
        Returns the database name hint.
      • listResources

        @Nonnull
        public java.util.List<DataConnectionResource> listResources()
        Lists all MongoDB collections in all databases.
      • destroy

        public void destroy()
        Closes underlying client.
      • mongoDataConnectionConf

        @Nonnull
        public static DataConnectionConfig mongoDataConnectionConf​(java.lang.String name,
                                                                   java.lang.String connectionString)
        Helper method to create new MongoDataConnection with given name and connection string.