mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
Merge remote-tracking branch 'upstream/master'
# Conflicts: # ebean-core/src/main/java/io/ebeaninternal/server/deploy/TablespaceMeta.java # ebean-core/src/main/java/io/ebeaninternal/server/type/RsetDataReader.java # ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java # ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java # ebean-ddl-generator/src/test/java/io/ebeaninternal/dbmigration/model/ModelContainerApplyTest.java # ebean-test/src/test/java/misc/migration/v1_0/EBasic.java # ebean-test/src/test/java/misc/migration/v1_1/MtmChild.java # ebean-test/src/test/java/misc/migration/v1_1/MtmMaster.java # ebean-test/src/test/java/org/tests/json/TestDbJson_List.java # ebean-test/src/test/resources/extra-ddl.xml # ebean-test/src/test/resources/migrationtest/dbmigration/db2fori/idx_db2.migrations # ebean-test/src/test/resources/migrationtest/dbmigration/db2legacy/idx_db2.migrations # ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/I__create_tablespaces.sql # ebean-test/src/test/resources/migrationtest/dbmigration/db2luw/idx_db2.migrations # ebean-test/src/test/resources/migrationtest/dbmigration/db2zos/idx_db2.migrations # ebean-test/src/test/resources/migrationtest/dbmigration/model/1.0__initial.model.xml # ebean-test/src/test/resources/migrationtest/dbmigration/model/1.1.model.xml
This commit is contained in:
commit
0c6c1abb55
943 files changed
+2654
-1723
No files matched your search
+36
-28
@@ -4,7 +4,6 @@ import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebean.config.NamingConvention;
|
||||
import io.ebean.config.dbplatform.DbHistorySupport;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.util.StringHelper;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
|
||||
@@ -62,7 +61,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
|
||||
private final boolean strictMode;
|
||||
|
||||
private final boolean alterHistoryTables;
|
||||
private final PlatformHistoryDdl.TableBased tableHistory;
|
||||
|
||||
/**
|
||||
* Helper class that is used to execute the migration ddl before and after the migration action.
|
||||
@@ -181,11 +180,10 @@ public class BaseTableDdl implements TableDdl {
|
||||
this.platformDdl = platformDdl;
|
||||
this.platformDdl.configure(config);
|
||||
this.strictMode = config.isDdlStrictMode();
|
||||
DbHistorySupport hist = platformDdl.getPlatform().getHistorySupport();
|
||||
if (hist == null) {
|
||||
this.alterHistoryTables = false;
|
||||
if (platformDdl.historyDdl instanceof PlatformHistoryDdl.TableBased) {
|
||||
this.tableHistory = (PlatformHistoryDdl.TableBased) platformDdl.historyDdl;
|
||||
} else {
|
||||
this.alterHistoryTables = platformDdl.historyDdl.alterHistoryTables();
|
||||
this.tableHistory = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,9 +235,8 @@ public class BaseTableDdl implements TableDdl {
|
||||
writeInlineForeignKeys(apply, createTable);
|
||||
}
|
||||
apply.newLine().append(")");
|
||||
if (createTable.getTablespace() != null) {
|
||||
platformDdl.addTablespace(apply, createTable.getTablespace(), createTable.getIndexTablespace(), createTable.getLobTablespace());
|
||||
}
|
||||
|
||||
addTableTableSpaces(apply, createTable);
|
||||
addTableStorageEngine(apply, createTable);
|
||||
addTableCommentInline(apply, createTable);
|
||||
if (partitionMode != null) {
|
||||
@@ -271,6 +268,8 @@ public class BaseTableDdl implements TableDdl {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String sequenceName(CreateTable createTable, List<Column> pk) {
|
||||
return namingConvention.getSequenceName(createTable.getName(), pk.get(0).getName());
|
||||
}
|
||||
@@ -292,6 +291,19 @@ public class BaseTableDdl implements TableDdl {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tablespace declaration.
|
||||
*/
|
||||
protected void addTableTableSpaces(DdlBuffer apply, CreateTable createTable) {
|
||||
String tableSpace = platformDdl.extract(createTable.getTablespace());
|
||||
if (hasValue(tableSpace)) {
|
||||
platformDdl.addTablespace(apply,
|
||||
tableSpace,
|
||||
platformDdl.extract(createTable.getIndexTablespace()),
|
||||
platformDdl.extract(createTable.getLobTablespace()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the table storage engine clause.
|
||||
*/
|
||||
@@ -621,8 +633,8 @@ public class BaseTableDdl implements TableDdl {
|
||||
if (isTrue(addColumn.isWithHistory())) {
|
||||
platformDdl.regenerateHistoryTriggers(writer, tableName);
|
||||
// make same changes to the history table
|
||||
if (alterHistoryTables) {
|
||||
String historyTable = historyTable(tableName);
|
||||
if (tableHistory != null) {
|
||||
String historyTable = tableHistory.historyTableName(tableName);
|
||||
for (Column column : columns) {
|
||||
alterTableAddColumn(writer, historyTable, column, true, true);
|
||||
}
|
||||
@@ -656,14 +668,17 @@ public class BaseTableDdl implements TableDdl {
|
||||
*/
|
||||
@Override
|
||||
public void generate(DdlWrite writer, AlterTable alterTable) {
|
||||
if (hasValue(alterTable.getTablespace())
|
||||
|| hasValue(alterTable.getIndexTablespace())
|
||||
|| hasValue(alterTable.getLobTablespace())) {
|
||||
String tableSpace = platformDdl.extract(alterTable.getTablespace());
|
||||
String indexSpace = platformDdl.extract(alterTable.getIndexTablespace());
|
||||
String lobSpace = platformDdl.extract(alterTable.getLobTablespace());
|
||||
if (hasValue(tableSpace)
|
||||
|| hasValue(indexSpace)
|
||||
|| hasValue(lobSpace)) {
|
||||
|
||||
writer.apply().appendStatement(platformDdl.alterTableTablespace(alterTable.getName(),
|
||||
DdlHelp.toTablespace(alterTable.getTablespace()),
|
||||
DdlHelp.toTablespace(alterTable.getIndexTablespace()),
|
||||
DdlHelp.toTablespace(alterTable.getLobTablespace())));
|
||||
DdlHelp.toTablespace(tableSpace),
|
||||
DdlHelp.toTablespace(indexSpace),
|
||||
DdlHelp.toTablespace(lobSpace)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -678,8 +693,8 @@ public class BaseTableDdl implements TableDdl {
|
||||
if (isTrue(dropColumn.isWithHistory())) {
|
||||
platformDdl.regenerateHistoryTriggers(writer, tableName);
|
||||
// also drop from the history table
|
||||
if (alterHistoryTables) {
|
||||
alterTableDropColumn(writer, historyTable(tableName), dropColumn.getColumnName());
|
||||
if (tableHistory != null) {
|
||||
alterTableDropColumn(writer, tableHistory.historyTableName(tableName), dropColumn.getColumnName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -757,13 +772,6 @@ public class BaseTableDdl implements TableDdl {
|
||||
platformDdl.addColumnComment(writer.applyPostAlter(), alterColumn.getTableName(), alterColumn.getColumnName(), alterColumn.getComment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the history table given the base table name.
|
||||
*/
|
||||
protected String historyTable(String baseTable) {
|
||||
return naming.normaliseTable(baseTable) + historyTableSuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* alter all the base attributes (type/default/notnull) of the column together.
|
||||
* Some platforms (like mysql/sqlserver/hana) must do that in one statement,
|
||||
@@ -784,9 +792,9 @@ public class BaseTableDdl implements TableDdl {
|
||||
}
|
||||
if (applyToHistory) {
|
||||
platformDdl.regenerateHistoryTriggers(writer, alter.getTableName());
|
||||
if (alterHistoryTables) {
|
||||
if (tableHistory != null) {
|
||||
AlterColumn alterHistoryColumn = new AlterColumn();
|
||||
alterHistoryColumn.setTableName(historyTable(alter.getTableName()));
|
||||
alterHistoryColumn.setTableName(tableHistory.historyTableName(alter.getTableName()));
|
||||
alterHistoryColumn.setColumnName(alter.getColumnName());
|
||||
// ignore default value (not needed on history tables)
|
||||
alterHistoryColumn.setCurrentType(alter.getCurrentType());
|
||||
|
||||
+12
-4
@@ -104,15 +104,21 @@ public class DB2Ddl extends PlatformDdl {
|
||||
+ "\n" + dropIndex(uniqueConstraintName, tableName);
|
||||
}
|
||||
|
||||
private void assertNoSchema(String objName) {
|
||||
if (objName.indexOf('.') != -1) {
|
||||
throw new UnsupportedOperationException("Schemas are not yet supported. ObjectName: '" + objName + "'");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String alterTableDropConstraint(String tableName, String constraintName) {
|
||||
assertNoSchema(tableName);
|
||||
StringBuilder sb = new StringBuilder(300);
|
||||
sb.append("delimiter $$\n")
|
||||
.append("begin\n")
|
||||
.append("if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = '")
|
||||
.append("if exists (select constname from syscat.tabconst where tabschema = current_schema and ucase(constname) = '")
|
||||
.append(maxConstraintName(constraintName).toUpperCase())
|
||||
|
||||
.append("' and tabname = '").append(naming.normaliseTable(tableName).toUpperCase()).append("') then\n")
|
||||
.append("' and ucase(tabname) = '").append(naming.normaliseTable(tableName).toUpperCase()).append("') then\n")
|
||||
|
||||
.append(" prepare stmt from 'alter table ").append(tableName)
|
||||
.append(" drop constraint ").append(maxConstraintName(constraintName)).append("';\n")
|
||||
@@ -126,10 +132,11 @@ public class DB2Ddl extends PlatformDdl {
|
||||
|
||||
@Override
|
||||
public String dropIndex(String indexName, String tableName, boolean concurrent) {
|
||||
assertNoSchema(indexName);
|
||||
StringBuilder sb = new StringBuilder(300);
|
||||
sb.append("delimiter $$\n")
|
||||
.append("begin\n")
|
||||
.append("if exists (select indname from syscat.indexes where indschema = current_schema and indname = '")
|
||||
.append("if exists (select indname from syscat.indexes where indschema = current_schema and ucase(indname) = '")
|
||||
.append(maxConstraintName(indexName).toUpperCase()).append("') then\n")
|
||||
.append(" prepare stmt from 'drop index ").append(maxConstraintName(indexName)).append("';\n")
|
||||
.append(" execute stmt;\n")
|
||||
@@ -140,10 +147,11 @@ public class DB2Ddl extends PlatformDdl {
|
||||
|
||||
@Override
|
||||
public String dropSequence(String sequenceName) {
|
||||
assertNoSchema(sequenceName);
|
||||
StringBuilder sb = new StringBuilder(300);
|
||||
sb.append("delimiter $$\n");
|
||||
sb.append("begin\n");
|
||||
sb.append("if exists (select seqschema from syscat.sequences where seqschema = current_schema and seqname = '")
|
||||
sb.append("if exists (select seqschema from syscat.sequences where seqschema = current_schema and ucase(seqname) = '")
|
||||
.append(maxConstraintName(sequenceName).toUpperCase()).append("') then\n");
|
||||
sb.append(" prepare stmt from 'drop sequence ").append(maxConstraintName(sequenceName)).append("';\n");
|
||||
sb.append(" execute stmt;\n");
|
||||
|
||||
+18
-21
@@ -1,7 +1,6 @@
|
||||
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
|
||||
@@ -14,35 +13,41 @@ import io.ebeaninternal.dbmigration.model.MTable;
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*/
|
||||
public class Db2HistoryDdl implements PlatformHistoryDdl {
|
||||
public class Db2HistoryDdl extends DbTableBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
|
||||
private String systemPeriodStart;
|
||||
private String systemPeriodEnd;
|
||||
private String transactionId;
|
||||
private PlatformDdl platformDdl;
|
||||
private DbConstraintNaming constraintNaming;
|
||||
private String historySuffix;
|
||||
|
||||
@Override
|
||||
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
|
||||
super.configure(config, platformDdl);
|
||||
this.systemPeriodStart = config.getAsOfSysPeriod() + "_start";
|
||||
this.systemPeriodEnd = config.getAsOfSysPeriod() + "_end";
|
||||
this.transactionId = config.getAsOfSysPeriod() + "_txn"; // required for DB2
|
||||
this.platformDdl = platformDdl;
|
||||
this.constraintNaming = config.getConstraintNaming();
|
||||
this.historySuffix = config.getHistoryTableSuffix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createWithHistory(DdlWrite writer, MTable table) {
|
||||
String tableName = table.getName();
|
||||
String historyTableName = historyTable(tableName);
|
||||
String historyTableName = historyTableName(tableName);
|
||||
|
||||
// DB2 requires an EXACT copy (same column types with null/non-null, same order)
|
||||
addSysPeriodColumns(writer, tableName);
|
||||
writer.applyPostAlter().append("create table ").append(historyTableName)
|
||||
.append(" as (select * from ").append(tableName).append(") with no data").endOfStatement();
|
||||
DdlBuffer tableBuf = writer.applyPostAlter();
|
||||
tableBuf.append("create table ").append(historyTableName)
|
||||
.append(" as (select * from ").append(tableName).append(") with no data");
|
||||
|
||||
if (table.getTablespaceMeta() != null) {
|
||||
String tableSpace = platformDdl.extract(table.getTablespaceMeta().getTablespaceName());
|
||||
if (tableSpace != null && !tableSpace.isEmpty()) {
|
||||
platformDdl.addTablespace(tableBuf,
|
||||
tableSpace,
|
||||
platformDdl.extract(table.getTablespaceMeta().getIndexTablespace()),
|
||||
platformDdl.extract(table.getTablespaceMeta().getLobTablespace()));
|
||||
}
|
||||
}
|
||||
tableBuf.endOfStatement();
|
||||
enableSystemVersioning(writer.applyPostAlter(), tableName);
|
||||
platformDdl.alterTable(writer, tableName).setHistoryHandled();
|
||||
|
||||
@@ -74,7 +79,7 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
|
||||
platformDdl.alterTableDropColumn(writer, baseTable, transactionId);
|
||||
|
||||
// drop the history table
|
||||
writer.applyPostAlter().append("drop table ").append(historyTable(baseTable)).endOfStatement();
|
||||
writer.applyPostAlter().append("drop table ").append(historyTableName(baseTable)).endOfStatement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,10 +91,6 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
|
||||
createWithHistory(writer, table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alterHistoryTables() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTriggers(DdlWrite writer, String tableName) {
|
||||
@@ -107,11 +108,7 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
|
||||
}
|
||||
|
||||
public void enableSystemVersioning(DdlBuffer apply, String tableName) {
|
||||
apply.append("alter table ").append(tableName).append(" add versioning use history table ").append(historyTable(tableName)).endOfStatement();
|
||||
}
|
||||
|
||||
protected String historyTable(String tableName) {
|
||||
return constraintNaming.normaliseTable(tableName) + historySuffix;
|
||||
apply.append("alter table ").append(tableName).append(" add versioning use history table ").append(historyTableName(tableName)).endOfStatement();
|
||||
}
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
|
||||
/**
|
||||
* Base implementation for all histories, where we must maintain history table (trigger based, db2 and hana)
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*
|
||||
*/
|
||||
public abstract class DbTableBasedHistoryDdl implements PlatformHistoryDdl.TableBased {
|
||||
|
||||
private DbConstraintNaming constraintNaming;
|
||||
private String historySuffix;
|
||||
protected PlatformDdl platformDdl;
|
||||
|
||||
@Override
|
||||
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
|
||||
this.platformDdl = platformDdl;
|
||||
this.historySuffix = config.getHistoryTableSuffix();
|
||||
this.constraintNaming = config.getConstraintNaming();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String historyTableName(String baseTableName) {
|
||||
return normalise(baseTableName, historySuffix);
|
||||
}
|
||||
|
||||
protected String normalise(String tableName, String suffix) {
|
||||
String normalized = quote(normalise(tableName) + suffix);
|
||||
int lastPeriod = tableName.lastIndexOf('.');
|
||||
return tableName.substring(0, lastPeriod + 1) + normalized;
|
||||
}
|
||||
|
||||
protected String normalise(String tableName) {
|
||||
return constraintNaming.normaliseTable(tableName);
|
||||
}
|
||||
|
||||
protected String quote(String dbName) {
|
||||
return platformDdl.quote(dbName);
|
||||
}
|
||||
|
||||
}
|
||||
+11
-32
@@ -1,7 +1,6 @@
|
||||
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
|
||||
@@ -15,18 +14,14 @@ import java.util.List;
|
||||
/**
|
||||
* Uses DB triggers to maintain a history table.
|
||||
*/
|
||||
public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
|
||||
protected DbConstraintNaming constraintNaming;
|
||||
|
||||
protected PlatformDdl platformDdl;
|
||||
public abstract class DbTriggerBasedHistoryDdl extends DbTableBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
|
||||
protected String sysPeriod;
|
||||
protected String sysPeriodStart;
|
||||
protected String sysPeriodEnd;
|
||||
|
||||
protected String viewSuffix;
|
||||
protected String historySuffix;
|
||||
|
||||
|
||||
protected String sysPeriodType = "datetime(6)";
|
||||
protected String now = "now(6)";
|
||||
@@ -37,11 +32,9 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
|
||||
@Override
|
||||
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
|
||||
this.platformDdl = platformDdl;
|
||||
super.configure(config, platformDdl);
|
||||
this.sysPeriod = config.getAsOfSysPeriod();
|
||||
this.viewSuffix = config.getAsOfViewSuffix();
|
||||
this.historySuffix = config.getHistoryTableSuffix();
|
||||
this.constraintNaming = config.getConstraintNaming();
|
||||
|
||||
this.sysPeriodStart = sysPeriod + "_start";
|
||||
this.sysPeriodEnd = sysPeriod + "_end";
|
||||
@@ -121,33 +114,24 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
|
||||
protected abstract void dropTriggers(DdlBuffer buffer, String baseTable);
|
||||
|
||||
|
||||
protected String normalise(String tableName) {
|
||||
return constraintNaming.normaliseTable(tableName);
|
||||
}
|
||||
|
||||
protected String historyTableName(String baseTableName) {
|
||||
return quote(normalise(baseTableName) + historySuffix);
|
||||
}
|
||||
|
||||
protected String historyViewName(String baseTableName) {
|
||||
return quote(normalise(baseTableName) + viewSuffix);
|
||||
return normalise(baseTableName, viewSuffix);
|
||||
}
|
||||
|
||||
protected String procedureName(String baseTableName) {
|
||||
return normalise(baseTableName) + "_history_version";
|
||||
return normalise(baseTableName, "_history_version");
|
||||
}
|
||||
|
||||
protected String triggerName(String baseTableName) {
|
||||
return normalise(baseTableName) + "_history_upd";
|
||||
return normalise(baseTableName, "_history_upd");
|
||||
}
|
||||
|
||||
protected String updateTriggerName(String baseTableName) {
|
||||
return normalise(baseTableName) + "_history_upd";
|
||||
return normalise(baseTableName, "_history_upd");
|
||||
}
|
||||
|
||||
protected String deleteTriggerName(String baseTableName) {
|
||||
return normalise(baseTableName) + "_history_del";
|
||||
return normalise(baseTableName, "_history_del");
|
||||
}
|
||||
|
||||
protected void addSysPeriodColumns(DdlWrite writer, String baseTableName, String whenCreatedColumn) {
|
||||
@@ -163,6 +147,8 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
protected void createHistoryTable(DdlBuffer apply, MTable table) {
|
||||
createHistoryTableAs(apply, table);
|
||||
createHistoryTableWithPeriod(apply);
|
||||
// TODO: add tablespace here (currently no DbTriggerBased platforms with tablespace support)
|
||||
apply.endOfStatement();
|
||||
}
|
||||
|
||||
protected void createHistoryTableAs(DdlBuffer apply, MTable table) {
|
||||
@@ -183,7 +169,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
writeColumnDefinition(apply, sysPeriodStart, sysPeriodType);
|
||||
apply.append(",").newLine();
|
||||
writeColumnDefinition(apply, sysPeriodEnd, sysPeriodType);
|
||||
apply.newLine().append(")").endOfStatement();
|
||||
apply.newLine().append(")");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,12 +250,5 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
return table.allHistoryColumns(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alterHistoryTables() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected String quote(String dbName) {
|
||||
return platformDdl.quote(dbName);
|
||||
}
|
||||
}
|
||||
+2
-16
@@ -1,7 +1,6 @@
|
||||
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlAlterTable;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer;
|
||||
import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite;
|
||||
@@ -12,21 +11,16 @@ import io.ebeaninternal.dbmigration.model.MTable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class HanaHistoryDdl implements PlatformHistoryDdl {
|
||||
public class HanaHistoryDdl extends DbTableBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
|
||||
private String systemPeriodStart;
|
||||
private String systemPeriodEnd;
|
||||
private PlatformDdl platformDdl;
|
||||
private DbConstraintNaming constraintNaming;
|
||||
private String historySuffix;
|
||||
|
||||
@Override
|
||||
public void configure(DatabaseConfig config, PlatformDdl platformDdl) {
|
||||
super.configure(config, platformDdl);
|
||||
this.systemPeriodStart = config.getAsOfSysPeriod() + "_start";
|
||||
this.systemPeriodEnd = config.getAsOfSysPeriod() + "_end";
|
||||
this.platformDdl = platformDdl;
|
||||
this.constraintNaming = config.getConstraintNaming();
|
||||
this.historySuffix = config.getHistoryTableSuffix();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,11 +89,6 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
|
||||
createWithHistory(writer, table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alterHistoryTables() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTriggers(DdlWrite writer, String tableName) {
|
||||
DdlAlterTable alter = platformDdl.alterTable(writer, tableName);
|
||||
@@ -140,8 +129,5 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
|
||||
apply.endOfStatement();
|
||||
}
|
||||
|
||||
protected String historyTableName(String tableName) {
|
||||
return constraintNaming.normaliseTable(tableName) + historySuffix;
|
||||
}
|
||||
|
||||
}
|
||||
+17
-12
@@ -317,10 +317,13 @@ public class PlatformDdl {
|
||||
// if columnType is different for different platforms, use pattern
|
||||
// @Column(columnDefinition = PLATFORM1;DEFINITION1;PLATFORM2;DEFINITON2;DEFINITON-DEFAULT)
|
||||
// e.g. @Column(columnDefinition = "db2;blob(64M);sqlserver,h2;varchar(227);varchar(127)")
|
||||
private String extract(String type) {
|
||||
String[] tmp = type.split(";");
|
||||
protected String extract(String type) {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
String[] tmp = type.split(";", -1); // do not discard trailing empty strings
|
||||
if (tmp.length % 2 == 0) {
|
||||
throw new IllegalArgumentException("You need an odd number of arguments. See Issue #2559 for details");
|
||||
throw new IllegalArgumentException("You need an odd number of arguments in '" + type + "'. See Issue #2559 for details");
|
||||
}
|
||||
for (int i = 0; i < tmp.length - 2; i += 2) {
|
||||
String[] platforms = tmp[i].split(",");
|
||||
@@ -518,13 +521,6 @@ public class PlatformDdl {
|
||||
return "alter table " + quote(tableName) + " " + dropConstraintIfExists + " " + maxConstraintName(constraintName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the table to an other tablespace.
|
||||
*/
|
||||
public String alterTableTablespace(String tablename, String tableSpace, String indexSpace, String lobSpace) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a unique constraint to the table.
|
||||
* <p>
|
||||
@@ -793,10 +789,19 @@ public class PlatformDdl {
|
||||
|
||||
/**
|
||||
* Adds tablespace declaration. Now only supported for db2.
|
||||
* @throws IOException
|
||||
*/
|
||||
public void addTablespace(DdlBuffer apply, String tablespaceName, String indexTablespace, String lobTablespace) {
|
||||
// now only supported for db2
|
||||
throw new UnsupportedOperationException("Tablespaces are not supported for this platform");
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the table to an other tablespace.
|
||||
*/
|
||||
public String alterTableTablespace(String tablename, String tableSpace, String indexSpace, String lobSpace) {
|
||||
if (tableSpace != null || indexSpace != null || lobSpace != null) {
|
||||
throw new UnsupportedOperationException("Tablespaces are not supported for this platform");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String quote(String dbName) {
|
||||
|
||||
+11
-8
@@ -31,14 +31,6 @@ public interface PlatformHistoryDdl {
|
||||
*/
|
||||
void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable);
|
||||
|
||||
/**
|
||||
* Returns true, if alters on the live tables should be applied also to the history tables. This is required for DbTriggerBased
|
||||
* histories or on platforms like Hana, which are not SQL2011 history compatible (at least from DDL perspective)
|
||||
*/
|
||||
default boolean alterHistoryTables() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate the history triggers/stored function due to column added/dropped/included or excluded.
|
||||
*
|
||||
@@ -47,4 +39,15 @@ public interface PlatformHistoryDdl {
|
||||
default void updateTriggers(DdlWrite writer, String tableName) {
|
||||
// nop
|
||||
}
|
||||
|
||||
/**
|
||||
* When history is table based, then alters on the live tables are applied also to the history tables. This is required for
|
||||
* DbTriggerBased histories or on platforms like Hana, which are not SQL2011 history compatible (at least from DDL perspective)
|
||||
*/
|
||||
interface TableBased extends PlatformHistoryDdl {
|
||||
/**
|
||||
* Returns the history table name with propert quotes.
|
||||
*/
|
||||
public String historyTableName(String baseTableName);
|
||||
}
|
||||
}
|
||||
+19
@@ -107,4 +107,23 @@ public class PostgresHistoryDdl extends DbTriggerBasedHistoryDdl {
|
||||
buffer.append(");").newLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String procedureName(String baseTableName) {
|
||||
return normalise(baseTableName) + "_history_version";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String triggerName(String baseTableName) {
|
||||
return normalise(baseTableName) + "_history_upd";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String updateTriggerName(String baseTableName) {
|
||||
return normalise(baseTableName) + "_history_upd";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String deleteTriggerName(String baseTableName) {
|
||||
return normalise(baseTableName) + "_history_del";
|
||||
}
|
||||
}
|
||||
+17
@@ -4,6 +4,7 @@ import io.localtest.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.config.dbplatform.db2.DB2LuwPlatform;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.hana.HanaPlatform;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
@@ -42,6 +43,9 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
return handler(new HanaPlatform());
|
||||
}
|
||||
|
||||
private DdlHandler db2Handler() {
|
||||
return handler(new DB2LuwPlatform());
|
||||
}
|
||||
@Test
|
||||
public void addColumn_nullable_noConstraint() throws Exception {
|
||||
|
||||
@@ -219,6 +223,19 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
assertThat(writer.dropAll().getBuffer().trim()).isEqualTo("drop table foo cascade;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTableWithTableSpace() throws Exception {
|
||||
|
||||
DdlWrite writer = new DdlWrite();
|
||||
DdlHandler handler = db2Handler();
|
||||
|
||||
handler.generate(writer, Helper.getCreateTable());
|
||||
|
||||
assertThat(writer.toString())
|
||||
.contains("create table foo (")
|
||||
.contains(") in fooSpace index in fooIndexSpace long in fooLobSpace;");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateChangeSet() throws Exception {
|
||||
|
||||
|
||||
+3
-2
@@ -34,8 +34,9 @@ public class ModelContainerApplyTest {
|
||||
|
||||
MTable foo = model.getTable("foo");
|
||||
assertThat(foo.getComment()).isEqualTo("comment");
|
||||
assertThat(foo.getTablespaceMeta().getTablespaceName()).isEqualTo("fooSpace");
|
||||
assertThat(foo.getTablespaceMeta().getIndexTablespace()).isEqualTo("fooIndexSpace");
|
||||
assertThat(foo.getTablespaceMeta().getTablespaceName()).isEqualTo("db2;fooSpace;");
|
||||
assertThat(foo.getTablespaceMeta().getIndexTablespace()).isEqualTo("db2;fooIndexSpace;");
|
||||
assertThat(foo.getTablespaceMeta().getLobTablespace()).isEqualTo("db2;fooLobSpace;");
|
||||
assertThat(foo.isWithHistory()).isEqualTo(false);
|
||||
assertThat(foo.allColumns()).extracting("name").contains("col1", "col3", "added_to_foo");
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<changeSet type="apply">
|
||||
|
||||
<createTable name="foo" pkName="pk_foo" withHistory="false" tablespace="fooSpace" indexTablespace="fooIndexSpace" comment="comment">
|
||||
<createTable name="foo" pkName="pk_foo" withHistory="false" tablespace="db2;fooSpace;" indexTablespace="db2;fooIndexSpace;" lobTablespace="db2;fooLobSpace;" comment="comment">
|
||||
<column name="col1" type="varchar(4)" notnull="true" primaryKey="true"/>
|
||||
<column name="col2" type="varchar(30)" notnull="true"/>
|
||||
<column name="col3" type="varchar(30)" notnull="true"/>
|
||||
|
||||
Reference in new issue
Block a user