Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attempt to parse empty SQL scripts #11353

Merged
merged 3 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
Expand Down Expand Up @@ -706,25 +705,22 @@ private void handleHibernateORMWithNoPersistenceXml(
// sql-load-script
Optional<String> importFile = getSqlLoadScript(launchMode);

if (!importFile.isPresent()) {
// explicitly set a no file and ignore all other operations
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES, NO_SQL_LOAD_SCRIPT_FILE);
} else {
if (importFile.isPresent()) {
Path loadScriptPath = applicationArchivesBuildItem.getRootArchive().getChildPath(importFile.get());

if (loadScriptPath != null && !Files.isDirectory(loadScriptPath)) {
// enlist resource if present
resourceProducer.produce(new NativeImageResourceBuildItem(importFile.get()));
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES, importFile.get());
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR,
MultipleLinesSqlCommandExtractor.class.getName());

} else if (hibernateConfig.sqlLoadScript.isPresent()) {
//raise exception if explicit file is not present (i.e. not the default)
throw new ConfigurationError(
"Unable to find file referenced in '" + HIBERNATE_ORM_CONFIG_PREFIX + "sql-load-script="
+ hibernateConfig.sqlLoadScript.get() + "'. Remove property or add file to your path.");
}
} else {
//Disable implicit loading of the default import script (import.sql)
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES, "");
}

// Caching
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.hibernate.orm.runtime.service;

import java.util.Map;

import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractor;
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractorInitiator;
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;

public final class QuarkusImportSqlCommandExtractorInitiator implements StandardServiceInitiator<ImportSqlCommandExtractor> {
public static final ImportSqlCommandExtractorInitiator INSTANCE = new ImportSqlCommandExtractorInitiator();
private static final MultipleLinesSqlCommandExtractor SERVICE_INSTANCE = new MultipleLinesSqlCommandExtractor();

@Override
public ImportSqlCommandExtractor initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return SERVICE_INSTANCE;
}

@Override
public Class<ImportSqlCommandExtractor> getServiceInitiated() {
return ImportSqlCommandExtractor.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hibernate.resource.beans.spi.ManagedBeanRegistryInitiator;
import org.hibernate.resource.transaction.internal.TransactionCoordinatorBuilderInitiator;
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractorInitiator;
import org.hibernate.tool.schema.internal.SchemaManagementToolInitiator;

import io.quarkus.hibernate.orm.runtime.customized.BootstrapOnlyProxyFactoryFactoryInitiator;
Expand Down Expand Up @@ -48,7 +47,7 @@ public List<StandardServiceInitiator> initialInitiatorList() {
serviceInitiators.add(ConfigurationServiceInitiator.INSTANCE);
serviceInitiators.add(PropertyAccessStrategyResolverInitiator.INSTANCE);

serviceInitiators.add(ImportSqlCommandExtractorInitiator.INSTANCE);
serviceInitiators.add(QuarkusImportSqlCommandExtractorInitiator.INSTANCE);
serviceInitiators.add(SchemaManagementToolInitiator.INSTANCE);

serviceInitiators.add(JdbcEnvironmentInitiator.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.datasource.runtime.DataSourcesBuildTimeConfig;
Expand Down Expand Up @@ -234,27 +233,23 @@ private ParsedPersistenceXmlDescriptor generateReactivePersistenceUnit(
// sql-load-script
Optional<String> importFile = getSqlLoadScript(launchMode);

if (!importFile.isPresent()) {
// explicitly set a no file and ignore all other operations
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES,
HibernateOrmProcessor.NO_SQL_LOAD_SCRIPT_FILE);
} else {
if (importFile.isPresent()) {
Path loadScriptPath = applicationArchivesBuildItem.getRootArchive().getChildPath(importFile.get());

if (loadScriptPath != null && !Files.isDirectory(loadScriptPath)) {
// enlist resource if present
resourceProducer.produce(new NativeImageResourceBuildItem(importFile.get()));
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES, importFile.get());
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR,
MultipleLinesSqlCommandExtractor.class.getName());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised you don't report the other changes in the reactive case given you told me it was the initial project reporting the issue. I will push an additional commit to do that and we can discuss it when you're back if it wasn't the thing to do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, yes I forgot there was similar code in the reactive processor.

To explain the "surprise": it's not the Reactive extension which was needing this; the change is required in Quarkus/ORM (blocking) to be compatible with ORM 5.4.20 - which is in turn required by Hibernate Reactive current master.

} else if (hibernateConfig.sqlLoadScript.isPresent()) {
//raise exception if explicit file is not present (i.e. not the default)
throw new ConfigurationError(
"Unable to find file referenced in '" + HibernateOrmProcessor.HIBERNATE_ORM_CONFIG_PREFIX
+ "sql-load-script="
+ hibernateConfig.sqlLoadScript.get() + "'. Remove property or add file to your path.");
}
} else {
//Disable implicit loading of the default import script (import.sql)
desc.getProperties().setProperty(AvailableSettings.HBM2DDL_IMPORT_FILES, "");
}

// Caching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import org.hibernate.resource.beans.spi.ManagedBeanRegistryInitiator;
import org.hibernate.resource.transaction.internal.TransactionCoordinatorBuilderInitiator;
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractorInitiator;
import org.hibernate.tool.schema.internal.SchemaManagementToolInitiator;

import io.quarkus.hibernate.orm.runtime.customized.BootstrapOnlyProxyFactoryFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.customized.QuarkusJndiServiceInitiator;
import io.quarkus.hibernate.orm.runtime.service.DialectFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.DisabledJMXInitiator;
import io.quarkus.hibernate.orm.runtime.service.InitialInitiatorListProvider;
import io.quarkus.hibernate.orm.runtime.service.QuarkusImportSqlCommandExtractorInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusMutableIdentifierGeneratorFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.QuarkusRegionFactoryInitiator;
import io.quarkus.hibernate.orm.runtime.service.StandardHibernateORMInitiatorListProvider;
Expand Down Expand Up @@ -64,7 +64,7 @@ public List<StandardServiceInitiator> initialInitiatorList() {
serviceInitiators.add(ConfigurationServiceInitiator.INSTANCE);
serviceInitiators.add(PropertyAccessStrategyResolverInitiator.INSTANCE);

serviceInitiators.add(ImportSqlCommandExtractorInitiator.INSTANCE);
serviceInitiators.add(QuarkusImportSqlCommandExtractorInitiator.INSTANCE);
serviceInitiators.add(SchemaManagementToolInitiator.INSTANCE);

serviceInitiators.add(JdbcEnvironmentInitiator.INSTANCE);
Expand Down