-
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 906907a
Showing
10 changed files
with
225 additions
and
2 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
42 changes: 42 additions & 0 deletions
42
...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,42 @@ | ||
package io.quarkus.hibernate.orm.deployment.devconsole; | ||
|
||
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.DevConsoleTemplateInfoBuildItem; | ||
import io.quarkus.hibernate.orm.deployment.PersistenceUnitDescriptorBuildItem; | ||
import io.quarkus.hibernate.orm.runtime.HibernateOrmRecorder; | ||
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem; | ||
import io.quarkus.vertx.http.deployment.RouteBuildItem; | ||
|
||
import java.util.List; | ||
|
||
import static io.quarkus.deployment.annotations.ExecutionTime.RUNTIME_INIT; | ||
|
||
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); | ||
} | ||
|
||
/** | ||
* Register an endpoint that generates create-schema script for given PU. | ||
*/ | ||
@BuildStep(onlyIf = IsDevelopment.class) | ||
@Record(RUNTIME_INIT) | ||
@Consume(SyntheticBeansRuntimeInitBuildItem.class) | ||
public RouteBuildItem myExtensionRoute(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, | ||
HibernateOrmRecorder hibernateOrmRecorder) { | ||
return nonApplicationRootPathBuildItem.routeBuilder() | ||
.route("pu-schema/:name") | ||
.handler(hibernateOrmRecorder.schemaGenerationHandler()) | ||
.build(); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
{! TODO: list available persistence units, add links to a detail page and to a page showing create-schema script for each PU !} | ||
|
||
<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:persistenceUnits.size}</span></a> | ||
|
||
|
||
{#for unit in info:persistenceUnits} | ||
<a href="/q/pu-schema/{unit.persistenceUnitName}" class="badge badge-light"> | ||
{unit.persistenceUnitName}</a> | ||
{/for} |
43 changes: 43 additions & 0 deletions
43
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,43 @@ | ||
{! TODO: a temporary page which shows list of all PUs and a list of all managed entities in each PU. !} | ||
|
||
{#include main} | ||
{#style} | ||
.annotation { | ||
color: gray; | ||
} | ||
{/style} | ||
{#title}Persistence Units{/title} | ||
{#body} | ||
|
||
{#if info:persistenceUnits.isEmpty} | ||
<p>No persistence units found.</p> | ||
{#else} | ||
<p>Count: {info:persistenceUnits}</p> | ||
<table class="table table-striped"> | ||
<thead class="thead-dark"> | ||
<tr> | ||
<th scope="col">Persistence Unit Name</th> | ||
<th scope="col">Size</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{#for unit in info:persistenceUnits} | ||
<tr> | ||
<td> | ||
{unit.persistenceUnitName} | ||
</td> | ||
<td> | ||
<ul> | ||
{#for cls in unit.managedClassNames} | ||
<li>{cls}</li> | ||
{/for} | ||
</ul> | ||
</td> | ||
</tr> | ||
{/for} | ||
</tbody> | ||
</table> | ||
{/if} | ||
|
||
{/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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
import io.quarkus.hibernate.orm.runtime.session.ForwardingSession; | ||
import io.quarkus.hibernate.orm.runtime.tenant.DataSourceTenantConnectionResolver; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
import io.vertx.core.Handler; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
/** | ||
* @author Emmanuel Bernard [email protected] | ||
|
@@ -119,4 +121,8 @@ protected Session delegate() { | |
}; | ||
} | ||
|
||
public Handler<RoutingContext> schemaGenerationHandler() { | ||
return new PersistenceUnitSchemaGenerationHandler(); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...rc/main/java/io/quarkus/hibernate/orm/runtime/PersistenceUnitSchemaGenerationHandler.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,41 @@ | ||
package io.quarkus.hibernate.orm.runtime; | ||
|
||
import io.netty.handler.codec.http.HttpResponseStatus; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.http.HttpServerResponse; | ||
import io.vertx.ext.web.RoutingContext; | ||
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; | ||
|
||
import javax.persistence.spi.PersistenceProviderResolverHolder; | ||
|
||
/** | ||
* This handler is used in DevUI to generate a create-schema script for given PU. | ||
*/ | ||
public class PersistenceUnitSchemaGenerationHandler implements Handler<RoutingContext> { | ||
@Override | ||
public void handle(RoutingContext routingContext) { | ||
HttpServerResponse response = routingContext.response(); | ||
response.setChunked(true); | ||
response.putHeader("content-type", "text/plain"); | ||
|
||
String name = routingContext.pathParam("name"); | ||
|
||
if (name == null || name.isEmpty()) { | ||
for (PersistenceUnitDescriptor descriptor : PersistenceUnitsHolder.getPersistenceUnitDescriptors()) { | ||
response.write(descriptor.getName()).write("\n"); | ||
} | ||
} else { | ||
FastBootHibernatePersistenceProvider persistenceProvider = (FastBootHibernatePersistenceProvider) | ||
PersistenceProviderResolverHolder.getPersistenceProviderResolver().getPersistenceProviders().get(0); | ||
|
||
String schema = persistenceProvider.generateSchemaToString(name, null); | ||
if (schema == null) { | ||
response.setStatusCode(HttpResponseStatus.NOT_FOUND.code()); | ||
response.write("Persistence unit '" + name + "' not found."); | ||
} else { | ||
response.write(schema); | ||
} | ||
} | ||
response.end(); | ||
} | ||
} |
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
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