Update migration tasks

This commit is contained in:
James Agnew 2018-09-17 13:19:40 -04:00
parent 44dccb8e3f
commit c34dfda413
1 changed files with 20 additions and 14 deletions

View File

@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.migrate.tasks.api;
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -206,24 +206,30 @@ public class BaseMigrationTasks<T extends Enum> {
public class BuilderModifyColumnWithNameAndNullable {
public void withType(BaseTableColumnTypeTask.ColumnTypeEnum theColumnType) {
withType(theColumnType, 0);
withType(theColumnType, null);
}
public void withType(BaseTableColumnTypeTask.ColumnTypeEnum theColumnType, int theLength) {
public void withType(BaseTableColumnTypeTask.ColumnTypeEnum theColumnType, Integer theLength) {
if (theColumnType == BaseTableColumnTypeTask.ColumnTypeEnum.STRING) {
if (theLength == 0) {
if (theLength == null || theLength == 0) {
throw new IllegalArgumentException("Can not specify length 0 for column of type " + theColumnType);
}
ModifyColumnTask task = new ModifyColumnTask();
task.setColumnName(myColumnName);
task.setTableName(myTableName);
task.setColumnLength(theLength);
task.setNullable(myNullable);
task.setColumnType(theColumnType);
addTask(task);
} else if (theLength > 0) {
throw new IllegalArgumentException("Can not specify length for column of type " + theColumnType);
} else {
if (theLength != null) {
throw new IllegalArgumentException("Can not specify length for column of type " + theColumnType);
}
}
ModifyColumnTask task = new ModifyColumnTask();
task.setColumnName(myColumnName);
task.setTableName(myTableName);
if (theLength != null) {
task.setColumnLength(theLength);
}
task.setNullable(myNullable);
task.setColumnType(theColumnType);
addTask(task);
}
}