Un ejemplo completo se verá así
crear una clase que implementa CustomTaskChange o CustomSqlChange.
package com.example;
import liquibase.change.custom.CustomTaskChange;
import liquibase.database.Database;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.CustomChangeException;
import liquibase.exception.SetupException;
import liquibase.exception.ValidationErrors;
import liquibase.logging.LogFactory;
import liquibase.resource.ResourceAccessor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class DataLoaderTask implements CustomTaskChange {
//to hold the parameter value
private String file;
private ResourceAccessor resourceAccessor;
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
@Override
public void execute(Database database) throws CustomChangeException {
JdbcConnection databaseConnection = (JdbcConnection) database.getConnection();
try {
//Opening my data file
BufferedReader in = new BufferedReader(
new InputStreamReader(resourceAccessor.getResourceAsStream(file)));
//Ignore header
String str = in.readLine();
while ((str = in.readLine()) != null && !str.trim().equals("")) {
LogFactory.getLogger().info("Processing line "+ str);
//Do whatever is necessary
}
in.close();
} catch (Exception e) {
throw new CustomChangeException(e);
}
}
@Override
public String getConfirmationMessage() {
return null;
}
@Override
public void setUp() throws SetupException {
}
@Override
public void setFileOpener(ResourceAccessor resourceAccessor) {
this.resourceAccessor = resourceAccessor;
}
@Override
public ValidationErrors validate(Database database) {
return null;
}
}
en el XML de cambios que usted podría utilizar la clase de la siguiente manera
<changeSet id="1" author="murali" runAlways="false" failOnError="true" >
<customChange class="com.example.DataLoaderTask">
<param name="file" value="/com/example/data/user.csv" />
</customChange>
</changeSet>
Para mí el archivo de datos es en el directorio src/main/resources/com/example/datos
Espero que esto ayude
No lo creo –