Package org.reldb.wrapd.sqldb
Class Database
java.lang.Object
org.reldb.wrapd.sqldb.Database
public class Database
extends java.lang.Object
Database access layer.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Database.ConnectionUser<T>
Used to define lambda expressions that make use of a Connection and return a value of type T.static interface
Database.PreparedStatementUser<T>
Used to define lambda expressions that make use of a PreparedStatement and return a value of type T.static interface
Database.ResultSetReceiver<T>
Used to define lambda expressions that receive a ResultSet for processing.static class
Database.SQLEvent
An instance of an SQL query, for monitoring queries processed by a Database.class
Database.Transaction<T>
Encapsulates a transaction.static interface
Database.TransactionRunner<T>
Used to define lambda expressions for transactional processing.static interface
Database.XactGo<T>
Used to define lambda expressions for more ergonomic transaction processing. -
Field Summary
Fields Modifier and Type Field Description org.reldb.toolbox.events.EventHandler<Database.SQLEvent>
sqlEvents
Subscribe to monitor queries processed by a Database. -
Constructor Summary
Constructors Constructor Description Database(javax.sql.DataSource dataSource, java.lang.String dbTablenamePrefix, Customisations customisations)
Construct a Database. -
Method Summary
Modifier and Type Method Description static java.lang.Object[]
allArguments(java.lang.Object... parms)
Given multiple argument arrays, combine them into one unified argument list for passing to a parametrised query's "Object ...Response<TupleTypeGenerator.GenerateResult>
createTupleFromQuery(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String query, java.lang.Object... parms)
Use a SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.TupleTypeGenerator.GenerateResult
createTupleFromQuery(java.sql.Connection connection, java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String query, java.lang.Object... parms)
Use a parametric SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.Response<TupleTypeGenerator.GenerateResult>
createTupleFromQueryAll(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String query)
Use a SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.TupleTypeGenerator.GenerateResult
createTupleFromQueryAll(java.sql.Connection connection, java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String query)
Use a SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.Response<TupleTypeGenerator.GenerateResult>
createTupleFromQueryAllForUpdate(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String tableName, java.lang.String query)
Use a SELECT query to generate a corresponding UpdatableTuple-derived class to represent future evaluations of the same query or similar queries.TupleTypeGenerator.GenerateResult
createTupleFromQueryAllForUpdate(java.sql.Connection connection, java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String tableName, java.lang.String query)
Use a SELECT query to generate a corresponding UpdatableTuple-derived class to represent future evaluations of the same query or similar queries.Response<TupleTypeGenerator.GenerateResult>
createTupleFromQueryForUpdate(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String tableName, java.lang.String query, java.lang.Object... parms)
Use a SELECT query to generate a corresponding UpdatableTuple-derived class to represent future evaluations of the same query or similar queries.TupleTypeGenerator.GenerateResult
createTupleFromQueryForUpdate(java.sql.Connection connection, java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String tableName, java.lang.String query, java.lang.Object[] parms)
Use a parametric SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.protected void
distributeSQLEvent(java.lang.String location, java.lang.String query)
Distribute a SQLEvent to interested listeners.static java.lang.String
emptyToNull(java.lang.String str)
If the String argument is null or an empty string, return null.java.lang.String[]
getKeyColumnNamesFor(java.lang.String tableName)
Get primary key for a given table.java.lang.String[]
getKeyColumnNamesFor(java.sql.Connection connection, java.lang.String tableName)
Get primary key for a given table.java.lang.Class<?>
getTypeOfFirstColumn(java.lang.String query, java.lang.Object[] args)
Obtain the type of the first column of a query.java.lang.Class<?>
getTypeOfFirstColumn(java.sql.Connection connection, java.lang.String query, java.lang.Object[] args)
Obtain the type of the first column of a query.static Database.ResultSetReceiver<TupleTypeGenerator.GenerateResult>
newResultSetGeneratesTupleClass(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, Customisations customisations)
Obtain a lambda to generate a new Tuple-derived class from a ResultSet.static Database.ResultSetReceiver<TupleTypeGenerator.GenerateResult>
newResultSetGeneratesTupleClassForUpdate(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, Customisations customisations, java.lang.String tableName)
Obtain a lambda to generate a new UpdatableTuple-derived class from a ResultSet.<T extends Tuple>
Database.ResultSetReceiver<java.util.stream.Stream<T>>newResultSetToStream(java.lang.Class<T> tupleClass)
Obtain a lambda that converts a ResultSet to a Stream<T> where T extends Tuple.<T extends UpdatableTuple>
Database.ResultSetReceiver<java.util.stream.Stream<T>>newResultSetToStreamForUpdate(java.lang.Class<T> tupleClass)
Obtain a lambda that converts a ResultSet to a Stream<T> where T extends UpdatableTuple, and each Tuple is configured for a future update.static java.lang.String
nullTo(java.lang.String str, java.lang.String replacement)
If the String argument is null or an empty string, return a specified replacement string.static java.lang.String
nullToEmptyString(java.lang.String str)
If the String argument is null or an empty string, return an empty string.<T> Response<T>
processConnection(Database.ConnectionUser<T> connectionUser)
Use a connection.<T> Response<T>
processPreparedStatement(Database.PreparedStatementUser<T> preparedStatementUser, java.sql.Connection connection, java.lang.String query, java.lang.Object... parms)
Use a prepared statement.<T> Response<T>
processTransaction(Database.TransactionRunner<T> transactionRunner)
Execute some code in a transaction.<T extends Tuple>
java.util.stream.Stream<T>query(java.lang.String query, java.lang.Class<T> tupleClass, java.lang.Object... parms)
Obtain a stream of Tuple derivatives from a query evaluation.<T> T
query(java.lang.String query, Database.ResultSetReceiver<T> receiver, java.lang.Object... parms)
Issue a parametric SELECT query with '?' substitutions, process it, and return the result<T extends Tuple>
java.util.stream.Stream<T>query(java.sql.Connection connection, java.lang.String query, java.lang.Class<T> tupleClass, java.lang.Object... parms)
Obtain a stream of Tuple derivatives from a query evaluation.<T> T
query(java.sql.Connection connection, java.lang.String query, Database.ResultSetReceiver<T> receiver, java.lang.Object... parms)
Issue a parametric SELECT query with '?' substitutions, process it, and return the result<T extends Tuple>
java.util.stream.Stream<T>query(java.sql.Connection connection, Query<T> query)
Obtain a stream of Tuple derivatives from a query evaluation.<T extends Tuple>
java.util.stream.Stream<T>query(Query<T> query)
Obtain a stream of Tuple derivatives from a query evaluation.<T extends Tuple>
java.util.stream.Stream<T>queryAll(java.lang.String query, java.lang.Class<T> tupleClass)
Obtain a stream of Tuple derivatives from a query evaluation.<T> T
queryAll(java.lang.String query, Database.ResultSetReceiver<T> receiver)
Issue a SELECT query, process it, and return the result<T extends Tuple>
java.util.stream.Stream<T>queryAll(java.sql.Connection connection, java.lang.String query, java.lang.Class<T> tupleClass)
Obtain a stream of Tuple derivatives from a query evaluation.<T> T
queryAll(java.sql.Connection connection, java.lang.String query, Database.ResultSetReceiver<T> receiver)
Issue a SELECT query, process it, and return the result<T extends Tuple>
java.util.stream.Stream<T>queryAll(java.sql.Connection connection, Query<T> query)
Obtain a stream of Tuple derivatives from a query evaluation.<T extends Tuple>
java.util.stream.Stream<T>queryAll(Query<T> query)
Obtain a stream of Tuple derivatives from a query evaluation.<T extends UpdatableTuple>
java.util.stream.Stream<T>queryAllForUpdate(java.lang.String query, java.lang.Class<T> tupleClass)
Obtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.<T extends UpdatableTuple>
java.util.stream.Stream<T>queryAllForUpdate(java.sql.Connection connection, java.lang.String query, java.lang.Class<T> tupleClass)
Obtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.<T extends UpdatableTuple>
java.util.stream.Stream<T>queryAllForUpdate(java.sql.Connection connection, Query<T> query)
Obtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.<T extends UpdatableTuple>
java.util.stream.Stream<T>queryAllForUpdate(Query<T> query)
Obtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.<T extends UpdatableTuple>
java.util.stream.Stream<T>queryForUpdate(java.lang.String query, java.lang.Class<T> tupleClass, java.lang.Object... parms)
Obtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.<T extends UpdatableTuple>
java.util.stream.Stream<T>queryForUpdate(java.sql.Connection connection, java.lang.String query, java.lang.Class<T> tupleClass, java.lang.Object... parms)
Obtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.<T extends UpdatableTuple>
java.util.stream.Stream<T>queryForUpdate(java.sql.Connection connection, Query<T> query)
Obtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.<T extends UpdatableTuple>
java.util.stream.Stream<T>queryForUpdate(Query<T> query)
Obtain a stream of Tuple derivatives from a query evaluation for possible update.java.lang.String
replaceTableNames(java.lang.String query)
Wherever $$ appears in the argument, replace it with dbTableNamePrefix.java.lang.String
toString()
<T> Response<T>
transact(Database.XactGo<T> transactionRunner)
Run one or more database operations in a transaction wrapped with Xact for syntactic convenience.boolean
update(java.lang.String query, java.lang.Object... parms)
Issue a parametric update query with '?' substitutions.boolean
update(java.sql.Connection connection, java.lang.String query, java.lang.Object... parms)
Issue a parametric update query with '?' substitutions.boolean
update(java.sql.Connection connection, Update update)
Issue an update query.boolean
update(Update update)
Issue an update query.boolean
updateAll(java.lang.String sqlStatement)
Issue an update query.boolean
updateAll(java.sql.Connection connection, java.lang.String sqlStatement)
Issue an update query.boolean
updateAll(java.sql.Connection connection, Update update)
Issue an update query.boolean
updateAll(Update update)
Issue an update query.<T> T
useConnection(Database.ConnectionUser<T> connectionUser)
Use a connection.<T> T
usePreparedStatement(Database.PreparedStatementUser<T> preparedStatementUser, java.sql.Connection connection, java.lang.String query, java.lang.Object... parms)
Use a prepared statement.<T> Response<T>
useTransaction(Database.TransactionRunner<T> transactionRunner)
Execute some code in a transaction.java.util.Optional<?>
valueOf(java.lang.String query, java.lang.Object... parms)
Issue a parametric SELECT query with '?' substitutions and obtain a value for the first row in the first column.java.util.Optional<?>
valueOf(java.sql.Connection connection, java.lang.String query, java.lang.Object... parms)
Issue a parametric SELECT query with '?' substitutions and obtain a value for the first row in the first column.java.util.Optional<?>
valueOf(java.sql.Connection connection, Query<? extends Tuple> query)
Issue a parametric SELECT query with '?' substitutions and obtain a value for the first row in the first column.java.util.Optional<?>
valueOf(Query<? extends Tuple> query)
Issue a parametric SELECT query with '?' substitutions and obtain a value for the first row in the first column.java.util.Optional<?>
valueOfAll(java.lang.String query)
Issue a SELECT query and obtain a value for the first row in the first column.java.util.Optional<?>
valueOfAll(java.sql.Connection connection, java.lang.String query)
Issue a SELECT query and obtain a value for the first row in the first column.java.util.Optional<?>
valueOfAll(java.sql.Connection connection, Query<? extends Tuple> query)
Issue a SELECT query and obtain a value for the first row in the first column.java.util.Optional<?>
valueOfAll(Query<? extends Tuple> query)
Issue a SELECT query and obtain a value for the first row in the first column.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
sqlEvents
Subscribe to monitor queries processed by a Database.
-
-
Constructor Details
-
Database
public Database(javax.sql.DataSource dataSource, java.lang.String dbTablenamePrefix, Customisations customisations)Construct a Database.- Parameters:
dataSource
- Data sourcedbTablenamePrefix
- Table name prefixcustomisations
- DBMS-specific customisations
-
-
Method Details
-
distributeSQLEvent
protected void distributeSQLEvent(java.lang.String location, java.lang.String query)Distribute a SQLEvent to interested listeners.- Parameters:
location
- Where the query was generated or processed.query
- The SQL text of the query.
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
replaceTableNames
public java.lang.String replaceTableNames(java.lang.String query)Wherever $$ appears in the argument, replace it with dbTableNamePrefix.- Parameters:
query
- The source text.- Returns:
- The source text with every $$ replaced with the contents of dbTablenamePrefix.
-
processConnection
public <T> Response<T> processConnection(Database.ConnectionUser<T> connectionUser) throws java.sql.SQLExceptionUse a connection.- Type Parameters:
T
- Type of return value from use of connection.- Parameters:
connectionUser
- Instance of ConnectionUser, usually as a lambda expression.- Returns:
- A Response<T> containing either a T (indicating success) or a SQLException.
- Throws:
java.sql.SQLException
- Error obtaining connection.
-
useConnection
Use a connection.- Type Parameters:
T
- Type of return value from user of connection.- Parameters:
connectionUser
- Instance of ConnectionUser, usually as a lambda expression.- Returns:
- A value of type T as a result of using a Connection.
- Throws:
java.sql.SQLException
- Error.
-
updateAll
public boolean updateAll(java.sql.Connection connection, java.lang.String sqlStatement) throws java.sql.SQLExceptionIssue an update query.- Parameters:
connection
- Database connection.sqlStatement
- SQL query.- Returns:
- True if a ResultSet is returned, false otherwise.
- Throws:
java.sql.SQLException
- Error.
-
updateAll
public boolean updateAll(java.lang.String sqlStatement) throws java.sql.SQLExceptionIssue an update query.- Parameters:
sqlStatement
- SQL update query.- Returns:
- True if a ResultSet is returned, false otherwise.
- Throws:
java.sql.SQLException
- Error.
-
getTypeOfFirstColumn
public java.lang.Class<?> getTypeOfFirstColumn(java.sql.Connection connection, java.lang.String query, java.lang.Object[] args) throws java.sql.SQLExceptionObtain the type of the first column of a query. Used for ValueOf.- Parameters:
connection
- Database connection.query
- SELECT query that returns a single column, or multiple columns but only the first is used to obtain the value.args
- Optional parameter arguments.- Returns:
- Type of first column of result.
- Throws:
java.sql.SQLException
- Error.java.sql.SQLException
- Error.
-
getTypeOfFirstColumn
public java.lang.Class<?> getTypeOfFirstColumn(java.lang.String query, java.lang.Object[] args) throws java.sql.SQLExceptionObtain the type of the first column of a query. Used for ValueOf.- Parameters:
query
- SELECT query that returns a single column, or multiple columns but only the first is used to obtain the value.args
- Optional parameter arguments.- Returns:
- Type of first column of result.
- Throws:
java.sql.SQLException
- Error.java.sql.SQLException
- Error.
-
valueOfAll
public java.util.Optional<?> valueOfAll(java.sql.Connection connection, java.lang.String query) throws java.sql.SQLExceptionIssue a SELECT query and obtain a value for the first row in the first column. Intended to obtain a single value.- Parameters:
connection
- Database connection.query
- SELECT query that returns a single column, or multiple columns but only the first is used to obtain the value.- Returns:
- Value of first column of first row in result.
- Throws:
java.sql.SQLException
- Error.
-
valueOfAll
public java.util.Optional<?> valueOfAll(java.lang.String query) throws java.sql.SQLExceptionIssue a SELECT query and obtain a value for the first row in the first column. Intended to obtain a single value.- Parameters:
query
- SELECT query that returns a single column, or multiple columns but only the first is used to obtain the value.- Returns:
- Value of first column of first row in result.
- Throws:
java.sql.SQLException
- Error.
-
valueOfAll
public java.util.Optional<?> valueOfAll(java.sql.Connection connection, Query<? extends Tuple> query) throws java.sql.SQLExceptionIssue a SELECT query and obtain a value for the first row in the first column. Intended to obtain a single value.- Parameters:
connection
- Database connection.query
- Query that returns a single column, or multiple columns but only the first is used to obtain the value.- Returns:
- Value of first column of first row in result.
- Throws:
java.sql.SQLException
- Error.
-
valueOfAll
Issue a SELECT query and obtain a value for the first row in the first column. Intended to obtain a single value.- Parameters:
query
- Query that returns a single column, or multiple columns but only the first is used to obtain the value.- Returns:
- Value of first column of first row in result.
- Throws:
java.sql.SQLException
- Error.
-
processPreparedStatement
public <T> Response<T> processPreparedStatement(Database.PreparedStatementUser<T> preparedStatementUser, java.sql.Connection connection, java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionUse a prepared statement.- Type Parameters:
T
- Type of return value from user of connection.- Parameters:
preparedStatementUser
- Instance of PreparedStatementUser, usually as a lambda expression.connection
- Database connection.query
- SQL query, with optional parametric indicators (usually ?)parms
- Object[] of parameter arguments.- Returns:
- A value of type T as a result of using a PreparedStatement.
- Throws:
java.sql.SQLException
- Error.
-
usePreparedStatement
public <T> T usePreparedStatement(Database.PreparedStatementUser<T> preparedStatementUser, java.sql.Connection connection, java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionUse a prepared statement.- Type Parameters:
T
- Type of return value from user of connection.- Parameters:
preparedStatementUser
- Instance of PreparedStatementUser, usually as a lambda expression.connection
- Database connection.query
- SQL query, with optional parametric indicators (usually ?)parms
- Object[] of parameter arguments.- Returns:
- A value of type T as a result of using a PreparedStatement.
- Throws:
java.sql.SQLException
- Error.
-
update
public boolean update(java.sql.Connection connection, java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionIssue a parametric update query with '?' substitutions.- Parameters:
connection
- Database connection.query
- SQL update query text.parms
- Parameter arguments.- Returns:
- True if a ResultSet is returned, false otherwise.
- Throws:
java.sql.SQLException
- Error.
-
update
public boolean update(java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionIssue a parametric update query with '?' substitutions.- Parameters:
query
- SQL update query text.parms
- Parameter arguments.- Returns:
- True if a ResultSet is returned, false otherwise.
- Throws:
java.sql.SQLException
- Error.
-
valueOf
public java.util.Optional<?> valueOf(java.sql.Connection connection, java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionIssue a parametric SELECT query with '?' substitutions and obtain a value for the first row in the first column. Intended to obtain a single value.- Parameters:
connection
- Database connection.query
- SELECT query that returns a single column, or multiple columns but only the first is used to obtain the value.parms
- Parameter arguments.- Returns:
- Value of first column of first row in result.
- Throws:
java.sql.SQLException
- Error.
-
valueOf
public java.util.Optional<?> valueOf(java.sql.Connection connection, Query<? extends Tuple> query) throws java.sql.SQLExceptionIssue a parametric SELECT query with '?' substitutions and obtain a value for the first row in the first column. Intended to obtain a single value.- Parameters:
connection
- Database connection.query
- Query that returns a single column, or multiple columns but only the first is used to obtain the value.- Returns:
- Value of first column of first row in result.
- Throws:
java.sql.SQLException
- Error.
-
valueOf
public java.util.Optional<?> valueOf(java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionIssue a parametric SELECT query with '?' substitutions and obtain a value for the first row in the first column. Intended to obtain a single value.- Parameters:
query
- SELECT query that returns a single column, or multiple columns but only the first is used to obtain the value.parms
- Parameter arguments.- Returns:
- Value of first column of first row in result.
- Throws:
java.sql.SQLException
- Error.
-
valueOf
Issue a parametric SELECT query with '?' substitutions and obtain a value for the first row in the first column. Intended to obtain a single value.- Parameters:
query
- Query that returns a single column, or multiple columns but only the first is used to obtain the value.- Returns:
- Value of first column of first row in result.
- Throws:
java.sql.SQLException
- Error.
-
newResultSetGeneratesTupleClass
public static Database.ResultSetReceiver<TupleTypeGenerator.GenerateResult> newResultSetGeneratesTupleClass(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, Customisations customisations)Obtain a lambda to generate a new Tuple-derived class from a ResultSet.- Parameters:
codeDirectory
- Directory into which generated class (both source and .class) will be placed.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Name for new tuple class.customisations
- Customisations for specific DBMS types.- Returns:
- - lambda which will generate the class given a ResultSet.
-
newResultSetGeneratesTupleClassForUpdate
public static Database.ResultSetReceiver<TupleTypeGenerator.GenerateResult> newResultSetGeneratesTupleClassForUpdate(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, Customisations customisations, java.lang.String tableName)Obtain a lambda to generate a new UpdatableTuple-derived class from a ResultSet.- Parameters:
codeDirectory
- Directory into which generated class (both source and .class) will be placed.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Name for new tuple class.customisations
- Customisations for specific DBMS types.tableName
- Name of table this Tuple maps to. Null if not mapped to a table.- Returns:
- - lambda which will generate the class given a ResultSet.
-
createTupleFromQueryAll
public TupleTypeGenerator.GenerateResult createTupleFromQueryAll(java.sql.Connection connection, java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String query) throws java.sql.SQLExceptionUse a SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.- Parameters:
connection
- Connection to database, usually obtained via a Transaction.codeDirectory
- Directory in which compiled Tuple-derived source and .class will be generatedpackageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Desired name of Tuple-derived class.query
- Query to be evaluated.- Returns:
- Result of code generation.
- Throws:
java.sql.SQLException
- Error.
-
createTupleFromQueryAllForUpdate
public TupleTypeGenerator.GenerateResult createTupleFromQueryAllForUpdate(java.sql.Connection connection, java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String tableName, java.lang.String query) throws java.sql.SQLExceptionUse a SELECT query to generate a corresponding UpdatableTuple-derived class to represent future evaluations of the same query or similar queries.- Parameters:
connection
- Connection to database, usually obtained via a Transaction.codeDirectory
- Directory in which compiled Tuple-derived source and .class will be generatedpackageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Desired name of Tuple-derived class.tableName
- Name of table this Tuple maps to. Null if not mapped to a table.query
- Query to be evaluated.- Returns:
- Result of code generation.
- Throws:
java.sql.SQLException
- Error.
-
createTupleFromQueryAll
public Response<TupleTypeGenerator.GenerateResult> createTupleFromQueryAll(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String query) throws java.sql.SQLExceptionUse a SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.- Parameters:
codeDirectory
- Directory in which compiled Tuple-derived source and .class will be generated.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Desired name of Tuple-derived class.query
- Query to be evaluated.- Returns:
- Result of code generation.
- Throws:
java.sql.SQLException
- Error.
-
createTupleFromQueryAllForUpdate
public Response<TupleTypeGenerator.GenerateResult> createTupleFromQueryAllForUpdate(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String tableName, java.lang.String query) throws java.sql.SQLExceptionUse a SELECT query to generate a corresponding UpdatableTuple-derived class to represent future evaluations of the same query or similar queries.- Parameters:
codeDirectory
- Directory in which compiled UpdatableTuple-derived source and .class will be generated.packageSpec
- The package, in dotted notation, to which the UpdatableTuple belongs.tupleClassName
- Desired name of UpdatableTuple-derived class.tableName
- Name of table this UpdatableTuple maps to. Null if not mapped to a table.query
- Query to be evaluated.- Returns:
- Result of code generation.
- Throws:
java.sql.SQLException
- Error.
-
createTupleFromQuery
public TupleTypeGenerator.GenerateResult createTupleFromQuery(java.sql.Connection connection, java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionUse a parametric SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.- Parameters:
connection
- Connection to database, usually obtained via a Transaction.codeDirectory
- Directory in which compiled Tuple-derived source and .class will be generated.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Desired name of Tuple-derived class.query
- Query to be evaluated.parms
- Parameter arguments which positionally match to '?' in the query.- Returns:
- Result of code generation.
- Throws:
java.sql.SQLException
- Error.
-
createTupleFromQueryForUpdate
public TupleTypeGenerator.GenerateResult createTupleFromQueryForUpdate(java.sql.Connection connection, java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String tableName, java.lang.String query, java.lang.Object[] parms) throws java.sql.SQLExceptionUse a parametric SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.- Parameters:
connection
- Connection to database, usually obtained via a Transaction.codeDirectory
- Directory in which compiled Tuple-derived source and .class will be generated.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Desired name of Tuple-derived class.tableName
- Name of table this UpdatableTuple maps to. Null if not mapped to a table.query
- Query to be evaluated.parms
- Parameter arguments which positionally match to '?' in the query.- Returns:
- Result of code generation.
- Throws:
java.sql.SQLException
- Error.
-
createTupleFromQuery
public Response<TupleTypeGenerator.GenerateResult> createTupleFromQuery(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionUse a SELECT query to generate a corresponding Tuple-derived class to represent future evaluations of the same query or similar queries.- Parameters:
codeDirectory
- Directory in which compiled Tuple-derived source and .class will be generated.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Desired name of Tuple-derived class.query
- Query to be evaluated.parms
- Parameter arguments which positionally match to '?' in the query- Returns:
- Result of code generation.
- Throws:
java.sql.SQLException
- Error.
-
createTupleFromQueryForUpdate
public Response<TupleTypeGenerator.GenerateResult> createTupleFromQueryForUpdate(java.lang.String codeDirectory, java.lang.String packageSpec, java.lang.String tupleClassName, java.lang.String tableName, java.lang.String query, java.lang.Object... parms) throws java.sql.SQLExceptionUse a SELECT query to generate a corresponding UpdatableTuple-derived class to represent future evaluations of the same query or similar queries.- Parameters:
codeDirectory
- Directory in which compiled UpdatableTuple-derived source and .class will be generated.packageSpec
- The package, in dotted notation, to which the Tuple belongs.tupleClassName
- Desired name of UpdatableTuple-derived class.tableName
- Name of table this UpdatableTuple maps to. Null if not mapped to a table.query
- Query to be evaluated.parms
- Parameter arguments which positionally match to '?' in the query- Returns:
- Result of code generation.
- Throws:
java.sql.SQLException
- Error.
-
newResultSetToStream
public <T extends Tuple> Database.ResultSetReceiver<java.util.stream.Stream<T>> newResultSetToStream(java.lang.Class<T> tupleClass)Obtain a lambda that converts a ResultSet to a Stream<T> where T extends Tuple.- Type Parameters:
T
- T extends Tuple.- Parameters:
tupleClass
- The stream will be of instances of tupleClass.- Returns:
- A ResultSetReceiver<Stream<T>>.
-
newResultSetToStreamForUpdate
public <T extends UpdatableTuple> Database.ResultSetReceiver<java.util.stream.Stream<T>> newResultSetToStreamForUpdate(java.lang.Class<T> tupleClass)Obtain a lambda that converts a ResultSet to a Stream<T> where T extends UpdatableTuple, and each Tuple is configured for a future update.- Type Parameters:
T
- T extends Tuple.- Parameters:
tupleClass
- The stream will be of instances of tupleClass.- Returns:
- A ResultSetReceiver<Stream<T>> where the stream of tuples will have backup() invoked for each instance.
-
queryAll
public <T> T queryAll(java.sql.Connection connection, java.lang.String query, Database.ResultSetReceiver<T> receiver) throws java.sql.SQLExceptionIssue a SELECT query, process it, and return the result- Type Parameters:
T
- Return type- Parameters:
connection
- Database connection.query
- SQL query.receiver
- ResultSet receiver lambda.- Returns:
- Return value.
- Throws:
java.sql.SQLException
- Error.
-
queryAll
public <T> T queryAll(java.lang.String query, Database.ResultSetReceiver<T> receiver) throws java.sql.SQLExceptionIssue a SELECT query, process it, and return the result- Type Parameters:
T
- Return type.- Parameters:
query
- SQL query.receiver
- ResultSet receiver lambda.- Returns:
- Return value.
- Throws:
java.sql.SQLException
- Error.
-
queryAll
public <T extends Tuple> java.util.stream.Stream<T> queryAll(java.sql.Connection connection, java.lang.String query, java.lang.Class<T> tupleClass) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation.- Type Parameters:
T
- T extends Tuple.- Parameters:
connection
- Connection to database, typically obtained via a Transaction.query
- Query string.tupleClass
- Tuple derivative that represents rows in the ResultSet returned from evaluating the query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryAll
public <T extends Tuple> java.util.stream.Stream<T> queryAll(java.sql.Connection connection, Query<T> query) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation.- Type Parameters:
T
- T extends Tuple.- Parameters:
connection
- Database connection, typically obtained via a Transaction.query
- A Query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryAll
public <T extends Tuple> java.util.stream.Stream<T> queryAll(java.lang.String query, java.lang.Class<T> tupleClass) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation.- Type Parameters:
T
- T extends Tuple.- Parameters:
query
- SQL query string.tupleClass
- Tuple derivative that represents rows in the ResultSet returned from evaluating the query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryAll
public <T extends Tuple> java.util.stream.Stream<T> queryAll(Query<T> query) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation.- Type Parameters:
T
- T extends Tuple.- Parameters:
query
- A Query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryAllForUpdate
public <T extends UpdatableTuple> java.util.stream.Stream<T> queryAllForUpdate(java.sql.Connection connection, java.lang.String query, java.lang.Class<T> tupleClass) throws java.sql.SQLExceptionObtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.- Type Parameters:
T
- T extends UpdatableTuple.- Parameters:
connection
- Database connection, typically obtained via a Transactionquery
- Query string.tupleClass
- Tuple derivative that represents rows in the ResultSet returned from evaluating the query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryAllForUpdate
public <T extends UpdatableTuple> java.util.stream.Stream<T> queryAllForUpdate(java.sql.Connection connection, Query<T> query) throws java.sql.SQLExceptionObtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.- Type Parameters:
T
- T extends UpdatableTuple.- Parameters:
connection
- Connection to database, typically obtained via a Transactionquery
- A Query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryAllForUpdate
public <T extends UpdatableTuple> java.util.stream.Stream<T> queryAllForUpdate(java.lang.String query, java.lang.Class<T> tupleClass) throws java.sql.SQLExceptionObtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.- Type Parameters:
T
- T extends UpdatableTuple.- Parameters:
query
- Query string.tupleClass
- UpdatableTuple derivative that represents rows in the ResultSet returned from evaluating the query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryAllForUpdate
public <T extends UpdatableTuple> java.util.stream.Stream<T> queryAllForUpdate(Query<T> query) throws java.sql.SQLExceptionObtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.- Type Parameters:
T
- T extends UpdatableTuple.- Parameters:
query
- A Query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryForUpdate
public <T extends UpdatableTuple> java.util.stream.Stream<T> queryForUpdate(java.sql.Connection connection, java.lang.String query, java.lang.Class<T> tupleClass, java.lang.Object... parms) throws java.sql.SQLExceptionObtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.- Type Parameters:
T
- T extends UpdatableTuple.- Parameters:
connection
- Database connection, typically obtained via a Transaction.query
- Query string.tupleClass
- UpdatableTuple derivative that represents rows in the ResultSet returned from evaluating the query.parms
- Parameter argument list.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryForUpdate
public <T extends UpdatableTuple> java.util.stream.Stream<T> queryForUpdate(java.sql.Connection connection, Query<T> query) throws java.sql.SQLExceptionObtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.- Type Parameters:
T
- T extends UpdatableTuple.- Parameters:
connection
- Database connection, typically obtained via a Transaction.query
- A Query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryForUpdate
public <T extends UpdatableTuple> java.util.stream.Stream<T> queryForUpdate(java.lang.String query, java.lang.Class<T> tupleClass, java.lang.Object... parms) throws java.sql.SQLExceptionObtain a stream of UpdatableTuple derivatives from a query evaluation for possible update.- Type Parameters:
T
- T extends UpdatableTuple.- Parameters:
query
- Query string.tupleClass
- UpdatableTuple derivative that represents rows in the ResultSet returned from evaluating the query.parms
- Parameter argument list.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
queryForUpdate
public <T extends UpdatableTuple> java.util.stream.Stream<T> queryForUpdate(Query<T> query) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation for possible update.- Type Parameters:
T
- T extends UpdatableTuple.- Parameters:
query
- A Query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
query
public <T> T query(java.sql.Connection connection, java.lang.String query, Database.ResultSetReceiver<T> receiver, java.lang.Object... parms) throws java.sql.SQLExceptionIssue a parametric SELECT query with '?' substitutions, process it, and return the result- Type Parameters:
T
- Return type.- Parameters:
connection
- Database connection.query
- SQL SELECT query text.receiver
- ResultSet receiver lambda.parms
- Parameter arguments.- Returns:
- Return value.
- Throws:
java.sql.SQLException
- Error.
-
query
public <T> T query(java.lang.String query, Database.ResultSetReceiver<T> receiver, java.lang.Object... parms) throws java.sql.SQLExceptionIssue a parametric SELECT query with '?' substitutions, process it, and return the result- Type Parameters:
T
- Return type.- Parameters:
query
- SELECT query text.receiver
- ResultSet receiver lambda.parms
- Parameter arguments.- Returns:
- Return value.
- Throws:
java.sql.SQLException
- Error.
-
query
public <T extends Tuple> java.util.stream.Stream<T> query(java.sql.Connection connection, java.lang.String query, java.lang.Class<T> tupleClass, java.lang.Object... parms) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation.- Type Parameters:
T
- T extends Tuple.- Parameters:
connection
- Database connection, typically obtained via a Transaction.query
- Query string.tupleClass
- Tuple derivative that represents rows in the ResultSet returned from evaluating the query.parms
- Parameter argument list.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
query
public <T extends Tuple> java.util.stream.Stream<T> query(java.sql.Connection connection, Query<T> query) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation.- Type Parameters:
T
- T extends Tuple.- Parameters:
connection
- Database connection, typically obtained via a Transactionquery
- A Query.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
query
public <T extends Tuple> java.util.stream.Stream<T> query(java.lang.String query, java.lang.Class<T> tupleClass, java.lang.Object... parms) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation.- Type Parameters:
T
- T extends Tuple.- Parameters:
query
- Query string.tupleClass
- Tuple derivative that represents rows in the ResultSet returned from evaluating the query.parms
- Parameter argument list.- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
query
public <T extends Tuple> java.util.stream.Stream<T> query(Query<T> query) throws java.sql.SQLExceptionObtain a stream of Tuple derivatives from a query evaluation.- Type Parameters:
T
- T extends Tuple.- Parameters:
query
- A Query- Returns:
- Stream<T> Result stream.
- Throws:
java.sql.SQLException
- Error.
-
updateAll
Issue an update query.- Parameters:
update
- Update query specification.- Returns:
- True if a ResultSet is returned, false otherwise.
- Throws:
java.sql.SQLException
- Error.
-
updateAll
public boolean updateAll(java.sql.Connection connection, Update update) throws java.sql.SQLExceptionIssue an update query.- Parameters:
connection
- Database connection.update
- Update query specification.- Returns:
- True if a ResultSet is returned, false otherwise.
- Throws:
java.sql.SQLException
- Error.
-
update
Issue an update query.- Parameters:
update
- Parametric update query specification.- Returns:
- True if a ResultSet is returned, false otherwise.
- Throws:
java.sql.SQLException
- Error.
-
update
Issue an update query.- Parameters:
connection
- Database connection.update
- Parametric update query specification.- Returns:
- True if a ResultSet is returned, false otherwise.
- Throws:
java.sql.SQLException
- Error.
-
allArguments
public static java.lang.Object[] allArguments(java.lang.Object... parms)Given multiple argument arrays, combine them into one unified argument list for passing to a parametrised query's "Object ... parms", above.- Parameters:
parms
- Parameter arguments.- Returns:
- Object array of parameter arguments.
-
processTransaction
public <T> Response<T> processTransaction(Database.TransactionRunner<T> transactionRunner) throws java.sql.SQLExceptionExecute some code in a transaction.- Type Parameters:
T
- Response type parameter- Parameters:
transactionRunner
- The lambda specifying code to be run.- Returns:
- The transaction execution result.
- Throws:
java.sql.SQLException
- Error.
-
useTransaction
public <T> Response<T> useTransaction(Database.TransactionRunner<T> transactionRunner) throws java.sql.SQLExceptionExecute some code in a transaction.- Type Parameters:
T
- Response type parameter- Parameters:
transactionRunner
- The lambda specifying code to be run.- Returns:
- Result.
- Throws:
java.sql.SQLException
- Error.
-
transact
Run one or more database operations in a transaction wrapped with Xact for syntactic convenience.- Type Parameters:
T
- Response type parameter- Parameters:
transactionRunner
- The lambda defining one or more database operations- Returns:
- Result.
- Throws:
java.sql.SQLException
- Error.
-
getKeyColumnNamesFor
public java.lang.String[] getKeyColumnNamesFor(java.sql.Connection connection, java.lang.String tableName) throws java.sql.SQLExceptionGet primary key for a given table.- Parameters:
tableName
- Table name.connection
- Connection to database; typically obtained via a Transaction.- Returns:
- Array of column names comprising the primary key.
- Throws:
java.sql.SQLException
- Error.
-
getKeyColumnNamesFor
public java.lang.String[] getKeyColumnNamesFor(java.lang.String tableName) throws java.sql.SQLExceptionGet primary key for a given table.- Parameters:
tableName
- Table name.- Returns:
- Array of column names comprising the primary key.
- Throws:
java.sql.SQLException
- Error.
-
emptyToNull
public static java.lang.String emptyToNull(java.lang.String str)If the String argument is null or an empty string, return null.- Parameters:
str
- Input string or null.- Returns:
- String or null
-
nullTo
public static java.lang.String nullTo(java.lang.String str, java.lang.String replacement)If the String argument is null or an empty string, return a specified replacement string.- Parameters:
str
- Input string or null.replacement
- A replacement string.- Returns:
- A string.
-
nullToEmptyString
public static java.lang.String nullToEmptyString(java.lang.String str)If the String argument is null or an empty string, return an empty string.- Parameters:
str
- Input string or null.- Returns:
- A string.
-