Class OneDB


  • public class OneDB
    extends java.lang.Object
    A single database.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  OneDB.RowMapper<T>
      Functional interface for mapping from a ResultSet to T.
    • Constructor Summary

      Constructors 
      Constructor Description
      OneDB​(Config config)
      Creates a database with the provided config.
      OneDB​(java.lang.String name)
      Creates a database with the given name, reading the Config from the system environment.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void execute​(java.lang.String sql, java.lang.Object... params)
      Execute an SQL statement.
      void initialize()
      Initialize this database.
      org.jdbi.v3.core.Jdbi jdbi()
      Provides access to the Jdbi instance.
      org.jooq.DSLContext jooq()
      Entrypoint for using the Jooq DSL.
      org.jdbi.v3.core.Handle open()
      Open a Handle to this database.
      <T> java.util.stream.Stream<T> select​(OneDB.RowMapper<T> mapper, java.lang.String sql, java.lang.Object... params)
      Run an SQL query.
      <X extends java.lang.Exception>
      void
      useHandle​(org.jdbi.v3.core.HandleConsumer<X> consumer)
      Use a Jdbi Handle.
      <R,​X extends java.lang.Exception>
      R
      withHandle​(org.jdbi.v3.core.HandleCallback<R,​X> callback)
      Execute a callback with a Jdbi Handle.
      • Methods inherited from class java.lang.Object

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

      • OneDB

        public OneDB​(java.lang.String name)
        Creates a database with the given name, reading the Config from the system environment.
        Parameters:
        name - the db name
      • OneDB

        public OneDB​(Config config)
        Creates a database with the provided config.
        Parameters:
        config - the configuration for this database
    • Method Detail

      • initialize

        public void initialize()
        Initialize this database. It is not required to call initialize, as it will be performed the first time that it is needed. However, sometimes it is desierable to have initialization performed at a known time (e.g., on startup).
      • jdbi

        public org.jdbi.v3.core.Jdbi jdbi()
        Provides access to the Jdbi instance. The methods on OneDB are designed to cover the most common use cases. The Jdbi instance is available if they do not fit your needs.
        Returns:
        the Jdbi instance
      • jooq

        public org.jooq.DSLContext jooq()
        Entrypoint for using the Jooq DSL.
        Returns:
        the Jooq DSLContext
      • open

        public org.jdbi.v3.core.Handle open()
        Open a Handle to this database.
        Returns:
        an open Handle instance
      • useHandle

        public <X extends java.lang.Exception> void useHandle​(org.jdbi.v3.core.HandleConsumer<X> consumer)
                                                       throws X extends java.lang.Exception
        Use a Jdbi Handle.
        Type Parameters:
        X - exeception that may be thrown by the consumer
        Parameters:
        consumer - the consumer that uses the Handle
        Throws:
        X - if consumer does
        X extends java.lang.Exception
      • withHandle

        public <R,​X extends java.lang.Exception> R withHandle​(org.jdbi.v3.core.HandleCallback<R,​X> callback)
                                                             throws X extends java.lang.Exception
        Execute a callback with a Jdbi Handle.
        Type Parameters:
        R - return type of callback
        X - exception that may be thrown by the callback
        Parameters:
        callback - the code to run with the Handle
        Returns:
        the result of the callback
        Throws:
        X - if callback does
        X extends java.lang.Exception
      • execute

        public void execute​(java.lang.String sql,
                            java.lang.Object... params)
        Execute an SQL statement.
        Parameters:
        sql - the SQL to execute
        params - the parameters to include in the sql
      • select

        public <T> java.util.stream.Stream<T> select​(OneDB.RowMapper<T> mapper,
                                                     java.lang.String sql,
                                                     java.lang.Object... params)
        Run an SQL query.
        Type Parameters:
        T - the return type of the mapper
        Parameters:
        mapper - Function to convert from ResultSet to the result we want
        sql - the SQL to execute
        params - the parameters to include in the sql
        Returns:
        a Stream of mapped results