From 175c0781ebe746a48ef10aa9b66fc5e0a970bab8 Mon Sep 17 00:00:00 2001 From: Diederik Muylwyk Date: Tue, 8 Oct 2019 11:55:03 -0400 Subject: [PATCH 1/3] Add case for handling JDBC type CLOB in JdbcUtils. --- .../src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java index f1c889442be..14ba712aa2d 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java @@ -235,6 +235,8 @@ public class JdbcUtils { return new ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP, length); case Types.BLOB: return new ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.BLOB, length); + case Types.CLOB: + return new ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.CLOB, length); default: throw new IllegalArgumentException("Don't know how to handle datatype " + dataType + " for column " + theColumnName + " on table " + theTableName); } From 23264f497f7e66cd0183f958f25eabf6ce51cd10 Mon Sep 17 00:00:00 2001 From: Diederik Muylwyk Date: Tue, 8 Oct 2019 13:19:35 -0400 Subject: [PATCH 2/3] Added test. --- .../jpa/migrate/taskdef/ModifyColumnTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java index 470870226f0..f26ee4c56d7 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java @@ -9,7 +9,28 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.*; public class ModifyColumnTest extends BaseTest { + @Test + public void testColumnWithJdbcTypeClob() throws SQLException { + executeSql("create table SOMETABLE (TEXTCOL varchar2(255 char), TEXTCOL2 clob)"); + ModifyColumnTask task = new ModifyColumnTask(); + task.setTableName("SOMETABLE"); + task.setColumnName("TEXTCOL"); + task.setColumnType(AddColumnTask.ColumnTypeEnum.STRING); + task.setNullable(true); + task.setColumnLength(250); + getMigrator().addTask(task); + + getMigrator().migrate(); + + assertEquals(new JdbcUtils.ColumnType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 250), JdbcUtils.getColumnType(getConnectionProperties(), "SOMETABLE", "TEXTCOL")); + assertEquals(1, task.getExecutedStatements().size()); + + // Make sure additional migrations don't crash + getMigrator().migrate(); + getMigrator().migrate(); + + } @Test public void testColumnAlreadyExists() throws SQLException { From 3c24e14a71f9d48a106a50cf2308c36e4736f3c7 Mon Sep 17 00:00:00 2001 From: Diederik Muylwyk Date: Tue, 8 Oct 2019 13:39:13 -0400 Subject: [PATCH 3/3] Fixed test based on wrong assumption. --- .../java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java index f26ee4c56d7..3a0a12c8237 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java @@ -11,7 +11,7 @@ import static org.junit.Assert.*; public class ModifyColumnTest extends BaseTest { @Test public void testColumnWithJdbcTypeClob() throws SQLException { - executeSql("create table SOMETABLE (TEXTCOL varchar2(255 char), TEXTCOL2 clob)"); + executeSql("create table SOMETABLE (TEXTCOL clob)"); ModifyColumnTask task = new ModifyColumnTask(); task.setTableName("SOMETABLE");