Fix postgres startup failure (#5539)

* Fix postgres startup failure

* Spotless
This commit is contained in:
James Agnew 2023-12-06 12:33:34 -05:00 committed by GitHub
parent 5fa20438b6
commit 9027138962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 28 deletions

View File

@ -578,8 +578,8 @@
</dialect>
<dialect>
<className>ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgresDialect</className>
<prependFile>classpath:ca/uhn/fhir/jpa/docs/database/hapifhirpostgres94-init01.sql</prependFile>
<targetFileName>postgres.sql</targetFileName>
<appendFile>classpath:ca/uhn/fhir/jpa/docs/database/hapifhirpostgres94-init01.sql</appendFile>
</dialect>
</dialects>
<outputDirectory>${project.build.directory}/classes/ca/uhn/hapi/fhir/jpa/docs/database</outputDirectory>

View File

@ -112,15 +112,7 @@ public class DdlGeneratorHibernate61 {
}
}
if (isNotBlank(nextDialect.getPrependFile())) {
ResourceLoader loader = new DefaultResourceLoader(classLoader);
Resource resource = loader.getResource(nextDialect.getPrependFile());
try (Writer w = new FileWriter(outputFile, false)) {
w.append(resource.getContentAsString(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new MojoFailureException("Failed to write to file " + outputFile + ": " + e.getMessage(), e);
}
}
writeContentsToFile(nextDialect.getPrependFile(), classLoader, outputFile);
String outputFileName = outputFile.getAbsolutePath();
ourLog.info("Writing to file: {}", outputFileName);
@ -130,6 +122,21 @@ public class DdlGeneratorHibernate61 {
schemaExport.setDelimiter(";");
schemaExport.setOutputFile(outputFileName);
schemaExport.execute(targetTypes, action, metadata, standardRegistry);
writeContentsToFile(nextDialect.getAppendFile(), classLoader, outputFile);
}
}
private static void writeContentsToFile(String prependFile, ClassLoader classLoader, File outputFile)
throws MojoFailureException {
if (isNotBlank(prependFile)) {
ResourceLoader loader = new DefaultResourceLoader(classLoader);
Resource resource = loader.getResource(prependFile);
try (Writer w = new FileWriter(outputFile, true)) {
w.append(resource.getContentAsString(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new MojoFailureException("Failed to write to file " + outputFile + ": " + e.getMessage(), e);
}
}
}

View File

@ -68,11 +68,29 @@ public class GenerateDdlMojo extends AbstractMojo {
generator.generateDdl();
}
public static void main(String[] args) throws MojoExecutionException, MojoFailureException {
/*
* Note, to execute this, add the following snippet to this module's POM. The whole project won't work with
* that added, but you can add it temporarily in order to debug this in IJ:
* <dependency>
* <groupId>ca.uhn.hapi.fhir</groupId>
* <artifactId>hapi-fhir-jpaserver-model</artifactId>
* <version>${project.version}</version>
* </dependency>
*/
GenerateDdlMojo m = new GenerateDdlMojo();
m.packageNames = List.of("ca.uhn.fhir.jpa.model.entity");
m.outputDirectory = "hapi-tinder-plugin/target";
m.dialects = List.of(new Dialect("ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect", "h2.sql"));
m.execute();
}
public static class Dialect {
private String className;
private String targetFileName;
private String prependFile;
private String appendFile;
public Dialect() {
super();
@ -84,6 +102,14 @@ public class GenerateDdlMojo extends AbstractMojo {
setTargetFileName(theTargetFileName);
}
public String getAppendFile() {
return appendFile;
}
public void setAppendFile(String theAppendFile) {
appendFile = theAppendFile;
}
public String getClassName() {
return className;
}
@ -108,21 +134,4 @@ public class GenerateDdlMojo extends AbstractMojo {
prependFile = thePrependFile;
}
}
public static void main(String[] args) throws MojoExecutionException, MojoFailureException {
/*
* Note, to execute this, add the following snippet to this module's POM. The whole project won't work with
* that added, but you can add it temporarily in order to debug this in IJ:
* <dependency>
* <groupId>ca.uhn.hapi.fhir</groupId>
* <artifactId>hapi-fhir-jpaserver-model</artifactId>
* <version>${project.version}</version>
* </dependency>
*/
GenerateDdlMojo m = new GenerateDdlMojo();
m.packageNames = List.of("ca.uhn.fhir.jpa.model.entity");
m.outputDirectory = "hapi-tinder-plugin/target";
m.dialects = List.of(new Dialect("ca.uhn.fhir.jpa.model.dialect.HapiFhirH2Dialect", "h2.sql"));
m.execute();
}
}

View File

@ -963,7 +963,7 @@
<reflections_version>0.9.11</reflections_version>
<servicemix_saxon_version>9.8.0-15</servicemix_saxon_version>
<servicemix_xmlresolver_version>1.2_5</servicemix_xmlresolver_version>
<swagger_version>2.1.12</swagger_version>
<swagger_version>2.2.19</swagger_version>
<slf4j_version>2.0.3</slf4j_version>
<log4j_to_slf4j_version>2.19.0</log4j_to_slf4j_version>
<spring_version>6.0.12</spring_version>