Class JdbcDb

java.lang.Object
io.inversion.Db<JdbcDb>
io.inversion.jdbc.JdbcDb

public class JdbcDb extends io.inversion.Db<JdbcDb>
Exposes the tables of a JDBC data source as REST Collections.
  • Field Details

    • ddlUrls

      protected final List<String> ddlUrls
      Urls to DDL files that should be executed on startup of this Db.
    • stringQuote

      protected char stringQuote
    • columnQuote

      protected char columnQuote
    • driver

      protected String driver
      The JDBC driver class name.
    • url

      protected String url
      The JDBC url.

      Generally you will want to have this value dependency inject this at runtime by setting "${name}.url=${MY_DB_URL}" somewhere where it can be discovered by Config...for example as an environment variable or in an inversion.properties file.

      See Also:
      Config, Configuration
    • user

      protected String user
      The JDBC username.

      Generally you will want to have this value dependency inject this at runtime by setting "${name}.user=${MY_DB_USER_NAME}" somewhere where it can be discovered by Config...for example as an environment variable or in an inversion.properties file.

      See Also:
      Config, Configuration
    • pass

      protected String pass
      The JDBC password.

      Generally you will want to have this value dependency inject this at runtime by setting "${name}.user=${MY_DB_USER_NAME}" somewhere where it can be discovered by Config...for example as an environment variable or in an inversion.properties file.

      See Also:
      Config, Configuration
    • poolMax

      protected int poolMax
      The maximum number of connections in the JDBC Connection pool, defaults to 50.
    • idleConnectionTestPeriod

      protected int idleConnectionTestPeriod
    • autoCommit

      protected boolean autoCommit
      Should the JDBC connection be set to autoCommit.

      By default, autoCommit is false because the system is setup to execute all sql statements for a single Request inside of one transaction that commits just before the root Response is returned to the caller.

    • calcRowsFound

      protected boolean calcRowsFound
      For MySQL only, set this to false to turn off SQL_CALC_FOUND_ROWS and SELECT FOUND_ROWS()
  • Constructor Details

  • Method Details

    • doStartup

      protected void doStartup(io.inversion.Api api)
      Overrides:
      doStartup in class io.inversion.Db<JdbcDb>
    • doShutdown

      protected void doShutdown()
      Overrides:
      doShutdown in class io.inversion.Db<JdbcDb>
    • getType

      public String getType()
      Overrides:
      getType in class io.inversion.Db<JdbcDb>
    • doSelect

      public io.inversion.Results doSelect(io.inversion.Collection coll, List<io.inversion.rql.Term> columnMappedTerms) throws io.inversion.ApiException
      Specified by:
      doSelect in class io.inversion.Db<JdbcDb>
      Throws:
      io.inversion.ApiException
    • doUpsert

      public List<String> doUpsert(io.inversion.Collection table, List<Map<String,​Object>> rows) throws io.inversion.ApiException
      Specified by:
      doUpsert in class io.inversion.Db<JdbcDb>
      Throws:
      io.inversion.ApiException
    • doPatch

      public void doPatch(io.inversion.Collection table, List<Map<String,​Object>> rows) throws io.inversion.ApiException
      Overrides:
      doPatch in class io.inversion.Db<JdbcDb>
      Throws:
      io.inversion.ApiException
    • delete

      public void delete(io.inversion.Collection table, List<Map<String,​Object>> columnMappedIndexValues) throws io.inversion.ApiException
      Specified by:
      delete in class io.inversion.Db<JdbcDb>
      Throws:
      io.inversion.ApiException
    • getConnection

      public Connection getConnection() throws io.inversion.ApiException
      Shortcut for getConnection(true);
      Returns:
      a connection
      Throws:
      io.inversion.ApiException
    • getConnection

      public Connection getConnection(boolean managed) throws io.inversion.ApiException
      Returns a JDBC connection to the underlying JDBC db.

      If managed is true the Connection is shared on the ThreadLocal with autoCommit managed by this Db and an EngineListener. Callers should NOT close this connection. It will not create a connection pool leak. All managed connections attached to the ThreadLocal are closed/returned to the pool when the Engine finishes serving a s Request.

      If managed is false, a completely new Connection is returned.

      Parameters:
      managed - should this be a net new collection or a pool connection that is automatically closed when the Request ends
      Returns:
      a Connection
      Throws:
      io.inversion.ApiException
    • getConnection0

      protected Connection getConnection0(boolean managed) throws io.inversion.ApiException
      Throws:
      io.inversion.ApiException
    • createConnectionPool

      protected DataSource createConnectionPool() throws Exception
      Throws:
      Exception
    • buildCollections

      public void buildCollections() throws io.inversion.ApiException
      Overrides:
      buildCollections in class io.inversion.Db<JdbcDb>
      Throws:
      io.inversion.ApiException
    • withType

      public JdbcDb withType(String type)
      Overrides:
      withType in class io.inversion.Db<JdbcDb>
    • withConfig

      public JdbcDb withConfig(String driver, String url, String user, String pass)
    • getDriver

      public String getDriver()
    • withDriver

      public JdbcDb withDriver(String driver)
    • getUrl

      public String getUrl()
    • withUrl

      public JdbcDb withUrl(String url)
    • getUser

      public String getUser()
    • withUser

      public JdbcDb withUser(String user)
    • getPass

      public String getPass()
    • withPass

      public JdbcDb withPass(String pass)
    • getPoolMax

      public int getPoolMax()
    • setPoolMax

      public void setPoolMax(int poolMax)
    • getIdleConnectionTestPeriod

      public int getIdleConnectionTestPeriod()
    • setIdleConnectionTestPeriod

      public void setIdleConnectionTestPeriod(int idleConnectionTestPeriod)
    • withStringQuote

      public JdbcDb withStringQuote(char stringQuote)
    • withColumnQuote

      public JdbcDb withColumnQuote(char columnQuote)
    • quoteCol

      public String quoteCol(String columnName)
    • quoteStr

      public String quoteStr(String string)
    • withDdlUrl

      public JdbcDb withDdlUrl(String... ddlUrl)
    • isAutoCommit

      public boolean isAutoCommit()
    • withAutoCommit

      public JdbcDb withAutoCommit(boolean autoCommit)