Package ortus.boxlang.runtime.services
Class DatasourceService
java.lang.Object
ortus.boxlang.runtime.services.BaseService
ortus.boxlang.runtime.services.DatasourceService
- All Implemented Interfaces:
IService
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.
-
Field Summary
Fields inherited from class ortus.boxlang.runtime.services.BaseService
name, runtime, timerUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclear()
Clear all registered datasources and close all connections.Clear all registered driversHow many drivers are registered?get
(DatasourceConfig config) Get a datasource by config.Get a datasource by (Key) name.Get a driver by nameString[]
Get an array of all registered driver namesGet the generic JDBC driverString[]
getNames()
Get an array of all registered datasources nameshas
(DatasourceConfig config) Do we have a datasource registered with the manager using a configuration?Do we have a datasource registered with the manager?Has a driver been registered?void
onShutdown
(Boolean force) The shutdown event is fired when the runtime shuts downvoid
The startup event is fired when the runtime starts upregister
(DatasourceConfig config) Registers a datasource with the manager.register
(Key name, DataSource datasource) Registers a datasource with the manager.Registers a datasource with the manager.registerDriver
(IJDBCDriver driver) Register a new driverremove
(DatasourceConfig config) Remove a datasurce by key nameRemove a datasurce by key nameremoveDriver
(Key name) Remove a driver by namesize()
How many datasources are registered?Methods inherited from class ortus.boxlang.runtime.services.BaseService
announce, announce, announce, announce, getName, getRuntime, getTimerUtil
-
Constructor Details
-
DatasourceService
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 interfaceIService
- Specified by:
onStartup
in classBaseService
-
onShutdown
The shutdown event is fired when the runtime shuts down- Specified by:
onShutdown
in interfaceIService
- Specified by:
onShutdown
in classBaseService
- Parameters:
force
- If true, forces the shutdown of the scheduler
-
registerDriver
Register a new driver- Parameters:
driver
- The driver to register- Returns:
- DatasourceService
-
getDriver
Get a driver by name- Parameters:
name
- The name of the driver- Returns:
- The driver, if found, or `null`
-
getGenericDriver
Get the generic JDBC driver- Returns:
- The generic JDBC driver
-
hasDriver
Has a driver been registered?- Parameters:
name
- The name of the driver- Returns:
- True if the driver is registered, false otherwise
-
removeDriver
Remove a driver by name- Parameters:
name
- The name of the driver
-
clearDrivers
Clear all registered drivers -
driverSize
How many drivers are registered? -
getDriverNames
Get an array of all registered driver names -
register
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
Registers a datasource with the manager. If the datasource is already registered it will just return it.- Parameters:
name
- The name of the datasourceproperties
- The datasource properties- Returns:
- A new or already registered datasource
-
register
Registers a datasource with the manager.- Parameters:
name
- The name of the datasourcedatasource
- The datasource to register- Returns:
- The datasource that was registered
-
has
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
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
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
Get a datasource by config.- Parameters:
config
- Datasource configuration struct.- Returns:
- An instance of the datasource, if found, or `null`.
-
remove
Remove a datasurce by key name- Parameters:
name
- Name of the datasource to remove
-
remove
Remove a datasurce by key name- Parameters:
config
- Datasource configuration struct.
-
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
How many datasources are registered? -
getNames
Get an array of all registered datasources names
-