Class JdbcOutputFormat<In,JdbcIn,JdbcExec extends JdbcBatchStatementExecutor<JdbcIn>>
- java.lang.Object
-
- org.apache.flink.api.common.io.RichOutputFormat<In>
-
- org.apache.flink.connector.jdbc.internal.JdbcOutputFormat<In,JdbcIn,JdbcExec>
-
- All Implemented Interfaces:
Flushable,Serializable,org.apache.flink.api.common.io.OutputFormat<In>,org.apache.flink.api.java.typeutils.InputTypeConfigurable
- Direct Known Subclasses:
JdbcRowOutputFormat
@Internal public class JdbcOutputFormat<In,JdbcIn,JdbcExec extends JdbcBatchStatementExecutor<JdbcIn>> extends org.apache.flink.api.common.io.RichOutputFormat<In> implements Flushable, org.apache.flink.api.java.typeutils.InputTypeConfigurable
A JDBC outputFormat that supports batching records before writing records to database.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJdbcOutputFormat.BuilderBuilder for aJdbcOutputFormat.static interfaceJdbcOutputFormat.RecordExtractor<F,T>An interface to extract a value from given argument.static interfaceJdbcOutputFormat.StatementExecutorFactory<T extends JdbcBatchStatementExecutor<?>>A factory for creatingJdbcBatchStatementExecutorinstance.
-
Field Summary
Fields Modifier and Type Field Description protected JdbcConnectionProviderconnectionProvider
-
Constructor Summary
Constructors Constructor Description JdbcOutputFormat(JdbcConnectionProvider connectionProvider, JdbcExecutionOptions executionOptions, JdbcOutputFormat.StatementExecutorFactory<JdbcExec> statementExecutorFactory, JdbcOutputFormat.RecordExtractor<In,JdbcIn> recordExtractor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddToBatch(In original, JdbcIn extracted)protected voidattemptFlush()static JdbcOutputFormat.Builderbuilder()voidclose()Executes prepared statement and closes all resources of this instance.voidconfigure(org.apache.flink.configuration.Configuration parameters)voidflush()ConnectiongetConnection()JdbcExecutionOptionsgetExecutionOptions()Returns configuredJdbcExecutionOptions.voidopen(int taskNumber, int numTasks)Connects to the target database and initializes the prepared statement.voidsetInputType(org.apache.flink.api.common.typeinfo.TypeInformation<?> type, org.apache.flink.api.common.ExecutionConfig executionConfig)voidupdateExecutor(boolean reconnect)voidwriteRecord(In record)-
Methods inherited from class org.apache.flink.api.common.io.RichOutputFormat
getRuntimeContext, setRuntimeContext
-
-
-
-
Field Detail
-
connectionProvider
protected final JdbcConnectionProvider connectionProvider
-
-
Constructor Detail
-
JdbcOutputFormat
public JdbcOutputFormat(@Nonnull JdbcConnectionProvider connectionProvider, @Nonnull JdbcExecutionOptions executionOptions, @Nonnull JdbcOutputFormat.StatementExecutorFactory<JdbcExec> statementExecutorFactory, @Nonnull JdbcOutputFormat.RecordExtractor<In,JdbcIn> recordExtractor)
-
-
Method Detail
-
setInputType
public void setInputType(org.apache.flink.api.common.typeinfo.TypeInformation<?> type, org.apache.flink.api.common.ExecutionConfig executionConfig)- Specified by:
setInputTypein interfaceorg.apache.flink.api.java.typeutils.InputTypeConfigurable
-
configure
public void configure(org.apache.flink.configuration.Configuration parameters)
- Specified by:
configurein interfaceorg.apache.flink.api.common.io.OutputFormat<In>
-
open
public void open(int taskNumber, int numTasks) throws IOExceptionConnects to the target database and initializes the prepared statement.- Specified by:
openin interfaceorg.apache.flink.api.common.io.OutputFormat<In>- Parameters:
taskNumber- The number of the parallel instance.- Throws:
IOException
-
writeRecord
public final void writeRecord(In record) throws IOException
- Specified by:
writeRecordin interfaceorg.apache.flink.api.common.io.OutputFormat<In>- Throws:
IOException
-
addToBatch
protected void addToBatch(In original, JdbcIn extracted) throws SQLException
- Throws:
SQLException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
attemptFlush
protected void attemptFlush() throws SQLException- Throws:
SQLException
-
close
public void close()
Executes prepared statement and closes all resources of this instance.- Specified by:
closein interfaceorg.apache.flink.api.common.io.OutputFormat<In>
-
builder
public static JdbcOutputFormat.Builder builder()
-
updateExecutor
public void updateExecutor(boolean reconnect) throws SQLException, ClassNotFoundException- Throws:
SQLExceptionClassNotFoundException
-
getExecutionOptions
public JdbcExecutionOptions getExecutionOptions()
Returns configuredJdbcExecutionOptions.
-
getConnection
@VisibleForTesting public Connection getConnection()
-
-