Package org.apache.nifi.util.db
Class JdbcCommon
java.lang.Object
org.apache.nifi.util.db.JdbcCommon
JDBC / SQL common functions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfaceAn interface for callback methods which allows processing of a row during the convertToAvroStream() processing. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intprivate static final org.slf4j.Loggerstatic final Patternstatic final Stringstatic final intstatic final intstatic final Stringstatic final Patternstatic final Patternprivate static final DateTimeFormatterprivate static final DateTimeFormatter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddNullableField(org.apache.avro.SchemaBuilder.FieldAssembler<org.apache.avro.Schema> builder, String columnName, Function<org.apache.avro.SchemaBuilder.BaseTypeBuilder<org.apache.avro.SchemaBuilder.UnionAccumulator<org.apache.avro.SchemaBuilder.NullDefault<org.apache.avro.Schema>>>, org.apache.avro.SchemaBuilder.UnionAccumulator<org.apache.avro.SchemaBuilder.NullDefault<org.apache.avro.Schema>>> func) static longconvertToAvroStream(ResultSet rs, OutputStream outStream, boolean convertNames) static longconvertToAvroStream(ResultSet rs, OutputStream outStream, String recordName, boolean convertNames) static longconvertToAvroStream(ResultSet rs, OutputStream outStream, String recordName, JdbcCommon.ResultSetRowCallback callback, boolean convertNames) static longconvertToAvroStream(ResultSet rs, OutputStream outStream, String recordName, JdbcCommon.ResultSetRowCallback callback, int maxRows, boolean convertNames) static longconvertToAvroStream(ResultSet rs, OutputStream outStream, JdbcCommon.AvroConversionOptions options, JdbcCommon.ResultSetRowCallback callback) static voidcreateEmptyAvroStream(OutputStream outStream) static org.apache.avro.Schemastatic org.apache.avro.SchemacreateSchema(ResultSet rs, String recordName, boolean convertNames) static org.apache.avro.SchemacreateSchema(ResultSet rs, JdbcCommon.AvroConversionOptions options) Creates an Avro schema from a result set.static DateTimeFormattergetDateTimeFormatter(String pattern) static StringnormalizeNameForAvro(String inputName) static voidsetParameter(PreparedStatement stmt, int parameterIndex, String parameterValue, int jdbcType, String valueFormat) Determines how to map the given value to the appropriate JDBC data type and sets the parameter on the provided PreparedStatementprivate static voidsetParameterAtIndex(PreparedStatement stmt, Map<String, SensitiveValueWrapper> attributes, String flowFileAttributeKey) static voidsetParameters(PreparedStatement stmt, Map<String, String> attributes) Sets all of the appropriate parameters on the given PreparedStatement, based on the given FlowFile attributes.static voidsetSensitiveParameters(PreparedStatement stmt, Map<String, SensitiveValueWrapper> attributes) Sets all of the appropriate parameters on the given PreparedStatement, based on the given FlowFile attributes and masks sensitive values.
-
Field Details
-
MAX_DIGITS_IN_BIGINT
public static final int MAX_DIGITS_IN_BIGINT- See Also:
-
MAX_DIGITS_IN_INT
public static final int MAX_DIGITS_IN_INT- See Also:
-
DEFAULT_PRECISION_VALUE
public static final int DEFAULT_PRECISION_VALUE- See Also:
-
DEFAULT_SCALE_VALUE
public static final int DEFAULT_SCALE_VALUE- See Also:
-
LONG_PATTERN
-
SQL_TYPE_ATTRIBUTE_PATTERN
-
NUMBER_PATTERN
-
MIME_TYPE_AVRO_BINARY
- See Also:
-
MASKED_LOG_VALUE
- See Also:
-
logger
private static final org.slf4j.Logger logger -
TIME_FORMATTER
-
TIMESTAMP_FORMATTER
-
-
Constructor Details
-
JdbcCommon
public JdbcCommon()
-
-
Method Details
-
convertToAvroStream
public static long convertToAvroStream(ResultSet rs, OutputStream outStream, boolean convertNames) throws SQLException, IOException - Throws:
SQLExceptionIOException
-
convertToAvroStream
public static long convertToAvroStream(ResultSet rs, OutputStream outStream, String recordName, boolean convertNames) throws SQLException, IOException - Throws:
SQLExceptionIOException
-
convertToAvroStream
public static long convertToAvroStream(ResultSet rs, OutputStream outStream, String recordName, JdbcCommon.ResultSetRowCallback callback, boolean convertNames) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
convertToAvroStream
public static long convertToAvroStream(ResultSet rs, OutputStream outStream, String recordName, JdbcCommon.ResultSetRowCallback callback, int maxRows, boolean convertNames) throws SQLException, IOException - Throws:
SQLExceptionIOException
-
createEmptyAvroStream
- Throws:
IOException
-
convertToAvroStream
public static long convertToAvroStream(ResultSet rs, OutputStream outStream, JdbcCommon.AvroConversionOptions options, JdbcCommon.ResultSetRowCallback callback) throws SQLException, IOException - Throws:
SQLExceptionIOException
-
createSchema
- Throws:
SQLException
-
createSchema
public static org.apache.avro.Schema createSchema(ResultSet rs, String recordName, boolean convertNames) throws SQLException - Throws:
SQLException
-
addNullableField
private static void addNullableField(org.apache.avro.SchemaBuilder.FieldAssembler<org.apache.avro.Schema> builder, String columnName, Function<org.apache.avro.SchemaBuilder.BaseTypeBuilder<org.apache.avro.SchemaBuilder.UnionAccumulator<org.apache.avro.SchemaBuilder.NullDefault<org.apache.avro.Schema>>>, org.apache.avro.SchemaBuilder.UnionAccumulator<org.apache.avro.SchemaBuilder.NullDefault<org.apache.avro.Schema>>> func) -
createSchema
public static org.apache.avro.Schema createSchema(ResultSet rs, JdbcCommon.AvroConversionOptions options) throws SQLException Creates an Avro schema from a result set. If the table/record name is known a priori and provided, use that as a fallback for the record name if it cannot be retrieved from the result set, and finally fall back to a default value.- Parameters:
rs- The result set to convert to Avrooptions- Specify various options- Returns:
- A Schema object representing the result set converted to an Avro record
- Throws:
SQLException- if any error occurs during conversion
-
normalizeNameForAvro
-
setParameters
public static void setParameters(PreparedStatement stmt, Map<String, String> attributes) throws SQLExceptionSets all of the appropriate parameters on the given PreparedStatement, based on the given FlowFile attributes.- Parameters:
stmt- the statement to set the parameters onattributes- the attributes from which to derive parameter indices, values, and types- Throws:
SQLException- if the PreparedStatement throws a SQLException when the appropriate setter is called
-
setSensitiveParameters
public static void setSensitiveParameters(PreparedStatement stmt, Map<String, SensitiveValueWrapper> attributes) throws SQLExceptionSets all of the appropriate parameters on the given PreparedStatement, based on the given FlowFile attributes and masks sensitive values.- Parameters:
stmt- the statement to set the parameters onattributes- the attributes from which to derive parameter indices, values, and types- Throws:
SQLException- if the PreparedStatement throws a SQLException when the appropriate setter is called
-
setParameterAtIndex
private static void setParameterAtIndex(PreparedStatement stmt, Map<String, SensitiveValueWrapper> attributes, String flowFileAttributeKey) throws SQLException- Throws:
SQLException
-
setParameter
public static void setParameter(PreparedStatement stmt, int parameterIndex, String parameterValue, int jdbcType, String valueFormat) throws SQLException, UnsupportedEncodingException, ParseException Determines how to map the given value to the appropriate JDBC data type and sets the parameter on the provided PreparedStatement- Parameters:
stmt- the PreparedStatement to set the parameter onparameterIndex- the index of the SQL parameter to setparameterValue- the value of the SQL parameter to setjdbcType- the JDBC Type of the SQL parameter to set- Throws:
SQLException- if the PreparedStatement throws a SQLException when calling the appropriate setterUnsupportedEncodingExceptionParseException
-
getDateTimeFormatter
-