diff --git a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/BaseDdlHandler.java b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/BaseDdlHandler.java index bb3d8ed5b..c1e27faf0 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/BaseDdlHandler.java +++ b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/BaseDdlHandler.java @@ -5,6 +5,7 @@ import com.avaje.ebean.dbmigration.ddlgeneration.platform.BaseTableDdl; import com.avaje.ebean.dbmigration.ddlgeneration.platform.PlatformDdl; import com.avaje.ebean.dbmigration.migration.AddColumn; import com.avaje.ebean.dbmigration.migration.AddHistoryTable; +import com.avaje.ebean.dbmigration.migration.AddTableComment; import com.avaje.ebean.dbmigration.migration.AlterColumn; import com.avaje.ebean.dbmigration.migration.ChangeSet; import com.avaje.ebean.dbmigration.migration.CreateIndex; @@ -37,6 +38,8 @@ public class BaseDdlHandler implements DdlHandler { generate(writer, (CreateTable) change); } else if (change instanceof DropTable) { generate(writer, (DropTable) change); + } else if (change instanceof AddTableComment) { + generate(writer, (AddTableComment) change); } else if (change instanceof CreateIndex) { generate(writer, (CreateIndex) change); } else if (change instanceof DropIndex) { @@ -70,6 +73,11 @@ public class BaseDdlHandler implements DdlHandler { tableDdl.generate(writer, dropTable); } + @Override + public void generate(DdlWrite writer, AddTableComment addTableComment) throws IOException { + tableDdl.generate(writer, addTableComment); + } + @Override public void generate(DdlWrite writer, AddColumn addColumn) throws IOException { tableDdl.generate(writer, addColumn); diff --git a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/DdlHandler.java b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/DdlHandler.java index 2f929122c..0285fa47e 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/DdlHandler.java +++ b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/DdlHandler.java @@ -2,6 +2,7 @@ package com.avaje.ebean.dbmigration.ddlgeneration; import com.avaje.ebean.dbmigration.migration.AddColumn; import com.avaje.ebean.dbmigration.migration.AddHistoryTable; +import com.avaje.ebean.dbmigration.migration.AddTableComment; import com.avaje.ebean.dbmigration.migration.AlterColumn; import com.avaje.ebean.dbmigration.migration.ChangeSet; import com.avaje.ebean.dbmigration.migration.CreateIndex; @@ -14,6 +15,7 @@ import com.avaje.ebean.dbmigration.migration.DropTable; import java.io.IOException; /** + * DDL generation interface. */ public interface DdlHandler { @@ -23,6 +25,8 @@ public interface DdlHandler { void generate(DdlWrite writer, DropTable dropTable) throws IOException; + void generate(DdlWrite writer, AddTableComment addTableComment) throws IOException; + void generate(DdlWrite writer, AddColumn addColumn) throws IOException; void generate(DdlWrite writer, DropColumn dropColumn) throws IOException; diff --git a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/TableDdl.java b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/TableDdl.java index 1fa2b2e9f..ba080cae2 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/TableDdl.java +++ b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/TableDdl.java @@ -2,6 +2,7 @@ package com.avaje.ebean.dbmigration.ddlgeneration; import com.avaje.ebean.dbmigration.migration.AddColumn; import com.avaje.ebean.dbmigration.migration.AddHistoryTable; +import com.avaje.ebean.dbmigration.migration.AddTableComment; import com.avaje.ebean.dbmigration.migration.AlterColumn; import com.avaje.ebean.dbmigration.migration.CreateIndex; import com.avaje.ebean.dbmigration.migration.CreateTable; @@ -42,6 +43,11 @@ public interface TableDdl { */ void generate(DdlWrite writer, DropColumn dropColumn) throws IOException; + /** + * Write the AddTableComment change. + */ + void generate(DdlWrite writer, AddTableComment addTableComment) throws IOException; + /** * Write the AddHistoryTable change. */ diff --git a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/BaseTableDdl.java b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/BaseTableDdl.java index cb26d5433..c20d09fe5 100644 --- a/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/BaseTableDdl.java +++ b/src/main/java/com/avaje/ebean/dbmigration/ddlgeneration/platform/BaseTableDdl.java @@ -10,6 +10,7 @@ import com.avaje.ebean.dbmigration.ddlgeneration.TableDdl; import com.avaje.ebean.dbmigration.ddlgeneration.platform.util.IndexSet; import com.avaje.ebean.dbmigration.migration.AddColumn; import com.avaje.ebean.dbmigration.migration.AddHistoryTable; +import com.avaje.ebean.dbmigration.migration.AddTableComment; import com.avaje.ebean.dbmigration.migration.AlterColumn; import com.avaje.ebean.dbmigration.migration.Column; import com.avaje.ebean.dbmigration.migration.CreateIndex; @@ -554,6 +555,13 @@ public class BaseTableDdl implements TableDdl { } } + @Override + public void generate(DdlWrite writer, AddTableComment addTableComment) throws IOException { + if (hasValue(addTableComment.getComment())) { + platformDdl.addTableComment(writer.apply(), addTableComment.getName(), addTableComment.getComment()); + } + } + /** * Add add column DDL. */ @@ -634,7 +642,9 @@ public class BaseTableDdl implements TableDdl { if (hasValue(alterColumn.getUniqueOneToOne())) { alterColumnAddUniqueOneToOneConstraint(writer, alterColumn); } - + if (hasValue(alterColumn.getComment())) { + alterColumnComment(writer, alterColumn); + } boolean alterCheckConstraint = hasValue(alterColumn.getCheckConstraint()); @@ -664,6 +674,10 @@ public class BaseTableDdl implements TableDdl { } } + private void alterColumnComment(DdlWrite writer, AlterColumn alterColumn) throws IOException { + platformDdl.addColumnComment(writer.apply(), alterColumn.getTableName(), alterColumn.getColumnName(), alterColumn.getComment()); + } + /** * Return the name of the history table given the base table name. */ diff --git a/src/main/java/com/avaje/ebean/dbmigration/migration/AddTableComment.java b/src/main/java/com/avaje/ebean/dbmigration/migration/AddTableComment.java new file mode 100644 index 000000000..40d50c625 --- /dev/null +++ b/src/main/java/com/avaje/ebean/dbmigration/migration/AddTableComment.java @@ -0,0 +1,87 @@ + +package com.avaje.ebean.dbmigration.migration; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *
Java class for anonymous complex type. + * + *
The following schema fragment specifies the expected content contained within this class. + * + *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="comment" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "")
+@XmlRootElement(name = "addTableComment")
+public class AddTableComment {
+
+ @XmlAttribute(name = "name", required = true)
+ protected String name;
+ @XmlAttribute(name = "comment", required = true)
+ protected String comment;
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setName(String value) {
+ this.name = value;
+ }
+
+ /**
+ * Gets the value of the comment property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getComment() {
+ return comment;
+ }
+
+ /**
+ * Sets the value of the comment property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setComment(String value) {
+ this.comment = value;
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebean/dbmigration/migration/AlterColumn.java b/src/main/java/com/avaje/ebean/dbmigration/migration/AlterColumn.java
index 90c86842a..7f8c683ca 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/migration/AlterColumn.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/migration/AlterColumn.java
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlType;
* <attribute name="currentDefaultValue" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="notnull" type="{http://www.w3.org/2001/XMLSchema}boolean" />
* <attribute name="currentNotnull" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ * <attribute name="comment" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="historyExclude" type="{http://www.w3.org/2001/XMLSchema}boolean" />
* <attribute name="checkConstraint" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="checkConstraintName" type="{http://www.w3.org/2001/XMLSchema}string" />
@@ -68,6 +69,8 @@ public class AlterColumn {
protected Boolean notnull;
@XmlAttribute(name = "currentNotnull")
protected Boolean currentNotnull;
+ @XmlAttribute(name = "comment")
+ protected String comment;
@XmlAttribute(name = "historyExclude")
protected Boolean historyExclude;
@XmlAttribute(name = "checkConstraint")
@@ -309,6 +312,30 @@ public class AlterColumn {
this.currentNotnull = value;
}
+ /**
+ * Gets the value of the comment property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getComment() {
+ return comment;
+ }
+
+ /**
+ * Sets the value of the comment property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setComment(String value) {
+ this.comment = value;
+ }
+
/**
* Gets the value of the historyExclude property.
*
diff --git a/src/main/java/com/avaje/ebean/dbmigration/migration/ChangeSet.java b/src/main/java/com/avaje/ebean/dbmigration/migration/ChangeSet.java
index 4db9e88c2..8341525c5 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/migration/ChangeSet.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/migration/ChangeSet.java
@@ -52,6 +52,7 @@ public class ChangeSet {
@XmlElement(name = "createTable", type = CreateTable.class),
@XmlElement(name = "dropTable", type = DropTable.class),
@XmlElement(name = "renameTable", type = RenameTable.class),
+ @XmlElement(name = "addTableComment", type = AddTableComment.class),
@XmlElement(name = "addHistoryTable", type = AddHistoryTable.class),
@XmlElement(name = "dropHistoryTable", type = DropHistoryTable.class),
@XmlElement(name = "addColumn", type = AddColumn.class),
@@ -98,6 +99,7 @@ public class ChangeSet {
* {@link CreateTable }
* {@link DropTable }
* {@link RenameTable }
+ * {@link AddTableComment }
* {@link AddHistoryTable }
* {@link DropHistoryTable }
* {@link AddColumn }
diff --git a/src/main/java/com/avaje/ebean/dbmigration/migration/ObjectFactory.java b/src/main/java/com/avaje/ebean/dbmigration/migration/ObjectFactory.java
index c285edd1d..632e62006 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/migration/ObjectFactory.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/migration/ObjectFactory.java
@@ -101,6 +101,14 @@ public class ObjectFactory {
return new DefaultTablespace();
}
+ /**
+ * Create an instance of {@link AddTableComment }
+ *
+ */
+ public AddTableComment createAddTableComment() {
+ return new AddTableComment();
+ }
+
/**
* Create an instance of {@link RenameTable }
*
diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/MColumn.java b/src/main/java/com/avaje/ebean/dbmigration/model/MColumn.java
index 20e5eb3a0..286261ca7 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/model/MColumn.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/model/MColumn.java
@@ -260,7 +260,7 @@ public class MColumn {
return c;
}
- private boolean different(String val1, String val2) {
+ protected static boolean different(String val1, String val2) {
return (val1 == null) ? val2 != null : !val1.equals(val2);
}
@@ -314,7 +314,10 @@ public class MColumn {
alter.setDefaultValue(newColumn.defaultValue);
}
}
-
+ if (different(comment, newColumn.comment)) {
+ AlterColumn alter = getAlterColumn(tableName, tableWithHistory);
+ alter.setComment(newColumn.comment);
+ }
if (different(checkConstraint, newColumn.checkConstraint)) {
AlterColumn alter = getAlterColumn(tableName, tableWithHistory);
if (hasValue(checkConstraint) && !hasValue(newColumn.checkConstraint)) {
diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/MTable.java b/src/main/java/com/avaje/ebean/dbmigration/model/MTable.java
index 343d8f65b..d1753f6a5 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/model/MTable.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/model/MTable.java
@@ -2,6 +2,7 @@ package com.avaje.ebean.dbmigration.model;
import com.avaje.ebean.dbmigration.migration.AddColumn;
import com.avaje.ebean.dbmigration.migration.AddHistoryTable;
+import com.avaje.ebean.dbmigration.migration.AddTableComment;
import com.avaje.ebean.dbmigration.migration.AlterColumn;
import com.avaje.ebean.dbmigration.migration.Column;
import com.avaje.ebean.dbmigration.migration.CreateTable;
@@ -285,6 +286,13 @@ public class MTable {
if (addColumn != null) {
modelDiff.addAddColumn(addColumn);
}
+
+ if (MColumn.different(comment, newTable.comment)) {
+ AddTableComment addTableComment = new AddTableComment();
+ addTableComment.setName(name);
+ addTableComment.setComment(newTable.comment);
+ modelDiff.addTableComment(addTableComment);
+ }
}
/**
diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/ModelDiff.java b/src/main/java/com/avaje/ebean/dbmigration/model/ModelDiff.java
index f851143b2..da50becb7 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/model/ModelDiff.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/model/ModelDiff.java
@@ -2,6 +2,7 @@ package com.avaje.ebean.dbmigration.model;
import com.avaje.ebean.dbmigration.migration.AddColumn;
import com.avaje.ebean.dbmigration.migration.AddHistoryTable;
+import com.avaje.ebean.dbmigration.migration.AddTableComment;
import com.avaje.ebean.dbmigration.migration.AlterColumn;
import com.avaje.ebean.dbmigration.migration.ChangeSet;
import com.avaje.ebean.dbmigration.migration.ChangeSetType;
@@ -237,4 +238,11 @@ public class ModelDiff {
public void addCreateIndex(CreateIndex createIndex) {
applyChanges.add(createIndex);
}
+
+ /**
+ * Add a table comment to the 'apply' changes.
+ */
+ public void addTableComment(AddTableComment addTableComment) {
+ applyChanges.add(addTableComment);
+ }
}
diff --git a/src/main/resources/ebean-dbmigration-1.0.xsd b/src/main/resources/ebean-dbmigration-1.0.xsd
index 2ada00820..4233f28ef 100644
--- a/src/main/resources/ebean-dbmigration-1.0.xsd
+++ b/src/main/resources/ebean-dbmigration-1.0.xsd
@@ -152,6 +152,13 @@
+