Allow multiple PK column in addTable migrator
This commit is contained in:
parent
536f46c89e
commit
a61527d4cb
|
@ -36,7 +36,7 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
|
|||
private static final Logger ourLog = LoggerFactory.getLogger(AddTableByColumnTask.class);
|
||||
|
||||
private List<AddColumnTask> myAddColumnTasks = new ArrayList<>();
|
||||
private String myPkColumn;
|
||||
private List<String> myPkColumns;
|
||||
|
||||
public AddTableByColumnTask(String theProductVersion, String theSchemaVersion) {
|
||||
super(theProductVersion, theSchemaVersion);
|
||||
|
@ -53,8 +53,8 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
|
|||
myAddColumnTasks.add(theTask);
|
||||
}
|
||||
|
||||
public void setPkColumn(String thePkColumn) {
|
||||
myPkColumn = thePkColumn;
|
||||
public void setPkColumns(List<String> thePkColumns) {
|
||||
myPkColumns = thePkColumns;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,7 +82,12 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
|
|||
}
|
||||
|
||||
sb.append(" PRIMARY KEY (");
|
||||
sb.append(myPkColumn);
|
||||
for (int i = 0; i < myPkColumns.size(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(myPkColumns.get(i));
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
sb.append(" ) ");
|
||||
|
@ -115,7 +120,7 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
|
|||
return new EqualsBuilder()
|
||||
.appendSuper(super.equals(theO))
|
||||
.append(myAddColumnTasks, that.myAddColumnTasks)
|
||||
.append(myPkColumn, that.myPkColumn)
|
||||
.append(myPkColumns, that.myPkColumns)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
|
@ -124,7 +129,7 @@ public class AddTableByColumnTask extends BaseTableTask<AddTableByColumnTask> {
|
|||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myAddColumnTasks)
|
||||
.append(myPkColumn)
|
||||
.append(myPkColumns)
|
||||
.toHashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@ import ca.uhn.fhir.jpa.migrate.taskdef.*;
|
|||
import org.apache.commons.lang3.Validate;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Builder {
|
||||
|
||||
private final String myRelease;
|
||||
|
@ -76,8 +79,8 @@ public class Builder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public BuilderAddTableByColumns addTableByColumns(String theVersion, String theTableName, String thePkColumnName) {
|
||||
return new BuilderAddTableByColumns(myRelease, theVersion, mySink, theTableName, thePkColumnName);
|
||||
public BuilderAddTableByColumns addTableByColumns(String theVersion, String theTableName, String... thePkColumnNames) {
|
||||
return new BuilderAddTableByColumns(myRelease, theVersion, mySink, theTableName, Arrays.asList(thePkColumnNames));
|
||||
}
|
||||
|
||||
public void addIdGenerator(String theVersion, String theGeneratorName) {
|
||||
|
@ -115,12 +118,12 @@ public class Builder {
|
|||
private final String myVersion;
|
||||
private final AddTableByColumnTask myTask;
|
||||
|
||||
public BuilderAddTableByColumns(String theRelease, String theVersion, BaseMigrationTasks.IAcceptsTasks theSink, String theTableName, String thePkColumnName) {
|
||||
public BuilderAddTableByColumns(String theRelease, String theVersion, BaseMigrationTasks.IAcceptsTasks theSink, String theTableName, List<String> thePkColumnNames) {
|
||||
super(theRelease, theSink, theTableName);
|
||||
myVersion = theVersion;
|
||||
myTask = new AddTableByColumnTask(myRelease, theVersion);
|
||||
myTask.setTableName(theTableName);
|
||||
myTask.setPkColumn(thePkColumnName);
|
||||
myTask.setPkColumns(thePkColumnNames);
|
||||
theSink.addTask(myTask);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue