diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseColumnCalculatorTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseColumnCalculatorTask.java index 909d830bec3..447a95df39c 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseColumnCalculatorTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseColumnCalculatorTask.java @@ -37,11 +37,10 @@ import java.util.*; import java.util.concurrent.*; import java.util.function.Function; -public abstract class BaseColumnCalculatorTask extends BaseTableColumnTask { +public abstract class BaseColumnCalculatorTask extends BaseTableColumnTask { protected static final Logger ourLog = LoggerFactory.getLogger(BaseColumnCalculatorTask.class); private int myBatchSize = 10000; - private Map, Object>> myCalculators = new HashMap<>(); private ThreadPoolExecutor myExecutor; public void setBatchSize(int theBatchSize) { @@ -191,12 +190,6 @@ public abstract class BaseColumnCalculatorTask extends BaseTableColumnTask, Object> theConsumer) { - Validate.isTrue(myCalculators.containsKey(theColumnName) == false); - myCalculators.put(theColumnName, theConsumer); - return this; - } - private class MyRowCallbackHandler implements RowCallbackHandler { private List> myRows = new ArrayList<>(); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTask.java index 567ebf7e052..703e64c510b 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTask.java @@ -25,13 +25,17 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.thymeleaf.util.StringUtils; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; +import java.util.function.Function; public abstract class BaseTableColumnTask extends BaseTableTask { - private String myColumnName; + protected Map, Object>> myCalculators = new HashMap<>(); + protected String myColumnName; //If a concrete class decides to, they can define a custom WHERE clause for the task. - private String myWhereClause; + protected String myWhereClause; public BaseTableColumnTask(String theProductVersion, String theSchemaVersion) { super(theProductVersion, theSchemaVersion); @@ -75,4 +79,10 @@ public abstract class BaseTableColumnTask extends BaseTableTask { super.generateHashCode(theBuilder); theBuilder.append(myColumnName); } + + public BaseTableColumnTask addCalculator(String theColumnName, Function, Object> theConsumer) { + Validate.isTrue(myCalculators.containsKey(theColumnName) == false); + myCalculators.put(theColumnName, theConsumer); + return this; + } } diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java index 7b8fdb0c097..7220bf0ced6 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java @@ -78,9 +78,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { spidxDate.addColumn("20200225.2", "SP_VALUE_HIGH_DATE_ORDINAL").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.INT); spidxDate.addTask(new CalculateOrdinalDatesTask(VersionEnum.V4_3_0, "20200225.3") - .setColumnName("SP_VALUE_LOW_DATE_ORDINAL") //It doesn't matter which of the two we choose as they will both be null. .addCalculator("SP_VALUE_LOW_DATE_ORDINAL", t -> ResourceIndexedSearchParamDate.calculateOrdinalValue(t.getDate("SP_VALUE_LOW"))) .addCalculator("SP_VALUE_HIGH_DATE_ORDINAL", t -> ResourceIndexedSearchParamDate.calculateOrdinalValue(t.getDate("SP_VALUE_HIGH"))) + .setColumnName("SP_VALUE_LOW_DATE_ORDINAL") //It doesn't matter which of the two we choose as they will both be null. ); // @@ -541,8 +541,8 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .withColumns("HASH_IDENTITY", "SP_LATITUDE", "SP_LONGITUDE"); spidxCoords .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.5") - .setColumnName("HASH_IDENTITY") .addCalculator("HASH_IDENTITY", t -> BaseResourceIndexedSearchParam.calculateHashIdentity(new PartitionSettings(), null, t.getResourceType(), t.getString("SP_NAME"))) + .setColumnName("HASH_IDENTITY") ); } @@ -564,8 +564,8 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .dropIndex("20180903.9", "IDX_SP_DATE"); spidxDate .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.10") - .setColumnName("HASH_IDENTITY") .addCalculator("HASH_IDENTITY", t -> BaseResourceIndexedSearchParam.calculateHashIdentity(new PartitionSettings(), null, t.getResourceType(), t.getString("SP_NAME"))) + .setColumnName("HASH_IDENTITY") ); } @@ -585,8 +585,8 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .withColumns("HASH_IDENTITY", "SP_VALUE"); spidxNumber .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.14") - .setColumnName("HASH_IDENTITY") .addCalculator("HASH_IDENTITY", t -> BaseResourceIndexedSearchParam.calculateHashIdentity(new PartitionSettings(), null, t.getResourceType(), t.getString("SP_NAME"))) + .setColumnName("HASH_IDENTITY") ); } @@ -622,10 +622,10 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .withColumns("HASH_IDENTITY_SYS_UNITS", "SP_VALUE"); spidxQuantity .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.22") - .setColumnName("HASH_IDENTITY") .addCalculator("HASH_IDENTITY", t -> BaseResourceIndexedSearchParam.calculateHashIdentity(new PartitionSettings(), null, t.getResourceType(), t.getString("SP_NAME"))) .addCalculator("HASH_IDENTITY_AND_UNITS", t -> ResourceIndexedSearchParamQuantity.calculateHashUnits(new PartitionSettings(), null, t.getResourceType(), t.getString("SP_NAME"), t.getString("SP_UNITS"))) .addCalculator("HASH_IDENTITY_SYS_UNITS", t -> ResourceIndexedSearchParamQuantity.calculateHashSystemAndUnits(new PartitionSettings(), null, t.getResourceType(), t.getString("SP_NAME"), t.getString("SP_SYSTEM"), t.getString("SP_UNITS"))) + .setColumnName("HASH_IDENTITY") ); }