Record Class QueryTemplateWithParameters
java.lang.Object
java.lang.Record
de.calamanari.adl.sql.QueryTemplateWithParameters
- Record Components:
qmTemplate- template with positional parametersorderedParameters- parameters in order of appearance in the templateqmPositions- parameter question mark positions in order of appearance in the template
- All Implemented Interfaces:
Serializable
public record QueryTemplateWithParameters(String qmTemplate, List<QueryParameter> orderedParameters, List<Integer> qmPositions)
extends Record
implements Serializable
An
QueryTemplateWithParameters combines an SQL-script with positional parameters (question marks) with the parameters to be set once the
related PreparedStatement has been created.- Author:
- Karl Eilebrecht
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionQueryTemplateWithParameters(String qmTemplate, List<QueryParameter> orderedParameters, List<Integer> qmPositions) In general you should useof(String, List)instead of directly calling this constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(PreparedStatement stmt) Applies the parameters to thePreparedStatementcreated from theqmTemplate().voidThis method returns the SQL-string with the positional parameters replaced with string arguments.Convenience method to create aPreparedStatementand apply all parametersfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static QueryTemplateWithParametersof(String queryTemplate, List<QueryParameter> parameters) Takes a template with named parameters (${id}references) and a list of parameters to produce a query template with positional parameters to be executed later as aPreparedStatementafter callingapply(PreparedStatement)to set the parameters safely.Returns the value of theorderedParametersrecord component.Returns the value of theqmPositionsrecord component.Returns the value of theqmTemplaterecord component.This method is fail-safe and falls back to the regular toString()-method if anything goes wrong.
In this case the returned String starts with an error indicator.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
QueryTemplateWithParameters
public QueryTemplateWithParameters(String qmTemplate, List<QueryParameter> orderedParameters, List<Integer> qmPositions) In general you should useof(String, List)instead of directly calling this constructor- Parameters:
qmTemplate- template with positional parametersorderedParameters- parameters in order of appearance in the templateqmPositions- parameter question mark positions in order of appearance in the template
-
-
Method Details
-
of
Takes a template with named parameters (${id}references) and a list of parameters to produce a query template with positional parameters to be executed later as aPreparedStatementafter callingapply(PreparedStatement)to set the parameters safely.- Parameters:
queryTemplate- template with named parameters (name=id)parameters- available parameters, can be a superset of the parameters required by the template- Returns:
- template with related parameters
-
createPreparedStatement
Convenience method to create aPreparedStatementand apply all parameters- Parameters:
conn-- Returns:
PreparedStatementwith all parameters from this template applied, ready to be executed- Throws:
SQLException
-
apply
Applies the parameters to thePreparedStatementcreated from theqmTemplate().- Parameters:
stmt-- Throws:
SQLException
-
applyUnsafe
This method returns the SQL-string with the positional parameters replaced with string arguments. It relies on the formatters configured for theAdlSqlTypes.Warning! This method is in general NOT SUITABLE FOR EXECUTING SQLs because (even with escaping!) we cannot harden this against SQL-injection. It is impossible to predict the behavior of all possible driver/db combinations. Only
PreparedStatements can guarantee sufficient safety.- Throws:
de.calamanari.adl.cnv.tps.AdlFormattingException- in case of errors- See Also:
-
toDebugString
This method is fail-safe and falls back to the regular toString()-method if anything goes wrong.
In this case the returned String starts with an error indicator.- Returns:
- returns a (usually functional) version of the statement, for debugging/logging purposes
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
qmTemplate
Returns the value of theqmTemplaterecord component.- Returns:
- the value of the
qmTemplaterecord component
-
orderedParameters
Returns the value of theorderedParametersrecord component.- Returns:
- the value of the
orderedParametersrecord component
-
qmPositions
Returns the value of theqmPositionsrecord component.- Returns:
- the value of the
qmPositionsrecord component
-