Skip to content

Commit

Permalink
Hibernate ORM DevUI - Fix import file not being appended to DDL schema
Browse files Browse the repository at this point in the history
The import file name was not correctly handed over to the SchemaExport
utility.
  • Loading branch information
TomasHofman committed Aug 10, 2021
1 parent 591c0de commit 66e1b37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public PersistenceUnitsInfo get() {
}

public static void pushPersistenceUnit(String persistenceUnitName,
Metadata metadata, ServiceRegistry serviceRegistry) {
Metadata metadata, ServiceRegistry serviceRegistry, String importFile) {
INSTANCE.getPersistenceUnits().add(persistenceUnitName);

String createSchema = generateDDL(SchemaExport.Action.CREATE, metadata, serviceRegistry);
String createSchema = generateDDL(SchemaExport.Action.CREATE, metadata, serviceRegistry, importFile);
INSTANCE.createDDLs.put(persistenceUnitName, createSchema);

String dropSchema = generateDDL(SchemaExport.Action.DROP, metadata, serviceRegistry);
String dropSchema = generateDDL(SchemaExport.Action.DROP, metadata, serviceRegistry, importFile);
INSTANCE.dropDDLs.put(persistenceUnitName, dropSchema);

for (PersistentClass entityBinding : metadata.getEntityBindings()) {
Expand All @@ -60,10 +60,12 @@ public static void pushPersistenceUnit(String persistenceUnitName,
}
}

private static String generateDDL(SchemaExport.Action action, Metadata metadata, ServiceRegistry serviceRegistry) {
private static String generateDDL(SchemaExport.Action action, Metadata metadata, ServiceRegistry serviceRegistry,
String importFiles) {
SchemaExport schemaExport = new SchemaExport();
schemaExport.setFormat(true);
schemaExport.setDelimiter(";");
schemaExport.setImportFiles(importFiles);
StringWriter writer = new StringWriter();
schemaExport.doExecution(action, false, metadata, serviceRegistry,
new TargetDescriptor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.hibernate.orm.runtime.devconsole;

import static org.hibernate.cfg.AvailableSettings.HBM2DDL_IMPORT_FILES;

import org.hibernate.boot.Metadata;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
Expand All @@ -12,7 +14,8 @@ public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactor
SessionFactoryServiceRegistry sessionFactoryServiceRegistry) {
HibernateOrmDevConsoleInfoSupplier.pushPersistenceUnit(
(String) sessionFactoryImplementor.getProperties().get(AvailableSettings.PERSISTENCE_UNIT_NAME),
metadata, sessionFactoryServiceRegistry);
metadata, sessionFactoryServiceRegistry,
(String) sessionFactoryImplementor.getProperties().get(HBM2DDL_IMPORT_FILES));
}

@Override
Expand Down

0 comments on commit 66e1b37

Please sign in to comment.