-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - draft of DevUI pages for Hibernate ORM
* provide information about persistence units and their managed entities * allow user to generate create-schema script
- Loading branch information
1 parent
3b461a2
commit ed51b55
Showing
15 changed files
with
498 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ent/src/main/java/io/quarkus/hibernate/orm/deployment/devconsole/DevConsoleProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkus.hibernate.orm.deployment.devconsole; | ||
|
||
import static io.quarkus.deployment.annotations.ExecutionTime.RUNTIME_INIT; | ||
|
||
import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem; | ||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.Consume; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; | ||
import io.quarkus.hibernate.orm.runtime.HibernateOrmDevConsoleRecorder; | ||
import io.quarkus.hibernate.orm.runtime.PersistenceUnitInfoSupplier; | ||
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem; | ||
import io.quarkus.vertx.http.deployment.RouteBuildItem; | ||
|
||
public class DevConsoleProcessor { | ||
|
||
/** | ||
* Collect a list of available persistence units for the DevUI templates. | ||
*/ | ||
/* | ||
* @BuildStep(onlyIf = IsDevelopment.class) | ||
* public DevConsoleTemplateInfoBuildItem collectDeploymentUnits(List<PersistenceUnitDescriptorBuildItem> persistenceUnits) | ||
* { | ||
* return new DevConsoleTemplateInfoBuildItem("persistenceUnits", persistenceUnits); | ||
* } | ||
*/ | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
public DevConsoleRuntimeTemplateInfoBuildItem collectDeploymentUnits() { | ||
return new DevConsoleRuntimeTemplateInfoBuildItem("persistence", new PersistenceUnitInfoSupplier()); | ||
} | ||
|
||
/** | ||
* Register an endpoint that generates create-schema script for given PU. | ||
*/ | ||
@BuildStep(onlyIf = IsDevelopment.class) | ||
@Record(RUNTIME_INIT) | ||
@Consume(SyntheticBeansRuntimeInitBuildItem.class) | ||
public RouteBuildItem schemaGenerationRoute(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, | ||
HibernateOrmDevConsoleRecorder hibernateOrmRecorder) { | ||
return nonApplicationRootPathBuildItem.routeBuilder() | ||
.route("pu-schema/:name") | ||
.handler(hibernateOrmRecorder.schemaGenerationHandler()) | ||
.build(); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
extensions/hibernate-orm/deployment/src/main/resources/dev-templates/embedded.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<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.managedEntities.size}</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.allNamedQueries.size}</span></a> | ||
|
||
{! | ||
{#for unit in info:persistenceUnits} | ||
<a href="/q/pu-schema/{unit.persistenceUnitName}" class="badge badge-light"> | ||
{unit.persistenceUnitName}</a> | ||
{/for} | ||
!} |
36 changes: 36 additions & 0 deletions
36
extensions/hibernate-orm/deployment/src/main/resources/dev-templates/managed-entities.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{#include main} | ||
{#style} | ||
.annotation { | ||
color: gray; | ||
} | ||
{/style} | ||
{#title}Managed Entities{/title} | ||
{#body} | ||
|
||
{#if info:persistence.managedEntities.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> | ||
<th scope="col">Persistence Unit</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#for entity in info:persistence.managedEntities} | ||
<tr> | ||
<td>{count}</td> | ||
<td>{entity.className}</td> | ||
<td>{entity.tableName}</td> | ||
<td>{entity.persistenceUnitName}</td> | ||
</tr> | ||
{/for} | ||
</tbody> | ||
</table> | ||
{/if} | ||
|
||
{/body} | ||
{/include} |
40 changes: 40 additions & 0 deletions
40
extensions/hibernate-orm/deployment/src/main/resources/dev-templates/named-queries.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{#include main} | ||
{#style} | ||
.annotation { | ||
color: gray; | ||
} | ||
{/style} | ||
{#title}Named Queries{/title} | ||
{#body} | ||
|
||
{#if info:persistence.allNamedQueries.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.allNamedQueries} | ||
<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} | ||
|
||
{/body} | ||
{/include} |
70 changes: 70 additions & 0 deletions
70
extensions/hibernate-orm/deployment/src/main/resources/dev-templates/persistence-units.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{#include main} | ||
{#style} | ||
.ddl-script { | ||
background-color: white; | ||
padding: 5px; | ||
} | ||
{/style} | ||
{#title}Persistence Units{/title} | ||
{#body} | ||
|
||
{#if info:persistence.persistenceUnits.isEmpty} | ||
<p>No persistence units found.</p> | ||
{#else} | ||
<table class="table table-striped"> | ||
<thead class="thead-dark"> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">Persistence Unit Name</th> | ||
<th scope="col">DDL</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#for unit in info:persistence.persistenceUnits} | ||
<tr> | ||
<td>{count}</td> | ||
<td>{unit.name}</td> | ||
<td> | ||
<p> | ||
<b>Create script:</b> | ||
<a href="#" onclick="copyToClipboard('create-script-{count}');"> | ||
<i class="fa fa-clipboard"></i><span class="badge">Copy</span></a> | ||
</p> | ||
|
||
<pre id="create-script-{count}" class="ddl-script"></pre> | ||
<script> | ||
<!-- | ||
window.onload = (event) => { | ||
jQuery.get( "http://localhost:8080/q/pu-schema/%3Cdefault%3E", function( data ) { | ||
$( "#create-script-{count}" ).html( data ); | ||
}); | ||
}; | ||
//--> | ||
|
||
|
||
</script> | ||
</td> | ||
</tr> | ||
{/for} | ||
</tbody> | ||
</table> | ||
{/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'); | ||
} | ||
//--> | ||
|
||
</script> | ||
|
||
{/body} | ||
{/include} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...untime/src/main/java/io/quarkus/hibernate/orm/runtime/HibernateOrmDevConsoleRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.hibernate.orm.runtime; | ||
|
||
import io.quarkus.runtime.annotations.Recorder; | ||
import io.vertx.core.Handler; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@Recorder | ||
public class HibernateOrmDevConsoleRecorder { | ||
|
||
public Handler<RoutingContext> schemaGenerationHandler() { | ||
return new PersistenceUnitSchemaGenerationHandler(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,5 +118,4 @@ protected Session delegate() { | |
} | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.