Package csw.database

Class DatabaseServiceFactory


  • public class DatabaseServiceFactory
    extends java.lang.Object
    DatabaseServiceFactory provides a mechanism to connect to the database server and get the handle of Jooq's DSLContext. To know in detail about Jooq please refer {@link https://www.jooq.org/learn/}.

    param: actorSystem component's actor system, used for 1) reading the database configurations and 2) schedule the task of database connection param: values used for testing purposes, to manually set the values for credentials instead of reading from env vars

    • Constructor Summary

      Constructors 
      Constructor Description
      DatabaseServiceFactory​(akka.actor.typed.ActorSystem<?> actorSystem)
      Creates the DatabaseServiceFactory.
      DatabaseServiceFactory​(akka.actor.typed.ActorSystem<?> actorSystem, scala.collection.immutable.Map<java.lang.String,​java.lang.String> values)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<org.jooq.DSLContext> jMakeDsl()
      A java method to Creates a connection to database using the configuration read from application.conf.
      java.util.concurrent.CompletableFuture<org.jooq.DSLContext> jMakeDsl​(ILocationService locationService, java.lang.String dbName)
      A java method to create connection to database with default read access.
      java.util.concurrent.CompletableFuture<org.jooq.DSLContext> jMakeDsl​(ILocationService locationService, java.lang.String dbName, java.lang.String usernameHolder, java.lang.String passwordHolder)
      A java method to create the connection to database with credentials picked from environment variables.
      scala.concurrent.Future<org.jooq.DSLContext> makeDsl()
      Creates a connection to database using the configuration read from application.conf.
      scala.concurrent.Future<org.jooq.DSLContext> makeDsl​(int port)  
      scala.concurrent.Future<org.jooq.DSLContext> makeDsl​(csw.location.api.scaladsl.LocationService locationService, java.lang.String dbName)
      Creates connection to database with default read access.
      scala.concurrent.Future<org.jooq.DSLContext> makeDsl​(csw.location.api.scaladsl.LocationService locationService, java.lang.String dbName, java.lang.String usernameHolder, java.lang.String passwordHolder)
      Creates connection to database with credentials picked from environment variables.
      static java.lang.String ReadPasswordHolder()  
      static java.lang.String ReadUsernameHolder()  
      • Methods inherited from class java.lang.Object

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

      • DatabaseServiceFactory

        public DatabaseServiceFactory​(akka.actor.typed.ActorSystem<?> actorSystem,
                                      scala.collection.immutable.Map<java.lang.String,​java.lang.String> values)
      • DatabaseServiceFactory

        public DatabaseServiceFactory​(akka.actor.typed.ActorSystem<?> actorSystem)
        Creates the DatabaseServiceFactory. It is not injected in CswContext like other csw services. Instead developers are expected to create an instance of DatabaseServiceFactory and then use it.

        Parameters:
        actorSystem - component's actor system, used for 1) reading the database configurations and 2) schedule the task of database connection
    • Method Detail

      • ReadUsernameHolder

        public static java.lang.String ReadUsernameHolder()
      • ReadPasswordHolder

        public static java.lang.String ReadPasswordHolder()
      • makeDsl

        public scala.concurrent.Future<org.jooq.DSLContext> makeDsl​(csw.location.api.scaladsl.LocationService locationService,
                                                                    java.lang.String dbName)
        Creates connection to database with default read access. The username and password for read access is picked from environment variables set on individual's machine i.e. DB_READ_USERNAME and DB_READ_PASSWORD. It is expected that developers set these variables before calling this method.

        Parameters:
        locationService - used to locate the database server
        dbName - used to connect to the database
        Returns:
        a Future that completes with Jooq's DSLContext or fails with DatabaseException. DSLContext provide methods like fetchAsync, executeAsync, executeBatch, etc. Moreover, see JooqHelper for java and JooqExtentions for scala which provides wrapper methods on Jooq's DSLContext.
      • makeDsl

        public scala.concurrent.Future<org.jooq.DSLContext> makeDsl​(csw.location.api.scaladsl.LocationService locationService,
                                                                    java.lang.String dbName,
                                                                    java.lang.String usernameHolder,
                                                                    java.lang.String passwordHolder)
        Creates connection to database with credentials picked from environment variables. Names of these environment variables is expected as method parameters and developers are expected to set these variables before calling this method.

        Parameters:
        locationService - used to locate the database server
        dbName - used to connect to the database
        usernameHolder - name of env variable from which the username will be read
        passwordHolder - name of env variable from which the password will be read
        Returns:
        a Future that completes with Jooq's DSLContext or fails with DatabaseException. DSLContext provide methods like fetchAsync, executeAsync, executeBatch, etc. Moreover, see JooqHelper for java and JooqExtentions for scala which provides wrapper methods on Jooq's DSLContext.
      • jMakeDsl

        public java.util.concurrent.CompletableFuture<org.jooq.DSLContext> jMakeDsl​(ILocationService locationService,
                                                                                    java.lang.String dbName)
        A java method to create connection to database with default read access. The username and password for read access is picked from environment variables set on individual's machine i.e. DB_READ_USERNAME and DB_READ_PASSWORD. It is expected that developers set these variables before calling this method.

        Parameters:
        locationService - used to locate the database server
        dbName - used to connect to the database
        Returns:
        a CompletableFuture that completes with Jooq's DSLContext or fails with DatabaseException. DSLContext provide methods like fetchAsync, executeAsync, executeBatch, etc. Moreover, see JooqHelper for java and JooqExtentions for scala which provides wrapper methods on Jooq's DSLContext.
      • jMakeDsl

        public java.util.concurrent.CompletableFuture<org.jooq.DSLContext> jMakeDsl​(ILocationService locationService,
                                                                                    java.lang.String dbName,
                                                                                    java.lang.String usernameHolder,
                                                                                    java.lang.String passwordHolder)
        A java method to create the connection to database with credentials picked from environment variables. Names of these environment variables is expected as method parameters and developers are expected to set these variables before calling this method.

        Parameters:
        locationService - used to locate the database server
        dbName - used to connect to the database
        usernameHolder - name of env variable from which the username will be read
        passwordHolder - name of env variable from which the password will be read
        Returns:
        a CompletableFuture that completes with Jooq's DSLContext or fails with DatabaseException. DSLContext provide methods like fetchAsync, executeAsync, executeBatch, etc. Moreover, see JooqHelper for java and JooqExtentions for scala which provides wrapper methods on Jooq's DSLContext.
      • makeDsl

        public scala.concurrent.Future<org.jooq.DSLContext> makeDsl()
        Creates a connection to database using the configuration read from application.conf. Refer the reference.conf/database documentation to know how to provide database connection properties.

        Returns:
        a Future that completes with Jooq's DSLContext or fails with DatabaseException. DSLContext provide methods like fetchAsync, executeAsync, executeBatch, etc. Moreover, see JooqHelper for java and JooqExtentions for scala which provides wrapper methods on Jooq's DSLContext.
      • jMakeDsl

        public java.util.concurrent.CompletableFuture<org.jooq.DSLContext> jMakeDsl()
        A java method to Creates a connection to database using the configuration read from application.conf. Refer the reference.conf/database documentation to know how to provide database connection properties.

        Returns:
        a CompletableFuture that completes with Jooq's DSLContext or fails with DatabaseException. DSLContext provide methods like fetchAsync, executeAsync, executeBatch, etc. Moreover, see JooqHelper for java and JooqExtentions for scala which provides wrapper methods on Jooq's DSLContext.
      • makeDsl

        public scala.concurrent.Future<org.jooq.DSLContext> makeDsl​(int port)