Package com.helixframework.db.ps
Interface PreparedStatementSupport
public interface PreparedStatementSupport
Interface providing utility methods for setting parameters in a
PreparedStatement
with nullable values. This interface is intended to simplify handling of null values when
setting parameters in SQL statements.-
Method Summary
Modifier and TypeMethodDescriptiondefault voidsetBooleanOrDefault(PreparedStatement ps, int parameterIndex, Boolean value, Boolean defaultValue) Sets the specified parameter to a boolean value or a default value in aPreparedStatement.default voidsetBooleanOrNull(PreparedStatement ps, int parameterIndex, Boolean value) Sets the specified parameter to a boolean value or to NULL in aPreparedStatement.default voidsetDoubleOrDefault(PreparedStatement ps, int parameterIndex, Double value, Double defaultValue) Sets the specified parameter to a double value or a default value in aPreparedStatement.default voidsetDoubleOrNull(PreparedStatement ps, int parameterIndex, Double value) Sets the specified parameter to a double value or to NULL in aPreparedStatement.default voidsetIntOrDefault(PreparedStatement ps, int parameterIndex, Integer value, Integer defaultValue) Sets the specified parameter to an integer value or a default value in aPreparedStatement.default voidsetIntOrNull(PreparedStatement ps, int parameterIndex, Integer value) Sets the specified parameter to an integer value or to NULL in aPreparedStatement.default voidsetJsonbOrNull(PreparedStatement ps, int parameterIndex, Object value, Class<?> clazz, com.fasterxml.jackson.databind.ObjectMapper mapper) Sets the given value as a JSONB string in the specified parameter index of thePreparedStatement.default voidsetLongOrDefault(PreparedStatement ps, int parameterIndex, Long value, Long defaultValue) Sets the specified parameter to a long value or a default value in aPreparedStatement.default voidsetLongOrNull(PreparedStatement ps, int parameterIndex, Long value) Sets the specified parameter to a long value or to NULL in aPreparedStatement.default voidsetObjectOrNull(PreparedStatement ps, int parameterIndex, Object value, int type) Sets the specified parameter in aPreparedStatementto the given object value or to NULL.default voidsetZonedDateTimeOrDefault(PreparedStatement ps, int parameterIndex, ZonedDateTime value, ZonedDateTime defaultValue) Sets the specified parameter to the givenZonedDateTimevalue or a default value in aPreparedStatement.default voidsetZonedDateTimeOrNull(PreparedStatement ps, int parameterIndex, ZonedDateTime value) Sets the specified parameter in aPreparedStatementto the givenZonedDateTimevalue or to NULL.
-
Method Details
-
setIntOrNull
default void setIntOrNull(PreparedStatement ps, int parameterIndex, Integer value) throws SQLException Sets the specified parameter to an integer value or to NULL in aPreparedStatement. If the provided value is non-null, it sets the parameter to the integer value; otherwise, it sets the parameter to NULL with the SQL typeTypes.INTEGER.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theIntegervalue to set, or null to set the parameter to NULL- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setIntOrDefault
default void setIntOrDefault(PreparedStatement ps, int parameterIndex, Integer value, Integer defaultValue) throws SQLException Sets the specified parameter to an integer value or a default value in aPreparedStatement. If the provided value is non-null, it sets the parameter to the integer value; otherwise, it sets the parameter to the provided default value.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theIntegervalue to set, or null to use the default valuedefaultValue- theIntegervalue to use if the provided value is null- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setLongOrNull
default void setLongOrNull(PreparedStatement ps, int parameterIndex, Long value) throws SQLException Sets the specified parameter to a long value or to NULL in aPreparedStatement. If the provided value is non-null, it sets the parameter to the long value; otherwise, it sets the parameter to NULL with the SQL typeTypes.BIGINT.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theLongvalue to set, or null to set the parameter to NULL- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setLongOrDefault
default void setLongOrDefault(PreparedStatement ps, int parameterIndex, Long value, Long defaultValue) throws SQLException Sets the specified parameter to a long value or a default value in aPreparedStatement. If the provided value is non-null, it sets the parameter to the long value; otherwise, it sets the parameter to the provided default value.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theLongvalue to set, or null to use the default valuedefaultValue- theLongvalue to use if the provided value is null- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setDoubleOrNull
default void setDoubleOrNull(PreparedStatement ps, int parameterIndex, Double value) throws SQLException Sets the specified parameter to a double value or to NULL in aPreparedStatement. If the provided value is non-null, it sets the parameter to the double value; otherwise, it sets the parameter to NULL with the SQL typeTypes.DOUBLE.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theDoublevalue to set, or null to set the parameter to NULL- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setDoubleOrDefault
default void setDoubleOrDefault(PreparedStatement ps, int parameterIndex, Double value, Double defaultValue) throws SQLException Sets the specified parameter to a double value or a default value in aPreparedStatement. If the provided value is non-null, it sets the parameter to the double value; otherwise, it sets the parameter to the provided default value.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theDoublevalue to set, or null to use the default valuedefaultValue- theDoublevalue to use if the provided value is null- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setBooleanOrNull
default void setBooleanOrNull(PreparedStatement ps, int parameterIndex, Boolean value) throws SQLException Sets the specified parameter to a boolean value or to NULL in aPreparedStatement. If the provided value is non-null, it sets the parameter to the boolean value; otherwise, it sets the parameter to NULL with the SQL typeTypes.BOOLEAN.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theBooleanvalue to set, or null to set the parameter to NULL- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setBooleanOrDefault
default void setBooleanOrDefault(PreparedStatement ps, int parameterIndex, Boolean value, Boolean defaultValue) throws SQLException Sets the specified parameter to a boolean value or a default value in aPreparedStatement. If the provided value is non-null, it sets the parameter to the boolean value; otherwise, it sets the parameter to the provided default value.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theBooleanvalue to set, or null to use the default valuedefaultValue- theBooleanvalue to use if the provided value is null- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setObjectOrNull
default void setObjectOrNull(PreparedStatement ps, int parameterIndex, Object value, int type) throws SQLException Sets the specified parameter in aPreparedStatementto the given object value or to NULL. If the provided value is non-null, it sets the parameter to the object value with the specified SQL type. Otherwise, it sets the parameter to NULL with the given SQL type.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- the object value to set, or null to set the parameter to NULLtype- the SQL type to use when setting the parameter- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setZonedDateTimeOrNull
default void setZonedDateTimeOrNull(PreparedStatement ps, int parameterIndex, ZonedDateTime value) throws SQLException Sets the specified parameter in aPreparedStatementto the givenZonedDateTimevalue or to NULL. If the providedZonedDateTimevalue is non-null, it is converted to anOffsetDateTimeand the parameter is set using the SQL typeTypes.TIMESTAMP_WITH_TIMEZONE. Otherwise, the parameter is set to NULL with the SQL typeTypes.TIMESTAMP_WITH_TIMEZONE.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theZonedDateTimevalue to set, or null to set the parameter to NULL- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setZonedDateTimeOrDefault
default void setZonedDateTimeOrDefault(PreparedStatement ps, int parameterIndex, ZonedDateTime value, ZonedDateTime defaultValue) throws SQLException Sets the specified parameter to the givenZonedDateTimevalue or a default value in aPreparedStatement. If the providedZonedDateTimevalue is non-null, it is converted to anOffsetDateTimeand the parameter is set using the SQL typeTypes.TIMESTAMP_WITH_TIMEZONE. Otherwise, the parameter is set to the provideddefaultValue, which is also converted to anOffsetDateTimeand set using the same SQL type.- Parameters:
ps- thePreparedStatementwhere the parameter will be setparameterIndex- the index of the parameter to set, starting from 1value- theZonedDateTimevalue to set, or null to use the default valuedefaultValue- theZonedDateTimevalue to use if the provided value is null- Throws:
SQLException- if a database access error occurs or the parameter index is invalid
-
setJsonbOrNull
default void setJsonbOrNull(PreparedStatement ps, int parameterIndex, Object value, Class<?> clazz, com.fasterxml.jackson.databind.ObjectMapper mapper) throws SQLException Sets the given value as a JSONB string in the specified parameter index of thePreparedStatement. If the value is null, sets the parameter to SQL null with the typeTypes.OTHER.- Parameters:
ps- thePreparedStatementto set the parameter onparameterIndex- the index of the parameter to setvalue- the object value to serialize and set as a JSONB string, or null to set SQL nullclazz- theClasstype of the value being serialized (not directly used in this method)mapper- theObjectMapperinstance used to serialize the object to JSONB- Throws:
SQLException- if a database access error occurs or object serialization to JSON fails
-