Refactor: BaseDdlBuffer uses StringBuilder instead of StringWriter. Makes IOException obsolete.

This commit is contained in:
Roland Praml committed 2022-02-08 16:04:14 +01:00
1 parent 7bea0d0eb2
commit 6e5eb6b963
20 files changed
+164 -210

No files matched your search

@@ -2,8 +2,6 @@ package io.ebeaninternal.dbmigration.ddlgeneration;
import io.ebeaninternal.dbmigration.model.MConfiguration;
import java.io.IOException;
/**
* Buffer to append generated DDL to.
*/
@@ -22,37 +20,37 @@ public interface DdlBuffer {
/**
* Append a statement allowing for null or empty statements.
*/
DdlBuffer appendStatement(String content) throws IOException;
DdlBuffer appendStatement(String content);
/**
* Append DDL content to the buffer.
*/
DdlBuffer append(String content) throws IOException;
DdlBuffer append(String content);
/**
* Append DDL content to the buffer with space padding.
*/
DdlBuffer append(String type, int space) throws IOException;
DdlBuffer append(String type, int space);
/**
* Append a value that is potentially null or empty and proceed it with a space if so.
*/
DdlBuffer appendWithSpace(String foreignKeyRestrict) throws IOException;
DdlBuffer appendWithSpace(String foreignKeyRestrict);
/**
* Append new line character to the buffer.
*/
DdlBuffer newLine() throws IOException;
DdlBuffer newLine();
/**
* Append the end of statement content.
*/
DdlBuffer endOfStatement() throws IOException;
DdlBuffer endOfStatement();
/**
* End of a change - add some whitespace.
*/
DdlBuffer end() throws IOException;
DdlBuffer end();
/**
* Return the buffer content.
@@ -7,7 +7,6 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlHandler;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import java.io.IOException;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -52,31 +51,27 @@ public abstract class AbstractHanaDdl extends PlatformDdl {
: (alter.getDefaultValue() != null ? alter.getDefaultValue() : alter.getCurrentDefaultValue());
String defaultValueClause = (defaultValue == null || defaultValue.isEmpty()) ? "" : " default " + defaultValue;
try {
DdlBuffer buffer = new BaseDdlBuffer(null);
if (!isConvertible(currentType, type)) {
// add an intermediate conversion if possible
if (isNumberType(currentType)) {
// numbers can always be converted to decimal
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
.append(" decimal ").append(defaultValueClause).append(notnullClause).append(alterColumnSuffix)
.endOfStatement();
DdlBuffer buffer = new BaseDdlBuffer(null);
if (!isConvertible(currentType, type)) {
// add an intermediate conversion if possible
if (isNumberType(currentType)) {
// numbers can always be converted to decimal
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
.append(" decimal ").append(defaultValueClause).append(notnullClause).append(alterColumnSuffix)
.endOfStatement();
} else if (isStringType(currentType)) {
// strings can always be converted to nclob
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
.append(" nclob ").append(defaultValueClause).append(notnullClause).append(alterColumnSuffix)
.endOfStatement();
}
} else if (isStringType(currentType)) {
// strings can always be converted to nclob
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
.append(" nclob ").append(defaultValueClause).append(notnullClause).append(alterColumnSuffix)
.endOfStatement();
}
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
.append(" ").append(type).append(defaultValueClause).append(notnullClause).append(alterColumnSuffix);
return buffer.getBuffer();
} catch (IOException e) {
throw new RuntimeException(e);
}
buffer.append("alter table ").append(tableName).append(" ").append(alterColumn).append(" ").append(columnName)
.append(" ").append(type).append(defaultValueClause).append(notnullClause).append(alterColumnSuffix);
return buffer.getBuffer();
}
@Override
@@ -121,19 +116,16 @@ public abstract class AbstractHanaDdl extends PlatformDdl {
@Override
public String alterTableDropUniqueConstraint(String tableName, String uniqueConstraintName) {
DdlBuffer buffer = new BaseDdlBuffer(null);
try {
buffer.append("delimiter $$").newLine();
buffer.append("do").newLine();
buffer.append("begin").newLine();
buffer.append("declare exit handler for sql_error_code 397 begin end").endOfStatement();
buffer.append("exec 'alter table ").append(tableName).append(" ").append(dropUniqueConstraint).append(" ")
.append(maxConstraintName(uniqueConstraintName)).append("'").endOfStatement();
buffer.append("end").endOfStatement();
buffer.append("$$");
return buffer.getBuffer();
} catch (IOException e) {
throw new RuntimeException(e);
}
buffer.append("delimiter $$").newLine();
buffer.append("do").newLine();
buffer.append("begin").newLine();
buffer.append("declare exit handler for sql_error_code 397 begin end").endOfStatement();
buffer.append("exec 'alter table ").append(tableName).append(" ").append(dropUniqueConstraint).append(" ")
.append(maxConstraintName(uniqueConstraintName)).append("'").endOfStatement();
buffer.append("end").endOfStatement();
buffer.append("$$");
return buffer.getBuffer();
}
@Override
@@ -146,7 +138,7 @@ public abstract class AbstractHanaDdl extends PlatformDdl {
* foreign keys. That's why we call a user stored procedure here
*/
@Override
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException {
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) {
buffer.append("CALL usp_ebean_drop_column('").append(tableName).append("', '").append(columnName).append("')")
.endOfStatement();
}
@@ -3,21 +3,19 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.model.MConfiguration;
import java.io.IOException;
import java.io.StringWriter;
/**
* Base implementation of DdlBuffer using an underlying writer.
*/
public class BaseDdlBuffer implements DdlBuffer {
protected final StringWriter writer;
protected final StringBuilder writer;
protected final MConfiguration configuration;
public BaseDdlBuffer(MConfiguration configuration) {
this.configuration = configuration;
this.writer = new StringWriter();
this.writer = new StringBuilder();
}
@Override
@@ -27,19 +25,19 @@ public class BaseDdlBuffer implements DdlBuffer {
@Override
public boolean isEmpty() {
return writer.getBuffer().length() == 0;
return writer.length() == 0;
}
@Override
public DdlBuffer appendWithSpace(String foreignKeyRestrict) throws IOException {
if (foreignKeyRestrict != null && !foreignKeyRestrict.isEmpty()) {
writer.append(" ").append(foreignKeyRestrict);
public DdlBuffer appendWithSpace(String content) {
if (content != null && !content.isEmpty()) {
writer.append(" ").append(content);
}
return this;
}
@Override
public DdlBuffer appendStatement(String content) throws IOException {
public DdlBuffer appendStatement(String content) {
if (content != null && !content.isEmpty()) {
writer.append(content);
endOfStatement();
@@ -48,19 +46,19 @@ public class BaseDdlBuffer implements DdlBuffer {
}
@Override
public DdlBuffer append(String content) throws IOException {
public DdlBuffer append(String content) {
writer.append(content);
return this;
}
@Override
public DdlBuffer append(String content, int space) throws IOException {
public DdlBuffer append(String content, int space) {
writer.append(content);
appendSpace(space, content);
return this;
}
protected void appendSpace(int max, String content) throws IOException {
protected void appendSpace(int max, String content) {
int space = max - content.length();
if (space > 0) {
for (int i = 0; i < space; i++) {
@@ -71,7 +69,7 @@ public class BaseDdlBuffer implements DdlBuffer {
}
@Override
public DdlBuffer endOfStatement() throws IOException {
public DdlBuffer endOfStatement() {
writer.append(";\n");
return this;
}
@@ -81,7 +79,7 @@ public class BaseDdlBuffer implements DdlBuffer {
* This should be just whitespace or a sql comment.
*/
@Override
public DdlBuffer end() throws IOException {
public DdlBuffer end() {
if (!isEmpty()) {
writer.append("\n");
}
@@ -89,7 +87,7 @@ public class BaseDdlBuffer implements DdlBuffer {
}
@Override
public DdlBuffer newLine() throws IOException {
public DdlBuffer newLine() {
writer.append("\n");
return this;
}
@@ -6,8 +6,6 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlHandler;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlOptions;
import java.io.IOException;
public class ClickHouseDdl extends PlatformDdl {
private static final String LOG_TABLE = "ENGINE = Log()";
@@ -32,7 +30,7 @@ public class ClickHouseDdl extends PlatformDdl {
* Add an table storage engine to the create table statement.
*/
@Override
public void tableStorageEngine(DdlBuffer apply, String storageEngine) throws IOException {
public void tableStorageEngine(DdlBuffer apply, String storageEngine) {
if (storageEngine == null) {
// default to Log() table but really should all be explicit (need arguments for MergeTree etc)
storageEngine = LOG_TABLE;
@@ -9,8 +9,6 @@ import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.model.MColumn;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
/**
@@ -49,7 +47,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void updateTriggers(DdlWrite writer, HistoryTableUpdate update) throws IOException {
public void updateTriggers(DdlWrite writer, HistoryTableUpdate update) {
MTable table = writer.getTable(update.getBaseTable());
if (table == null) {
@@ -61,13 +59,13 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
/**
* Replace the existing triggers/stored procedures/views for history table support given the included columns.
*/
protected abstract void updateHistoryTriggers(DbTriggerUpdate triggerUpdate) throws IOException;
protected abstract void updateHistoryTriggers(DbTriggerUpdate triggerUpdate);
/**
* Process the HistoryTableUpdate which can result in changes to the apply, rollback
* and drop scripts.
*/
protected void updateTriggers(DdlWrite writer, MTable table, HistoryTableUpdate update) throws IOException {
protected void updateTriggers(DdlWrite writer, MTable table, HistoryTableUpdate update) {
writer.applyHistoryTrigger().append("-- changes: ").append(update.description()).newLine();
@@ -83,7 +81,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException {
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) {
String baseTable = dropHistoryTable.getBaseTable();
@@ -93,7 +91,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException {
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) {
String baseTable = addHistoryTable.getBaseTable();
MTable table = writer.getTable(baseTable);
@@ -105,7 +103,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void createWithHistory(DdlWrite writer, MTable table) throws IOException {
public void createWithHistory(DdlWrite writer, MTable table) {
String baseTable = table.getName();
String whenCreatedColumn = table.getWhenCreatedColumn();
@@ -118,11 +116,11 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
createTriggers(writer, table);
}
protected abstract void createTriggers(DdlWrite writer, MTable table) throws IOException;
protected abstract void createTriggers(DdlWrite writer, MTable table);
protected abstract void dropTriggers(DdlBuffer buffer, String baseTable) throws IOException;
protected abstract void dropTriggers(DdlBuffer buffer, String baseTable);
protected void createStoredFunction(DdlWrite writer, MTable table) throws IOException {
protected void createStoredFunction(DdlWrite writer, MTable table) {
// do nothing
}
@@ -150,7 +148,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
return normalise(baseTableName) + "_history_del";
}
protected void addHistoryTable(DdlWrite writer, MTable table, String whenCreatedColumn) throws IOException {
protected void addHistoryTable(DdlWrite writer, MTable table, String whenCreatedColumn) {
String baseTableName = table.getName();
@@ -161,7 +159,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
createWithHistoryView(apply, baseTableName);
}
protected void addSysPeriodColumns(DdlBuffer apply, String baseTableName, String whenCreatedColumn) throws IOException {
protected void addSysPeriodColumns(DdlBuffer apply, String baseTableName, String whenCreatedColumn) {
apply.append("alter table ").append(baseTableName).append(" add column ")
.append(sysPeriodStart).append(" ").append(sysPeriodType).append(" default ").append(now).endOfStatement();
@@ -173,12 +171,12 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
}
protected void createHistoryTable(DdlBuffer apply, MTable table) throws IOException {
protected void createHistoryTable(DdlBuffer apply, MTable table) {
createHistoryTableAs(apply, table);
createHistoryTableWithPeriod(apply);
}
protected void createHistoryTableAs(DdlBuffer apply, MTable table) throws IOException {
protected void createHistoryTableAs(DdlBuffer apply, MTable table) {
apply.append(platformDdl.getCreateTableCommandPrefix()).append(" ").append(table.getName()).append(historySuffix).append("(").newLine();
for (MColumn column : table.allColumns()) {
if (!column.isDraftOnly()) {
@@ -188,7 +186,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
}
}
protected void createHistoryTableWithPeriod(DdlBuffer apply) throws IOException {
protected void createHistoryTableWithPeriod(DdlBuffer apply) {
writeColumnDefinition(apply, sysPeriodStart, sysPeriodType);
apply.append(",").newLine();
writeColumnDefinition(apply, sysPeriodEnd, sysPeriodType);
@@ -198,7 +196,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
/**
* Write the column definition to the create table statement.
*/
protected void writeColumnDefinition(DdlBuffer buffer, String columnName, String type) throws IOException {
protected void writeColumnDefinition(DdlBuffer buffer, String columnName, String type) {
String platformType = platformDdl.convert(type);
buffer.append(" ");
@@ -206,7 +204,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
buffer.append(platformType);
}
protected void createWithHistoryView(DdlBuffer apply, String baseTableName) throws IOException {
protected void createWithHistoryView(DdlBuffer apply, String baseTableName) {
apply
.append("create view ").append(baseTableName).append(viewSuffix)
@@ -220,7 +218,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
* For postgres/h2/mysql we need to drop and recreate the view. Well, we could add columns to the end of the view
* but otherwise we need to drop and create it.
*/
protected void recreateHistoryView(DbTriggerUpdate update) throws IOException {
protected void recreateHistoryView(DbTriggerUpdate update) {
DdlBuffer buffer = update.dropDependencyBuffer();
// we need to drop the view early/first before any changes to the tables etc
@@ -230,24 +228,24 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
createWithHistoryView(update.historyViewBuffer(), update.getBaseTable());
}
protected void appendSysPeriodColumns(DdlBuffer apply, String prefix) throws IOException {
protected void appendSysPeriodColumns(DdlBuffer apply, String prefix) {
appendColumnName(apply, prefix, sysPeriodStart);
appendColumnName(apply, prefix, sysPeriodEnd);
}
protected void dropHistoryTableEtc(DdlBuffer buffer, String baseTableName) throws IOException {
protected void dropHistoryTableEtc(DdlBuffer buffer, String baseTableName) {
buffer.append("drop view ").append(baseTableName).append(viewSuffix).endOfStatement();
dropSysPeriodColumns(buffer, baseTableName);
buffer.append("drop table ").append(baseTableName).append(historySuffix).endOfStatement().end();
}
protected void dropSysPeriodColumns(DdlBuffer buffer, String baseTableName) throws IOException {
protected void dropSysPeriodColumns(DdlBuffer buffer, String baseTableName) {
platformDdl.alterTableDropColumn(buffer, baseTableName, sysPeriodStart);
platformDdl.alterTableDropColumn(buffer, baseTableName, sysPeriodEnd);
}
protected void appendInsertIntoHistory(DdlBuffer buffer, String historyTable, List<String> columns) throws IOException {
protected void appendInsertIntoHistory(DdlBuffer buffer, String historyTable, List<String> columns) {
buffer.append(" insert into ").append(historyTable).append(" (").append(sysPeriodStart).append(",").append(sysPeriodEnd).append(",");
appendColumnNames(buffer, columns, "");
@@ -256,7 +254,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
buffer.append(");").newLine();
}
void appendColumnNames(DdlBuffer buffer, List<String> columns, String columnPrefix) throws IOException {
void appendColumnNames(DdlBuffer buffer, List<String> columns, String columnPrefix) {
for (int i = 0; i < columns.size(); i++) {
if (i > 0) {
buffer.append(", ");
@@ -269,7 +267,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
/**
* Append a single column to the buffer if it is not null.
*/
void appendColumnName(DdlBuffer buffer, String prefix, String columnName) throws IOException {
void appendColumnName(DdlBuffer buffer, String prefix, String columnName) {
if (columnName != null) {
buffer.append(prefix).append(columnName);
}
@@ -4,8 +4,6 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
/**
* H2 history support using DB triggers to maintain a history table.
*/
@@ -20,26 +18,26 @@ public class H2HistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void dropTriggers(DdlBuffer buffer, String baseTable) throws IOException {
protected void dropTriggers(DdlBuffer buffer, String baseTable) {
buffer.append("drop trigger ").append(updateTriggerName(baseTable)).endOfStatement();
}
@Override
protected void createTriggers(DdlWrite writer, MTable table) throws IOException {
protected void createTriggers(DdlWrite writer, MTable table) {
String baseTableName = table.getName();
DdlBuffer apply = writer.applyHistoryTrigger();
addCreateTrigger(apply, updateTriggerName(baseTableName), baseTableName);
}
@Override
protected void updateHistoryTriggers(DbTriggerUpdate update) throws IOException {
protected void updateHistoryTriggers(DbTriggerUpdate update) {
recreateHistoryView(update);
DdlBuffer buffer = update.historyTriggerBuffer();
dropTriggers(buffer, update.getBaseTable());
addCreateTrigger(buffer, updateTriggerName(update.getBaseTable()), update.getBaseTable());
}
private void addCreateTrigger(DdlBuffer apply, String triggerName, String baseTable) throws IOException {
private void addCreateTrigger(DdlBuffer apply, String triggerName, String baseTable) {
// Note that this does not take into account the historyTable name (excepts _history suffix) and
// does not take into account excluded columns (all columns included in history)
apply
@@ -3,8 +3,6 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import java.io.IOException;
public class HanaColumnStoreDdl extends AbstractHanaDdl {
public HanaColumnStoreDdl(DatabasePlatform platform) {
@@ -32,19 +30,15 @@ public class HanaColumnStoreDdl extends AbstractHanaDdl {
@Override
public String dropIndex(String indexName, String tableName, boolean concurrent) {
DdlBuffer buffer = new BaseDdlBuffer(null);
try {
buffer.append("delimiter $$").newLine();
buffer.append("do").newLine();
buffer.append("begin").newLine();
buffer.append("declare exit handler for sql_error_code 261 begin end").endOfStatement();
buffer.append("exec '").append(dropIndexIfExists).append(maxConstraintName(indexName)).append("'")
.endOfStatement();
buffer.append("end").endOfStatement();
buffer.append("$$");
return buffer.getBuffer();
} catch (IOException e) {
throw new RuntimeException(e);
}
buffer.append("delimiter $$").newLine();
buffer.append("do").newLine();
buffer.append("begin").newLine();
buffer.append("declare exit handler for sql_error_code 261 begin end").endOfStatement();
buffer.append("exec '").append(dropIndexIfExists).append(maxConstraintName(indexName)).append("'")
.endOfStatement();
buffer.append("end").endOfStatement();
buffer.append("$$");
return buffer.getBuffer();
}
}
@@ -8,7 +8,6 @@ import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.model.MColumn;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -32,7 +31,7 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void createWithHistory(DdlWrite writer, MTable table) throws IOException {
public void createWithHistory(DdlWrite writer, MTable table) {
String tableName = table.getName();
String historyTableName = tableName + historySuffix;
DdlBuffer apply = writer.applyHistoryView();
@@ -73,12 +72,12 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException {
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) {
dropHistoryTable(writer.applyDropDependencies(), dropHistoryTable.getBaseTable(),
dropHistoryTable.getBaseTable() + historySuffix);
}
protected void dropHistoryTable(DdlBuffer apply, String baseTable, String historyTable) throws IOException {
protected void dropHistoryTable(DdlBuffer apply, String baseTable, String historyTable) {
// disable system versioning
disableSystemVersioning(apply, baseTable);
@@ -93,7 +92,7 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException {
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) {
MTable table = writer.getTable(addHistoryTable.getBaseTable());
if (table == null) {
throw new IllegalStateException("MTable " + addHistoryTable.getBaseTable() + " not found in writer? (required for history DDL)");
@@ -107,7 +106,7 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
}
protected void writeColumnDefinition(DdlBuffer buffer, String columnName, String type, String defaultValue,
boolean isNotNull, String generated) throws IOException {
boolean isNotNull, String generated) {
String platformType = platformDdl.convert(type);
buffer.append(" ").append(platformDdl.lowerColumnName(columnName));
@@ -123,11 +122,11 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
}
}
public void disableSystemVersioning(DdlBuffer apply, String tableName) throws IOException {
public void disableSystemVersioning(DdlBuffer apply, String tableName) {
disableSystemVersioning(apply, tableName, false);
}
public void disableSystemVersioning(DdlBuffer apply, String tableName, boolean uniqueStatement) throws IOException {
public void disableSystemVersioning(DdlBuffer apply, String tableName, boolean uniqueStatement) {
apply.append("alter table ").append(tableName).append(" drop system versioning");
if (uniqueStatement) {
// needed for the DB migration test to prevent the statement from being filtered
@@ -138,7 +137,7 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
}
public void enableSystemVersioning(DdlBuffer apply, String tableName, String historyTableName, boolean validated,
boolean uniqueStatement) throws IOException {
boolean uniqueStatement) {
apply.append("alter table ").append(tableName).append(" add system versioning history table ").append(historyTableName);
if (!validated) {
apply.append(" not validated");
@@ -7,8 +7,6 @@ import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
/**
* History DDL for MariaDB.
*/
@@ -20,12 +18,12 @@ public class MariaDbHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void createWithHistory(DdlWrite writer, MTable table) throws IOException {
public void createWithHistory(DdlWrite writer, MTable table) {
String baseTable = table.getName();
enableSystemVersioning(writer, baseTable);
}
private void enableSystemVersioning(DdlWrite writer, String baseTable) throws IOException {
private void enableSystemVersioning(DdlWrite writer, String baseTable) {
DdlBuffer apply = writer.applyHistoryView();
apply.append("alter table ").append(baseTable).append(" add system versioning").endOfStatement();
@@ -34,14 +32,14 @@ public class MariaDbHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException {
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) {
String baseTable = dropHistoryTable.getBaseTable();
DdlBuffer apply = writer.applyHistoryView();
apply.append("alter table ").append(baseTable).append(" drop system versioning").endOfStatement();
}
@Override
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException {
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) {
String baseTable = addHistoryTable.getBaseTable();
enableSystemVersioning(writer, baseTable);
}
@@ -6,7 +6,6 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.Column;
import java.io.IOException;
import java.util.Collection;
/**
@@ -38,7 +37,7 @@ public class MySqlDdl extends PlatformDdl {
}
@Override
public void alterTableDropColumn(final DdlBuffer buffer, final String tableName, final String columnName) throws IOException {
public void alterTableDropColumn(final DdlBuffer buffer, final String tableName, final String columnName) {
if (this.useMigrationStoredProcedures) {
buffer.append("CALL usp_ebean_drop_column('").append(tableName).append("', '").append(columnName).append("')").endOfStatement();
} else {
@@ -127,7 +126,7 @@ public class MySqlDdl extends PlatformDdl {
}
@Override
protected void writeColumnDefinition(DdlBuffer buffer, Column column, DdlIdentity identity) throws IOException {
protected void writeColumnDefinition(DdlBuffer buffer, Column column, DdlIdentity identity) {
super.writeColumnDefinition(buffer, column, identity);
String comment = column.getComment();
if (!StringHelper.isNull(comment)) {
@@ -140,7 +139,7 @@ public class MySqlDdl extends PlatformDdl {
}
@Override
public void inlineTableComment(DdlBuffer apply, String tableComment) throws IOException {
public void inlineTableComment(DdlBuffer apply, String tableComment) {
if (tableComment.length() > 1000) {
tableComment = tableComment.substring(0, 1000);
}
@@ -151,7 +150,7 @@ public class MySqlDdl extends PlatformDdl {
* Add table comment as a separate statement (from the create table statement).
*/
@Override
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) throws IOException {
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) {
if (DdlHelp.isDropComment(tableComment)) {
tableComment = "";
}
@@ -168,7 +167,7 @@ public class MySqlDdl extends PlatformDdl {
* Locks all tables for triggers that have to be updated.
*/
@Override
public void lockTables(DdlBuffer buffer, Collection<String> tables) throws IOException {
public void lockTables(DdlBuffer buffer, Collection<String> tables) {
if (!tables.isEmpty()) {
buffer.append("lock tables ");
int i = 0;
@@ -187,7 +186,7 @@ public class MySqlDdl extends PlatformDdl {
* Unlocks all tables for triggers that have to be updated.
*/
@Override
public void unlockTables(DdlBuffer buffer, Collection<String> tables) throws IOException {
public void unlockTables(DdlBuffer buffer, Collection<String> tables) {
buffer.append("unlock tables").endOfStatement();
}
@@ -4,8 +4,6 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
/**
* MySql history support using DB triggers to maintain a history table.
*/
@@ -15,13 +13,13 @@ public class MySqlHistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void dropTriggers(DdlBuffer buffer, String baseTable) throws IOException {
protected void dropTriggers(DdlBuffer buffer, String baseTable) {
buffer.append("drop trigger ").append(updateTriggerName(baseTable)).endOfStatement();
buffer.append("drop trigger ").append(deleteTriggerName(baseTable)).endOfStatement();
}
@Override
protected void createTriggers(DdlWrite writer, MTable table) throws IOException {
protected void createTriggers(DdlWrite writer, MTable table) {
DbTriggerUpdate update = createDbTriggerUpdate(writer, table);
@@ -30,7 +28,7 @@ public class MySqlHistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void updateHistoryTriggers(DbTriggerUpdate update) throws IOException {
protected void updateHistoryTriggers(DbTriggerUpdate update) {
recreateHistoryView(update);
@@ -42,7 +40,7 @@ public class MySqlHistoryDdl extends DbTriggerBasedHistoryDdl {
addBeforeDelete(deleteTriggerName(baseTable), update);
}
private void addBeforeUpdate(String triggerName, DbTriggerUpdate update) throws IOException {
private void addBeforeUpdate(String triggerName, DbTriggerUpdate update) {
DdlBuffer apply = update.historyTriggerBuffer();
apply
@@ -55,7 +53,7 @@ public class MySqlHistoryDdl extends DbTriggerBasedHistoryDdl {
.append("end$$").newLine();
}
private void addBeforeDelete(String triggerName, DbTriggerUpdate update) throws IOException {
private void addBeforeDelete(String triggerName, DbTriggerUpdate update) {
DdlBuffer apply = update.historyTriggerBuffer();
apply
@@ -6,8 +6,6 @@ import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
/**
* Default history implementation that does nothing. Needs to be replaced
* with an appropriate implementation for the given database platform.
@@ -20,7 +18,7 @@ public class NoHistorySupportDdl implements PlatformHistoryDdl {
}
@Override
public void createWithHistory(DdlWrite writer, MTable table) throws IOException {
public void createWithHistory(DdlWrite writer, MTable table) {
// does nothing
}
@@ -30,7 +28,7 @@ public class NoHistorySupportDdl implements PlatformHistoryDdl {
}
@Override
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException {
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) {
// does nothing
}
@@ -4,8 +4,6 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
/**
* NuoDB history support using DB triggers to maintain a history table.
*/
@@ -17,14 +15,14 @@ public class NuoDbHistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void dropTriggers(DdlBuffer buffer, String baseTable) throws IOException {
protected void dropTriggers(DdlBuffer buffer, String baseTable) {
buffer.append("drop trigger ").append(updateTriggerName(baseTable)).endOfStatement();
buffer.append("drop trigger ").append(deleteTriggerName(baseTable)).endOfStatement();
}
@Override
protected void createTriggers(DdlWrite writer, MTable table) throws IOException {
protected void createTriggers(DdlWrite writer, MTable table) {
DbTriggerUpdate update = createDbTriggerUpdate(writer, table);
@@ -33,7 +31,7 @@ public class NuoDbHistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void updateHistoryTriggers(DbTriggerUpdate update) throws IOException {
protected void updateHistoryTriggers(DbTriggerUpdate update) {
recreateHistoryView(update);
@@ -45,7 +43,7 @@ public class NuoDbHistoryDdl extends DbTriggerBasedHistoryDdl {
addBeforeDelete(deleteTriggerName(baseTable), update);
}
private void addBeforeUpdate(String triggerName, DbTriggerUpdate update) throws IOException {
private void addBeforeUpdate(String triggerName, DbTriggerUpdate update) {
DdlBuffer apply = update.historyTriggerBuffer();
addTriggerStart(triggerName, update, apply, " before update for each row as ");
@@ -54,7 +52,7 @@ public class NuoDbHistoryDdl extends DbTriggerBasedHistoryDdl {
addEndTrigger(apply);
}
private void addBeforeDelete(String triggerName, DbTriggerUpdate update) throws IOException {
private void addBeforeDelete(String triggerName, DbTriggerUpdate update) {
DdlBuffer apply = update.historyTriggerBuffer();
addTriggerStart(triggerName, update, apply, " before delete for each row as");
@@ -62,14 +60,14 @@ public class NuoDbHistoryDdl extends DbTriggerBasedHistoryDdl {
addEndTrigger(apply);
}
private void addTriggerStart(String triggerName, DbTriggerUpdate update, DdlBuffer apply, String s) throws IOException {
private void addTriggerStart(String triggerName, DbTriggerUpdate update, DdlBuffer apply, String s) {
apply
.append("delimiter $$").newLine()
.append("create or replace trigger ").append(triggerName).append(" for ").append(update.getBaseTable())
.append(s).newLine();
}
private void addEndTrigger(DdlBuffer apply) throws IOException {
private void addEndTrigger(DdlBuffer apply) {
apply.append("end_trigger")
.endOfStatement()
.append("$$").newLine()
@@ -21,7 +21,6 @@ import io.ebeaninternal.dbmigration.migration.Column;
import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
@@ -234,7 +233,7 @@ public class PlatformDdl {
/**
* Write all the table columns converting to platform types as necessary.
*/
public void writeTableColumns(DdlBuffer apply, List<Column> columns, DdlIdentity identity) throws IOException {
public void writeTableColumns(DdlBuffer apply, List<Column> columns, DdlIdentity identity) {
for (int i = 0; i < columns.size(); i++) {
if (i > 0) {
apply.append(",");
@@ -258,7 +257,7 @@ public class PlatformDdl {
/**
* Write the column definition to the create table statement.
*/
protected void writeColumnDefinition(DdlBuffer buffer, Column column, DdlIdentity identity) throws IOException {
protected void writeColumnDefinition(DdlBuffer buffer, Column column, DdlIdentity identity) {
String columnDefn = convert(column.getType());
if (identity.useIdentity() && isTrue(column.isPrimaryKey())) {
@@ -285,7 +284,7 @@ public class PlatformDdl {
/**
* Allow for platform overriding (e.g. ClickHouse).
*/
protected void writeColumnNotNull(DdlBuffer buffer) throws IOException {
protected void writeColumnNotNull(DdlBuffer buffer) {
buffer.append(" not null");
}
@@ -337,28 +336,28 @@ public class PlatformDdl {
/**
* Add history support to this table using the platform specific mechanism.
*/
public void createWithHistory(DdlWrite writer, MTable table) throws IOException {
public void createWithHistory(DdlWrite writer, MTable table) {
historyDdl.createWithHistory(writer, table);
}
/**
* Drop history support for a given table.
*/
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException {
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) {
historyDdl.dropHistoryTable(writer, dropHistoryTable);
}
/**
* Add history support to an existing table.
*/
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException {
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) {
historyDdl.addHistoryTable(writer, addHistoryTable);
}
/**
* Regenerate the history triggers (or function) due to a column being added/dropped/excluded or included.
*/
public void regenerateHistoryTriggers(DdlWrite write, HistoryTableUpdate update) throws IOException {
public void regenerateHistoryTriggers(DdlWrite write, HistoryTableUpdate update) {
historyDdl.updateTriggers(write, update);
}
@@ -521,7 +520,7 @@ public class PlatformDdl {
return buffer.toString();
}
public void alterTableAddColumn(DdlBuffer buffer, String tableName, Column column, boolean onHistoryTable, String defaultValue) throws IOException {
public void alterTableAddColumn(DdlBuffer buffer, String tableName, Column column, boolean onHistoryTable, String defaultValue) {
String convertedType = convert(column.getType());
@@ -558,7 +557,7 @@ public class PlatformDdl {
}
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException {
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) {
buffer.append("alter table ").append(tableName).append(" ").append(dropColumn).append(" ").append(columnName)
.append(dropColumnSuffix).endOfStatement();
}
@@ -676,21 +675,21 @@ public class PlatformDdl {
/**
* Add an inline table comment to the create table statement.
*/
public void inlineTableComment(DdlBuffer apply, String tableComment) throws IOException {
public void inlineTableComment(DdlBuffer apply, String tableComment) {
// do nothing by default (MySql only)
}
/**
* Add an table storage engine to the create table statement.
*/
public void tableStorageEngine(DdlBuffer apply, String storageEngine) throws IOException {
public void tableStorageEngine(DdlBuffer apply, String storageEngine) {
// do nothing by default
}
/**
* Add table comment as a separate statement (from the create table statement).
*/
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) throws IOException {
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) {
if (DdlHelp.isDropComment(tableComment)) {
tableComment = "";
}
@@ -700,7 +699,7 @@ public class PlatformDdl {
/**
* Add column comment as a separate statement.
*/
public void addColumnComment(DdlBuffer apply, String table, String column, String comment) throws IOException {
public void addColumnComment(DdlBuffer apply, String table, String column, String comment) {
if (DdlHelp.isDropComment(comment)) {
comment = "";
}
@@ -710,14 +709,14 @@ public class PlatformDdl {
/**
* Use this to generate a prolog for each script (stored procedures)
*/
public void generateProlog(DdlWrite write) throws IOException {
public void generateProlog(DdlWrite write) {
}
/**
* Use this to generate an epilog. Will be added at the end of script
*/
public void generateEpilog(DdlWrite write) throws IOException {
public void generateEpilog(DdlWrite write) {
}
@@ -743,14 +742,14 @@ public class PlatformDdl {
/**
* Mysql-specific: Locks all tables for triggers that have to be updated.
*/
public void lockTables(DdlBuffer buffer, Collection<String> tables) throws IOException {
public void lockTables(DdlBuffer buffer, Collection<String> tables) {
}
/**
* Mysql-specific: Unlocks all tables for triggers that have to be updated.
*/
public void unlockTables(DdlBuffer buffer, Collection<String> tables) throws IOException {
public void unlockTables(DdlBuffer buffer, Collection<String> tables) {
}
@@ -769,7 +768,7 @@ public class PlatformDdl {
return false;
}
public void addTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn) throws IOException {
public void addTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn) {
// only supported by postgres initially
}
}
@@ -6,8 +6,6 @@ import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
/**
* Defines the implementation for adding history support to a table.
*/
@@ -21,20 +19,20 @@ public interface PlatformHistoryDdl {
/**
* Creates a new table and add history support to the table using platform specific mechanism.
*/
void createWithHistory(DdlWrite writer, MTable table) throws IOException;
void createWithHistory(DdlWrite writer, MTable table);
/**
* Drop history support for the given table.
*/
void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException;
void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable);
/**
* Add history support to the given table.
*/
void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException;
void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable);
/**
* Regenerate the history triggers/stored function due to column added/dropped/included or excluded.
*/
void updateTriggers(DdlWrite write, HistoryTableUpdate baseTable) throws IOException;
void updateTriggers(DdlWrite write, HistoryTableUpdate baseTable);
}
@@ -3,8 +3,6 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import java.io.IOException;
/**
* Postgres specific DDL.
*/
@@ -40,7 +38,7 @@ public class PostgresDdl extends PlatformDdl {
}
@Override
public void addTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn) throws IOException {
public void addTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn) {
apply.append(" partition by range (").append(partitionColumn).append(")");
}
@@ -4,7 +4,6 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
import java.util.List;
/**
@@ -21,7 +20,7 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
* Use Postgres create table like to create the history table.
*/
@Override
protected void createHistoryTable(DdlBuffer apply, MTable table) throws IOException {
protected void createHistoryTable(DdlBuffer apply, MTable table) {
apply.append("create table ").append(table.getName()).append(historySuffix)
.append("(like ").append(table.getName()).append(")").endOfStatement();
}
@@ -30,7 +29,7 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
* Use Postgres range type rather than start and end timestamps.
*/
@Override
protected void addSysPeriodColumns(DdlBuffer apply, String baseTableName, String whenCreatedColumn) throws IOException {
protected void addSysPeriodColumns(DdlBuffer apply, String baseTableName, String whenCreatedColumn) {
apply
.append("alter table ").append(baseTableName)
.append(" add column ").append(sysPeriod).append(" tstzrange not null default tstzrange(").append(now).append(", null)")
@@ -43,17 +42,17 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void appendSysPeriodColumns(DdlBuffer apply, String prefix) throws IOException {
protected void appendSysPeriodColumns(DdlBuffer apply, String prefix) {
appendColumnName(apply, prefix, sysPeriod);
}
@Override
protected void dropSysPeriodColumns(DdlBuffer buffer, String baseTableName) throws IOException {
protected void dropSysPeriodColumns(DdlBuffer buffer, String baseTableName) {
buffer.append("alter table ").append(baseTableName).append(" drop column ").append(sysPeriod).endOfStatement();
}
@Override
protected void createTriggers(DdlWrite writer, MTable table) throws IOException {
protected void createTriggers(DdlWrite writer, MTable table) {
String baseTableName = table.getName();
String procedureName = procedureName(baseTableName);
String triggerName = triggerName(baseTableName);
@@ -66,14 +65,14 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void dropTriggers(DdlBuffer buffer, String baseTable) throws IOException {
protected void dropTriggers(DdlBuffer buffer, String baseTable) {
// rollback trigger then function
buffer.append("drop trigger if exists ").append(triggerName(baseTable)).append(" on ").append(baseTable).append(" cascade").endOfStatement();
buffer.append("drop function if exists ").append(procedureName(baseTable)).append("()").endOfStatement();
buffer.end();
}
protected void createOrReplaceFunction(DdlBuffer apply, String procedureName, String historyTable, List<String> includedColumns) throws IOException {
protected void createOrReplaceFunction(DdlBuffer apply, String procedureName, String historyTable, List<String> includedColumns) {
apply
.append("create or replace function ").append(procedureName).append("() returns trigger as $$").newLine();
@@ -105,7 +104,7 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void createStoredFunction(DdlWrite writer, MTable table) throws IOException {
protected void createStoredFunction(DdlWrite writer, MTable table) {
String procedureName = procedureName(table.getName());
String historyTable = historyTableName(table.getName());
@@ -114,14 +113,14 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
}
@Override
protected void updateHistoryTriggers(DbTriggerUpdate update) throws IOException {
protected void updateHistoryTriggers(DbTriggerUpdate update) {
String procedureName = procedureName(update.getBaseTable());
recreateHistoryView(update);
createOrReplaceFunction(update.historyTriggerBuffer(), procedureName, update.getHistoryTable(), update.getColumns());
}
@Override
protected void appendInsertIntoHistory(DdlBuffer buffer, String historyTable, List<String> columns) throws IOException {
protected void appendInsertIntoHistory(DdlBuffer buffer, String historyTable, List<String> columns) {
buffer.append(" insert into ").append(historyTable).append(" (").append(sysPeriod).append(",");
appendColumnNames(buffer, columns, "");
buffer.append(") values (tstzrange(lowerTs,upperTs), ");
@@ -6,8 +6,6 @@ import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import java.io.IOException;
/**
* MS SQL Server platform specific DDL.
*/
@@ -185,7 +183,7 @@ public class SqlServerDdl extends PlatformDdl {
* Add table comment as a separate statement (from the create table statement).
*/
@Override
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) throws IOException {
public void addTableComment(DdlBuffer apply, String tableName, String tableComment) {
// do nothing for MS SQL Server (cause it requires stored procedures etc)
}
@@ -194,7 +192,7 @@ public class SqlServerDdl extends PlatformDdl {
* Add column comment as a separate statement.
*/
@Override
public void addColumnComment(DdlBuffer apply, String table, String column, String comment) throws IOException {
public void addColumnComment(DdlBuffer apply, String table, String column, String comment) {
// do nothing for MS SQL Server (cause it requires stored procedures etc)
}
@@ -204,7 +202,7 @@ public class SqlServerDdl extends PlatformDdl {
* (constraints, default values, indices and foreign keys). That's why we call a user stored procedure here
*/
@Override
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) throws IOException {
public void alterTableDropColumn(DdlBuffer buffer, String tableName, String columnName) {
buffer.append("EXEC usp_ebean_drop_column ").append(tableName).append(", ").append(columnName).endOfStatement();
}
@@ -213,7 +211,7 @@ public class SqlServerDdl extends PlatformDdl {
* This writes the multi value datatypes needed for MultiValueBind.
*/
@Override
public void generateProlog(DdlWrite write) throws IOException {
public void generateProlog(DdlWrite write) {
super.generateProlog(write);
generateTVPDefinitions(write, "bigint");
@@ -227,7 +225,7 @@ public class SqlServerDdl extends PlatformDdl {
}
private void generateTVPDefinitions(DdlWrite write, String definition) throws IOException {
private void generateTVPDefinitions(DdlWrite write, String definition) {
int pos = definition.indexOf('(');
String name = pos == -1 ? definition : definition.substring(0, pos);
@@ -236,12 +234,12 @@ public class SqlServerDdl extends PlatformDdl {
//createTVP(write.apply(), name, definition);
}
private void dropTVP(DdlBuffer ddl, String name) throws IOException {
private void dropTVP(DdlBuffer ddl, String name) {
ddl.append("if exists (select name from sys.types where name = 'ebean_").append(name)
.append("_tvp') drop type ebean_").append(name).append("_tvp").endOfStatement();
}
private void createTVP(DdlBuffer ddl, String name, String definition) throws IOException {
private void createTVP(DdlBuffer ddl, String name, String definition) {
ddl.append("if not exists (select name from sys.types where name = 'ebean_").append(name)
.append("_tvp') create type ebean_").append(name).append("_tvp as table (c1 ").append(definition).append(")")
.endOfStatement();
@@ -7,8 +7,6 @@ import io.ebeaninternal.dbmigration.migration.AddHistoryTable;
import io.ebeaninternal.dbmigration.migration.DropHistoryTable;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
/**
* @author Vilmos Nagy
*/
@@ -26,7 +24,7 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void createWithHistory(DdlWrite writer, MTable table) throws IOException {
public void createWithHistory(DdlWrite writer, MTable table) {
String baseTable = table.getName();
enableSystemVersioning(writer, baseTable);
}
@@ -43,7 +41,7 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
return historyTable;
}
private void enableSystemVersioning(DdlWrite writer, String baseTable) throws IOException {
private void enableSystemVersioning(DdlWrite writer, String baseTable) {
DdlBuffer apply = writer.applyHistoryView();
apply.append("alter table ").append(baseTable).newLine()
.append(" add ").append(systemPeriodStart).append(" datetime2 GENERATED ALWAYS AS ROW START NOT NULL DEFAULT SYSUTCDATETIME(),").newLine()
@@ -59,7 +57,7 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException {
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) {
String baseTable = dropHistoryTable.getBaseTable();
DdlBuffer apply = writer.applyHistoryView();
apply.append("-- dropping history support for ").append(baseTable).endOfStatement();
@@ -78,13 +76,13 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
}
@Override
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException {
public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) {
String baseTable = addHistoryTable.getBaseTable();
enableSystemVersioning(writer, baseTable);
}
@Override
public void updateTriggers(DdlWrite writer, HistoryTableUpdate baseTable) throws IOException {
public void updateTriggers(DdlWrite writer, HistoryTableUpdate baseTable) {
// SQL Server 2016 does not need triggers
DdlBuffer apply = writer.applyHistoryView();
String baseTableName = baseTable.getBaseTable();
@@ -3,12 +3,10 @@ package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
import io.ebeaninternal.dbmigration.model.MTable;
import java.io.IOException;
public class YugabyteHistoryDdl extends PostgresHistoryDdl {
@Override
protected void createHistoryTable(DdlBuffer apply, MTable table) throws IOException {
protected void createHistoryTable(DdlBuffer apply, MTable table) {
createHistoryTableAs(apply, table);
writeColumnDefinition(apply, sysPeriod, "tstzrange");
apply.newLine().append(")").endOfStatement();