-
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.
- Loading branch information
1 parent
2737375
commit cecdcc4
Showing
12 changed files
with
149 additions
and
84 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
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
File renamed without changes.
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
33 changes: 33 additions & 0 deletions
33
...roal/runtime/src/main/java/io/quarkus/agroal/runtime/schema/CleanDatabaseInterceptor.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,33 @@ | ||
package io.quarkus.agroal.runtime.schema; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.InvocationContext; | ||
|
||
public class CleanDatabaseInterceptor { | ||
|
||
final List<DatabaseSchemaProvider> providers; | ||
|
||
public CleanDatabaseInterceptor() { | ||
this.providers = new ArrayList<>(); | ||
ServiceLoader<DatabaseSchemaProvider> dbs = ServiceLoader.load(DatabaseSchemaProvider.class, | ||
Thread.currentThread().getContextClassLoader()); | ||
for (DatabaseSchemaProvider i : dbs) { | ||
providers.add(i); | ||
} | ||
} | ||
|
||
@AroundInvoke | ||
public Object intercept(InvocationContext context) throws Exception { | ||
try { | ||
return context.proceed(); | ||
} finally { | ||
for (DatabaseSchemaProvider i : providers) { | ||
i.resetAllDatabases(); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...agroal/runtime/src/main/java/io/quarkus/agroal/runtime/schema/DatabaseSchemaProvider.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,11 @@ | ||
package io.quarkus.agroal.runtime.schema; | ||
|
||
/** | ||
* A service interface that can be used to reset the database for dev and test mode. | ||
*/ | ||
public interface DatabaseSchemaProvider { | ||
|
||
void resetDatabase(String dbName); | ||
|
||
void resetAllDatabases(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,13 @@ | |
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.runtime.BeanContainer; | ||
import io.quarkus.arc.runtime.BeanContainerListener; | ||
import io.quarkus.devconsole.runtime.spi.DevConsolePostHandler; | ||
import io.quarkus.hibernate.orm.runtime.boot.QuarkusPersistenceUnitDefinition; | ||
import io.quarkus.hibernate.orm.runtime.integration.HibernateOrmIntegrationRuntimeDescriptor; | ||
import io.quarkus.hibernate.orm.runtime.proxies.PreGeneratedProxies; | ||
import io.quarkus.hibernate.orm.runtime.schema.SchemaManagementIntegrator; | ||
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.core.MultiMap; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
/** | ||
* @author Emmanuel Bernard [email protected] | ||
|
@@ -59,6 +55,10 @@ public void setupPersistenceProvider(HibernateOrmRuntimeConfig hibernateOrmRunti | |
public BeanContainerListener initMetadata(List<QuarkusPersistenceUnitDefinition> parsedPersistenceXmlDescriptors, | ||
Scanner scanner, Collection<Class<? extends Integrator>> additionalIntegrators, | ||
PreGeneratedProxies proxyDefinitions) { | ||
SchemaManagementIntegrator.clearDsMap(); | ||
for (QuarkusPersistenceUnitDefinition i : parsedPersistenceXmlDescriptors) { | ||
SchemaManagementIntegrator.mapDatasource(i.getDataSource(), i.getName()); | ||
} | ||
return new BeanContainerListener() { | ||
@Override | ||
public void created(BeanContainer beanContainer) { | ||
|
@@ -123,17 +123,4 @@ protected Session delegate() { | |
} | ||
}; | ||
} | ||
|
||
public Handler<RoutingContext> devConsoleCleanDatabaseHandler() { | ||
// the usual issue of Vert.x hanging on to the first TCCL and setting it on all its threads | ||
final ClassLoader currentCl = Thread.currentThread().getContextClassLoader(); | ||
return new DevConsolePostHandler() { | ||
@Override | ||
protected void handlePost(RoutingContext event, MultiMap form) throws Exception { | ||
String name = form.get("name"); | ||
SchemaManagementIntegrator.recreateDatabase(name); | ||
flashMessage(event, "Action invoked"); | ||
} | ||
}; | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
...ntime/src/main/java/io/quarkus/hibernate/orm/runtime/schema/CleanDatabaseInterceptor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.