All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.dbdoc.TableWriter Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package liquibase.dbdoc;

import liquibase.change.Change;
import liquibase.database.Database;
import liquibase.database.structure.Column;
import liquibase.database.structure.Table;
import liquibase.database.typeconversion.TypeConverterFactory;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TableWriter extends HTMLWriter {

    public TableWriter(File rootOutputDir, Database database) {
        super(new File(rootOutputDir, "tables"), database);
    }

    @Override
    protected String createTitle(Object object) {
        return "Changes affecting table \""+object.toString() + "\"";
    }

    @Override
    protected void writeCustomHTML(FileWriter fileWriter, Object object, List changes, Database database) throws IOException {
        writeColumns(fileWriter, ((Table) object), database);
    }

    private void writeColumns(FileWriter fileWriter, Table table, Database database) throws IOException {
        List> cells = new ArrayList>();

        for (Column column : table.getColumns()) {
            cells.add(Arrays.asList(TypeConverterFactory.getInstance().findTypeConverter(database).convertToDatabaseTypeString(column, database),
                    "" + column.getName() + ""));
            //todo: add foreign key info to columns?
        }


        writeTable("Current Columns", cells, fileWriter);

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy