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
Nested Classes Modifier and Type Class Description static class
LoadDataChange.LOAD_DATA_TYPE
protected static class
LoadDataChange.LoadDataRowConfig
-
Nested classes/interfaces inherited from interface liquibase.serializer.LiquibaseSerializable
LiquibaseSerializable.SerializationType
-
-
Field Summary
Fields Modifier and Type Field Description static Pattern
BASE64_PATTERN
static String
DEFAULT_COMMENT_PATTERN
CSV Lines starting with that sign(s) will be treated as comments by default-
Fields 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
Constructors Constructor Description LoadDataChange()
-
Method Summary
-
Methods inherited from class liquibase.change.AbstractTableChange
getCatalogName, getSchemaName, setCatalogName, setSchemaName, setTableName
-
Methods inherited from class liquibase.change.AbstractChange
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, 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 Detail
-
DEFAULT_COMMENT_PATTERN
public static final String DEFAULT_COMMENT_PATTERN
CSV Lines starting with that sign(s) will be treated as comments by default- See Also:
- Constant Field Values
-
BASE64_PATTERN
public static final Pattern BASE64_PATTERN
-
-
Method Detail
-
getValueToWrite
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.- 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
public boolean supports(Database database)
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
public boolean generateRollbackStatementsVolatile(Database database)
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
public String getTableName()
- Overrides:
getTableName
in classAbstractTableChange
-
getFile
public String getFile()
-
setFile
public void setFile(String file)
-
getUsePreparedStatements
public Boolean getUsePreparedStatements()
-
setUsePreparedStatements
public void setUsePreparedStatements(Boolean usePreparedStatements)
-
getCommentLineStartsWith
public String getCommentLineStartsWith()
-
setCommentLineStartsWith
public void setCommentLineStartsWith(String commentLineStartsWith)
-
isRelativeToChangelogFile
public Boolean isRelativeToChangelogFile()
-
setRelativeToChangelogFile
public void setRelativeToChangelogFile(Boolean relativeToChangelogFile)
-
getEncoding
public String getEncoding()
-
setEncoding
public void setEncoding(String encoding)
-
getSeparator
public String getSeparator()
-
setSeparator
public void setSeparator(String separator)
-
getQuotchar
public String getQuotchar()
-
setQuotchar
public void setQuotchar(String quotchar)
-
addColumn
public void addColumn(LoadDataColumnConfig column)
Description copied from interface:ChangeWithColumns
Add a column configuration to the Change.- Specified by:
addColumn
in interfaceChangeWithColumns<LoadDataColumnConfig>
-
getColumns
public List<LoadDataColumnConfig> getColumns()
Description copied from interface:ChangeWithColumns
Return all theColumnConfig
objects defined for thisChange
- Specified by:
getColumns
in interfaceChangeWithColumns<LoadDataColumnConfig>
-
setColumns
public void setColumns(List<LoadDataColumnConfig> columns)
- Specified by:
setColumns
in interfaceChangeWithColumns<LoadDataColumnConfig>
-
columnIdString
protected String columnIdString(int index, LoadDataColumnConfig columnConfig)
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
protected ValidationErrors validateColumns(ValidationErrors validationErrors)
Validate all columns and collect errors in 'validationErrors'- Parameters:
validationErrors
- ValidationErrors to collect errors- Returns:
- validationErrors
-
generateStatements
public SqlStatement[] generateStatements(Database database)
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
protected boolean supportsBatchUpdates(Database database)
-
validate
public ValidationErrors validate(Database database)
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
protected LoadDataColumnConfig columnConfigFromName(String name, Integer idx)
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
public boolean generateStatementsVolatile(Database database)
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
public CSVReader getCSVReader() throws IOException, LiquibaseException
- Throws:
IOException
LiquibaseException
-
getRelativeTo
protected String getRelativeTo()
-
createPreparedStatement
protected ExecutablePreparedStatementBase createPreparedStatement(Database database, String catalogName, String schemaName, String tableName, List<LoadDataColumnConfig> columns, ChangeSet changeSet, ResourceAccessor resourceAccessor)
-
createStatement
protected InsertStatement createStatement(String catalogName, String schemaName, String tableName)
-
createStatementSet
protected InsertSetStatement createStatementSet(String catalogName, String schemaName, String tableName)
-
getColumnConfig
protected LoadDataColumnConfig getColumnConfig(int index, String header)
-
checkStatus
public ChangeStatus checkStatus(Database database)
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
public String 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
public CheckSum generateCheckSum()
Description copied from class:AbstractChange
Implementation generates checksum by serializing the change withStringChangeLogSerializer
- Specified by:
generateCheckSum
in interfaceChange
- Overrides:
generateCheckSum
in classAbstractChange
-
warn
public Warnings warn(Database database)
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
public String getSerializedObjectNamespace()
- Specified by:
getSerializedObjectNamespace
in interfaceLiquibaseSerializable
- Overrides:
getSerializedObjectNamespace
in classAbstractChange
-
generateStatementsFromRows
protected SqlStatement[] generateStatementsFromRows(Database database, List<LoadDataChange.LoadDataRowConfig> rows)
-
-