From ded7d44974c33c9cdee5be2aaf993e7a4620237d Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Wed, 8 Aug 2018 23:29:29 +1200 Subject: [PATCH] Add support for Postgres range partition DDL plus refactor xsd definitions that had got out of sync (#1465) * Add partition meta mapping * Fix to allow schema prefix on select dynamic formula * Add partition meta mapping * Migration XSD Update * Fix to allow schema prefix on select dynamic formula * Bump ebean-migration to 11.8.1 --- pom.xml | 6 +- .../ddlgeneration/platform/BaseTableDdl.java | 9 +- .../ddlgeneration/platform/PlatformDdl.java | 8 + .../ddlgeneration/platform/PostgresDdl.java | 13 ++ .../dbmigration/migration/AddColumn.java | 12 +- .../migration/AddHistoryTable.java | 4 +- .../migration/AddTableComment.java | 4 +- .../migration/AddUniqueConstraint.java | 72 +++++---- .../dbmigration/migration/AlterColumn.java | 82 +++++++--- .../migration/AlterForeignKey.java | 25 ++- .../migration/AlterHistoryTable.java | 4 +- .../dbmigration/migration/Apply.java | 4 +- .../dbmigration/migration/ChangeSet.java | 20 +-- .../dbmigration/migration/ChangeSetType.java | 7 +- .../dbmigration/migration/Column.java | 64 ++++++-- .../dbmigration/migration/Configuration.java | 4 +- .../dbmigration/migration/CreateIndex.java | 4 +- .../dbmigration/migration/CreateTable.java | 74 +++++++-- .../dbmigration/migration/DdlScript.java | 49 ++++-- .../migration/DefaultTablespace.java | 4 +- .../dbmigration/migration/DropColumn.java | 4 +- .../migration/DropHistoryTable.java | 4 +- .../dbmigration/migration/DropIndex.java | 4 +- .../dbmigration/migration/DropTable.java | 26 +-- .../dbmigration/migration/ForeignKey.java | 5 +- .../dbmigration/migration/IdentityType.java | 2 +- .../dbmigration/migration/Migration.java | 12 +- .../dbmigration/migration/ObjectFactory.java | 153 +++++++++--------- .../dbmigration/migration/RenameColumn.java | 4 +- .../dbmigration/migration/RenameTable.java | 4 +- .../dbmigration/migration/Rollback.java | 4 +- .../dbmigration/migration/Sql.java | 4 +- .../migration/UniqueConstraint.java | 33 ++-- .../model/MCompoundUniqueConstraint.java | 27 ++-- .../dbmigration/model/MTable.java | 19 +++ .../model/build/ModelBuildBeanVisitor.java | 1 + .../build/ModelBuildPropertyVisitor.java | 4 +- .../server/deploy/BeanDescriptor.java | 20 ++- .../server/deploy/PartitionMeta.java | 27 ++++ .../deploy/meta/DeployBeanDescriptor.java | 18 +++ .../server/deploy/parse/AnnotationClass.java | 7 + .../server/query/SqlTreeBuilder.java | 8 +- src/main/resources/ebean-dbmigration-1.0.xsd | 40 ++++- src/main/resources/ebean-extraddl-1.0.xsd | 2 + .../migrationtest/model/1.1.model.xml | 24 ++- .../migrationtest/model/1.3.model.xml | 4 +- 46 files changed, 639 insertions(+), 290 deletions(-) create mode 100644 src/main/java/io/ebeaninternal/server/deploy/PartitionMeta.java diff --git a/pom.xml b/pom.xml index ee4a78d73..d07b0a928 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ io.ebean ebean - 11.19.4-SNAPSHOT + 11.20.1-SNAPSHOT jar ebean @@ -117,7 +117,7 @@ io.ebean ebean-annotation - 4.1 + 4.2 @@ -135,7 +135,7 @@ io.ebean ebean-migration - 11.7.1 + 11.8.1 diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java index 47930bce1..7b3c72bb9 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java +++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/BaseTableDdl.java @@ -257,6 +257,8 @@ public class BaseTableDdl implements TableDdl { useSequence = (IdType.SEQUENCE == useDbIdentityType); } + String partitionMode = createTable.getPartitionMode(); + DdlBuffer apply = writer.apply(); apply.append("create table ").append(tableName).append(" ("); writeTableColumns(apply, columns, useIdentity); @@ -265,7 +267,9 @@ public class BaseTableDdl implements TableDdl { writeCompoundUniqueConstraints(apply, createTable); if (!pk.isEmpty()) { // defined on the columns - writePrimaryKeyConstraint(apply, createTable.getPkName(), toColumnNames(pk)); + if (partitionMode == null || !platformDdl.suppressPrimaryKeyOnPartition()) { + writePrimaryKeyConstraint(apply, createTable.getPkName(), toColumnNames(pk)); + } } if (platformDdl.isInlineForeignKeys()) { writeInlineForeignKeys(writer, createTable); @@ -273,6 +277,9 @@ public class BaseTableDdl implements TableDdl { apply.newLine().append(")"); addTableCommentInline(apply, createTable); + if (partitionMode != null) { + platformDdl.addTablePartition(apply, partitionMode, createTable.getPartitionColumn()); + } apply.endOfStatement(); addComments(apply, createTable); diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java index b2320c7b9..515004bd5 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java +++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PlatformDdl.java @@ -662,4 +662,12 @@ public class PlatformDdl { public void unlockTables(DdlBuffer buffer, Collection tables) throws IOException { } + + public boolean suppressPrimaryKeyOnPartition() { + return false; + } + + public void addTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn) throws IOException { + // only supported by postgres initially + } } diff --git a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PostgresDdl.java b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PostgresDdl.java index 709e6f026..5230f14a0 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PostgresDdl.java +++ b/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PostgresDdl.java @@ -1,6 +1,9 @@ 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. @@ -16,6 +19,11 @@ public class PostgresDdl extends PlatformDdl { this.columnSetNull = "drop not null"; } + @Override + public boolean suppressPrimaryKeyOnPartition() { + return true; + } + @Override protected String convertArrayType(String logicalArrayType) { return NativeDbArray.logicalToNative(logicalArrayType); @@ -38,4 +46,9 @@ public class PostgresDdl extends PlatformDdl { } return columnDefn; } + + @Override + public void addTablePartition(DdlBuffer apply, String partitionMode, String partitionColumn) throws IOException { + apply.append(" partition by range (").append(partitionColumn).append(")"); + } } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/AddColumn.java b/src/main/java/io/ebeaninternal/dbmigration/migration/AddColumn.java index f3423c852..3de2c81ec 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/AddColumn.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/AddColumn.java @@ -12,9 +12,9 @@ import java.util.List; /** *

Java class for anonymous complex type. - *

+ * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

  * <complexType>
  *   <complexContent>
@@ -45,20 +45,20 @@ public class AddColumn {
 
   /**
    * Gets the value of the column property.
-   * 

+ * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the column property. - *

+ * *

* For example, to add a new item, do as follows: *

    *    getColumn().add(newItem);
    * 
- *

- *

+ * + * *

* Objects of the following type(s) are allowed in the list * {@link Column } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/AddHistoryTable.java b/src/main/java/io/ebeaninternal/dbmigration/migration/AddHistoryTable.java index 7af32e7da..5ea02ada8 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/AddHistoryTable.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/AddHistoryTable.java @@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/AddTableComment.java b/src/main/java/io/ebeaninternal/dbmigration/migration/AddTableComment.java
index c9b21ff63..e8564fa0a 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/AddTableComment.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/AddTableComment.java
@@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/AddUniqueConstraint.java b/src/main/java/io/ebeaninternal/dbmigration/migration/AddUniqueConstraint.java
index 8ed14b23f..01dacaead 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/AddUniqueConstraint.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/AddUniqueConstraint.java
@@ -9,11 +9,21 @@ import javax.xml.bind.annotation.XmlType;
 
 /**
  * 

Java class for anonymous complex type. - *

+ * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

- * TODO
+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <attribute name="constraintName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="tableName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="columnNames" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="oneToOne" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *       <attribute name="nullableColumns" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
  * 
*/ @XmlAccessorType(XmlAccessType.FIELD) @@ -23,18 +33,14 @@ public class AddUniqueConstraint { @XmlAttribute(name = "constraintName", required = true) protected String constraintName; - @XmlAttribute(name = "tableName", required = true) protected String tableName; - @XmlAttribute(name = "columnNames", required = true) protected String columnNames; - - @XmlAttribute(name = "nullableColumns", required = true) - protected String nullableColumns; - - @XmlAttribute(name = "oneToOne", required = false) + @XmlAttribute(name = "oneToOne") protected Boolean oneToOne; + @XmlAttribute(name = "nullableColumns") + protected String nullableColumns; /** * Gets the value of the constraintName property. @@ -55,7 +61,7 @@ public class AddUniqueConstraint { public void setConstraintName(String value) { this.constraintName = value; } - + /** * Gets the value of the tableName property. * @@ -65,15 +71,15 @@ public class AddUniqueConstraint { public String getTableName() { return tableName; } - + /** * Sets the value of the tableName property. * * @param value allowed object is * {@link String } */ - public void setTableName(String tableName) { - this.tableName = tableName; + public void setTableName(String value) { + this.tableName = value; } /** @@ -96,6 +102,26 @@ public class AddUniqueConstraint { this.columnNames = value; } + /** + * Gets the value of the oneToOne property. + * + * @return possible object is + * {@link Boolean } + */ + public Boolean isOneToOne() { + return oneToOne; + } + + /** + * Sets the value of the oneToOne property. + * + * @param value allowed object is + * {@link Boolean } + */ + public void setOneToOne(Boolean value) { + this.oneToOne = value; + } + /** * Gets the value of the nullableColumns property. * @@ -115,23 +141,5 @@ public class AddUniqueConstraint { public void setNullableColumns(String value) { this.nullableColumns = value; } - - /** - * Gets the value of the oneToOne property. - * - * @return true if oneToOne was set - */ - public boolean isOneToOne() { - return Boolean.TRUE.equals(oneToOne); - } - - /** - * Sets the value of the oneToOne property. - * - * @param value boolean - */ - public void setOneToOne(boolean oneToOne) { - this.oneToOne = oneToOne; - } } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/AlterColumn.java b/src/main/java/io/ebeaninternal/dbmigration/migration/AlterColumn.java index 47f9a413b..1723abc50 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/AlterColumn.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/AlterColumn.java @@ -3,7 +3,6 @@ package io.ebeaninternal.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.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import java.util.ArrayList; @@ -12,13 +11,17 @@ import java.util.List; /** *

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">
+ *       <sequence>
+ *         <element name="before" type="{http://ebean-orm.github.io/xml/ns/dbmigration}ddl-script" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element name="after" type="{http://ebean-orm.github.io/xml/ns/dbmigration}ddl-script" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
  *       <attribute name="columnName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
  *       <attribute name="tableName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
  *       <attribute name="withHistory" type="{http://www.w3.org/2001/XMLSchema}boolean" />
@@ -50,16 +53,14 @@ import java.util.List;
  */
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {
-    "before", "after"
+  "before",
+  "after"
 })
 @XmlRootElement(name = "alterColumn")
 public class AlterColumn {
 
-  @XmlElement(required = false)
   protected List before;
-  @XmlElement(required = false)
   protected List after;
-
   @XmlAttribute(name = "columnName", required = true)
   protected String columnName;
   @XmlAttribute(name = "tableName", required = true)
@@ -109,6 +110,60 @@ public class AlterColumn {
   @XmlAttribute(name = "dropForeignKeyIndex")
   protected String dropForeignKeyIndex;
 
+  /**
+   * Gets the value of the before property.
+   *
+   * 

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the before property. + * + *

+ * For example, to add a new item, do as follows: + *

+   *    getBefore().add(newItem);
+   * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link DdlScript } + */ + public List getBefore() { + if (before == null) { + before = new ArrayList<>(); + } + return this.before; + } + + /** + * Gets the value of the after property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the after property. + * + *

+ * For example, to add a new item, do as follows: + *

+   *    getAfter().add(newItem);
+   * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link DdlScript } + */ + public List getAfter() { + if (after == null) { + after = new ArrayList<>(); + } + return this.after; + } + /** * Gets the value of the columnName property. * @@ -589,17 +644,4 @@ public class AlterColumn { this.dropForeignKeyIndex = value; } - public List getBefore() { - if (before == null) { - before = new ArrayList<>(); - } - return before; - } - - public List getAfter() { - if (after == null) { - after = new ArrayList<>(); - } - return after; - } } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/AlterForeignKey.java b/src/main/java/io/ebeaninternal/dbmigration/migration/AlterForeignKey.java index ed0ccf000..deb5e812f 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/AlterForeignKey.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/AlterForeignKey.java @@ -9,21 +9,34 @@ import javax.xml.bind.annotation.XmlType; /** *

Java class for anonymous complex type. - *

+ * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

- * TODO
+ * <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="columnNames" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="refColumnNames" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="refTableName" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="indexName" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="tableName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="onDelete" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="onUpdate" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
  * 
*/ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") -@XmlRootElement(name = "foreignKey") +@XmlRootElement(name = "alterForeignKey") public class AlterForeignKey { @XmlAttribute(name = "name", required = true) protected String name; - @XmlAttribute(name = "columnNames", required = true) + @XmlAttribute(name = "columnNames") protected String columnNames; @XmlAttribute(name = "refColumnNames") protected String refColumnNames; @@ -37,6 +50,7 @@ public class AlterForeignKey { protected String onDelete; @XmlAttribute(name = "onUpdate") protected String onUpdate; + /** * Gets the value of the name property. * @@ -196,4 +210,5 @@ public class AlterForeignKey { public void setOnUpdate(String value) { this.onUpdate = value; } + } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/AlterHistoryTable.java b/src/main/java/io/ebeaninternal/dbmigration/migration/AlterHistoryTable.java index feb807968..f77e1d8f2 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/AlterHistoryTable.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/AlterHistoryTable.java @@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/Apply.java b/src/main/java/io/ebeaninternal/dbmigration/migration/Apply.java
index 5c40b242b..8b9a3913d 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/Apply.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/Apply.java
@@ -9,9 +9,9 @@ import javax.xml.bind.annotation.XmlValue;
 
 /**
  * 

Java class for anonymous complex type. - *

+ * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

  * <complexType>
  *   <simpleContent>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSet.java b/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSet.java
index be9259950..5fa984ce1 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSet.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSet.java
@@ -13,9 +13,9 @@ import java.util.List;
 
 /**
  * 

Java class for anonymous complex type. - *

+ * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

  * <complexType>
  *   <complexContent>
@@ -50,16 +50,16 @@ public class ChangeSet {
     @XmlElement(name = "dropTable", type = DropTable.class),
     @XmlElement(name = "renameTable", type = RenameTable.class),
     @XmlElement(name = "addTableComment", type = AddTableComment.class),
+    @XmlElement(name = "addUniqueConstraint", type = AddUniqueConstraint.class),
     @XmlElement(name = "addHistoryTable", type = AddHistoryTable.class),
     @XmlElement(name = "dropHistoryTable", type = DropHistoryTable.class),
+    @XmlElement(name = "alterForeignKey", type = AlterForeignKey.class),
     @XmlElement(name = "addColumn", type = AddColumn.class),
     @XmlElement(name = "dropColumn", type = DropColumn.class),
     @XmlElement(name = "alterColumn", type = AlterColumn.class),
     @XmlElement(name = "renameColumn", type = RenameColumn.class),
     @XmlElement(name = "createIndex", type = CreateIndex.class),
-    @XmlElement(name = "dropIndex", type = DropIndex.class),
-    @XmlElement(name = "addUniqueConstraint", type = AddUniqueConstraint.class),
-    @XmlElement(name = "alterForeignKey", type = AlterForeignKey.class),
+    @XmlElement(name = "dropIndex", type = DropIndex.class)
   })
   protected List changeSetChildren;
   @XmlAttribute(name = "type", required = true)
@@ -77,20 +77,20 @@ public class ChangeSet {
 
   /**
    * Gets the value of the changeSetChildren property.
-   * 

+ * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the changeSetChildren property. - *

+ * *

* For example, to add a new item, do as follows: *

    *    getChangeSetChildren().add(newItem);
    * 
- *

- *

+ * + * *

* Objects of the following type(s) are allowed in the list * {@link Configuration } @@ -99,8 +99,10 @@ public class ChangeSet { * {@link DropTable } * {@link RenameTable } * {@link AddTableComment } + * {@link AddUniqueConstraint } * {@link AddHistoryTable } * {@link DropHistoryTable } + * {@link AlterForeignKey } * {@link AddColumn } * {@link DropColumn } * {@link AlterColumn } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSetType.java b/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSetType.java index 4537e85c5..c3e8c80ed 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSetType.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/ChangeSetType.java @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlType; /** *

Java class for changeSetType. - *

+ * *

The following schema fragment specifies the expected content contained within this class. *

*

@@ -16,6 +16,7 @@ import javax.xml.bind.annotation.XmlType;
  *     <enumeration value="apply"/>
  *     <enumeration value="pendingDrops"/>
  *     <enumeration value="baseline"/>
+ *     <enumeration value="drop"/>
  *   </restriction>
  * </simpleType>
  * 
@@ -29,7 +30,9 @@ public enum ChangeSetType { @XmlEnumValue("pendingDrops") PENDING_DROPS("pendingDrops"), @XmlEnumValue("baseline") - BASELINE("baseline"); + BASELINE("baseline"), + @XmlEnumValue("drop") + DROP("drop"); private final String value; ChangeSetType(String v) { diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/Column.java b/src/main/java/io/ebeaninternal/dbmigration/migration/Column.java index 0aefdfbc8..b393e1936 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/Column.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/Column.java @@ -3,7 +3,6 @@ package io.ebeaninternal.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.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import java.util.ArrayList; @@ -12,13 +11,17 @@ import java.util.List; /** *

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">
+ *       <sequence>
+ *         <element name="before" type="{http://ebean-orm.github.io/xml/ns/dbmigration}ddl-script" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element name="after" type="{http://ebean-orm.github.io/xml/ns/dbmigration}ddl-script" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
  *       <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
  *       <attribute name="type" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
  *       <attribute name="defaultValue" type="{http://www.w3.org/2001/XMLSchema}string" />
@@ -43,16 +46,14 @@ import java.util.List;
  */
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {
-  "before", "after"
+  "before",
+  "after"
 })
 @XmlRootElement(name = "column")
 public class Column {
 
-  @XmlElement(required = false)
   protected List before;
-  @XmlElement(required = false)
   protected List after;
-
   @XmlAttribute(name = "name", required = true)
   protected String name;
   @XmlAttribute(name = "type", required = true)
@@ -88,19 +89,58 @@ public class Column {
   @XmlAttribute(name = "comment")
   protected String comment;
 
-
+  /**
+   * Gets the value of the before property.
+   *
+   * 

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the before property. + * + *

+ * For example, to add a new item, do as follows: + *

+   *    getBefore().add(newItem);
+   * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link DdlScript } + */ public List getBefore() { if (before == null) { before = new ArrayList<>(); } - return before; + return this.before; } + /** + * Gets the value of the after property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the after property. + * + *

+ * For example, to add a new item, do as follows: + *

+   *    getAfter().add(newItem);
+   * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link DdlScript } + */ public List getAfter() { if (after == null) { after = new ArrayList<>(); } - return after; + return this.after; } /** @@ -384,7 +424,7 @@ public class Column { } /** - * Gets the value of the foreignOnDelete property. + * Gets the value of the foreignKeyOnDelete property. * * @return possible object is * {@link String } @@ -404,7 +444,7 @@ public class Column { } /** - * Gets the value of the foreignOnUpdate property. + * Gets the value of the foreignKeyOnUpdate property. * * @return possible object is * {@link String } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/Configuration.java b/src/main/java/io/ebeaninternal/dbmigration/migration/Configuration.java index 8c84632ba..dad4879b8 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/Configuration.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/Configuration.java @@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/CreateIndex.java b/src/main/java/io/ebeaninternal/dbmigration/migration/CreateIndex.java
index 5e753e084..9e581d0c3 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/CreateIndex.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/CreateIndex.java
@@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java b/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
index d9f0b788a..cf27b1ce0 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/CreateTable.java
@@ -14,9 +14,9 @@ import java.util.List;
 
 /**
  * 

Java class for anonymous complex type. - *

+ * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

  * <complexType>
  *   <complexContent>
@@ -28,6 +28,8 @@ import java.util.List;
  *       </sequence>
  *       <attGroup ref="{http://ebean-orm.github.io/xml/ns/dbmigration}tablespaceAttributes"/>
  *       <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="partitionMode" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="partitionColumn" type="{http://www.w3.org/2001/XMLSchema}string" />
  *       <attribute name="withHistory" type="{http://www.w3.org/2001/XMLSchema}boolean" />
  *       <attribute name="draft" type="{http://www.w3.org/2001/XMLSchema}boolean" />
  *       <attribute name="identityType" type="{http://ebean-orm.github.io/xml/ns/dbmigration}identityType" />
@@ -55,6 +57,10 @@ public class CreateTable {
   protected List foreignKey;
   @XmlAttribute(name = "name", required = true)
   protected String name;
+  @XmlAttribute(name = "partitionMode")
+  protected String partitionMode;
+  @XmlAttribute(name = "partitionColumn")
+  protected String partitionColumn;
   @XmlAttribute(name = "withHistory")
   protected Boolean withHistory;
   @XmlAttribute(name = "draft")
@@ -80,20 +86,20 @@ public class CreateTable {
 
   /**
    * Gets the value of the column property.
-   * 

+ * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the column property. - *

+ * *

* For example, to add a new item, do as follows: *

    *    getColumn().add(newItem);
    * 
- *

- *

+ * + * *

* Objects of the following type(s) are allowed in the list * {@link Column } @@ -107,20 +113,20 @@ public class CreateTable { /** * Gets the value of the uniqueConstraint property. - *

+ * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the uniqueConstraint property. - *

+ * *

* For example, to add a new item, do as follows: *

    *    getUniqueConstraint().add(newItem);
    * 
- *

- *

+ * + * *

* Objects of the following type(s) are allowed in the list * {@link UniqueConstraint } @@ -134,20 +140,20 @@ public class CreateTable { /** * Gets the value of the foreignKey property. - *

+ * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the foreignKey property. - *

+ * *

* For example, to add a new item, do as follows: *

    *    getForeignKey().add(newItem);
    * 
- *

- *

+ * + * *

* Objects of the following type(s) are allowed in the list * {@link ForeignKey } @@ -179,6 +185,46 @@ public class CreateTable { this.name = value; } + /** + * Gets the value of the partitionMode property. + * + * @return possible object is + * {@link String } + */ + public String getPartitionMode() { + return partitionMode; + } + + /** + * Sets the value of the partitionMode property. + * + * @param value allowed object is + * {@link String } + */ + public void setPartitionMode(String value) { + this.partitionMode = value; + } + + /** + * Gets the value of the partitionColumn property. + * + * @return possible object is + * {@link String } + */ + public String getPartitionColumn() { + return partitionColumn; + } + + /** + * Sets the value of the partitionColumn property. + * + * @param value allowed object is + * {@link String } + */ + public void setPartitionColumn(String value) { + this.partitionColumn = value; + } + /** * Gets the value of the withHistory property. * diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/DdlScript.java b/src/main/java/io/ebeaninternal/dbmigration/migration/DdlScript.java index be259f394..12d1f1cff 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/DdlScript.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/DdlScript.java @@ -1,42 +1,61 @@ package io.ebeaninternal.dbmigration.migration; -import java.util.ArrayList; -import java.util.List; - 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.XmlElement; import javax.xml.bind.annotation.XmlType; -import javax.xml.bind.annotation.XmlValue; +import java.util.ArrayList; +import java.util.List; /** - *

Java class for anonymous complex type. - *

+ *

Java class for ddl-script complex type. + * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

- * TODO @Rob: Can this generated automatically?
+ * <complexType name="ddl-script">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="ddl" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded"/>
+ *       </sequence>
+ *       <attribute name="platforms" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
  * 
*/ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { +@XmlType(name = "ddl-script", propOrder = { "ddl" }) -@XmlRootElement(name = "ddl-script") public class DdlScript { - @XmlValue + @XmlElement(required = true) protected List ddl; - @XmlAttribute(name = "platforms") protected String platforms; /** - * Gets the value of the value property. + * Gets the value of the ddl property. * - * @return possible object is + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the ddl property. + * + *

+ * For example, to add a new item, do as follows: + *

+   *    getDdl().add(newItem);
+   * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list * {@link String } */ public List getDdl() { diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/DefaultTablespace.java b/src/main/java/io/ebeaninternal/dbmigration/migration/DefaultTablespace.java index 2e1981622..92fa6d744 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/DefaultTablespace.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/DefaultTablespace.java @@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/DropColumn.java b/src/main/java/io/ebeaninternal/dbmigration/migration/DropColumn.java
index 9d125415d..03062cff2 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/DropColumn.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/DropColumn.java
@@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/DropHistoryTable.java b/src/main/java/io/ebeaninternal/dbmigration/migration/DropHistoryTable.java
index 8471b2c52..608b2bc23 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/DropHistoryTable.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/DropHistoryTable.java
@@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/DropIndex.java b/src/main/java/io/ebeaninternal/dbmigration/migration/DropIndex.java
index 71e472a5a..5a70943a3 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/DropIndex.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/DropIndex.java
@@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/DropTable.java b/src/main/java/io/ebeaninternal/dbmigration/migration/DropTable.java
index 6d9a0f076..beb22f36a 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/DropTable.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/DropTable.java
@@ -9,14 +9,16 @@ 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="sequenceCol" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="sequenceName" type="{http://www.w3.org/2001/XMLSchema}string" />
  *     </restriction>
  *   </complexContent>
  * </complexType>
@@ -64,16 +66,6 @@ public class DropTable {
     return sequenceCol;
   }
 
-  /**
-   * Gets the value of the sequenceName property.
-   *
-   * @return possible object is
-   * {@link String }
-   */
-  public String getSequenceName() {
-    return sequenceName;
-  }
-
   /**
    * Sets the value of the sequenceCol property.
    *
@@ -84,6 +76,16 @@ public class DropTable {
     this.sequenceCol = value;
   }
 
+  /**
+   * Gets the value of the sequenceName property.
+   *
+   * @return possible object is
+   * {@link String }
+   */
+  public String getSequenceName() {
+    return sequenceName;
+  }
+
   /**
    * Sets the value of the sequenceName property.
    *
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/ForeignKey.java b/src/main/java/io/ebeaninternal/dbmigration/migration/ForeignKey.java
index 37d314207..867e918cf 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/ForeignKey.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/ForeignKey.java
@@ -9,9 +9,9 @@ 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>
@@ -47,6 +47,7 @@ public class ForeignKey {
   protected String onDelete;
   @XmlAttribute(name = "onUpdate")
   protected String onUpdate;
+
   /**
    * Gets the value of the name property.
    *
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/IdentityType.java b/src/main/java/io/ebeaninternal/dbmigration/migration/IdentityType.java
index 4d95169b3..3d59cd0ce 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/IdentityType.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/IdentityType.java
@@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlType;
 
 /**
  * 

Java class for identityType. - *

+ * *

The following schema fragment specifies the expected content contained within this class. *

*

diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/Migration.java b/src/main/java/io/ebeaninternal/dbmigration/migration/Migration.java
index fea9ef068..c830a44d0 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/Migration.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/Migration.java
@@ -11,9 +11,9 @@ import java.util.List;
 
 /**
  * 

Java class for anonymous complex type. - *

+ * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

  * <complexType>
  *   <complexContent>
@@ -38,20 +38,20 @@ public class Migration {
 
   /**
    * Gets the value of the changeSet property.
-   * 

+ * *

* This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a set method for the changeSet property. - *

+ * *

* For example, to add a new item, do as follows: *

    *    getChangeSet().add(newItem);
    * 
- *

- *

+ * + * *

* Objects of the following type(s) are allowed in the list * {@link ChangeSet } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/ObjectFactory.java b/src/main/java/io/ebeaninternal/dbmigration/migration/ObjectFactory.java index 472d67261..ac15ca0d5 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/ObjectFactory.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/ObjectFactory.java @@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlRegistry; /** * This object contains factory methods for each * Java content interface and Java element interface - * generated in the io.ebean.dbmigration.migration package. + * generated in the io.ebeaninternal.dbmigration.migration package. *

An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML @@ -21,23 +21,23 @@ public class ObjectFactory { /** - * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: io.ebean.dbmigration.migration + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: io.ebeaninternal.dbmigration.migration */ public ObjectFactory() { } /** - * Create an instance of {@link Rollback } + * Create an instance of {@link AddUniqueConstraint } */ - public Rollback createRollback() { - return new Rollback(); + public AddUniqueConstraint createAddUniqueConstraint() { + return new AddUniqueConstraint(); } /** - * Create an instance of {@link AddColumn } + * Create an instance of {@link CreateTable } */ - public AddColumn createAddColumn() { - return new AddColumn(); + public CreateTable createCreateTable() { + return new CreateTable(); } /** @@ -48,10 +48,10 @@ public class ObjectFactory { } /** - * Create an instance of {@link CreateTable } + * Create an instance of {@link DdlScript } */ - public CreateTable createCreateTable() { - return new CreateTable(); + public DdlScript createDdlScript() { + return new DdlScript(); } /** @@ -68,13 +68,6 @@ public class ObjectFactory { return new ForeignKey(); } - /** - * Create an instance of {@link Apply } - */ - public Apply createApply() { - return new Apply(); - } - /** * Create an instance of {@link Configuration } */ @@ -89,13 +82,6 @@ public class ObjectFactory { return new DefaultTablespace(); } - /** - * Create an instance of {@link AddTableComment } - */ - public AddTableComment createAddTableComment() { - return new AddTableComment(); - } - /** * Create an instance of {@link RenameTable } */ @@ -111,10 +97,10 @@ public class ObjectFactory { } /** - * Create an instance of {@link AlterColumn } + * Create an instance of {@link AlterForeignKey } */ - public AlterColumn createAlterColumn() { - return new AlterColumn(); + public AlterForeignKey createAlterForeignKey() { + return new AlterForeignKey(); } /** @@ -124,6 +110,69 @@ public class ObjectFactory { return new DropColumn(); } + /** + * Create an instance of {@link Sql } + */ + public Sql createSql() { + return new Sql(); + } + + /** + * Create an instance of {@link Apply } + */ + public Apply createApply() { + return new Apply(); + } + + /** + * Create an instance of {@link Rollback } + */ + public Rollback createRollback() { + return new Rollback(); + } + + /** + * Create an instance of {@link DropIndex } + */ + public DropIndex createDropIndex() { + return new DropIndex(); + } + + /** + * Create an instance of {@link RenameColumn } + */ + public RenameColumn createRenameColumn() { + return new RenameColumn(); + } + + /** + * Create an instance of {@link DropTable } + */ + public DropTable createDropTable() { + return new DropTable(); + } + + /** + * Create an instance of {@link AddColumn } + */ + public AddColumn createAddColumn() { + return new AddColumn(); + } + + /** + * Create an instance of {@link AddTableComment } + */ + public AddTableComment createAddTableComment() { + return new AddTableComment(); + } + + /** + * Create an instance of {@link AlterColumn } + */ + public AlterColumn createAlterColumn() { + return new AlterColumn(); + } + /** * Create an instance of {@link CreateIndex } */ @@ -138,20 +187,6 @@ public class ObjectFactory { return new ChangeSet(); } - /** - * Create an instance of {@link Sql } - */ - public Sql createSql() { - return new Sql(); - } - - /** - * Create an instance of {@link DropTable } - */ - public DropTable createDropTable() { - return new DropTable(); - } - /** * Create an instance of {@link AddHistoryTable } */ @@ -159,20 +194,6 @@ public class ObjectFactory { return new AddHistoryTable(); } - /** - * Create an instance of {@link RenameColumn } - */ - public RenameColumn createRenameColumn() { - return new RenameColumn(); - } - - /** - * Create an instance of {@link DropIndex } - */ - public DropIndex createDropIndex() { - return new DropIndex(); - } - /** * Create an instance of {@link AlterHistoryTable } */ @@ -187,24 +208,4 @@ public class ObjectFactory { return new Migration(); } - /** - * Create an instance of {@link DdlScript } - */ - public DdlScript createDdlScript() { - return new DdlScript(); - } - - /** - * Create an instance of {@link AddUniqueConstraint } - */ - public AddUniqueConstraint createAddUniqueConstraint() { - return new AddUniqueConstraint(); - } - - /** - * Create an instance of {@link AddUniqueConstraint } - */ - public AlterForeignKey createAlterForeignKey() { - return new AlterForeignKey(); - } } diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/RenameColumn.java b/src/main/java/io/ebeaninternal/dbmigration/migration/RenameColumn.java index 3838725e6..23c8bee30 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/migration/RenameColumn.java +++ b/src/main/java/io/ebeaninternal/dbmigration/migration/RenameColumn.java @@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/RenameTable.java b/src/main/java/io/ebeaninternal/dbmigration/migration/RenameTable.java
index a4eb9185f..02221fcb6 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/RenameTable.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/RenameTable.java
@@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/Rollback.java b/src/main/java/io/ebeaninternal/dbmigration/migration/Rollback.java
index 8647f8d88..994b201c3 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/Rollback.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/Rollback.java
@@ -9,9 +9,9 @@ import javax.xml.bind.annotation.XmlValue;
 
 /**
  * 

Java class for anonymous complex type. - *

+ * *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

  * <complexType>
  *   <simpleContent>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/Sql.java b/src/main/java/io/ebeaninternal/dbmigration/migration/Sql.java
index f65d32003..02532da78 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/Sql.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/Sql.java
@@ -9,9 +9,9 @@ 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>
diff --git a/src/main/java/io/ebeaninternal/dbmigration/migration/UniqueConstraint.java b/src/main/java/io/ebeaninternal/dbmigration/migration/UniqueConstraint.java
index d4c61fd8f..79a6f5e05 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/migration/UniqueConstraint.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/migration/UniqueConstraint.java
@@ -9,15 +9,17 @@ 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="columnNames" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="oneToOne" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *       <attribute name="nullableColumns" type="{http://www.w3.org/2001/XMLSchema}string" />
  *     </restriction>
  *   </complexContent>
  * </complexType>
@@ -30,16 +32,13 @@ public class UniqueConstraint {
 
   @XmlAttribute(name = "name", required = true)
   protected String name;
-
   @XmlAttribute(name = "columnNames", required = true)
   protected String columnNames;
-
-  @XmlAttribute(name = "oneToOne", required = false)
+  @XmlAttribute(name = "oneToOne")
   protected Boolean oneToOne;
-
-  @XmlAttribute(name = "nullableColumns", required = true)
+  @XmlAttribute(name = "nullableColumns")
   protected String nullableColumns;
-  
+
   /**
    * Gets the value of the name property.
    *
@@ -79,23 +78,25 @@ public class UniqueConstraint {
   public void setColumnNames(String value) {
     this.columnNames = value;
   }
-  
+
   /**
    * Gets the value of the oneToOne property.
    *
-   * @return true if oneToOne was set
+   * @return possible object is
+   * {@link Boolean }
    */
-  public boolean isOneToOne() {
-    return Boolean.TRUE.equals(oneToOne);
+  public Boolean isOneToOne() {
+    return oneToOne;
   }
-  
+
   /**
    * Sets the value of the oneToOne property.
    *
-   * @param value boolean
+   * @param value allowed object is
+   *              {@link Boolean }
    */
-  public void setOneToOne(boolean oneToOne) {
-    this.oneToOne = oneToOne;
+  public void setOneToOne(Boolean value) {
+    this.oneToOne = value;
   }
 
   /**
diff --git a/src/main/java/io/ebeaninternal/dbmigration/model/MCompoundUniqueConstraint.java b/src/main/java/io/ebeaninternal/dbmigration/model/MCompoundUniqueConstraint.java
index daf3a19e2..aee6f1963 100644
--- a/src/main/java/io/ebeaninternal/dbmigration/model/MCompoundUniqueConstraint.java
+++ b/src/main/java/io/ebeaninternal/dbmigration/model/MCompoundUniqueConstraint.java
@@ -1,11 +1,12 @@
 package io.ebeaninternal.dbmigration.model;
 
-import java.util.Arrays;
-import java.util.Objects;
-
 import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp;
 import io.ebeaninternal.dbmigration.migration.AddUniqueConstraint;
 import io.ebeaninternal.dbmigration.migration.UniqueConstraint;
+
+import java.util.Arrays;
+import java.util.Objects;
+
 /**
  * A unique constraint for multiple columns.
  * 

@@ -26,13 +27,13 @@ public class MCompoundUniqueConstraint { * The columns combined to be unique. */ private final String[] columns; - + private String[] nullableColumns; - public MCompoundUniqueConstraint(String[] columns, boolean oneToOne, String name) { + public MCompoundUniqueConstraint(String[] columns, Boolean oneToOne, String name) { this.name = name; this.columns = columns; - this.oneToOne = oneToOne; + this.oneToOne = Boolean.TRUE.equals(oneToOne); } /** @@ -55,6 +56,7 @@ public class MCompoundUniqueConstraint { public String getName() { return name; } + public UniqueConstraint getUniqueConstraint() { UniqueConstraint uq = new UniqueConstraint(); uq.setName(getName()); @@ -63,6 +65,7 @@ public class MCompoundUniqueConstraint { uq.setOneToOne(isOneToOne()); return uq; } + /** * Return a AddUniqueConstraint migration for this constraint. */ @@ -87,7 +90,7 @@ public class MCompoundUniqueConstraint { dropUniqueConstraint.setNullableColumns(join(nullableColumns)); return dropUniqueConstraint; } - + public void setNullableColumns(String[] nullableColumns) { if (nullableColumns != null && nullableColumns.length == 0) { this.nullableColumns = null; @@ -109,12 +112,12 @@ public class MCompoundUniqueConstraint { } return sb.toString(); } - + @Override public int hashCode() { return Arrays.hashCode(columns) + 31 * Objects.hash(name, oneToOne); } - + @Override public boolean equals(Object obj) { if (obj == this) { @@ -125,8 +128,8 @@ public class MCompoundUniqueConstraint { } MCompoundUniqueConstraint other = (MCompoundUniqueConstraint) obj; return Arrays.equals(columns, other.columns) - && Arrays.equals(nullableColumns, other.nullableColumns) - && Objects.equals(name, other.name) - && oneToOne == other.oneToOne; + && Arrays.equals(nullableColumns, other.nullableColumns) + && Objects.equals(name, other.name) + && oneToOne == other.oneToOne; } } diff --git a/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java b/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java index c53e3aad7..024071aea 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java +++ b/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java @@ -1,5 +1,6 @@ package io.ebeaninternal.dbmigration.model; +import io.ebean.annotation.PartitionMode; import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp; import io.ebeaninternal.dbmigration.ddlgeneration.platform.SplitColumns; import io.ebeaninternal.dbmigration.migration.AddColumn; @@ -14,6 +15,7 @@ import io.ebeaninternal.dbmigration.migration.DropTable; import io.ebeaninternal.dbmigration.migration.ForeignKey; import io.ebeaninternal.dbmigration.migration.IdentityType; import io.ebeaninternal.dbmigration.migration.UniqueConstraint; +import io.ebeaninternal.server.deploy.PartitionMeta; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,6 +63,8 @@ public class MTable { */ private boolean draft; + private PartitionMeta partitionMeta; + /** * Primary key name. */ @@ -237,6 +241,10 @@ public class MTable { createTable.setName(name); createTable.setPkName(pkName); createTable.setComment(comment); + if (partitionMeta != null) { + createTable.setPartitionMode(partitionMeta.getMode().name()); + createTable.setPartitionColumn(partitionMeta.getProperty()); + } createTable.setTablespace(tablespace); createTable.setIndexTablespace(indexTablespace); createTable.setSequenceName(sequenceName); @@ -419,6 +427,13 @@ public class MTable { return draft; } + /** + * Return true if this table is partitioned. + */ + public boolean isPartitioned() { + return partitionMeta != null; + } + public void setPkName(String pkName) { this.pkName = pkName; } @@ -745,4 +760,8 @@ public class MTable { compoundKey.setIndexName(null); } } + + public void setPartitionMeta(PartitionMeta partitionMeta) { + this.partitionMeta = partitionMeta; + } } diff --git a/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java b/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java index 74a7dd856..8ac300074 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java +++ b/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildBeanVisitor.java @@ -36,6 +36,7 @@ public class ModelBuildBeanVisitor implements BeanVisitor { } MTable table = new MTable(descriptor.getBaseTable()); + table.setPartitionMeta(descriptor.getPartitionMeta()); table.setComment(descriptor.getDbComment()); if (descriptor.isHistorySupport()) { table.setWithHistory(true); diff --git a/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildPropertyVisitor.java b/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildPropertyVisitor.java index 0c89d4a6d..0e366a9b1 100644 --- a/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildPropertyVisitor.java +++ b/src/main/java/io/ebeaninternal/dbmigration/model/build/ModelBuildPropertyVisitor.java @@ -192,7 +192,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor { col.setDbMigrationInfos(p.getDbMigrationInfos()); col.setDefaultValue(p.getDbColumnDefault()); if (columns.length == 1) { - if (p.hasForeignKey()) { + if (p.hasForeignKey() && !importedProperty.getBeanDescriptor().suppressForeignKey()) { // single references column (put it on the column) String refTable = importedProperty.getBeanDescriptor().getBaseTable(); if (refTable == null) { @@ -251,7 +251,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor { col.setIdentity(true); } TableJoin primaryKeyJoin = p.getBeanDescriptor().getPrimaryKeyJoin(); - if (primaryKeyJoin != null) { + if (primaryKeyJoin != null && !table.isPartitioned()) { TableJoinColumn[] columns = primaryKeyJoin.columns(); col.setReferences(primaryKeyJoin.getTable() + "." + columns[0].getForeignDbColumn()); col.setForeignKeyName(determineForeignKeyConstraintName(col.getName())); diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java index 05076b078..4a0c711d5 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java @@ -7,6 +7,7 @@ import io.ebean.SqlUpdate; import io.ebean.Transaction; import io.ebean.ValuePair; import io.ebean.annotation.DocStoreMode; +import io.ebean.annotation.PartitionMode; import io.ebean.bean.BeanCollection; import io.ebean.bean.EntityBean; import io.ebean.bean.EntityBeanIntercept; @@ -204,6 +205,8 @@ public class BeanDescriptor implements BeanType, STreeType { private final String draftTable; + private final PartitionMeta partitionMeta; + /** * DB table comment. */ @@ -482,6 +485,7 @@ public class BeanDescriptor implements BeanType, STreeType { this.baseTableVersionsBetween = deploy.getBaseTableVersionsBetween(); this.dependentTables = deploy.getDependentTables(); this.dbComment = deploy.getDbComment(); + this.partitionMeta = deploy.getPartitionMeta(); this.autoTunable = EntityType.ORM == entityType && (beanFinder == null); // helper object used to derive lists of properties @@ -2816,6 +2820,20 @@ public class BeanDescriptor implements BeanType, STreeType { return dbComment; } + /** + * Return true if foreign keys to the base table should be suppressed. + */ + public boolean suppressForeignKey() { + return partitionMeta != null; + } + + /** + * Return the partition details of the bean. + */ + public PartitionMeta getPartitionMeta() { + return partitionMeta; + } + /** * Return the dependent tables for a view based entity. *

@@ -3160,7 +3178,7 @@ public class BeanDescriptor implements BeanType, STreeType { public boolean hasIdPropertyOnly(EntityBeanIntercept ebi) { return ebi.hasIdOnly(idPropertyIndex); } - + public boolean isIdLoaded(EntityBeanIntercept ebi) { return ebi.isLoadedProperty(idPropertyIndex); } diff --git a/src/main/java/io/ebeaninternal/server/deploy/PartitionMeta.java b/src/main/java/io/ebeaninternal/server/deploy/PartitionMeta.java new file mode 100644 index 000000000..d041ae0a1 --- /dev/null +++ b/src/main/java/io/ebeaninternal/server/deploy/PartitionMeta.java @@ -0,0 +1,27 @@ +package io.ebeaninternal.server.deploy; + +import io.ebean.annotation.PartitionMode; + +public class PartitionMeta { + + private final PartitionMode mode; + + private String property; + + public PartitionMeta(PartitionMode mode, String property) { + this.mode = mode; + this.property = property; + } + + public PartitionMode getMode() { + return mode; + } + + public String getProperty() { + return property; + } + + public void setProperty(String dbColumn) { + this.property = dbColumn; + } +} diff --git a/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java b/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java index 24eca35eb..e6688c222 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java +++ b/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java @@ -3,6 +3,7 @@ package io.ebeaninternal.server.deploy.meta; import io.ebean.annotation.Cache; import io.ebean.annotation.DocStore; import io.ebean.annotation.DocStoreMode; +import io.ebean.annotation.PartitionMode; import io.ebean.config.ServerConfig; import io.ebean.config.TableName; import io.ebean.config.dbplatform.IdType; @@ -27,6 +28,7 @@ import io.ebeaninternal.server.deploy.ChainedBeanQueryAdapter; import io.ebeaninternal.server.deploy.DeployPropertyParserMap; import io.ebeaninternal.server.deploy.IndexDefinition; import io.ebeaninternal.server.deploy.InheritInfo; +import io.ebeaninternal.server.deploy.PartitionMeta; import io.ebeaninternal.server.deploy.TableJoin; import io.ebeaninternal.server.deploy.parse.DeployBeanInfo; import io.ebeaninternal.server.idgen.UuidV1IdGenerator; @@ -193,6 +195,8 @@ public class DeployBeanDescriptor { private String dbComment; + private PartitionMeta partitionMeta; + /** * One of NONE, INDEX or EMBEDDED. */ @@ -305,6 +309,20 @@ public class DeployBeanDescriptor { return dbComment; } + public void setPartitionMeta(PartitionMeta partitionMeta) { + this.partitionMeta = partitionMeta; + } + + public PartitionMeta getPartitionMeta() { + if (partitionMeta != null) { + DeployBeanProperty beanProperty = getBeanProperty(partitionMeta.getProperty()); + if (beanProperty != null) { + partitionMeta.setProperty(beanProperty.getDbColumn()); + } + } + return partitionMeta; + } + public void setDraftable() { draftable = true; } diff --git a/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java b/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java index f28f5e303..083d04b61 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java +++ b/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java @@ -2,6 +2,7 @@ package io.ebeaninternal.server.deploy.parse; import io.ebean.annotation.Cache; import io.ebean.annotation.DbComment; +import io.ebean.annotation.DbPartition; import io.ebean.annotation.DocStore; import io.ebean.annotation.Draftable; import io.ebean.annotation.DraftableElement; @@ -16,6 +17,7 @@ import io.ebean.util.AnnotationUtil; import io.ebeaninternal.server.deploy.BeanDescriptor.EntityType; import io.ebeaninternal.server.deploy.IndexDefinition; import io.ebeaninternal.server.deploy.InheritInfo; +import io.ebeaninternal.server.deploy.PartitionMeta; import io.ebeaninternal.server.deploy.meta.DeployBeanProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -152,6 +154,11 @@ public class AnnotationClass extends AnnotationParser { } } + DbPartition partition = AnnotationUtil.findAnnotationRecursive(cls, DbPartition.class); + if (partition != null) { + descriptor.setPartitionMeta(new PartitionMeta(partition.mode(), partition.property())); + } + Draftable draftable = AnnotationUtil.findAnnotationRecursive(cls, Draftable.class); if (draftable != null) { descriptor.setDraftable(); diff --git a/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java b/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java index 9cfaad7e8..e7682b8f8 100644 --- a/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java +++ b/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java @@ -412,7 +412,13 @@ public final class SqlTreeBuilder { if (!selectProps.containsProperty(baseName)) { STreeProperty p = desc.findPropertyWithDynamic(baseName); if (p == null) { - logger.error("property [" + propName + "] not found on " + desc + " for query - excluding it."); + // maybe dynamic formula with schema prefix + p = desc.findPropertyWithDynamic(propName); + if (p != null) { + selectProps.add(p); + } else { + logger.error("property [" + propName + "] not found on " + desc + " for query - excluding it."); + } } else if (p.isEmbedded()) { // add the embedded bean (and effectively diff --git a/src/main/resources/ebean-dbmigration-1.0.xsd b/src/main/resources/ebean-dbmigration-1.0.xsd index 58959aa46..a78d2fade 100644 --- a/src/main/resources/ebean-dbmigration-1.0.xsd +++ b/src/main/resources/ebean-dbmigration-1.0.xsd @@ -37,9 +37,17 @@ + + + + + + + + @@ -99,6 +107,8 @@ + + @@ -125,6 +135,18 @@ + + + + + + + + + + + + @@ -157,6 +179,8 @@ + + @@ -216,6 +240,10 @@ + + + + @@ -236,8 +264,8 @@ - - + + @@ -269,11 +297,14 @@ - - + + + + + @@ -310,6 +341,7 @@ + diff --git a/src/main/resources/ebean-extraddl-1.0.xsd b/src/main/resources/ebean-extraddl-1.0.xsd index b9b39bb02..93a7090d4 100644 --- a/src/main/resources/ebean-extraddl-1.0.xsd +++ b/src/main/resources/ebean-extraddl-1.0.xsd @@ -18,6 +18,8 @@ + + diff --git a/src/test/resources/dbmigration/migrationtest/model/1.1.model.xml b/src/test/resources/dbmigration/migrationtest/model/1.1.model.xml index 72f3ef7ab..5a2e4d63d 100644 --- a/src/test/resources/dbmigration/migrationtest/model/1.1.model.xml +++ b/src/test/resources/dbmigration/migrationtest/model/1.1.model.xml @@ -15,15 +15,21 @@ - -- rename all collisions + + -- rename all collisions + - insert into migtest_e_user (id) select distinct user_id from migtest_e_basic + + insert into migtest_e_user (id) select distinct user_id from migtest_e_basic + - update ${table} set ${column} = old_boolean + + update ${table} set ${column} = old_boolean + @@ -31,14 +37,16 @@ - - - - + + + + - alter table ${table} alter column ${column} TYPE bigint USING (${column}::integer) + + alter table ${table} alter column ${column} TYPE bigint USING (${column}::integer) + diff --git a/src/test/resources/dbmigration/migrationtest/model/1.3.model.xml b/src/test/resources/dbmigration/migrationtest/model/1.3.model.xml index 02d4777ba..d32d725be 100644 --- a/src/test/resources/dbmigration/migrationtest/model/1.3.model.xml +++ b/src/test/resources/dbmigration/migrationtest/model/1.3.model.xml @@ -18,8 +18,8 @@ - - + +