001package io.ebeaninternal.dbmigration.ddlgeneration.platform; 002 003import java.util.ArrayList; 004import java.util.List; 005 006/** 007 * Bean holding comments relating to a history table that needs to have it's 008 * associated triggers/function updated due to columns added/dropped/included 009 * or excluded. 010 */ 011public class HistoryTableUpdate { 012 013 /** 014 * Column change type. 015 */ 016 public enum Change { 017 ADD, 018 DROP, 019 INCLUDE, 020 EXCLUDE, 021 ALTER 022 } 023 024 private static class Column { 025 026 final Change change; 027 028 final String column; 029 030 public Column(Change change, String column) { 031 this.change = change; 032 this.column = column; 033 } 034 035 @Override 036 public String toString() { 037 return description(); 038 } 039 040 public String description() { 041 return change.name().toLowerCase() + " " + column; 042 } 043 044 } 045 046 private final String baseTable; 047 048 private final List<Column> columnChanges = new ArrayList<>(); 049 050 /** 051 * Construct with a given base table name. 052 */ 053 public HistoryTableUpdate(String baseTable) { 054 this.baseTable = baseTable; 055 } 056 057 /** 058 * Return a description of the changes that cause the history trigger/function 059 * to be regenerated (added, included, excluded and dropped columns). 060 */ 061 public String description() { 062 return columnChanges.toString(); 063 } 064 065 /** 066 * Add a comment for column added, dropped, included or excluded. 067 */ 068 public void add(Change change, String column) { 069 columnChanges.add(new Column(change, column)); 070 } 071 072 /** 073 * Return the base table name. 074 */ 075 public String getBaseTable() { 076 return baseTable; 077 } 078 079}