Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A complete example will look like this</p> <p><strong>Create a class that implements CustomTaskChange or CustomSqlChange.</strong> </p> <pre><code>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 &amp;&amp; !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; } } </code></pre> <p><strong>In the changeset xml you could use the class as below</strong></p> <pre><code>&lt;changeSet id="1" author="murali" runAlways="false" failOnError="true" &gt; &lt;customChange class="com.example.DataLoaderTask"&gt; &lt;param name="file" value="/com/example/data/user.csv" /&gt; &lt;/customChange&gt; &lt;/changeSet&gt; </code></pre> <p>For me the data file is in src/main/resources/com/example/data directory</p> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload