Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package liquibase.changelog.visitor;
import liquibase.change.Change;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.DatabaseChangeLog;
import liquibase.changelog.filter.ChangeSetFilterResult;
import liquibase.database.Database;
import liquibase.dbdoc.*;
import liquibase.exception.LiquibaseException;
import liquibase.resource.ResourceAccessor;
import liquibase.snapshot.DatabaseSnapshot;
import liquibase.snapshot.SnapshotControl;
import liquibase.snapshot.SnapshotGeneratorFactory;
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.Column;
import liquibase.structure.core.Table;
import liquibase.util.StreamUtil;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class DBDocVisitor implements ChangeSetVisitor {
private static final int MAX_RECENT_CHANGE = 50;
private Database database;
private SortedSet changeLogs;
private Map> changesByObject;
private Map> changesByAuthor;
private Map> changesToRunByObject;
private Map> changesToRunByAuthor;
private List changesToRun;
private List recentChanges;
private String rootChangeLogName;
private DatabaseChangeLog rootChangeLog;
public DBDocVisitor(Database database) {
this.database = database;
changesByObject = new HashMap<>();
changesByAuthor = new HashMap<>();
changeLogs = new TreeSet<>();
changesToRunByObject = new HashMap<>();
changesToRunByAuthor = new HashMap<>();
changesToRun = new ArrayList<>();
recentChanges = new ArrayList<>();
}
@Override
public ChangeSetVisitor.Direction getDirection() {
return ChangeSetVisitor.Direction.FORWARD;
}
@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set filterResults) throws LiquibaseException {
ChangeSet.RunStatus runStatus = this.database.getRunStatus(changeSet);
if (rootChangeLogName == null) {
rootChangeLogName = changeSet.getFilePath();
}
if (rootChangeLog == null) {
this.rootChangeLog = databaseChangeLog;
}
if (!changesByAuthor.containsKey(changeSet.getAuthor())) {
changesByAuthor.put(changeSet.getAuthor(), new ArrayList());
}
if (!changesToRunByAuthor.containsKey(changeSet.getAuthor())) {
changesToRunByAuthor.put(changeSet.getAuthor(), new ArrayList());
}
boolean toRun = runStatus.equals(ChangeSet.RunStatus.NOT_RAN) || runStatus.equals(ChangeSet.RunStatus.RUN_AGAIN);
for (Change change : changeSet.getChanges()) {
if (toRun) {
changesToRunByAuthor.get(changeSet.getAuthor()).add(change);
changesToRun.add(change);
} else {
changesByAuthor.get(changeSet.getAuthor()).add(change);
recentChanges.add(0, change);
}
}
ChangeLogInfo changeLogInfo = new ChangeLogInfo(changeSet.getChangeLog().getLogicalFilePath(), changeSet.getChangeLog().getPhysicalFilePath());
if (!changeLogs.contains(changeLogInfo)) {
changeLogs.add(changeLogInfo);
}
for (Change change : changeSet.getChanges()) {
Set affectedDatabaseObjects = change.getAffectedDatabaseObjects(database);
if (affectedDatabaseObjects != null) {
for (DatabaseObject dbObject : affectedDatabaseObjects) {
if (toRun) {
if (!changesToRunByObject.containsKey(dbObject)) {
changesToRunByObject.put(dbObject, new ArrayList());
}
changesToRunByObject.get(dbObject).add(change);
} else {
if (!changesByObject.containsKey(dbObject)) {
changesByObject.put(dbObject, new ArrayList());
}
changesByObject.get(dbObject).add(change);
}
}
}
}
}
public void writeHTML(File rootOutputDir, ResourceAccessor resourceAccessor) throws IOException,
LiquibaseException {
ChangeLogWriter changeLogWriter = new ChangeLogWriter(resourceAccessor, rootOutputDir);
HTMLWriter authorWriter = new AuthorWriter(rootOutputDir, database);
HTMLWriter tableWriter = new TableWriter(rootOutputDir, database);
HTMLWriter columnWriter = new ColumnWriter(rootOutputDir, database);
HTMLWriter pendingChangesWriter = new PendingChangesWriter(rootOutputDir, database);
HTMLWriter recentChangesWriter = new RecentChangesWriter(rootOutputDir, database);
HTMLWriter pendingSQLWriter = new PendingSQLWriter(rootOutputDir, database, rootChangeLog);
copyFile("liquibase/dbdoc/stylesheet.css", rootOutputDir);
copyFile("liquibase/dbdoc/index.html", rootOutputDir);
copyFile("liquibase/dbdoc/globalnav.html", rootOutputDir);
copyFile("liquibase/dbdoc/overview-summary.html", rootOutputDir);
DatabaseSnapshot snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(database.getDefaultSchema(), database, new SnapshotControl(database));
new ChangeLogListWriter(rootOutputDir).writeHTML(changeLogs);
SortedSet
tables = new TreeSet<>(snapshot.get(Table.class));
Iterator
tableIterator = tables.iterator();
while (tableIterator.hasNext()) {
if (database.isLiquibaseObject(tableIterator.next())) {
tableIterator.remove();
}
}
new TableListWriter(rootOutputDir).writeHTML(tables);
new AuthorListWriter(rootOutputDir).writeHTML(new TreeSet