Skip to content

Commit

Permalink
Merge pull request #16764 from TomasHofman/devui-db-schema-1.13
Browse files Browse the repository at this point in the history
DevUI pages for Hibernate ORM
  • Loading branch information
gsmet authored Aug 10, 2021
2 parents ecfe618 + 66e1b37 commit 19f7838
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -424,7 +425,8 @@ public void build(RecorderContext recorderContext, HibernateOrmRecorder recorder
List<HibernateOrmIntegrationStaticConfiguredBuildItem> integrationBuildItems,
ProxyDefinitionsBuildItem proxyDefinitions,
BuildProducer<FeatureBuildItem> feature,
BuildProducer<BeanContainerListenerBuildItem> beanContainerListener) throws Exception {
BuildProducer<BeanContainerListenerBuildItem> beanContainerListener,
LaunchModeBuildItem launchMode) throws Exception {

feature.produce(new FeatureBuildItem(Feature.HIBERNATE_ORM));
validateHibernatePropertiesNotUsed();
Expand Down Expand Up @@ -455,6 +457,9 @@ public void build(RecorderContext recorderContext, HibernateOrmRecorder recorder
for (String integratorClassName : ServiceUtil.classNamesNamedIn(classLoader, INTEGRATOR_SERVICE_FILE)) {
integratorClasses.add((Class<? extends Integrator>) recorderContext.classProxy(integratorClassName));
}
if (launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT) {
integratorClasses.add(HibernateOrmDevConsoleIntegrator.class);
}

Map<String, List<HibernateOrmIntegrationStaticDescriptor>> integrationStaticDescriptors = HibernateOrmIntegrationStaticConfiguredBuildItem
.collectDescriptors(integrationBuildItems);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.devconsole.HibernateOrmDevConsoleInfoSupplier;

public class DevConsoleProcessor {

@BuildStep(onlyIf = IsDevelopment.class)
public DevConsoleRuntimeTemplateInfoBuildItem collectDeploymentUnits() {
return new DevConsoleRuntimeTemplateInfoBuildItem("persistence", new HibernateOrmDevConsoleInfoSupplier());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<a href="{urlbase}/persistence-units" class="badge badge-light">
<i class="fa fa-boxes fa-fw"></i>
Persistence units <span class="badge badge-light">{info:persistence.persistenceUnits.size}</span></a>

<a href="{urlbase}/managed-entities" class="badge badge-light">
<i class="fa fa-table fa-fw"></i>
Entities <span class="badge badge-light">{info:persistence.numberOfEntities}</span></a>

<a href="{urlbase}/named-queries" class="badge badge-light">
<i class="fa fa-question-circle fa-fw"></i>
Named Queries <span class="badge badge-light">{info:persistence.numberOfNamedQueries}</span></a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{#include main}
{#style}
{/style}
{#title}Managed Entities{/title}
{#body}

{#if info:persistence.persistenceUnits.isEmpty}
<p>No persistence units were found.</p>
{#else}

{#for pu in info:persistence.persistenceUnits}
<h4><span class="badge">Persistence Unit</span> <i class="badge badge-info">{pu}</i></h4>

{#if info:persistence.getManagedEntities(pu).isEmpty}
<p>No entities were found.</p>
{#else}
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Class name</th>
<th scope="col">Table name</th>
</tr>
</thead>
<tbody>
{#for entity in info:persistence.getManagedEntities(pu)}
<tr>
<td>{count}.</td>
<td>{entity.className}</td>
<td>{entity.tableName}</td>
</tr>
{/for}
</tbody>
</table>
{/if}
{/for}

{/if}
{/body}
{/include}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{#include main}
{#style}
{/style}
{#title}Named Queries{/title}
{#body}

{#if info:persistence.persistenceUnits.isEmpty}
<p>No persistence units were found.</p>
{#else}

{#for pu in info:persistence.persistenceUnits}
<h4><span class="badge">Persistence Unit</span> <i class="badge badge-info">{pu}</i></h4>

{#if info:persistence.getAllNamedQueries(pu).isEmpty}
<p>No named queries were found.</p>
{#else}
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Query</th>
<th scope="col">Lock Mode</th>
<th scope="col">Cacheable</th>
<th scope="col">Query Type</th>
</tr>
</thead>
<tbody>
{#for query in info:persistence.getAllNamedQueries(pu)}
<tr>
<td>{count}.</td>
<td>{query.name}</td>
<td>{query.query}</td>
<td>{query.lockMode}</td>
<td>{query.cacheable}</td>
<td>{query.type}</td>
</tr>
{/for}
</tbody>
</table>
{/if}

{/for}
{/if}

{/body}
{/include}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{#include main}
{#style}
.ddl-script {
padding: 5px;
}
th .badge {
font-size: 100%;
}
{/style}
{#title}Persistence Units{/title}
{#body}

{#if info:persistence.persistenceUnits.isEmpty}
<p>No persistence units found.</p>
{#else}
{#for unit in info:persistence.persistenceUnits}
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col">Persistence Unit <i class="badge badge-info">{unit}</i></th>
</tr>
</thead>
<thead class="thead-light">
<tr>
<th scope="col">Create Script</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre id="create-script-{count}" class="ddl-script">{info:persistence.createDDLs.get(unit)}</pre>
<p class="float-right">
<a href="#" onclick="copyToClipboard('create-script-{count}'); return false;">
<i class="fa fa-clipboard"></i><span class="badge">Copy</span></a>
</p>
</td>
</tr>
<thead class="thead-light">
<tr>
<th scope="col">Drop Script</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre id="drop-script-{count}" class="ddl-script">{info:persistence.dropDDLs.get(unit)}</pre>
<p class="float-right">
<a href="#" onclick="copyToClipboard('drop-script-{count}'); return false;">
<i class="fa fa-clipboard"></i><span class="badge">Copy</span></a>
</p>
</td>
</tr>
</tbody>
</table>
{/for}
{/if}

<script>
<!--
function copyToClipboard(elementId) {
var element = document.getElementById(elementId);
var range = document.createRange();
range.setStartBefore(element.firstChild);
range.setEndAfter(element.lastChild);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
selection.removeAllRanges();
}
//-->

</script>

{/body}
{/include}
5 changes: 5 additions & 0 deletions extensions/hibernate-orm/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
Expand Down
Loading

0 comments on commit 19f7838

Please sign in to comment.