public class Query
extends java.lang.Object
implements java.lang.AutoCloseable
PreparedStatement that is wrapped with convenience methods and utilities.
This class simulates a parameter building pattern and all addParameter(*) methods must be called in the proper order of their expected binding sequence.
| Modifier and Type | Field and Description |
|---|---|
protected com.fasterxml.jackson.databind.ObjectMapper |
om
The
ObjectMapper instance to use for serializing/deserializing JSON. |
| Constructor and Description |
|---|
Query(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
java.sql.Connection connection,
java.lang.String query) |
| Modifier and Type | Method and Description |
|---|---|
Query |
addDateParameter(java.util.Date date)
Bind the given
Date to the PreparedStatement as a Date. |
Query |
addJsonParameter(java.lang.Object value)
Serializes value to a JSON string for persistence.
|
Query |
addParameter(boolean value) |
Query |
addParameter(java.sql.Date date) |
Query |
addParameter(double value) |
Query |
addParameter(int value) |
Query |
addParameter(long value) |
Query |
addParameter(java.lang.String value) |
Query |
addParameter(java.sql.Timestamp timestamp) |
protected Query |
addParameterInternal(com.netflix.conductor.dao.mysql.Query.InternalParameterSetter setter) |
Query |
addParameters(java.util.Collection values)
Add a collection of primitive values at once, in the order of the collection.
|
Query |
addParameters(java.lang.Object... values)
Add many primitive values at once.
|
Query |
addTimestampParameter(java.util.Date date)
Bind the given
Date to the PreparedStatement as a Timestamp. |
Query |
addTimestampParameter(long epochMillis)
Bind the given epoch millis to the PreparedStatement as a
Timestamp. |
void |
close() |
protected <V> V |
convert(java.lang.Object value,
java.lang.Class<V> returnType) |
protected java.lang.Boolean |
convertBoolean(java.lang.Object value) |
protected java.lang.Double |
convertDouble(java.lang.Object value) |
protected java.lang.Integer |
convertInt(java.lang.Object value) |
protected java.lang.Long |
convertLong(java.lang.Object value) |
protected java.lang.String |
convertString(java.lang.Object value) |
<V> java.util.List<V> |
executeAndFetch(java.lang.Class<V> returnType)
Execute the PreparedStatement and return a List of returnType values from the ResultSet.
|
<V> V |
executeAndFetch(ResultSetHandler<V> handler)
Execute the query and pass the
ResultSet to the given handler. |
<V> V |
executeAndFetchFirst(java.lang.Class<V> returnType)
Execute the statement and return only the first record from the result set.
|
long |
executeCount()
Convenience method for executing statements that return a single numeric value,
typically SELECT COUNT... style queries.
|
boolean |
executeDelete()
Convenience method for executing delete statements.
|
java.sql.ResultSet |
executeQuery()
Execute a query from the PreparedStatement and return the ResultSet.
|
java.lang.Object |
executeScalar() |
<V> V |
executeScalar(java.lang.Class<V> returnType)
Execute the PreparedStatement and return a single 'primitive' value from the ResultSet.
|
<V> java.util.List<V> |
executeScalarList(java.lang.Class<V> returnType)
Execute the PreparedStatement and return a List of 'primitive' values from the ResultSet.
|
int |
executeUpdate() |
boolean |
exists()
Utility method for evaluating the prepared statement as a query to check the existence of a record using a
numeric count or boolean return value.
|
protected <V> V |
fromJson(java.lang.String value,
java.lang.Class<V> returnType) |
static java.lang.String |
generateInBindings(int count)
Generate a String with count number of '?' placeholders for
PreparedStatement queries. |
protected int |
getAndIncrementIndex() |
protected int |
getIndex() |
protected <V> V |
getScalarFromResultSet(java.sql.ResultSet rs,
java.lang.Class<V> returnType) |
protected java.lang.String |
toJson(java.lang.Object value) |
protected final com.fasterxml.jackson.databind.ObjectMapper om
ObjectMapper instance to use for serializing/deserializing JSON.public Query(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
java.sql.Connection connection,
java.lang.String query)
public static java.lang.String generateInBindings(int count)
PreparedStatement queries.count - The number of '?' chars to generate.public Query addParameter(java.lang.String value)
public Query addParameter(int value)
public Query addParameter(boolean value)
public Query addParameter(long value)
public Query addParameter(double value)
public Query addParameter(java.sql.Date date)
public Query addParameter(java.sql.Timestamp timestamp)
public Query addJsonParameter(java.lang.Object value)
value - The value to serialize.public Query addDateParameter(java.util.Date date)
Date to the PreparedStatement as a Date.date - The java.util.Date to bind.public Query addTimestampParameter(java.util.Date date)
Date to the PreparedStatement as a Timestamp.date - The java.util.Date to bind.public Query addTimestampParameter(long epochMillis)
Timestamp.epochMillis - The epoch ms to create a new Timestamp from.public Query addParameters(java.util.Collection values)
values - The values to bind to the prepared statement.java.lang.IllegalArgumentException - If a non-primitive/unsupported type is encountered in the collection.addParameters(Object...)public Query addParameters(java.lang.Object... values)
values - The values to bind to the prepared statement.java.lang.IllegalArgumentException - If a non-primitive/unsupported type is encountered.public boolean exists()
The rawQuery provided must result in a Number or Boolean result.
com.netflix.conductor.core.execution.ApplicationException - If an unexpected return type cannot be evaluated to a Boolean result.public boolean executeDelete()
executeUpdate()public long executeCount()
public int executeUpdate()
PreparedStatement.executeUpdate()public java.sql.ResultSet executeQuery()
NOTE: The returned ResultSet must be closed/managed by the calling methods.
PreparedStatement.executeQuery()com.netflix.conductor.core.execution.ApplicationException - If any SQL errors occur.public java.lang.Object executeScalar()
public <V> V executeScalar(java.lang.Class<V> returnType)
V - The type parameter to return a List of.returnType - The type to return.com.netflix.conductor.core.execution.ApplicationException - returnType is unsupported, cannot be cast to from the result, or any SQL
errors occur.public <V> java.util.List<V> executeScalarList(java.lang.Class<V> returnType)
V - The type parameter to return a List of.returnType - The type Class return a List of.List<returnType>.com.netflix.conductor.core.execution.ApplicationException - returnType is unsupported, cannot be cast to from the result, or any SQL
errors occur.public <V> V executeAndFetchFirst(java.lang.Class<V> returnType)
V - The type parameter.returnType - The Class to return.public <V> java.util.List<V> executeAndFetch(java.lang.Class<V> returnType)
V - The type parameter to return a List of.returnType - The type Class return a List of.List<returnType>.com.netflix.conductor.core.execution.ApplicationException - returnType is unsupported, cannot be cast to from the result, or any SQL
errors occur.public <V> V executeAndFetch(ResultSetHandler<V> handler)
ResultSet to the given handler.V - The return type of this method.handler - The ResultSetHandler to execute.ResultSetHandler.apply(ResultSet).public void close()
close in interface java.lang.AutoCloseableprotected final Query addParameterInternal(com.netflix.conductor.dao.mysql.Query.InternalParameterSetter setter)
protected <V> V getScalarFromResultSet(java.sql.ResultSet rs,
java.lang.Class<V> returnType)
throws java.sql.SQLException
java.sql.SQLExceptionprotected <V> V convert(java.lang.Object value,
java.lang.Class<V> returnType)
protected java.lang.Integer convertInt(java.lang.Object value)
protected java.lang.Double convertDouble(java.lang.Object value)
protected java.lang.Long convertLong(java.lang.Object value)
protected java.lang.String convertString(java.lang.Object value)
protected java.lang.Boolean convertBoolean(java.lang.Object value)
protected java.lang.String toJson(java.lang.Object value)
protected <V> V fromJson(java.lang.String value,
java.lang.Class<V> returnType)
protected final int getIndex()
protected final int getAndIncrementIndex()