From f9a587bf941d162d71dfd97fae698d86c6cd53a0 Mon Sep 17 00:00:00 2001 From: Tomas Hofman Date: Fri, 23 Apr 2021 16:28:31 +0200 Subject: [PATCH 1/8] Hibernate ORM DevUI * provide information about persistence units and their managed entities * allow user to generate create-schema script --- extensions/hibernate-orm/deployment/pom.xml | 4 + .../devconsole/DevConsoleProcessor.java | 15 ++ .../resources/dev-templates/embedded.html | 11 ++ .../dev-templates/managed-entities.html | 33 ++++ .../dev-templates/named-queries.html | 37 ++++ .../dev-templates/persistence-units.html | 58 +++++++ extensions/hibernate-orm/runtime/pom.xml | 4 + .../FastBootHibernatePersistenceProvider.java | 23 +++ .../runtime/PersistenceUnitInfoSupplier.java | 159 ++++++++++++++++++ .../orm/runtime/PersistenceUnitsHolder.java | 9 +- .../FastBootEntityManagerFactoryBuilder.java | 44 +++++ .../PreconfiguredServiceRegistryBuilder.java | 8 +- 12 files changed, 403 insertions(+), 2 deletions(-) create mode 100644 extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java create mode 100644 extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html create mode 100644 extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html create mode 100644 extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html create mode 100644 extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html create mode 100644 extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitInfoSupplier.java diff --git a/extensions/hibernate-orm/deployment/pom.xml b/extensions/hibernate-orm/deployment/pom.xml index 75cea02da2efe..f525efe53e31f 100644 --- a/extensions/hibernate-orm/deployment/pom.xml +++ b/extensions/hibernate-orm/deployment/pom.xml @@ -41,6 +41,10 @@ io.quarkus quarkus-panache-hibernate-common-deployment + + io.quarkus + quarkus-vertx-http-deployment + io.quarkus quarkus-junit5-internal diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java new file mode 100644 index 0000000000000..a955ea0336641 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java @@ -0,0 +1,15 @@ +package io.quarkus.hibernate.orm.deployment.devconsole; + +import io.quarkus.deployment.IsDevelopment; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; +import io.quarkus.hibernate.orm.runtime.PersistenceUnitInfoSupplier; + +public class DevConsoleProcessor { + + @BuildStep(onlyIf = IsDevelopment.class) + public DevConsoleRuntimeTemplateInfoBuildItem collectDeploymentUnits() { + return new DevConsoleRuntimeTemplateInfoBuildItem("persistence", new PersistenceUnitInfoSupplier()); + } + +} diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html new file mode 100644 index 0000000000000..521a07c0e24f1 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html @@ -0,0 +1,11 @@ + + + Persistence units {info:persistence.persistenceUnits.size} + + + + Entities {info:persistence.managedEntities.size} + + + + Named Queries {info:persistence.allNamedQueries.size} diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html new file mode 100644 index 0000000000000..ffb0e52cd5883 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html @@ -0,0 +1,33 @@ +{#include main} +{#style} +{/style} +{#title}Managed Entities{/title} +{#body} + +{#if info:persistence.managedEntities.isEmpty} +

No entities were found.

+{#else} + + + + + + + + + + + {#for entity in info:persistence.managedEntities} + + + + + + + {/for} + +
#Class nameTable namePersistence Unit
{count}.{entity.className}{entity.tableName}{entity.persistenceUnitName}
+{/if} + +{/body} +{/include} diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html new file mode 100644 index 0000000000000..8bafda4a2fa46 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html @@ -0,0 +1,37 @@ +{#include main} +{#style} +{/style} +{#title}Named Queries{/title} +{#body} + +{#if info:persistence.allNamedQueries.isEmpty} +

No named queries were found.

+{#else} + + + + + + + + + + + + + {#for query in info:persistence.allNamedQueries} + + + + + + + + + {/for} + +
#NameQueryLock ModeCacheableQuery Type
{count}.{query.name}{query.query}{query.lockMode}{query.cacheable}{query.type}
+{/if} + +{/body} +{/include} diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html new file mode 100644 index 0000000000000..9d01ed2754660 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html @@ -0,0 +1,58 @@ +{#include main} +{#style} +.ddl-script { + background-color: white; + padding: 5px; +} +{/style} +{#title}Persistence Units{/title} +{#body} + +{#if info:persistence.persistenceUnits.isEmpty} +

No persistence units found.

+{#else} + + + + + + + + + + {#for unit in info:persistence.persistenceUnits} + + + + + + {/for} + +
#Persistence Unit NameDDL
{count}.{unit.name} +

+ Create script: + + Copy +

+
{info:persistence.createDDLs.get(unit.getName())}
+
+{/if} + + + +{/body} +{/include} diff --git a/extensions/hibernate-orm/runtime/pom.xml b/extensions/hibernate-orm/runtime/pom.xml index d1b7b59b09597..7a149ee01331c 100644 --- a/extensions/hibernate-orm/runtime/pom.xml +++ b/extensions/hibernate-orm/runtime/pom.xml @@ -41,6 +41,10 @@ io.quarkus quarkus-narayana-jta
+ + io.quarkus + quarkus-vertx-http + org.hibernate hibernate-core diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java index 533e342981f09..4322e5b6f9af1 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java @@ -1,5 +1,6 @@ package io.quarkus.hibernate.orm.runtime; +import java.io.StringWriter; import java.util.Collections; import java.util.List; import java.util.Map; @@ -99,6 +100,28 @@ public boolean generateSchema(String persistenceUnitName, Map map) { return true; } + /** + * TODO: Figure out how to provide separate "create" and "drop" scripts. Currently this only do "create". + * + * A variant of {@link #generateSchema(String persistenceUnitName, Map map)} that returns the SQL script as a string. + * + * @param persistenceUnitName PU name + * @param map should be always null, as Quarkus doesn't allow to provide any properties in runtime. + * @return schema as string + */ + @SuppressWarnings("rawtypes") + public String generateSchemaToString(String persistenceUnitName, Map map) { + final FastBootEntityManagerFactoryBuilder builder = (FastBootEntityManagerFactoryBuilder) getEntityManagerFactoryBuilderOrNull( + persistenceUnitName, map); + if (builder == null) { + log.trace("Could not obtain matching EntityManagerFactoryBuilder, returning null"); + return null; + } + StringWriter createWriter = new StringWriter(); + builder.generateSchema(createWriter); + return createWriter.toString(); + } + @Override public ProviderUtil getProviderUtil() { return providerUtil; diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitInfoSupplier.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitInfoSupplier.java new file mode 100644 index 0000000000000..85dbf22c57e62 --- /dev/null +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitInfoSupplier.java @@ -0,0 +1,159 @@ +package io.quarkus.hibernate.orm.runtime; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +import javax.persistence.spi.PersistenceProviderResolverHolder; + +import org.hibernate.LockOptions; +import org.hibernate.engine.spi.NamedQueryDefinition; +import org.hibernate.engine.spi.NamedSQLQueryDefinition; +import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; +import org.hibernate.mapping.PersistentClass; + +import io.quarkus.hibernate.orm.runtime.recording.RecordedState; + +public class PersistenceUnitInfoSupplier implements Supplier { + + @Override + public PersistenceUnitsInfo get() { + return composePersistenceUnitsInfo(PersistenceUnitsHolder.getPersistenceUnitDescriptors()); + } + + private PersistenceUnitsInfo composePersistenceUnitsInfo(List persistenceUnits) { + PersistenceUnitsInfo persistenceUnitsInfo = new PersistenceUnitsInfo(); + + FastBootHibernatePersistenceProvider persistenceProvider = (FastBootHibernatePersistenceProvider) PersistenceProviderResolverHolder + .getPersistenceProviderResolver().getPersistenceProviders().get(0); + + for (PersistenceUnitDescriptor descriptor : persistenceUnits) { + persistenceUnitsInfo.getPersistenceUnits().add(descriptor); + RecordedState recordedState = PersistenceUnitsHolder.popRecordedState(descriptor.getName()); + + String schema = persistenceProvider.generateSchemaToString(descriptor.getName(), null); + persistenceUnitsInfo.createDDLs.put(descriptor.getName(), schema); + + for (String className : descriptor.getManagedClassNames()) { + PersistentClass entityBinding = recordedState.getMetadata().getEntityBinding(className); + persistenceUnitsInfo.managedEntities.add(new PersistenceUnitInfoSupplier.EntityInfo(className, + entityBinding.getTable().getName(), descriptor.getName())); + } + + for (NamedQueryDefinition queryDefinition : recordedState.getMetadata().getNamedQueryDefinitions()) { + persistenceUnitsInfo.namedQueries.add(new QueryInfo(queryDefinition)); + } + + for (NamedSQLQueryDefinition staticQueryDefinition : recordedState.getMetadata().getNamedNativeQueryDefinitions()) { + persistenceUnitsInfo.namedNativeQueries.add(new QueryInfo(staticQueryDefinition)); + } + } + + return persistenceUnitsInfo; + } + + public static class PersistenceUnitsInfo { + + private final List persistenceUnits = new ArrayList<>(); + private final List managedEntities = new ArrayList<>(); + private final List namedQueries = new ArrayList<>(); + private final List namedNativeQueries = new ArrayList<>(); + private final Map createDDLs = new HashMap<>(); + + public List getPersistenceUnits() { + return persistenceUnits; + } + + public Map getCreateDDLs() { + return createDDLs; + } + + public List getManagedEntities() { + return managedEntities; + } + + public List getNamedQueries() { + return namedQueries; + } + + public List getNamedNativeQueries() { + return namedNativeQueries; + } + + public List getAllNamedQueries() { + ArrayList allQueries = new ArrayList<>(); + allQueries.addAll(namedQueries); + allQueries.addAll(namedNativeQueries); + return allQueries; + } + + } + + public static class EntityInfo { + + private final String className; + private final String tableName; + private final String persistenceUnitName; + + public EntityInfo(String className, String tableName, String persistenceUnitName) { + this.className = className; + this.tableName = tableName; + this.persistenceUnitName = persistenceUnitName; + } + + public String getClassName() { + return className; + } + + public String getTableName() { + return tableName; + } + + public String getPersistenceUnitName() { + return persistenceUnitName; + } + } + + public static class QueryInfo { + + private final String name; + private final String query; + private final boolean cacheable; + private final String lockMode; + private final String type; + + public QueryInfo(NamedQueryDefinition queryDefinition) { + this.name = queryDefinition.getName(); + this.query = queryDefinition.getQuery(); + this.cacheable = queryDefinition.isCacheable(); + LockOptions lockOptions = queryDefinition.getLockOptions(); + this.lockMode = lockOptions != null && lockOptions.getLockMode() != null + ? lockOptions.getLockMode().name() + : ""; + this.type = queryDefinition instanceof NamedSQLQueryDefinition ? "native" : "JPQL"; + } + + public String getName() { + return name; + } + + public String getQuery() { + return query; + } + + public boolean isCacheable() { + return cacheable; + } + + public String getLockMode() { + return lockMode; + } + + public String getType() { + return type; + } + + } +} diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitsHolder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitsHolder.java index fb9ba1c76f156..b675f8eb59756 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitsHolder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitsHolder.java @@ -14,6 +14,7 @@ import io.quarkus.hibernate.orm.runtime.boot.QuarkusPersistenceUnitDefinition; import io.quarkus.hibernate.orm.runtime.proxies.PreGeneratedProxies; import io.quarkus.hibernate.orm.runtime.recording.RecordedState; +import io.quarkus.runtime.LaunchMode; public final class PersistenceUnitsHolder { @@ -54,7 +55,13 @@ public static RecordedState popRecordedState(String persistenceUnitName) { if (persistenceUnitName == null) { key = NO_NAME_TOKEN; } - return persistenceUnits.recordedStates.remove(key); + // Do not remove the PU metadata in dev-mode, we need them to generate information for DevUI pages. + // In normal mode, we want to remove these metadata as the associated memory cost is large. + if (LaunchMode.DEVELOPMENT == LaunchMode.current()) { + return persistenceUnits.recordedStates.get(key); + } else { + return persistenceUnits.recordedStates.remove(key); + } } private static List convertPersistenceUnits( diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java index f7709c9edf8ab..a7316428f5281 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java @@ -1,7 +1,9 @@ package io.quarkus.hibernate.orm.runtime.boot; import java.io.Serializable; +import java.io.Writer; import java.security.NoSuchAlgorithmException; +import java.util.EnumSet; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityNotFoundException; @@ -24,9 +26,14 @@ import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.schema.TargetType; +import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToWriter; import org.hibernate.tool.schema.spi.CommandAcceptanceException; import org.hibernate.tool.schema.spi.DelayedDropRegistryNotAvailableImpl; import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator; +import org.hibernate.tool.schema.spi.ScriptTargetOutput; +import org.hibernate.tool.schema.spi.TargetDescriptor; import io.quarkus.hibernate.orm.runtime.RuntimeSettings; import io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata; @@ -92,6 +99,43 @@ public void generateSchema() { cancel(); } + /** + * TODO: provide a second writer parameter for "drop" script, or create a second method. + * + * @param createWriter + */ + public void generateSchema(final Writer createWriter) { + try { + SchemaExport schemaExport = new SchemaExport(); + schemaExport.setFormat(true); + schemaExport.setDelimiter(";"); + schemaExport.doExecution(SchemaExport.Action.CREATE, false, metadata, standardServiceRegistry, + new TargetDescriptor() { + + @Override + public EnumSet getTargetTypes() { + return EnumSet.of(TargetType.SCRIPT); + } + + @Override + public ScriptTargetOutput getScriptTargetOutput() { + return new ScriptTargetOutputToWriter(createWriter) { + @Override + public void accept(String command) { + super.accept(command); + } + }; + } + }); + + } catch (Exception e) { + throw persistenceException("Error performing schema management", e); + } + + // release this builder + cancel(); + } + protected PersistenceException persistenceException(String message, Exception cause) { // Provide a comprehensible message if there is an issue with SSL support Throwable t = cause; diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/registry/PreconfiguredServiceRegistryBuilder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/registry/PreconfiguredServiceRegistryBuilder.java index c90ac314b263a..065a0a9b2c777 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/registry/PreconfiguredServiceRegistryBuilder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/registry/PreconfiguredServiceRegistryBuilder.java @@ -106,7 +106,13 @@ public StandardServiceRegistryImpl buildNewServiceRegistry() { final Map settingsCopy = new HashMap(); settingsCopy.putAll(configurationValues); - destroyedRegistry.resetAndReactivate(bootstrapServiceRegistry, initiators, providedServices, settingsCopy); + // FIXME: resetAndReactivate() throws "IllegalStateException: Can't reactivate an active registry!" + // during persistenceProvider.generateSchema() execution (a new PersistenceProvider instance is constructed + // during this call). + // Is it OK to skip the resetAndReactivate() call when the registry is already active? + if (!destroyedRegistry.isActive()) { + destroyedRegistry.resetAndReactivate(bootstrapServiceRegistry, initiators, providedServices, settingsCopy); + } return destroyedRegistry; // return new StandardServiceRegistryImpl( From 90ca472e742e0741ab910eef9e78db49ed1b906a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 2 Aug 2021 12:28:25 +0200 Subject: [PATCH 2/8] Hibernate ORM DevUI - Move dev-console-specific code to a dedicated package --- .../orm/deployment/devconsole/DevConsoleProcessor.java | 2 +- .../runtime/{ => devconsole}/PersistenceUnitInfoSupplier.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) rename extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/{ => devconsole}/PersistenceUnitInfoSupplier.java (96%) diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java index a955ea0336641..6d07160dbbb98 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java @@ -3,7 +3,7 @@ import io.quarkus.deployment.IsDevelopment; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; -import io.quarkus.hibernate.orm.runtime.PersistenceUnitInfoSupplier; +import io.quarkus.hibernate.orm.runtime.devconsole.PersistenceUnitInfoSupplier; public class DevConsoleProcessor { diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitInfoSupplier.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/PersistenceUnitInfoSupplier.java similarity index 96% rename from extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitInfoSupplier.java rename to extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/PersistenceUnitInfoSupplier.java index 85dbf22c57e62..a6810be366e35 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitInfoSupplier.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/PersistenceUnitInfoSupplier.java @@ -1,4 +1,4 @@ -package io.quarkus.hibernate.orm.runtime; +package io.quarkus.hibernate.orm.runtime.devconsole; import java.util.ArrayList; import java.util.HashMap; @@ -8,6 +8,8 @@ import javax.persistence.spi.PersistenceProviderResolverHolder; +import io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider; +import io.quarkus.hibernate.orm.runtime.PersistenceUnitsHolder; import org.hibernate.LockOptions; import org.hibernate.engine.spi.NamedQueryDefinition; import org.hibernate.engine.spi.NamedSQLQueryDefinition; From 28330b13b457ada58fa78e00edeb2e61034febc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 2 Aug 2021 12:50:29 +0200 Subject: [PATCH 3/8] Hibernate ORM DevUI - Push info on startup instead of pulling it at runtime --- .../orm/deployment/HibernateOrmProcessor.java | 7 +- .../devconsole/DevConsoleProcessor.java | 4 +- .../dev-templates/persistence-units.html | 4 +- .../FastBootHibernatePersistenceProvider.java | 23 ----- .../orm/runtime/PersistenceUnitsHolder.java | 9 +- .../FastBootEntityManagerFactoryBuilder.java | 44 ---------- .../PreconfiguredServiceRegistryBuilder.java | 8 +- ...> HibernateOrmDevConsoleInfoSupplier.java} | 85 ++++++++++++------- .../HibernateOrmDevConsoleIntegrator.java | 23 +++++ 9 files changed, 87 insertions(+), 120 deletions(-) rename extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/{PersistenceUnitInfoSupplier.java => HibernateOrmDevConsoleInfoSupplier.java} (54%) create mode 100644 extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/HibernateOrmDevConsoleIntegrator.java diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java index 0c6789b669b03..7dd7c391e24dc 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java @@ -118,6 +118,7 @@ import io.quarkus.hibernate.orm.runtime.boot.scan.QuarkusScanner; import io.quarkus.hibernate.orm.runtime.boot.xml.RecordableXmlMapping; import io.quarkus.hibernate.orm.runtime.cdi.QuarkusArcBeanContainer; +import io.quarkus.hibernate.orm.runtime.devconsole.HibernateOrmDevConsoleIntegrator; import io.quarkus.hibernate.orm.runtime.integration.HibernateOrmIntegrationStaticDescriptor; import io.quarkus.hibernate.orm.runtime.proxies.PreGeneratedProxies; import io.quarkus.hibernate.orm.runtime.tenant.DataSourceTenantConnectionResolver; @@ -424,7 +425,8 @@ public void build(RecorderContext recorderContext, HibernateOrmRecorder recorder List integrationBuildItems, ProxyDefinitionsBuildItem proxyDefinitions, BuildProducer feature, - BuildProducer beanContainerListener) throws Exception { + BuildProducer beanContainerListener, + LaunchModeBuildItem launchMode) throws Exception { feature.produce(new FeatureBuildItem(Feature.HIBERNATE_ORM)); validateHibernatePropertiesNotUsed(); @@ -455,6 +457,9 @@ public void build(RecorderContext recorderContext, HibernateOrmRecorder recorder for (String integratorClassName : ServiceUtil.classNamesNamedIn(classLoader, INTEGRATOR_SERVICE_FILE)) { integratorClasses.add((Class) recorderContext.classProxy(integratorClassName)); } + if (launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT) { + integratorClasses.add(HibernateOrmDevConsoleIntegrator.class); + } Map> integrationStaticDescriptors = HibernateOrmIntegrationStaticConfiguredBuildItem .collectDescriptors(integrationBuildItems); diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java index 6d07160dbbb98..93187d742ec58 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java @@ -3,13 +3,13 @@ import io.quarkus.deployment.IsDevelopment; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; -import io.quarkus.hibernate.orm.runtime.devconsole.PersistenceUnitInfoSupplier; +import io.quarkus.hibernate.orm.runtime.devconsole.HibernateOrmDevConsoleInfoSupplier; public class DevConsoleProcessor { @BuildStep(onlyIf = IsDevelopment.class) public DevConsoleRuntimeTemplateInfoBuildItem collectDeploymentUnits() { - return new DevConsoleRuntimeTemplateInfoBuildItem("persistence", new PersistenceUnitInfoSupplier()); + return new DevConsoleRuntimeTemplateInfoBuildItem("persistence", new HibernateOrmDevConsoleInfoSupplier()); } } diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html index 9d01ed2754660..2f3de66167e5f 100644 --- a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html @@ -23,14 +23,14 @@ {#for unit in info:persistence.persistenceUnits} {count}. - {unit.name} + {unit}

Create script: Copy

-
{info:persistence.createDDLs.get(unit.getName())}
+
{info:persistence.createDDLs.get(unit)}
{/for} diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java index 4322e5b6f9af1..533e342981f09 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java @@ -1,6 +1,5 @@ package io.quarkus.hibernate.orm.runtime; -import java.io.StringWriter; import java.util.Collections; import java.util.List; import java.util.Map; @@ -100,28 +99,6 @@ public boolean generateSchema(String persistenceUnitName, Map map) { return true; } - /** - * TODO: Figure out how to provide separate "create" and "drop" scripts. Currently this only do "create". - * - * A variant of {@link #generateSchema(String persistenceUnitName, Map map)} that returns the SQL script as a string. - * - * @param persistenceUnitName PU name - * @param map should be always null, as Quarkus doesn't allow to provide any properties in runtime. - * @return schema as string - */ - @SuppressWarnings("rawtypes") - public String generateSchemaToString(String persistenceUnitName, Map map) { - final FastBootEntityManagerFactoryBuilder builder = (FastBootEntityManagerFactoryBuilder) getEntityManagerFactoryBuilderOrNull( - persistenceUnitName, map); - if (builder == null) { - log.trace("Could not obtain matching EntityManagerFactoryBuilder, returning null"); - return null; - } - StringWriter createWriter = new StringWriter(); - builder.generateSchema(createWriter); - return createWriter.toString(); - } - @Override public ProviderUtil getProviderUtil() { return providerUtil; diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitsHolder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitsHolder.java index b675f8eb59756..fb9ba1c76f156 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitsHolder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitsHolder.java @@ -14,7 +14,6 @@ import io.quarkus.hibernate.orm.runtime.boot.QuarkusPersistenceUnitDefinition; import io.quarkus.hibernate.orm.runtime.proxies.PreGeneratedProxies; import io.quarkus.hibernate.orm.runtime.recording.RecordedState; -import io.quarkus.runtime.LaunchMode; public final class PersistenceUnitsHolder { @@ -55,13 +54,7 @@ public static RecordedState popRecordedState(String persistenceUnitName) { if (persistenceUnitName == null) { key = NO_NAME_TOKEN; } - // Do not remove the PU metadata in dev-mode, we need them to generate information for DevUI pages. - // In normal mode, we want to remove these metadata as the associated memory cost is large. - if (LaunchMode.DEVELOPMENT == LaunchMode.current()) { - return persistenceUnits.recordedStates.get(key); - } else { - return persistenceUnits.recordedStates.remove(key); - } + return persistenceUnits.recordedStates.remove(key); } private static List convertPersistenceUnits( diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java index a7316428f5281..f7709c9edf8ab 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java @@ -1,9 +1,7 @@ package io.quarkus.hibernate.orm.runtime.boot; import java.io.Serializable; -import java.io.Writer; import java.security.NoSuchAlgorithmException; -import java.util.EnumSet; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityNotFoundException; @@ -26,14 +24,9 @@ import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistryImplementor; -import org.hibernate.tool.hbm2ddl.SchemaExport; -import org.hibernate.tool.schema.TargetType; -import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToWriter; import org.hibernate.tool.schema.spi.CommandAcceptanceException; import org.hibernate.tool.schema.spi.DelayedDropRegistryNotAvailableImpl; import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator; -import org.hibernate.tool.schema.spi.ScriptTargetOutput; -import org.hibernate.tool.schema.spi.TargetDescriptor; import io.quarkus.hibernate.orm.runtime.RuntimeSettings; import io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata; @@ -99,43 +92,6 @@ public void generateSchema() { cancel(); } - /** - * TODO: provide a second writer parameter for "drop" script, or create a second method. - * - * @param createWriter - */ - public void generateSchema(final Writer createWriter) { - try { - SchemaExport schemaExport = new SchemaExport(); - schemaExport.setFormat(true); - schemaExport.setDelimiter(";"); - schemaExport.doExecution(SchemaExport.Action.CREATE, false, metadata, standardServiceRegistry, - new TargetDescriptor() { - - @Override - public EnumSet getTargetTypes() { - return EnumSet.of(TargetType.SCRIPT); - } - - @Override - public ScriptTargetOutput getScriptTargetOutput() { - return new ScriptTargetOutputToWriter(createWriter) { - @Override - public void accept(String command) { - super.accept(command); - } - }; - } - }); - - } catch (Exception e) { - throw persistenceException("Error performing schema management", e); - } - - // release this builder - cancel(); - } - protected PersistenceException persistenceException(String message, Exception cause) { // Provide a comprehensible message if there is an issue with SSL support Throwable t = cause; diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/registry/PreconfiguredServiceRegistryBuilder.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/registry/PreconfiguredServiceRegistryBuilder.java index 065a0a9b2c777..c90ac314b263a 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/registry/PreconfiguredServiceRegistryBuilder.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/registry/PreconfiguredServiceRegistryBuilder.java @@ -106,13 +106,7 @@ public StandardServiceRegistryImpl buildNewServiceRegistry() { final Map settingsCopy = new HashMap(); settingsCopy.putAll(configurationValues); - // FIXME: resetAndReactivate() throws "IllegalStateException: Can't reactivate an active registry!" - // during persistenceProvider.generateSchema() execution (a new PersistenceProvider instance is constructed - // during this call). - // Is it OK to skip the resetAndReactivate() call when the registry is already active? - if (!destroyedRegistry.isActive()) { - destroyedRegistry.resetAndReactivate(bootstrapServiceRegistry, initiators, providedServices, settingsCopy); - } + destroyedRegistry.resetAndReactivate(bootstrapServiceRegistry, initiators, providedServices, settingsCopy); return destroyedRegistry; // return new StandardServiceRegistryImpl( diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/PersistenceUnitInfoSupplier.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/HibernateOrmDevConsoleInfoSupplier.java similarity index 54% rename from extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/PersistenceUnitInfoSupplier.java rename to extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/HibernateOrmDevConsoleInfoSupplier.java index a6810be366e35..787184a154d82 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/PersistenceUnitInfoSupplier.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/HibernateOrmDevConsoleInfoSupplier.java @@ -1,70 +1,89 @@ package io.quarkus.hibernate.orm.runtime.devconsole; +import java.io.StringWriter; import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Supplier; -import javax.persistence.spi.PersistenceProviderResolverHolder; - -import io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider; -import io.quarkus.hibernate.orm.runtime.PersistenceUnitsHolder; import org.hibernate.LockOptions; +import org.hibernate.boot.Metadata; import org.hibernate.engine.spi.NamedQueryDefinition; import org.hibernate.engine.spi.NamedSQLQueryDefinition; -import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; import org.hibernate.mapping.PersistentClass; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.schema.TargetType; +import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToWriter; +import org.hibernate.tool.schema.spi.ScriptTargetOutput; +import org.hibernate.tool.schema.spi.TargetDescriptor; -import io.quarkus.hibernate.orm.runtime.recording.RecordedState; +public class HibernateOrmDevConsoleInfoSupplier implements Supplier { -public class PersistenceUnitInfoSupplier implements Supplier { + private static final PersistenceUnitsInfo INSTANCE = new PersistenceUnitsInfo(); @Override public PersistenceUnitsInfo get() { - return composePersistenceUnitsInfo(PersistenceUnitsHolder.getPersistenceUnitDescriptors()); + return INSTANCE; } - private PersistenceUnitsInfo composePersistenceUnitsInfo(List persistenceUnits) { - PersistenceUnitsInfo persistenceUnitsInfo = new PersistenceUnitsInfo(); - - FastBootHibernatePersistenceProvider persistenceProvider = (FastBootHibernatePersistenceProvider) PersistenceProviderResolverHolder - .getPersistenceProviderResolver().getPersistenceProviders().get(0); - - for (PersistenceUnitDescriptor descriptor : persistenceUnits) { - persistenceUnitsInfo.getPersistenceUnits().add(descriptor); - RecordedState recordedState = PersistenceUnitsHolder.popRecordedState(descriptor.getName()); + public static void pushPersistenceUnit(String persistenceUnitName, + Metadata metadata, ServiceRegistry serviceRegistry) { + INSTANCE.getPersistenceUnits().add(persistenceUnitName); - String schema = persistenceProvider.generateSchemaToString(descriptor.getName(), null); - persistenceUnitsInfo.createDDLs.put(descriptor.getName(), schema); + String schema = generateDDL(SchemaExport.Action.CREATE, metadata, serviceRegistry); + INSTANCE.createDDLs.put(persistenceUnitName, schema); - for (String className : descriptor.getManagedClassNames()) { - PersistentClass entityBinding = recordedState.getMetadata().getEntityBinding(className); - persistenceUnitsInfo.managedEntities.add(new PersistenceUnitInfoSupplier.EntityInfo(className, - entityBinding.getTable().getName(), descriptor.getName())); - } + for (PersistentClass entityBinding : metadata.getEntityBindings()) { + INSTANCE.managedEntities.add(new HibernateOrmDevConsoleInfoSupplier.EntityInfo(entityBinding.getClassName(), + entityBinding.getTable().getName(), persistenceUnitName)); + } - for (NamedQueryDefinition queryDefinition : recordedState.getMetadata().getNamedQueryDefinitions()) { - persistenceUnitsInfo.namedQueries.add(new QueryInfo(queryDefinition)); - } + for (NamedQueryDefinition queryDefinition : metadata.getNamedQueryDefinitions()) { + INSTANCE.namedQueries.add(new QueryInfo(queryDefinition)); + } - for (NamedSQLQueryDefinition staticQueryDefinition : recordedState.getMetadata().getNamedNativeQueryDefinitions()) { - persistenceUnitsInfo.namedNativeQueries.add(new QueryInfo(staticQueryDefinition)); - } + for (NamedSQLQueryDefinition staticQueryDefinition : metadata.getNamedNativeQueryDefinitions()) { + INSTANCE.namedNativeQueries.add(new QueryInfo(staticQueryDefinition)); } + } - return persistenceUnitsInfo; + private static String generateDDL(SchemaExport.Action action, Metadata metadata, ServiceRegistry serviceRegistry) { + SchemaExport schemaExport = new SchemaExport(); + schemaExport.setFormat(true); + schemaExport.setDelimiter(";"); + StringWriter writer = new StringWriter(); + schemaExport.doExecution(action, false, metadata, serviceRegistry, + new TargetDescriptor() { + @Override + public EnumSet getTargetTypes() { + return EnumSet.of(TargetType.SCRIPT); + } + + @Override + public ScriptTargetOutput getScriptTargetOutput() { + return new ScriptTargetOutputToWriter(writer) { + @Override + public void accept(String command) { + super.accept(command); + } + }; + } + }); + return writer.toString(); } public static class PersistenceUnitsInfo { - private final List persistenceUnits = new ArrayList<>(); + private final List persistenceUnits = new ArrayList<>(); private final List managedEntities = new ArrayList<>(); private final List namedQueries = new ArrayList<>(); private final List namedNativeQueries = new ArrayList<>(); private final Map createDDLs = new HashMap<>(); - public List getPersistenceUnits() { + public List getPersistenceUnits() { return persistenceUnits; } diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/HibernateOrmDevConsoleIntegrator.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/HibernateOrmDevConsoleIntegrator.java new file mode 100644 index 0000000000000..eeda5d6989534 --- /dev/null +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/devconsole/HibernateOrmDevConsoleIntegrator.java @@ -0,0 +1,23 @@ +package io.quarkus.hibernate.orm.runtime.devconsole; + +import org.hibernate.boot.Metadata; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.integrator.spi.Integrator; +import org.hibernate.jpa.AvailableSettings; +import org.hibernate.service.spi.SessionFactoryServiceRegistry; + +public class HibernateOrmDevConsoleIntegrator implements Integrator { + @Override + public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactoryImplementor, + SessionFactoryServiceRegistry sessionFactoryServiceRegistry) { + HibernateOrmDevConsoleInfoSupplier.pushPersistenceUnit( + (String) sessionFactoryImplementor.getProperties().get(AvailableSettings.PERSISTENCE_UNIT_NAME), + metadata, sessionFactoryServiceRegistry); + } + + @Override + public void disintegrate(SessionFactoryImplementor sessionFactoryImplementor, + SessionFactoryServiceRegistry sessionFactoryServiceRegistry) { + // Nothing to do + } +} From 747b9ac22199633973d0d671146b5cad45d370c7 Mon Sep 17 00:00:00 2001 From: Tomas Hofman Date: Mon, 9 Aug 2021 09:17:28 +0200 Subject: [PATCH 4/8] Hibernate ORM DevUI - show separate table for each PU --- .../resources/dev-templates/embedded.html | 4 +- .../dev-templates/managed-entities.html | 15 +++-- .../dev-templates/named-queries.html | 14 +++- .../dev-templates/persistence-units.html | 41 ++++++++---- .../HibernateOrmDevConsoleInfoSupplier.java | 64 +++++++++++++------ 5 files changed, 98 insertions(+), 40 deletions(-) diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html index 521a07c0e24f1..7df9c3c4311f6 100644 --- a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html @@ -4,8 +4,8 @@ - Entities {info:persistence.managedEntities.size} + Entities {info:persistence.numberOfEntities} - Named Queries {info:persistence.allNamedQueries.size} + Named Queries {info:persistence.numberOfNamedQueries} diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html index ffb0e52cd5883..23d41cec746e3 100644 --- a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html @@ -4,7 +4,14 @@ {#title}Managed Entities{/title} {#body} -{#if info:persistence.managedEntities.isEmpty} +{#if info:persistence.persistenceUnits.isEmpty} +

No persistence units were found.

+{#else} + +{#for pu in info:persistence.persistenceUnits} +

Persistence Unit {pu}

+ +{#if info:persistence.getManagedEntities(pu).isEmpty}

No entities were found.

{#else} @@ -13,21 +20,21 @@ - - {#for entity in info:persistence.managedEntities} + {#for entity in info:persistence.getManagedEntities(pu)} - {/for}
# Class name Table namePersistence Unit
{count}. {entity.className} {entity.tableName}{entity.persistenceUnitName}
{/if} +{/for} +{/if} {/body} {/include} diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html index 8bafda4a2fa46..f1c76b6268185 100644 --- a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html @@ -4,7 +4,14 @@ {#title}Named Queries{/title} {#body} -{#if info:persistence.allNamedQueries.isEmpty} +{#if info:persistence.persistenceUnits.isEmpty} +

No persistence units were found.

+{#else} + +{#for pu in info:persistence.persistenceUnits} +

Persistence Unit {pu}

+ +{#if info:persistence.getAllNamedQueries(pu).isEmpty}

No named queries were found.

{#else} @@ -19,7 +26,7 @@ - {#for query in info:persistence.allNamedQueries} + {#for query in info:persistence.getAllNamedQueries(pu)} @@ -33,5 +40,8 @@
{count}. {query.name}
{/if} +{/for} +{/if} + {/body} {/include} diff --git a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html index 2f3de66167e5f..4d2bc1ca8c81b 100644 --- a/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html +++ b/extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html @@ -1,9 +1,11 @@ {#include main} {#style} .ddl-script { - background-color: white; padding: 5px; } +th .badge { + font-size: 100%; +} {/style} {#title}Persistence Units{/title} {#body} @@ -11,31 +13,46 @@ {#if info:persistence.persistenceUnits.isEmpty}

No persistence units found.

{#else} +{#for unit in info:persistence.persistenceUnits} - - - + + + + + + - {#for unit in info:persistence.persistenceUnits} - - + + + + + + + + + - {/for}
#Persistence Unit NameDDLPersistence Unit {unit}
Create Script
{count}.{unit} -

- Create script: - +

{info:persistence.createDDLs.get(unit)}
+

+ + Copy +

+
Drop Script
+
{info:persistence.dropDDLs.get(unit)}
+

+ Copy

-
{info:persistence.createDDLs.get(unit)}
+{/for} {/if}