Package liquibase.change.core
Class LoadDataChange
java.lang.Object
liquibase.AbstractExtensibleObject
liquibase.plugin.AbstractPlugin
liquibase.change.AbstractChange
liquibase.change.AbstractTableChange
liquibase.change.core.LoadDataChange
- All Implemented Interfaces:
Cloneable
,Change
,ChangeWithColumns<LoadDataColumnConfig>
,ExtensibleObject
,Plugin
,LiquibaseSerializable
- Direct Known Subclasses:
LoadUpdateDataChange
public class LoadDataChange
extends AbstractTableChange
implements ChangeWithColumns<LoadDataColumnConfig>
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
protected static class
Nested classes/interfaces inherited from interface liquibase.serializer.LiquibaseSerializable
LiquibaseSerializable.SerializationType
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Pattern
static final String
CSV Lines starting with that sign(s) will be treated as comments by defaultFields inherited from class liquibase.change.AbstractTableChange
catalogName, schemaName, tableName
Fields inherited from class liquibase.change.AbstractChange
NODENAME_COLUMN
Fields inherited from interface liquibase.change.Change
EMPTY_CHANGE, SHOULD_EXECUTE
Fields inherited from interface liquibase.serializer.LiquibaseSerializable
GENERIC_CHANGELOG_EXTENSION_NAMESPACE, GENERIC_SNAPSHOT_EXTENSION_NAMESPACE, STANDARD_CHANGELOG_NAMESPACE, STANDARD_SNAPSHOT_NAMESPACE
Fields inherited from interface liquibase.plugin.Plugin
PRIORITY_DATABASE, PRIORITY_DEFAULT, PRIORITY_NOT_APPLICABLE, PRIORITY_SPECIALIZED
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addColumn
(LoadDataColumnConfig column) Add a column configuration to the Change.checkStatus
(Database database) Validate that this change executed successfully against the given database.protected LoadDataColumnConfig
columnConfigFromName
(String name, Integer idx) Get the column using the name, index or the headerprotected String
columnIdString
(int index, LoadDataColumnConfig columnConfig) Returns a uniquestring
for the column for better identification.protected ExecutablePreparedStatementBase
createPreparedStatement
(Database database, String catalogName, String schemaName, String tableName, List<LoadDataColumnConfig> columns, ChangeSet changeSet, ResourceAccessor resourceAccessor) protected InsertStatement
createStatement
(String catalogName, String schemaName, String tableName) protected InsertSetStatement
createStatementSet
(String catalogName, String schemaName, String tableName) Implementation generates checksum by serializing the change withStringChangeLogSerializer
boolean
generateRollbackStatementsVolatile
(Database database) Implementation delegates logic to theSqlGenerator.generateRollbackStatementsIsVolatile(Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.generateStatements
(Database database) Generates theSqlStatement
objects required to run the change for the given database.protected SqlStatement[]
generateStatementsFromRows
(Database database, List<LoadDataChange.LoadDataRowConfig> rows) boolean
generateStatementsVolatile
(Database database) Implementation delegates logic to theSqlGenerator.generateStatementsIsVolatile(Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.protected LoadDataColumnConfig
getColumnConfig
(int index, String header) Return all theColumnConfig
objects defined for thisChange
Confirmation message to be displayed after the change is executed.getFile()
protected String
protected static String
getValueToWrite
(Object value) Transform a value read from a CSV file into a string to be written into the database if the column type is not known.protected boolean
protected boolean
isNullValue
(String value, LoadDataColumnConfig column) void
setColumns
(List<LoadDataColumnConfig> columns) void
setCommentLineStartsWith
(String commentLineStartsWith) void
setSeparator
(String separator) boolean
Implementation delegates logic to theSqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.protected boolean
supportsBatchUpdates
(Database database) Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to theSqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.void
validateColumn
(LoadDataColumnConfig columnConfig, ValidationErrors validationErrors, String columnIDString) protected ValidationErrors
validateColumns
(ValidationErrors validationErrors) Validate all columns and collect errors in 'validationErrors'Implementation delegates logic to theSqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
.Methods inherited from class liquibase.change.AbstractTableChange
getCatalogName, getSchemaName
Methods inherited from class liquibase.change.AbstractChange
createAlternateParameterNames, createChangeMetaData, createChangeParameterMetadata, createDescriptionMetaData, createEmptyColumnConfig, createExampleValueMetaData, createInverses, createMustEqualExistingMetaData, createRequiredDatabasesMetaData, createSerializationTypeMetaData, createSinceMetaData, createSupportedDatabasesMetaData, customLoadLogic, equals, finishInitialization, generateRollbackStatements, getAffectedDatabaseObjects, getChangeSet, getDescription, getExcludedFieldFilters, getResourceAccessor, getSerializableFieldNamespace, getSerializableFields, getSerializableFieldType, getSerializableFieldValue, getSerializedObjectName, hashCode, isInvalidProperty, load, modify, serialize, serializeValue, setChangeSet, setResourceAccessor, shouldExecuteChange, supportsRollback, toString
Methods inherited from class liquibase.AbstractExtensibleObject
clone, describe, get, get, get, getAttributes, getFieldValue, getObjectMetaData, getValuePath, has, set
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface liquibase.ExtensibleObject
clone, describe, get, get, getAttributes, getObjectMetaData, getValuePath, has, set
-
Field Details
-
DEFAULT_COMMENT_PATTERN
CSV Lines starting with that sign(s) will be treated as comments by default- See Also:
-
BASE64_PATTERN
-
-
Constructor Details
-
LoadDataChange
public LoadDataChange()
-
-
Method Details
-
getValueToWrite
Transform a value read from a CSV file into a string to be written into the database if the column type is not known.- Parameters:
value
- the value to transform- Returns:
- if the value is empty or the string "NULL" (case-insensitive), return the empty string. If not, the value "toString()" representation (trimmed of spaces left and right) is returned.
-
hasPreparedStatementsImplemented
protected boolean hasPreparedStatementsImplemented() -
supports
Description copied from class:AbstractChange
Implementation delegates logic to theSqlGenerator.supports(liquibase.statement.SqlStatement, liquibase.database.Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
. If no or null SqlStatements are returned by generateStatements then this method returns true. IfAbstractChange.generateStatementsVolatile(liquibase.database.Database)
returns true, we cannot call generateStatements and so assume true.- Specified by:
supports
in interfaceChange
- Overrides:
supports
in classAbstractChange
-
generateRollbackStatementsVolatile
Description copied from class:AbstractChange
Implementation delegates logic to theSqlGenerator.generateRollbackStatementsIsVolatile(Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
If no or null SqlStatements are returned by generateRollbackStatements then this method returns false.- Specified by:
generateRollbackStatementsVolatile
in interfaceChange
- Overrides:
generateRollbackStatementsVolatile
in classAbstractChange
-
getTableName
- Overrides:
getTableName
in classAbstractTableChange
-
getFile
-
getUsePreparedStatements
-
getCommentLineStartsWith
-
setCommentLineStartsWith
-
isRelativeToChangelogFile
-
getEncoding
-
getSeparator
-
setSeparator
-
getQuotchar
-
addColumn
Description copied from interface:ChangeWithColumns
Add a column configuration to the Change.- Specified by:
addColumn
in interfaceChangeWithColumns<LoadDataColumnConfig>
-
getColumns
Description copied from interface:ChangeWithColumns
Return all theColumnConfig
objects defined for thisChange
- Specified by:
getColumns
in interfaceChangeWithColumns<LoadDataColumnConfig>
-
setColumns
- Specified by:
setColumns
in interfaceChangeWithColumns<LoadDataColumnConfig>
-
columnIdString
Returns a uniquestring
for the column for better identification. The returnedstring
includes the index of the column and, if available, its name.- Parameters:
index
- the index of the columncolumnConfig
- the column configuration- Returns:
- a string in the format " / column[index] (name:'columnName')" or " / column[index]" if the column name is not available.
-
validateColumns
Validate all columns and collect errors in 'validationErrors'- Parameters:
validationErrors
- ValidationErrors to collect errors- Returns:
- validationErrors
-
generateStatements
Description copied from interface:Change
Generates theSqlStatement
objects required to run the change for the given database. NOTE: This method may be called multiple times throughout the changelog execution process and may be called in documentation generation and other integration points as well. If this method reads from the current database state or uses any other logic that will be affected by whether previous changeSets have ran or not, you must return true fromChange.generateStatementsVolatile(liquibase.database.Database)
.- Specified by:
generateStatements
in interfaceChange
-
supportsBatchUpdates
-
validate
Description copied from class:AbstractChange
Implementation checks the ChangeParameterMetaData for declared required fields and also delegates logic to theSqlGenerator.validate(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
. If no or null SqlStatements are returned by generateStatements then this method returns no errors. If there are no parameters than this method returns no errors- Specified by:
validate
in interfaceChange
- Overrides:
validate
in classAbstractChange
-
validateColumn
public void validateColumn(LoadDataColumnConfig columnConfig, ValidationErrors validationErrors, String columnIDString) -
columnConfigFromName
Get the column using the name, index or the header- Parameters:
name
- name or header of the column searchedidx
- the index of the column searched- Returns:
- The column having the name or header equal to "name" or the index equal to idx or a new LoadDataColumnConfig if not found
-
generateStatementsVolatile
Description copied from class:AbstractChange
Implementation delegates logic to theSqlGenerator.generateStatementsIsVolatile(Database)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
. If zero or null SqlStatements are returned by generateStatements then this method returns false.- Specified by:
generateStatementsVolatile
in interfaceChange
- Overrides:
generateStatementsVolatile
in classAbstractChange
-
getCSVReader
- Throws:
IOException
LiquibaseException
-
getRelativeTo
-
createPreparedStatement
protected ExecutablePreparedStatementBase createPreparedStatement(Database database, String catalogName, String schemaName, String tableName, List<LoadDataColumnConfig> columns, ChangeSet changeSet, ResourceAccessor resourceAccessor) -
createStatement
-
createStatementSet
protected InsertSetStatement createStatementSet(String catalogName, String schemaName, String tableName) -
getColumnConfig
-
checkStatus
Description copied from interface:Change
Validate that this change executed successfully against the given database. This will check that the update completed at a high level plus check details of the change. For example, a change to add a column will check that the column exists plus data type, default values, etc.- Specified by:
checkStatus
in interfaceChange
- Overrides:
checkStatus
in classAbstractChange
-
getConfirmationMessage
Description copied from interface:Change
Confirmation message to be displayed after the change is executed. Should include relevant configuration settings to make it as helpful as possible. This method may be called outside the changelog execution process, such as in documentation generation.- Specified by:
getConfirmationMessage
in interfaceChange
-
generateCheckSum
Description copied from class:AbstractChange
Implementation generates checksum by serializing the change withStringChangeLogSerializer
- Specified by:
generateCheckSum
in interfaceChange
- Overrides:
generateCheckSum
in classAbstractChange
-
warn
Description copied from class:AbstractChange
Implementation delegates logic to theSqlGenerator.warn(liquibase.statement.SqlStatement, liquibase.database.Database, liquibase.sqlgenerator.SqlGeneratorChain)
method on theSqlStatement
objects returned byChange.generateStatements(liquibase.database.Database)
. If a generated statement is not supported for the given database, no warning will be added since that is a validation error. If no or null SqlStatements are returned by generateStatements then this method returns no warnings.- Specified by:
warn
in interfaceChange
- Overrides:
warn
in classAbstractChange
-
getSerializedObjectNamespace
- Specified by:
getSerializedObjectNamespace
in interfaceLiquibaseSerializable
- Overrides:
getSerializedObjectNamespace
in classAbstractChange
-
generateStatementsFromRows
protected SqlStatement[] generateStatementsFromRows(Database database, List<LoadDataChange.LoadDataRowConfig> rows) -
isNullValue
-