Package csw.database

Class DatabaseServiceFactory

java.lang.Object
csw.database.DatabaseServiceFactory

public class DatabaseServiceFactory extends 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<String,String> values)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    CompletableFuture<org.jooq.DSLContext>
    A java method to Creates a connection to database using the configuration read from application.conf.
    CompletableFuture<org.jooq.DSLContext>
    jMakeDsl(ILocationService locationService, String dbName)
    A java method to create connection to database with default read access.
    CompletableFuture<org.jooq.DSLContext>
    jMakeDsl(ILocationService locationService, String dbName, String usernameHolder, String passwordHolder)
    A java method to create the connection to database with credentials picked from environment variables.
    scala.concurrent.Future<org.jooq.DSLContext>
    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, String dbName)
    Creates connection to database with default read access.
    scala.concurrent.Future<org.jooq.DSLContext>
    makeDsl(csw.location.api.scaladsl.LocationService locationService, String dbName, String usernameHolder, String passwordHolder)
    Creates connection to database with credentials picked from environment variables.
    static String
     
    static String
     

    Methods inherited from class java.lang.Object

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

    • DatabaseServiceFactory

      public DatabaseServiceFactory(akka.actor.typed.ActorSystem<?> actorSystem, scala.collection.immutable.Map<String,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 Details

    • ReadUsernameHolder

      public static String ReadUsernameHolder()
    • ReadPasswordHolder

      public static String ReadPasswordHolder()
    • makeDsl

      public scala.concurrent.Future<org.jooq.DSLContext> makeDsl(csw.location.api.scaladsl.LocationService locationService, 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, String dbName, String usernameHolder, 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 CompletableFuture<org.jooq.DSLContext> jMakeDsl(ILocationService locationService, 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 CompletableFuture<org.jooq.DSLContext> jMakeDsl(ILocationService locationService, String dbName, String usernameHolder, 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 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)