+ * 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 }
+ *
+ *
+ */
+ public List An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
@@ -23,36 +23,12 @@ public class ObjectFactory {
/**
- * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.avaje.ebean.dbmigration.migration
+ * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.avaje.ebean.dbmigration.migration
*
*/
public ObjectFactory() {
}
- /**
- * Create an instance of {@link Rollback }
- *
- */
- public Rollback createRollback() {
- return new Rollback();
- }
-
- /**
- * Create an instance of {@link AddColumn }
- *
- */
- public AddColumn createAddColumn() {
- return new AddColumn();
- }
-
- /**
- * Create an instance of {@link Column }
- *
- */
- public Column createColumn() {
- return new Column();
- }
-
/**
* Create an instance of {@link CreateTable }
*
@@ -61,6 +37,14 @@ public class ObjectFactory {
return new CreateTable();
}
+ /**
+ * Create an instance of {@link Column }
+ *
+ */
+ public Column createColumn() {
+ return new Column();
+ }
+
/**
* Create an instance of {@link UniqueConstraint }
*
@@ -69,6 +53,22 @@ public class ObjectFactory {
return new UniqueConstraint();
}
+ /**
+ * Create an instance of {@link ForeignKey }
+ *
+ */
+ public ForeignKey createForeignKey() {
+ return new ForeignKey();
+ }
+
+ /**
+ * Create an instance of {@link PrimaryKey }
+ *
+ */
+ public PrimaryKey createPrimaryKey() {
+ return new PrimaryKey();
+ }
+
/**
* Create an instance of {@link DropForeignKey }
*
@@ -77,14 +77,6 @@ public class ObjectFactory {
return new DropForeignKey();
}
- /**
- * Create an instance of {@link Apply }
- *
- */
- public Apply createApply() {
- return new Apply();
- }
-
/**
* Create an instance of {@link Configuration }
*
@@ -117,22 +109,6 @@ public class ObjectFactory {
return new DropHistoryTable();
}
- /**
- * Create an instance of {@link RenameView }
- *
- */
- public RenameView createRenameView() {
- return new RenameView();
- }
-
- /**
- * Create an instance of {@link AddForeignKey }
- *
- */
- public AddForeignKey createAddForeignKey() {
- return new AddForeignKey();
- }
-
/**
* Create an instance of {@link DropColumn }
*
@@ -149,14 +125,6 @@ public class ObjectFactory {
return new DropView();
}
- /**
- * Create an instance of {@link ChangeSet }
- *
- */
- public ChangeSet createChangeSet() {
- return new ChangeSet();
- }
-
/**
* Create an instance of {@link Sql }
*
@@ -166,11 +134,19 @@ public class ObjectFactory {
}
/**
- * Create an instance of {@link DropTable }
+ * Create an instance of {@link Apply }
*
*/
- public DropTable createDropTable() {
- return new DropTable();
+ public Apply createApply() {
+ return new Apply();
+ }
+
+ /**
+ * Create an instance of {@link Rollback }
+ *
+ */
+ public Rollback createRollback() {
+ return new Rollback();
}
/**
@@ -181,6 +157,14 @@ public class ObjectFactory {
return new CreateHistoryTable();
}
+ /**
+ * Create an instance of {@link RenameColumn }
+ *
+ */
+ public RenameColumn createRenameColumn() {
+ return new RenameColumn();
+ }
+
/**
* Create an instance of {@link CreateView }
*
@@ -190,11 +174,43 @@ public class ObjectFactory {
}
/**
- * Create an instance of {@link RenameColumn }
+ * Create an instance of {@link DropTable }
*
*/
- public RenameColumn createRenameColumn() {
- return new RenameColumn();
+ public DropTable createDropTable() {
+ return new DropTable();
+ }
+
+ /**
+ * Create an instance of {@link AddColumn }
+ *
+ */
+ public AddColumn createAddColumn() {
+ return new AddColumn();
+ }
+
+ /**
+ * Create an instance of {@link RenameView }
+ *
+ */
+ public RenameView createRenameView() {
+ return new RenameView();
+ }
+
+ /**
+ * Create an instance of {@link AddForeignKey }
+ *
+ */
+ public AddForeignKey createAddForeignKey() {
+ return new AddForeignKey();
+ }
+
+ /**
+ * Create an instance of {@link ChangeSet }
+ *
+ */
+ public ChangeSet createChangeSet() {
+ return new ChangeSet();
}
/**
diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/CurrentModel.java b/src/main/java/com/avaje/ebean/dbmigration/model/CurrentModel.java
index ca78b7893..506bfcc54 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/model/CurrentModel.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/model/CurrentModel.java
@@ -49,6 +49,10 @@ public class CurrentModel {
return model;
}
+ public void setChangeSet(ChangeSet changeSet) {
+ this.changeSet = changeSet;
+ }
+
public ChangeSet getChangeSet() {
read();
if (changeSet == null) {
@@ -90,6 +94,16 @@ public class CurrentModel {
return ddl.toString();
}
+ public DdlWrite generateDdl(ChangeSet changeSet) throws IOException {
+
+ DdlWrite write = new DdlWrite();
+
+ BaseDdlHandler handler = handler();
+ handler.generate(write, changeSet);
+
+ return write;
+ }
+
private void createDdl() throws IOException {
if (write == null) {
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 f24dfd1db..39a3d15d4 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/model/MColumn.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/model/MColumn.java
@@ -109,17 +109,15 @@ public class MColumn {
Column c = new Column();
c.setName(name);
c.setType(type);
- c.setNotnull(notnull);
+ if (notnull) c.setNotnull(notnull);
+ if (unique) c.setUnique(unique);
+ if (primaryKey) c.setPrimaryKey(primaryKey);
+ if (identity) c.setIdentity(identity);
+
c.setCheckConstraint(checkConstraint);
- c.setUnique(unique);
- c.setPrimaryKey(primaryKey);
- c.setIdentity(identity);
c.setReferences(references);
c.setDefaultValue(defaultValue);
- //c.setDeleteCascade();
- //c.setDeferrable(deferrable);
-
return c;
}
}
diff --git a/src/main/java/com/avaje/ebean/dbmigration/model/MCompoundForeignKey.java b/src/main/java/com/avaje/ebean/dbmigration/model/MCompoundForeignKey.java
index 84472f97e..4d48123ed 100644
--- a/src/main/java/com/avaje/ebean/dbmigration/model/MCompoundForeignKey.java
+++ b/src/main/java/com/avaje/ebean/dbmigration/model/MCompoundForeignKey.java
@@ -1,5 +1,8 @@
package com.avaje.ebean.dbmigration.model;
+import com.avaje.ebean.dbmigration.migration.Column;
+import com.avaje.ebean.dbmigration.migration.ForeignKey;
+
import java.util.ArrayList;
import java.util.List;
@@ -24,4 +27,28 @@ public class MCompoundForeignKey {
columns.add(dbCol);
referenceColumns.add(refColumn);
}
+
+ public ForeignKey createForeignKey() {
+ ForeignKey fk = new ForeignKey();
+ fk.setColumnNames(toColumnNames(columns));
+ fk.setRefColumnNames(toColumnNames(referenceColumns));
+ fk.setRefTableName(referenceTable);
+ return fk;
+ }
+
+ /**
+ * Return as an array of string column names.
+ */
+ private String toColumnNames(List