Skip to content

Commit

Permalink
Fix JPA nullable primitive columns (#5926)
Browse files Browse the repository at this point in the history
* Fix JPA nullable primitive columns

* Add changelog

* Spotless

* License headers

* Migration fix

* Spotless

* Cleanup

* Cleanup

* Add task skipping

* Update docs

* CLeanup

* Spotless

* Address review comments

* Test fix

* HAPI FHIR version bump
  • Loading branch information
jamesagnew committed Jun 18, 2024
1 parent ec0021c commit 47d6e35
Show file tree
Hide file tree
Showing 111 changed files with 721 additions and 352 deletions.
2 changes: 1 addition & 1 deletion hapi-deployable-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
4 changes: 2 additions & 2 deletions hapi-fhir-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-bom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<packaging>pom</packaging>
<name>HAPI FHIR BOM</name>

<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-checkstyle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/hapi-fhir-cli-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;
Expand All @@ -40,12 +38,12 @@
* NB since 2019-12-05: This class is kind of weirdly named now, since it can either use Flyway or not use Flyway
*/
public abstract class BaseFlywayMigrateDatabaseCommand<T extends Enum> extends BaseCommand {
private static final Logger ourLog = LoggerFactory.getLogger(BaseFlywayMigrateDatabaseCommand.class);

public static final String MIGRATE_DATABASE = "migrate-database";
public static final String NO_COLUMN_SHRINK = "no-column-shrink";
public static final String STRICT_ORDER = "strict-order";
public static final String SKIP_VERSIONS = "skip-versions";
public static final String ENABLE_HEAVYWEIGHT_MIGRATIONS = "enable-heavyweight-migrations";

private Set<String> myFlags;
private String myMigrationTableName;

Expand Down Expand Up @@ -100,6 +98,12 @@ public Options getOptions() {
SKIP_VERSIONS,
"Versions",
"A comma separated list of schema versions to skip. E.g. 4_1_0.20191214.2,4_1_0.20191214.4");
addOptionalOption(
retVal,
null,
ENABLE_HEAVYWEIGHT_MIGRATIONS,
false,
"If this flag is set, additional migration tasks will be executed that are considered unnecessary to execute on a database with a significant amount of data loaded. This option is not generally necessary.");

return retVal;
}
Expand All @@ -125,6 +129,7 @@ public void run(CommandLine theCommandLine) throws ParseException {

boolean dryRun = theCommandLine.hasOption("r");
boolean noColumnShrink = theCommandLine.hasOption(BaseFlywayMigrateDatabaseCommand.NO_COLUMN_SHRINK);
boolean runHeavyweight = theCommandLine.hasOption(ENABLE_HEAVYWEIGHT_MIGRATIONS);

String flags = theCommandLine.getOptionValue("x");
myFlags = Arrays.stream(defaultString(flags).split(","))
Expand All @@ -139,6 +144,7 @@ public void run(CommandLine theCommandLine) throws ParseException {

migrator.createMigrationTableIfRequired();
migrator.setDryRun(dryRun);
migrator.setRunHeavyweightSkippableTasks(runHeavyweight);
migrator.setNoColumnShrink(noColumnShrink);
String skipVersions = theCommandLine.getOptionValue(BaseFlywayMigrateDatabaseCommand.SKIP_VERSIONS);
addTasks(migrator, skipVersions);
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/hapi-fhir-cli-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-cli</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-client-okhttp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
type: fix
issue: 5926
title: "A number of columns in the JPA schema use primitive types (and therefore can never have a null value) but aren't marked as non-null."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
type: fix
issue: 5926
title: "A regression in HAPI FHIR 6.4.0 meant that ther JPA server schema migrator ran all tasks
even when the database was initially empty and the schema was being initialized by script.
This did not produce any incorrect results, but did impact the amount of time taken to initialize
an empty database. This has been corrected."
2 changes: 1 addition & 1 deletion hapi-fhir-jacoco/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jaxrsserver-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion hapi-fhir-jpaserver-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>7.3.7-SNAPSHOT</version>
<version>7.3.8-SNAPSHOT</version>

<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ public class Batch2JobInstanceEntity implements Serializable {
@Column(name = "WORK_CHUNKS_PURGED", nullable = false)
private boolean myWorkChunksPurged;

@Column(name = "PROGRESS_PCT")
@Column(name = "PROGRESS_PCT", nullable = false)
private double myProgress;

@Column(name = "ERROR_MSG", length = ERROR_MSG_MAX_LENGTH, nullable = true)
private String myErrorMessage;

@Column(name = "ERROR_COUNT")
@Column(name = "ERROR_COUNT", nullable = false)
private int myErrorCount;

@Column(name = "EST_REMAINING", length = TIME_REMAINING_LENGTH, nullable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,20 @@ public class Batch2WorkChunkEntity implements Serializable {

/**
* The number of times the work chunk has had its state set back to POLL_WAITING.
* <p>
* TODO: Note that this column was added in 7.2.0, so it is nullable in order to
* account for existing rows that were added before the column was added. In
* the future we should make this non-null.
*/
@Column(name = "POLL_ATTEMPTS", nullable = true)
private Integer myPollAttempts;

/**
* Default constructor for Hibernate.
*/
public Batch2WorkChunkEntity() {}
public Batch2WorkChunkEntity() {
myPollAttempts = 0;
}

/**
* Projection constructor for no-data path.
Expand Down Expand Up @@ -184,7 +190,7 @@ public Batch2WorkChunkEntity(
myRecordsProcessed = theRecordsProcessed;
myWarningMessage = theWarningMessage;
myNextPollTime = theNextPollTime;
myPollAttempts = thePollAttempts;
myPollAttempts = thePollAttempts != null ? thePollAttempts : 0;
}

public static Batch2WorkChunkEntity fromWorkChunk(WorkChunk theWorkChunk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class HapiFhirEnversRevision implements Serializable {
@SequenceGenerator(name = "SEQ_HFJ_REVINFO", sequenceName = "SEQ_HFJ_REVINFO")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_HFJ_REVINFO")
@RevisionNumber
@Column(name = "REV")
@Column(name = "REV", nullable = false)
private long myRev;

@RevisionTimestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ public class TermConcept implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "CODESYSTEM_PID",
nullable = false,
referencedColumnName = "PID",
foreignKey = @ForeignKey(name = "FK_CONCEPT_PID_CS_PID"))
private TermCodeSystemVersion myCodeSystem;

@Column(name = "CODESYSTEM_PID", insertable = false, updatable = false)
@Column(name = "CODESYSTEM_PID", insertable = false, updatable = false, nullable = false)
@GenericField(name = "myCodeSystemVersionPid")
private long myCodeSystemVersionPid;

Expand Down
Loading

0 comments on commit 47d6e35

Please sign in to comment.