public class DefaultCodeGen extends Object implements CodeGen, MergeHandler
Modifier and Type | Field and Description |
---|---|
static String |
FIELD_DEBEZIUM_CDC_OP |
CREATED_STATUS, EXECUTED_STATUS, PREPARED_STATUS
Constructor and Description |
---|
DefaultCodeGen()
Instantiates a new default code generator.
|
Modifier and Type | Method and Description |
---|---|
void |
addScriptToCleanOnException(String script)
Adds the script to clean on exception.
|
void |
addScriptToCleanUpAfter(String script)
Adds the script to clean up after.
|
void |
addScriptToCleanUpBefore(String script)
Adds the script to clean up before.
|
void |
addScriptToCreate(Destination destination,
String script)
Adds the script to create.
|
void |
addScriptToInit(Destination destination,
String script,
boolean cleanUpOnException,
String type,
boolean ignoreError)
Adds the script to init.
|
void |
assembleCode(EtlConfig config,
Scenario scenario,
Driver driver,
int loadIndex,
boolean silent)
Assembles prepared code.
|
void |
cleanUp(EtlConfig config,
Scenario scenario,
Driver driver,
Connection conn)
Clean up after last block of code is executed.
|
void |
cleanUpOnException(EtlConfig config,
Scenario scenario,
Driver driver,
Connection cleanUpConn)
Clean up database objects on exception.
|
void |
copy(CodeGen codeGen)
Copy parameters from other code generator.
|
void |
execute(EtlConfig config,
Scenario scenario,
Driver driver,
boolean silent,
Connection conn,
Connection cleanUpConn,
Destination destination)
Executes code.
|
List<String> |
getScriptsToCleanOnException()
Gets the list of scripts which should be executed to clean up database
object on exception.
|
int |
getStatus()
Gets the status of the code generator.
|
EtlUnit |
getUnit()
Gets the current unit.
|
void |
onMerge(OnException onException,
Connection conn,
String sql,
String keyField,
long row)
Executed when default etl "insert into" action is failed and etl scenario
is configured to try update instead.
|
void |
prepare(EtlConfig config,
Scenario scenario,
Destination destination,
boolean silent,
boolean onlyInit,
boolean isStreaming)
Prepares code for the destination using given config and scenario.
|
void |
reorderColumns(Destination destination,
DataSetConnector writer,
DataSetConnectorParams writerParams)
Reorder columns.
|
void |
reset()
Resets the status.
|
void |
runRemainingBatch(EtlConfig config,
Scenario scenario,
Connection conn,
Destination destination)
Run remaining batch statements.
|
String |
setCurrentCode(Driver driver,
String name,
int index)
Sets the current code.
|
void |
setTransactionMonitor(TransactionMonitor transactionMonitor)
Sets the transaction monitor.
|
void |
setUnit(EtlUnit unit)
Sets the current unit.
|
public static final String FIELD_DEBEZIUM_CDC_OP
public DefaultCodeGen()
public void setTransactionMonitor(TransactionMonitor transactionMonitor)
CodeGen
setTransactionMonitor
in interface CodeGen
transactionMonitor
- the new transaction monitorpublic void addScriptToCleanOnException(String script)
CodeGen
addScriptToCleanOnException
in interface CodeGen
script
- the scriptpublic void addScriptToCleanUpAfter(String script)
addScriptToCleanUpAfter
in interface CodeGen
script
- the scriptpublic void addScriptToCleanUpBefore(String script)
CodeGen
addScriptToCleanUpBefore
in interface CodeGen
script
- the scriptpublic void addScriptToCreate(Destination destination, String script)
CodeGen
addScriptToCreate
in interface CodeGen
destination
- the destinationscript
- the scriptpublic void addScriptToInit(Destination destination, String script, boolean cleanUpOnException, String type, boolean ignoreError)
CodeGen
addScriptToInit
in interface CodeGen
destination
- the destinationscript
- the scriptcleanUpOnException
- the "clean up on exception" flagtype
- the typeignoreError
- if true ignore error when executing scriptpublic void assembleCode(EtlConfig config, Scenario scenario, Driver driver, int loadIndex, boolean silent) throws Exception
CodeGen
prepare(...) is called
for each destination. The resulting code saved internally. assembleCode(...) assembles final
code by concatenating code for all destinations with added declarations, etc so it can be be executed in the
designated database. Also it splits code on chunks if necessary. For example Oracle limits size of the PL\SQL block
to approximately 3000 lines.
@param config
The config
@param scenario
The scenario
@param driver
The driver
@param loadIndex
If equals to 0
this chunk will be executed first.
assembleCode
in interface CodeGen
silent
- If true
logging is disabled for everything but
exceptionsException
- in case of any errorpublic void cleanUp(EtlConfig config, Scenario scenario, Driver driver, Connection conn) throws Exception
CodeGen
public void cleanUpOnException(EtlConfig config, Scenario scenario, Driver driver, Connection cleanUpConn) throws Exception
CodeGen
cleanUpOnException
in interface CodeGen
config
- the configscenario
- the scenariodriver
- the drivercleanUpConn
- the clean up connectionException
- the exceptionpublic void copy(CodeGen codeGen)
CodeGen
public void execute(EtlConfig config, Scenario scenario, Driver driver, boolean silent, Connection conn, Connection cleanUpConn, Destination destination) throws Exception
CodeGen
execute
in interface CodeGen
config
- The etl configscenario
- The scenariodriver
- The driversilent
- If true
logging is disabled for everything but
exceptionsconn
- The JDBC connectioncleanUpConn
- the clean up connectiondestination
- the destinationException
- in case of any errorpublic List<String> getScriptsToCleanOnException()
CodeGen
getScriptsToCleanOnException
in interface CodeGen
public int getStatus()
CodeGen
public void onMerge(OnException onException, Connection conn, String sql, String keyField, long row) throws Exception
MergeHandler
onMerge
in interface MergeHandler
onException
- the OnException objectconn
- the connectionsql
- the sql (usually insert statement)keyField
- the key fieldrow
- the rowException
- in case of any errorpublic void reorderColumns(Destination destination, DataSetConnector writer, DataSetConnectorParams writerParams)
CodeGen
reorderColumns
in interface CodeGen
destination
- the destinationpublic void prepare(EtlConfig config, Scenario scenario, Destination destination, boolean silent, boolean onlyInit, boolean isStreaming) throws Exception
CodeGen
prepare
in interface CodeGen
config
- The etl configscenario
- The scenariodestination
- The destinationsilent
- If true
logging is disabled for everything but
exceptionsonlyInit
- the only initisStreaming
- true if is streamingException
- in case of any errorpublic void reset()
CodeGen
public void runRemainingBatch(EtlConfig config, Scenario scenario, Connection conn, Destination destination) throws Exception
CodeGen
runRemainingBatch
in interface CodeGen
config
- the ETL configscenario
- the scenarioconn
- the connectiondestination
- the destinationException
- in case of any errorpublic String setCurrentCode(Driver driver, String name, int index)
driver
- the drivername
- the nameindex
- the indexCopyright © 2010-2020 Toolsverse. All Rights Reserved.