Skip to content

Commit

Permalink
Upgrade to Hibernate ORM 6.4.0.CR1
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Nov 2, 2023
1 parent 03982fc commit d0b4032
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
bytebuddy.version (just below), hibernate-orm.version-for-documentation (in docs/pom.xml)
and antlr.version.version in build-parent/pom.xml
WARNING again for diffs that don't provide enough context: when updating, see above -->
<hibernate-orm.version>6.3.1.Final</hibernate-orm.version>
<hibernate-orm.version>6.4.0.CR1</hibernate-orm.version>
<bytebuddy.version>1.14.7</bytebuddy.version> <!-- Version controlled by Hibernate ORM's needs -->
<hibernate-commons-annotations.version>6.0.6.Final</hibernate-commons-annotations.version> <!-- version controlled by Hibernate ORM -->
<hibernate-reactive.version>2.0.6.Final</hibernate-reactive.version>
Expand Down Expand Up @@ -190,7 +190,7 @@
<quarkus-spring-boot-api.version>2.1.SP1</quarkus-spring-boot-api.version>
<mockito.version>5.3.1</mockito.version>
<jna.version>5.8.0</jna.version><!-- should satisfy both testcontainers and mongodb -->
<antlr.version>4.10.1</antlr.version><!-- needs to align with same property in build-parent/pom.xml -->
<antlr.version>4.13.0</antlr.version><!-- needs to align with same property in build-parent/pom.xml -->
<quarkus-security.version>2.0.2.Final</quarkus-security.version>
<keycloak.version>22.0.5</keycloak.version>
<logstash-gelf.version>1.15.1</logstash-gelf.version>
Expand Down
2 changes: 1 addition & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<!-- MicroProfile TCK versions used to be defined here but have moved to the concrete tck modules -->

<!-- Antlr 4 is used by the PanacheQL parser but also needs to match the requirements of Hibernate ORM 6.x-->
<antlr.version>4.10.1</antlr.version>
<antlr.version>4.13.0</antlr.version>

<!-- SELinux access label, used when mounting local volumes into containers in tests -->
<volume.access.modifier>:Z</volume.access.modifier>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected void populate(String persistenceUnitName, SessionFactoryOptionsBuilder
// Should be added in case of discriminator strategy too, that is not handled by options.isMultiTenancyEnabled()
if (options.isMultiTenancyEnabled()
|| (multiTenancyStrategy != null && multiTenancyStrategy != MultiTenancyStrategy.NONE)) {
options.applyCurrentTenantIdentifierResolver(new HibernateCurrentTenantIdentifierResolver(persistenceUnitName));
options.applyCurrentTenantIdentifierResolver(new HibernateCurrentTenantIdentifierResolver<>(persistenceUnitName));
}

InjectableInstance<Interceptor> interceptorInstance = PersistenceUnitUtil.singleExtensionInstanceForPersistenceUnit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Michael Schnell
*
*/
public final class HibernateCurrentTenantIdentifierResolver implements CurrentTenantIdentifierResolver {
public final class HibernateCurrentTenantIdentifierResolver<T> implements CurrentTenantIdentifierResolver<T> {

private static final Logger LOG = Logger.getLogger(HibernateCurrentTenantIdentifierResolver.class);

Expand All @@ -26,15 +26,15 @@ public HibernateCurrentTenantIdentifierResolver(String persistenceUnitName) {
}

@Override
public String resolveCurrentTenantIdentifier() {
public T resolveCurrentTenantIdentifier() {

// Make sure that we're in a request
if (!Arc.container().requestContext().isActive()) {
return null;
}

TenantResolver resolver = tenantResolver(persistenceUnitName);
String tenantId = resolver.resolveTenantId();
TenantResolver<T> resolver = tenantResolver(persistenceUnitName);
T tenantId = resolver.resolveTenantId();
if (tenantId == null) {
throw new IllegalStateException("Method 'TenantResolver.resolveTenantId()' returned a null value. "
+ "Unfortunately Hibernate ORM does not allow null for tenant identifiers. "
Expand All @@ -51,19 +51,20 @@ public boolean validateExistingCurrentSessions() {
}

@Override
public boolean isRoot(String tenantId) {
public boolean isRoot(T tenantId) {
// Make sure that we're in a request
if (!Arc.container().requestContext().isActive()) {
return false;
}
TenantResolver resolver = tenantResolver(persistenceUnitName);
TenantResolver<T> resolver = tenantResolver(persistenceUnitName);
if (resolver == null) {
return false;
}
return resolver.isRoot(tenantId);
}

private static TenantResolver tenantResolver(String persistenceUnitName) {
@SuppressWarnings({"rawtypes", "unchecked"}) // The type T doesn't matter here
private static <T> TenantResolver<T> tenantResolver(String persistenceUnitName) {
InjectableInstance<TenantResolver> instance = PersistenceUnitUtil.legacySingleExtensionInstanceForPersistenceUnit(
TenantResolver.class, persistenceUnitName);
if (instance.isUnsatisfied()) {
Expand All @@ -72,7 +73,7 @@ private static TenantResolver tenantResolver(String persistenceUnitName) {
+ "You need to create an implementation for this interface to allow resolving the current tenant identifier.",
TenantResolver.class.getSimpleName(), persistenceUnitName));
}
return instance.get();
return (TenantResolver<T>) instance.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@
*
* @author Michael Schnell
*
* @param <T> The type of tenant identifiers.
* If you use `@TenantId`, this is the type of the `@TenantId`-annotated property.
* Otherwise, use `String`.
*
*/
public interface TenantResolver {
public interface TenantResolver<T> {

/**
* Returns the identifier of the default tenant.
*
* @return Default tenant.A non-{@literal null} value is required.
*/
String getDefaultTenantId();
T getDefaultTenantId();

/**
* Returns the current tenant identifier.
*
* @return the tenant identifier. This value will be used to select the proper configuration at runtime. A
* non-{@literal null} value is required.
*/
String resolveTenantId();
T resolveTenantId();

/**
* Does the given tenant id represent a "root" tenant with access to all partitions?
Expand All @@ -30,7 +34,7 @@ public interface TenantResolver {
*
* @return true is this is root tenant
*/
default boolean isRoot(String tenantId) {
default boolean isRoot(T tenantId) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@PersistenceUnitExtension
@RequestScoped
public class CustomHibernateTenantResolver implements TenantResolver {
public class CustomHibernateTenantResolver implements TenantResolver<String> {

static volatile boolean useRoutingContext = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.vertx.ext.web.RoutingContext;

@RequestScoped
public class CustomTenantResolver implements TenantResolver {
public class CustomTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(CustomTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@RequestScoped
@PersistenceUnit("inventory")
public class InventoryTenantResolver implements TenantResolver {
public class InventoryTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(InventoryTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension
@RequestScoped
public class CustomTenantResolver implements TenantResolver {
public class CustomTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(CustomTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension("inventory")
@RequestScoped
public class InventoryTenantResolver implements TenantResolver {
public class InventoryTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(InventoryTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension
@RequestScoped
public class CustomTenantResolver implements TenantResolver {
public class CustomTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(CustomTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension("inventory")
@RequestScoped
public class InventoryTenantResolver implements TenantResolver {
public class InventoryTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(InventoryTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension
@RequestScoped
public class CustomTenantResolver implements TenantResolver {
public class CustomTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(CustomTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension("inventory")
@RequestScoped
public class InventoryTenantResolver implements TenantResolver {
public class InventoryTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(InventoryTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension
@RequestScoped
public class CustomTenantResolver implements TenantResolver {
public class CustomTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(CustomTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension("inventory")
@RequestScoped
public class InventoryTenantResolver implements TenantResolver {
public class InventoryTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(InventoryTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@PersistenceUnitExtension
@RequestScoped
public class CustomTenantResolver implements TenantResolver {
public class CustomTenantResolver implements TenantResolver<String> {

private static final Logger LOG = Logger.getLogger(CustomTenantResolver.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@PersistenceUnitExtension
@RequestScoped
public class CustomTenantResolver implements TenantResolver {
public class CustomTenantResolver implements TenantResolver<String> {

private static final String DEFAULT_TENANT = "default";

Expand Down

0 comments on commit d0b4032

Please sign in to comment.