Package ortus.boxlang.runtime.jdbc
Class DataSource
java.lang.Object
ortus.boxlang.runtime.jdbc.DataSource
- All Implemented Interfaces:
Comparable<DataSource>
Encapsulates a datasource configuration and connection pool, providing methods for executing queries (transactionally or single) on the datasource.
-
Constructor Summary
ConstructorsConstructorDescriptionDataSource(DatasourceConfig config) Configure and initialize a new DataSourceRecord object from a struct of properties. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(DataSource otherConfig) Compares two DataSource objectsbooleanVerifies equality between two Datasource objectsExecute a query on the default connection.execute(String query, Connection conn, IBoxContext context) Execute a query on the connection, using the provided connection.execute(String query, List<QueryParameter> parameters, Connection conn, IBoxContext context) Execute a query with a List of parameters on a given connection.execute(String query, List<QueryParameter> parameters, IBoxContext context) Execute a query with a List of parameters on the default connection.execute(String query, IBoxContext context) Execute a query on the default connection, within the specific context.execute(String query, Array parameters, Connection conn, IBoxContext context) Execute a query with an array of parameters on a given connection.execute(String query, Array parameters, IBoxContext context) Execute a query with an array of parameters on the default connection.execute(String query, IStruct parameters, Connection conn, IBoxContext context) Execute a query with a struct of parameters on a given connection.execute(String query, IStruct parameters, IBoxContext context) Execute a query with a struct of parameters on the default connection.static DataSourcefromStruct(String name, IStruct properties) Helper builder to build out a new DataSource object from a struct of properties and a name.static DataSourcefromStruct(Key name, IStruct properties) Helper builder to build out a new DataSource object from a struct of properties and a name.Get the configuration object for this datasource.Get a connection to the configured datasource.getConnection(String username, String password) Get a connection to the configured datasource with the provided username and password.com.zaxxer.hikari.HikariDataSourceAllow access to the underlying HikariDataSource object.Get the original name of the datasource - this is NOT unique and should not be used for identification.Get the current pool statistics for the datasource.Get a unique datasource name which includes a hash of the properties Following the pattern:bx_{name}_{properties_hash}protected ConnectioninthashCode()Get's the hashcode according to the datasource's unique nameisAuthenticationMatch(String username, String password) Check the provided username and password against the current datasource credentials.Are we an on the fly datasource?shutdown()Shut down the datasource, including the connection pool and all connections.
-
Constructor Details
-
DataSource
Configure and initialize a new DataSourceRecord object from a struct of properties.- Parameters:
config- A struct of properties to configure the datasource. Hikari itself will require either `dataSourceClassName` or `jdbcUrl` to be defined, and potentially `username` and `password` as well.
-
-
Method Details
-
fromStruct
Helper builder to build out a new DataSource object from a struct of properties and a name.- Parameters:
name- The string name of the datasource.properties- A struct of properties to configure the datasource. Will likely be defined viaApplication.bxor a web admin.- Returns:
- a DataSource object configured from the provided struct.
-
fromStruct
Helper builder to build out a new DataSource object from a struct of properties and a name.- Parameters:
name- The name of the datasource.properties- A struct of properties to configure the datasource. Will likely be defined viaApplication.bxor a web admin.- Returns:
- a DataSource object configured from the provided struct.
-
getOriginalName
Get the original name of the datasource - this is NOT unique and should not be used for identification.- Returns:
- The original name of the datasource.
-
getUniqueName
Get a unique datasource name which includes a hash of the properties Following the pattern:bx_{name}_{properties_hash} -
isOnTheFly
Are we an on the fly datasource? -
hashCode
public int hashCode()Get's the hashcode according to the datasource's unique name -
equals
Verifies equality between two Datasource objects -
compareTo
Compares two DataSource objects- Specified by:
compareToin interfaceComparable<DataSource>- Parameters:
otherConfig- The other DataSource object to compare- Returns:
- A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
getConfiguration
Get the configuration object for this datasource.- Returns:
- The configuration object for this datasource.
-
getConnection
Get a connection to the configured datasource.- Returns:
- A JDBC connection to the configured datasource.
- Throws:
BoxRuntimeException- if connection could not be established.
-
getUnpooledConnection
-
getConnection
Get a connection to the configured datasource with the provided username and password.- Returns:
- A JDBC connection to the configured datasource.
- Throws:
BoxRuntimeException- if connection could not be established.
-
shutdown
Shut down the datasource, including the connection pool and all connections.- Returns:
- This DataSource object, which is now shut down and useless for any further operations.
-
execute
Execute a query on the default connection.- Parameters:
query- The SQL query to execute.- Returns:
- An array of Structs, each representing a row of the result set (if any). If there are no results (say, for an UPDATE statement), an empty array is returned.
-
execute
Execute a query on the default connection, within the specific context.- Parameters:
query- The SQL query to execute.context- The boxlang context for localization. Useful for localization; i.e., queries with date or time values.
-
execute
Execute a query on the connection, using the provided connection.Note the connection passed in is NOT closed automatically. It is up to the caller to close the connection when they are done with it. If you want an automanaged, i.e. autoclosed connection, use the
execute(String)method.- Parameters:
query- The SQL query to execute.conn- The connection to execute the query on. A connection is required - useexecute(String)if you don't wish to provide one.- Returns:
- An array of Structs, each representing a row of the result set (if any). If there are no results (say, for an UPDATE statement), an empty array is returned.
-
execute
public ExecutedQuery execute(String query, List<QueryParameter> parameters, Connection conn, IBoxContext context) Execute a query with a List of parameters on a given connection. -
execute
Execute a query with a List of parameters on the default connection. -
execute
Execute a query with an array of parameters on a given connection. -
execute
Execute a query with an array of parameters on the default connection. -
execute
public ExecutedQuery execute(String query, IStruct parameters, Connection conn, IBoxContext context) Execute a query with a struct of parameters on a given connection. -
execute
Execute a query with a struct of parameters on the default connection. -
isAuthenticationMatch
Check the provided username and password against the current datasource credentials.For obvious reasons, the string comparison is case-sensitive.
- Parameters:
username- Username to check against the established datasourcepassword- Password to check against the established datasource- Returns:
- True if the username and password match.
-
getHikariDataSource
public com.zaxxer.hikari.HikariDataSource getHikariDataSource()Allow access to the underlying HikariDataSource object.- Returns:
- The HikariDataSource object.
-
getPoolStats
Get the current pool statistics for the datasource.- Returns:
- A struct containing the current pool statistics, including active connections, idle connections, and total connections.
-