Class DatasourceService

java.lang.Object
ortus.boxlang.runtime.services.BaseService
ortus.boxlang.runtime.services.DatasourceService
All Implemented Interfaces:
IService

public class DatasourceService extends BaseService
The datasource manager which stores a registry of configured datasources.

Each datasource is a connection pool (or potential connection pool) to a database.

The datasource manager can look up datasources by name or by configuration. If by name, the datasource name will be prefixed with the application name or web server name, if those exist.

  • Constructor Details

    • DatasourceService

      public DatasourceService(BoxRuntime runtime)
      Constructor
      Parameters:
      runtime - The BoxRuntime
  • Method Details

    • onStartup

      public void onStartup()
      The startup event is fired when the runtime starts up
      Specified by:
      onStartup in interface IService
      Specified by:
      onStartup in class BaseService
    • onShutdown

      public void onShutdown(Boolean force)
      The shutdown event is fired when the runtime shuts down
      Specified by:
      onShutdown in interface IService
      Specified by:
      onShutdown in class BaseService
      Parameters:
      force - If true, forces the shutdown of the scheduler
    • registerDriver

      public DatasourceService registerDriver(IJDBCDriver driver)
      Register a new driver
      Parameters:
      driver - The driver to register
      Returns:
      DatasourceService
    • getDriver

      public IJDBCDriver getDriver(Key name)
      Get a driver by name
      Parameters:
      name - The name of the driver
      Returns:
      The driver, if found, or `null`
    • getGenericDriver

      public IJDBCDriver getGenericDriver()
      Get the generic JDBC driver
      Returns:
      The generic JDBC driver
    • hasDriver

      public Boolean hasDriver(Key name)
      Has a driver been registered?
      Parameters:
      name - The name of the driver
      Returns:
      True if the driver is registered, false otherwise
    • removeDriver

      public Boolean removeDriver(Key name)
      Remove a driver by name
      Parameters:
      name - The name of the driver
    • clearDrivers

      public DatasourceService clearDrivers()
      Clear all registered drivers
    • driverSize

      public Integer driverSize()
      How many drivers are registered?
    • getDriverNames

      public String[] getDriverNames()
      Get an array of all registered driver names
    • register

      public DataSource register(DatasourceConfig config)
      Registers a datasource with the manager. If the datasource is already registered it will just return it.
      Parameters:
      config - The datasource configuration object
      Returns:
      A new or already registered datasource
    • register

      public DataSource register(Key name, IStruct properties)
      Registers a datasource with the manager. If the datasource is already registered it will just return it.
      Parameters:
      name - The name of the datasource
      properties - The datasource properties
      Returns:
      A new or already registered datasource
    • register

      public DataSource register(Key name, DataSource datasource)
      Registers a datasource with the manager.
      Parameters:
      name - The name of the datasource
      datasource - The datasource to register
      Returns:
      The datasource that was registered
    • has

      public Boolean has(Key name)
      Do we have a datasource registered with the manager?
      Parameters:
      name - The name of the datasource
      Returns:
      True if the datasource is registered, false otherwise
    • has

      public Boolean has(DatasourceConfig config)
      Do we have a datasource registered with the manager using a configuration?
      Parameters:
      config - The datasource configuration
      Returns:
      True if the datasource is registered, false otherwise
    • get

      public DataSource get(Key name)
      Get a datasource by (Key) name.
      Parameters:
      name - Name of the datasource to retrieve - for example, `Key.of( "blog" )`
      Returns:
      An instance of the datasource, if found, or `null`.
    • get

      public DataSource get(DatasourceConfig config)
      Get a datasource by config.
      Parameters:
      config - Datasource configuration struct.
      Returns:
      An instance of the datasource, if found, or `null`.
    • remove

      public Boolean remove(Key name)
      Remove a datasurce by key name
      Parameters:
      name - Name of the datasource to remove
    • remove

      public Boolean remove(DatasourceConfig config)
      Remove a datasurce by key name
      Parameters:
      config - Datasource configuration struct.
    • clear

      public DatasourceService clear()
      Clear all registered datasources and close all connections.

      Will close all open connections and remove all datasources (including the default) from the manager.

    • size

      public Integer size()
      How many datasources are registered?
    • getNames

      public String[] getNames()
      Get an array of all registered datasources names