Skip to content

Commit

Permalink
DBZ-7388 Fix Hibernate API deprecated usages
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jan 24, 2024
1 parent 8290ee4 commit eaed100
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static class DebeziumOutboxConfigAggregateType {

/**
* The column's attribute converter fully qualified class name.
* @see javax.persistence.AttributeConverter
* @see jakarta.persistence.AttributeConverter
*/
@ConfigItem
public Optional<String> converter;
Expand All @@ -134,7 +134,7 @@ public static class DebeziumOutboxConfigAggregateId {

/**
* The column's attribute converter fully qualified class name.
* @see javax.persistence.AttributeConverter
* @see jakarta.persistence.AttributeConverter
*/
@ConfigItem
public Optional<String> converter;
Expand All @@ -156,7 +156,7 @@ public static class DebeziumOutboxConfigType {

/**
* The column's attribute converter fully qualified class name.
* @see javax.persistence.AttributeConverter
* @see jakarta.persistence.AttributeConverter
*/
@ConfigItem
public Optional<String> converter;
Expand All @@ -178,7 +178,7 @@ public static class DebeziumOutboxConfigTimestamp {

/**
* The column's attribute converter fully qualified class name.
* @see javax.persistence.AttributeConverter
* @see jakarta.persistence.AttributeConverter
*/
@ConfigItem
public Optional<String> converter;
Expand All @@ -200,7 +200,7 @@ public static class DebeziumOutboxConfigPayload {

/**
* The column's attribute converter fully qualified class name.
* @see javax.persistence.AttributeConverter
* @see jakarta.persistence.AttributeConverter
*/
@ConfigItem
public Optional<String> converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ private static JaxbHbmBasicAttributeType createTracingSpanAttribute(DebeziumOutb
column.setName(config.tracingSpan.name);
column.setLength(256);

if (config.tracingSpan.columnDefinition.isPresent()) {
column.setSqlType(config.tracingSpan.columnDefinition.get());
}
config.tracingSpan.columnDefinition.ifPresent(column::setSqlType);

attribute.getColumnOrFormula().add(column);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package io.debezium.outbox.reactive.quarkus.it;

import static io.debezium.outbox.reactive.quarkus.it.TestAsserts.assertIsType;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -16,6 +17,7 @@

import jakarta.inject.Inject;

import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.metamodel.spi.MetamodelImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.reactive.mutiny.Mutiny;
Expand Down Expand Up @@ -46,19 +48,19 @@ public abstract class AbstractOutboxTest {

@Test
public void testOutboxEntityMetamodelExists() throws Exception {
final MetamodelImplementor metadata = (MetamodelImplementor) sessionFactory.getMetamodel();
final EntityPersister persister = metadata.entityPersister(OutboxConstants.OUTBOX_ENTITY_FULLNAME);
final MappingMetamodelImplementor metadata = (MappingMetamodelImplementor) sessionFactory.getMetamodel();
final EntityPersister persister = metadata.findEntityDescriptor(OutboxConstants.OUTBOX_ENTITY_FULLNAME);
assertNotNull(persister);
// this assumes the default mapping settings, no custom converters or column types
assertEquals(UUID.class, persister.getIdentifierType().getReturnedClass());
assertEquals(String.class, persister.getPropertyType("aggregateType").getReturnedClass());
assertEquals(Long.class, persister.getPropertyType("aggregateId").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("type").getReturnedClass());
assertEquals(Instant.class, persister.getPropertyType("timestamp").getReturnedClass());
assertEquals(JsonNode.class, persister.getPropertyType("payload").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("name").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("name_upper").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("name_no_columndef").getReturnedClass());
assertIsType(persister, String.class, "aggregateType");
assertIsType(persister, Long.class, "aggregateId");
assertIsType(persister, String.class, "type");
assertIsType(persister, Instant.class, "timestamp");
assertIsType(persister, JsonNode.class, "payload");
assertIsType(persister, String.class, "name");
assertIsType(persister, String.class, "name_upper");
assertIsType(persister, String.class, "name_no_columndef");
}

@Test
Expand All @@ -80,8 +82,8 @@ public void firedEventGetsPersistedInOutboxTable() {
throw new RuntimeException(e);
}

final Map row = (Map) sessionFactory.withSession(
session -> session.createQuery("FROM OutboxEvent").getSingleResult())
final Map row = sessionFactory.withSession(
session -> session.createSelectionQuery("FROM OutboxEvent", Map.class).getSingleResult())
.await().indefinitely();
assertNotNull(row.get("id"));
assertEquals(1L, row.get("aggregateId"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void firedEventGetsPersistedInOutboxTable() {
catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
final Map row = (Map) sessionFactory.withSession(
session -> session.createQuery("FROM OutboxEvent").getSingleResult())
final Map row = sessionFactory.withSession(
session -> session.createSelectionQuery("FROM OutboxEvent", Map.class).getSingleResult())
.await().indefinitely();
assertNotNull(row.get("id"));
assertEquals(1L, row.get("aggregateId"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
*/
package io.debezium.outbox.reactive.quarkus.it;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

import org.hibernate.QueryException;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.metamodel.spi.MetamodelImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.junit.jupiter.api.Test;
Expand All @@ -31,18 +29,12 @@ public class OutboxWithoutOpenTelemetryTest extends AbstractOutboxTest {

@Test
public void testOutboxEntityMetamodelDoesntHaveTracingSpanColumn() throws Exception {
final MetamodelImplementor metadata = (MetamodelImplementor) sessionFactory.getMetamodel();
final MappingMetamodelImplementor metadata = (MappingMetamodelImplementor) sessionFactory.getMetamodel();

final EntityPersister persister = metadata.entityPersister(OutboxConstants.OUTBOX_ENTITY_FULLNAME);
final EntityPersister persister = metadata.findEntityDescriptor(OutboxConstants.OUTBOX_ENTITY_FULLNAME);
assertNotNull(persister);

try {
assertEquals(String.class, persister.getPropertyType("aggregateType").getReturnedClass());
persister.getPropertyType("tracingspancontext");
fail("Expected exception not thrown");
}
catch (QueryException e) {
assertEquals("could not resolve property: tracingspancontext of: io.debezium.outbox.quarkus.internal.OutboxEvent", e.getMessage());
}
TestAsserts.assertIsType(persister, String.class, "aggregateType");
TestAsserts.assertHasNoMapping(persister, "tracingspancontext");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.outbox.reactive.quarkus.it;

import org.hibernate.persister.entity.EntityPersister;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* @author Chris Cranford
*/
public class TestAsserts {

private TestAsserts() {
}

public static void assertIsType(EntityPersister persister, Class<?> type, String attributeName) {
assertEquals(type.getName(), persister.findAttributeMapping(attributeName).getJavaType().getTypeName());
}

public static void assertHasNoMapping(EntityPersister persister, String attributeName) {
assertNull(persister.findAttributeMapping(attributeName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package io.debezium.outbox.reactive.quarkus.internal;

import io.vertx.mutiny.core.eventbus.Message;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

Expand All @@ -24,6 +25,6 @@ public class DebeziumOutboxHandler {

public Uni<Object> persistToOutbox(ExportedEvent<?, ?> incomingEvent) {
return bus.<Object> request("debezium-outbox", incomingEvent, options)
.onItem().transform(message -> message.body());
.onItem().transform(Message::body);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package io.debezium.outbox.quarkus.it;

import static io.debezium.outbox.quarkus.it.TestAsserts.assertIsType;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -17,7 +18,7 @@
import jakarta.persistence.EntityManager;

import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.metamodel.spi.MetamodelImplementor;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.junit.jupiter.api.Test;

Expand All @@ -40,21 +41,21 @@ public abstract class AbstractOutboxTest {

@Test
public void testOutboxEntityMetamodelExists() throws Exception {
final MetamodelImplementor metadata = entityManager.unwrap(SessionImplementor.class).getFactory().getMetamodel();
final MappingMetamodelImplementor metadata = entityManager.unwrap(SessionImplementor.class).getFactory().getMappingMetamodel();

final EntityPersister persister = metadata.entityPersister(OutboxConstants.OUTBOX_ENTITY_FULLNAME);
final EntityPersister persister = metadata.findEntityDescriptor(OutboxConstants.OUTBOX_ENTITY_FULLNAME);
assertNotNull(persister);

// this assumes the default mapping settings, no custom converters or column types
assertEquals(UUID.class, persister.getIdentifierType().getReturnedClass());
assertEquals(String.class, persister.getPropertyType("aggregateType").getReturnedClass());
assertEquals(Long.class, persister.getPropertyType("aggregateId").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("type").getReturnedClass());
assertEquals(Instant.class, persister.getPropertyType("timestamp").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("payload").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("name").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("name_upper").getReturnedClass());
assertEquals(String.class, persister.getPropertyType("name_no_columndef").getReturnedClass());
assertIsType(persister, String.class, "aggregateType");
assertIsType(persister, Long.class, "aggregateId");
assertIsType(persister, String.class, "type");
assertIsType(persister, Instant.class, "timestamp");
assertIsType(persister, String.class, "payload");
assertIsType(persister, String.class, "name");
assertIsType(persister, String.class, "name_upper");
assertIsType(persister, String.class, "name_no_columndef");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/
package io.debezium.outbox.quarkus.it;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
Expand Down Expand Up @@ -36,7 +34,7 @@ public void testOutboxEntityMetamodelDoesntHaveTracingSpanColumn() throws Except
final EntityPersister persister = metadata.getEntityDescriptor(OutboxConstants.OUTBOX_ENTITY_FULLNAME);
assertNotNull(persister);

assertEquals(String.class.getName(), persister.findAttributeMapping("aggregateType").getJavaType().getTypeName());
assertNull(persister.findAttributeMapping("tracingspancontext"));
TestAsserts.assertIsType(persister, String.class, "aggregateType");
TestAsserts.assertHasNoMapping(persister, "tracingspancontext");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.outbox.quarkus.it;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.hibernate.persister.entity.EntityPersister;

/**
* @author Chris Cranford
*/
public class TestAsserts {

private TestAsserts() {
}

public static void assertIsType(EntityPersister persister, Class<?> type, String attributeName) {
assertEquals(type.getName(), persister.findAttributeMapping(attributeName).getJavaType().getTypeName());
}

public static void assertHasNoMapping(EntityPersister persister, String attributeName) {
assertNull(persister.findAttributeMapping(attributeName));
}
}

0 comments on commit eaed100

Please sign in to comment.