diff --git a/pom.xml b/pom.xml index 18b1cae9..51e7617b 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.1 + 3.0.0-SNAPSHOT @@ -22,10 +22,9 @@ spring-modulith-events spring-modulith-test spring-modulith-docs - spring-modulith-observability + spring-modulith-moments spring-modulith-starter-jpa - spring-modulith-starter-jpa-jakarta spring-modulith-starter-test @@ -111,6 +110,13 @@ limitations under the License. false + + spring-milestone + https://repo.spring.io/milestone + + false + + @@ -201,8 +207,8 @@ limitations under the License. org.apache.maven.plugins maven-compiler-plugin - 1.8 - 1.8 + 17 + 17 diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/model/Types.java b/spring-modulith-core/src/main/java/org/springframework/modulith/model/Types.java index 59de56f3..a4a10fd3 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/model/Types.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/model/Types.java @@ -82,7 +82,7 @@ class Types { @UtilityClass static class JavaXTypes { - private static final String BASE_PACKAGE = "javax"; + private static final String BASE_PACKAGE = "jakarta"; static final String AT_ENTITY = BASE_PACKAGE + ".persistence.Entity"; static final String AT_INJECT = BASE_PACKAGE + ".inject.Inject"; diff --git a/spring-modulith-core/src/test/java/org/springframework/modulith/model/ArchitecturallyEvidentTypeUnitTest.java b/spring-modulith-core/src/test/java/org/springframework/modulith/model/ArchitecturallyEvidentTypeUnitTest.java index 1409918b..b705fbd7 100644 --- a/spring-modulith-core/src/test/java/org/springframework/modulith/model/ArchitecturallyEvidentTypeUnitTest.java +++ b/spring-modulith-core/src/test/java/org/springframework/modulith/model/ArchitecturallyEvidentTypeUnitTest.java @@ -17,24 +17,24 @@ package org.springframework.modulith.model; import static org.assertj.core.api.Assertions.*; +import jakarta.persistence.Entity; + import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.UUID; import java.util.stream.Stream; -import javax.persistence.Entity; - import org.jmolecules.event.annotation.DomainEventHandler; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; -import org.springframework.modulith.model.ArchitecturallyEvidentType.SpringAwareArchitecturallyEvidentType; -import org.springframework.modulith.model.ArchitecturallyEvidentType.SpringDataAwareArchitecturallyEvidentType; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.EventListener; import org.springframework.data.repository.CrudRepository; +import org.springframework.modulith.model.ArchitecturallyEvidentType.SpringAwareArchitecturallyEvidentType; +import org.springframework.modulith.model.ArchitecturallyEvidentType.SpringDataAwareArchitecturallyEvidentType; import org.springframework.stereotype.Repository; import com.tngtech.archunit.core.domain.JavaClass; diff --git a/spring-modulith-events/pom.xml b/spring-modulith-events/pom.xml index 531e173d..66719f03 100644 --- a/spring-modulith-events/pom.xml +++ b/spring-modulith-events/pom.xml @@ -16,7 +16,6 @@ spring-modulith-events-core spring-modulith-events-jpa - spring-modulith-events-jpa-jakarta spring-modulith-events-jackson spring-modulith-events-tests spring-modulith-events-starter diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/pom.xml b/spring-modulith-events/spring-modulith-events-jpa-jakarta/pom.xml deleted file mode 100644 index 73c8f27c..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/pom.xml +++ /dev/null @@ -1,96 +0,0 @@ - - 4.0.0 - - - org.springframework.experimental - spring-modulith-events - 0.1.0-SNAPSHOT - ../pom.xml - - - Spring Modulith - Events - Jakarta JPA-based registry - spring-modulith-events-jpa-jakarta - - - 17 - org.springframework.modulith.events.jpa.jakarta - 6.0.0-M1 - - - - - - ${project.groupId} - spring-modulith-events-core - ${project.version} - - - - - - jakarta.persistence - jakarta.persistence-api - 3.0.0 - - - - org.springframework.boot - spring-boot-autoconfigure - true - - - - - - jakarta.xml.bind - jakarta.xml.bind-api - 3.0.1 - test - - - - - org.hibernate.orm - hibernate-core - 6.0.0.CR2 - test - - - - jakarta.transaction - jakarta.transaction-api - 2.0.1-RC1 - test - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework - spring-orm - test - - - - org.hsqldb - hsqldb - test - - - - - - - spring-milestone - https://repo.spring.io/milestone - - false - - - - - \ No newline at end of file diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublication.java b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublication.java deleted file mode 100644 index 92425f50..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublication.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.modulith.events.jpa; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; - -import java.time.Instant; -import java.util.UUID; - -/** - * @author Oliver Gierke - */ -@Data -@Entity -@NoArgsConstructor(force = true) -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) -class JpaEventPublication { - - private final @Id @Column(length = 16) UUID id; - private final Instant publicationDate; - private final String listenerId; - private final String serializedEvent; - private final Class eventType; - - private Instant completionDate; - - @Builder - static JpaEventPublication of(Instant publicationDate, String listenerId, Object serializedEvent, - Class eventType) { - return new JpaEventPublication(UUID.randomUUID(), publicationDate, listenerId, serializedEvent.toString(), - eventType); - } - - JpaEventPublication markCompleted() { - - this.completionDate = Instant.now(); - return this; - } -} diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationAutoConfiguration.java b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationAutoConfiguration.java deleted file mode 100644 index 058bb5d4..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationAutoConfiguration.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.modulith.events.jpa; - -import org.springframework.boot.autoconfigure.AutoConfigurationPackage; -import org.springframework.context.annotation.Configuration; - -/** - * @author Oliver Drotbohm - */ -@Configuration(proxyBeanMethods = false) -@AutoConfigurationPackage -class JpaEventPublicationAutoConfiguration {} diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfiguration.java b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfiguration.java deleted file mode 100644 index 59affa96..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfiguration.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.modulith.events.jpa; - -import lombok.RequiredArgsConstructor; - -import jakarta.persistence.EntityManager; - -import org.springframework.modulith.events.EventSerializer; -import org.springframework.modulith.events.config.EventPublicationConfigurationExtension; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Oliver Gierke - */ -@Configuration(proxyBeanMethods = false) -@RequiredArgsConstructor -class JpaEventPublicationConfiguration implements EventPublicationConfigurationExtension { - - @Bean - public JpaEventPublicationRegistry jpaEventPublicationRegistry(JpaEventPublicationRepository repository, - EventSerializer serializer) { - return new JpaEventPublicationRegistry(repository, serializer); - } - - @Bean - public JpaEventPublicationRepository jpaEventPublicationRepository(EntityManager em) { - return new JpaEventPublicationRepository(em); - } -} diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRegistry.java b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRegistry.java deleted file mode 100644 index 82c01e3d..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRegistry.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2017-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.modulith.events.jpa; - -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.time.Instant; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.springframework.modulith.events.CompletableEventPublication; -import org.springframework.modulith.events.EventPublication; -import org.springframework.modulith.events.EventPublicationRegistry; -import org.springframework.modulith.events.EventSerializer; -import org.springframework.modulith.events.PublicationTargetIdentifier; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; - -/** - * JPA based {@link EventPublicationRegistry}. - * - * @author Oliver Gierke - */ -@Slf4j -@RequiredArgsConstructor -class JpaEventPublicationRegistry implements EventPublicationRegistry, DisposableBean { - - private final @NonNull JpaEventPublicationRepository events; - private final @NonNull EventSerializer serializer; - - /* - * (non-Javadoc) - * @see org.springframework.events.EventPublicationRegistry#store(java.lang.Object, java.util.Collection) - */ - @Override - public void store(Object event, Stream listeners) { - - listeners.map(it -> CompletableEventPublication.of(event, it)) // - .map(this::map) // - .forEach(it -> events.create(it)); - } - - /* - * (non-Javadoc) - * @see org.springframework.events.EventPublicationRegistry#findIncompletePublications() - */ - @Override - public Iterable findIncompletePublications() { - - List result = events.findByCompletionDateIsNull().stream() // - .map(it -> JpaEventPublicationAdapter.of(it, serializer)) // - .collect(Collectors.toList()); - - return result; - } - - /* - * (non-Javadoc) - * @see org.springframework.events.EventPublicationRegistry#markCompleted(java.lang.Object, org.springframework.events.ListenerId) - */ - @Override - @Transactional(propagation = Propagation.REQUIRES_NEW) - public void markCompleted(Object event, PublicationTargetIdentifier listener) { - - Assert.notNull(event, "Domain event must not be null!"); - Assert.notNull(listener, "Listener identifier must not be null!"); - - events.findBySerializedEventAndListenerId(serializer.serialize(event), listener.toString()) // - .map(JpaEventPublicationRegistry::LOGCompleted) // - .ifPresent(it -> events.update(it.markCompleted())); - } - - /* - * (non-Javadoc) - * @see org.springframework.beans.factory.DisposableBean#destroy() - */ - @Override - public void destroy() throws Exception { - - List publications = events.findByCompletionDateIsNull(); - - if (publications.isEmpty()) { - - LOG.info("No publications outstanding!"); - return; - } - - LOG.info("Shutting down with the following publications left unfinished:"); - - for (int i = 0; i < publications.size(); i++) { - - String prefix = (i + 1) == publications.size() ? "└─" : "├─"; - JpaEventPublication it = publications.get(i); - - LOG.info("{} {} - {} - {}", prefix, it.getId(), it.getEventType().getName(), it.getListenerId()); - } - } - - private JpaEventPublication map(EventPublication publication) { - - JpaEventPublication result = JpaEventPublication.builder() // - .eventType(publication.getEvent().getClass()) // - .publicationDate(publication.getPublicationDate()) // - .listenerId(publication.getTargetIdentifier().toString()) // - .serializedEvent(serializer.serialize(publication.getEvent()).toString()) // - .build(); - - LOG.debug("Registering publication of {} with id {} for {}.", // - result.getEventType(), result.getId(), result.getListenerId()); - - return result; - } - - private static JpaEventPublication LOGCompleted(JpaEventPublication publication) { - - LOG.debug("Marking publication of event {} with id {} to listener {} completed.", // - publication.getEventType(), publication.getId(), publication.getListenerId()); - - return publication; - } - - @EqualsAndHashCode - @RequiredArgsConstructor(staticName = "of") - static class JpaEventPublicationAdapter implements EventPublication { - - private final JpaEventPublication publication; - private final EventSerializer serializer; - - /* - * (non-Javadoc) - * @see org.springframework.events.EventPublication#getEvent() - */ - @Override - public Object getEvent() { - return serializer.deserialize(publication.getSerializedEvent(), publication.getEventType()); - } - - /* - * (non-Javadoc) - * @see org.springframework.events.EventPublication#getListenerId() - */ - @Override - public PublicationTargetIdentifier getTargetIdentifier() { - return PublicationTargetIdentifier.of(publication.getListenerId()); - } - - /* - * (non-Javadoc) - * @see org.springframework.events.EventPublication#getPublicationDate() - */ - @Override - public Instant getPublicationDate() { - return publication.getPublicationDate(); - } - } -} diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java deleted file mode 100644 index 57155e4c..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.modulith.events.jpa; - -import jakarta.persistence.EntityManager; -import jakarta.persistence.TypedQuery; -import lombok.RequiredArgsConstructor; - -import java.util.List; -import java.util.Optional; - -import org.springframework.transaction.annotation.Transactional; - -/** - * Repository to store {@link JpaEventPublication}s. - * - * @author Oliver Drotbohm - */ -@RequiredArgsConstructor -public class JpaEventPublicationRepository { - - private final EntityManager entityManager; - - @Transactional - JpaEventPublication create(JpaEventPublication publication) { - - entityManager.persist(publication); - return publication; - } - - @Transactional - JpaEventPublication update(JpaEventPublication publication) { - - entityManager.merge(publication); - entityManager.flush(); - - return publication; - } - - /** - * Returns all {@link JpaEventPublication} that have not been completed yet. - */ - @Transactional(readOnly = true) - List findByCompletionDateIsNull() { - - String query = "select p from JpaEventPublication p where p.completionDate is null"; - - return entityManager.createQuery(query, JpaEventPublication.class).getResultList(); - } - - /** - * Return the {@link JpaEventPublication} for the given serialized event and listener identifier. - * - * @param event must not be {@literal null}. - * @param listenerId must not be {@literal null}. - * @return - */ - @Transactional(readOnly = true) - Optional findBySerializedEventAndListenerId(Object event, String listenerId) { - - String query = "select p from JpaEventPublication p where p.serializedEvent = ?1 and p.listenerId = ?2"; - - TypedQuery typedQuery = entityManager.createQuery(query, JpaEventPublication.class) - .setParameter(1, event) - .setParameter(2, listenerId); - - try { - return Optional.of(typedQuery.getSingleResult()); - } catch (Exception o_O) { - return Optional.empty(); - } - } -} diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/package-info.java b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/package-info.java deleted file mode 100644 index 9a6858fd..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/java/org/springframework/modulith/events/jpa/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -@org.springframework.lang.NonNullApi -package org.springframework.modulith.events.jpa; diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/resources/META-INF/spring-devtools.properties b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/resources/META-INF/spring-devtools.properties deleted file mode 100644 index 4ebaf768..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/resources/META-INF/spring-devtools.properties +++ /dev/null @@ -1 +0,0 @@ -restart.include.spring-modulith-events:/spring-modulith-events-jpa-[\\w-\\.]+\.jar diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/resources/META-INF/spring.factories b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 66c6805f..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,6 +0,0 @@ -org.springframework.modulith.events.config.EventPublicationConfigurationExtension=\ - org.springframework.modulith.events.jpa.JpaEventPublicationConfiguration - -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - org.springframework.modulith.events.jpa.JpaEventPublicationAutoConfiguration,\ - org.springframework.modulith.events.jpa.JpaEventPublicationConfiguration diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfigurationIntegrationTests.java b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfigurationIntegrationTests.java deleted file mode 100644 index 5be78a68..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfigurationIntegrationTests.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.modulith.events.jpa; - -import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -import jakarta.persistence.EntityManager; -import jakarta.persistence.TypedQuery; -import lombok.RequiredArgsConstructor; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.modulith.events.EventSerializer; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.TestConstructor; -import org.springframework.test.context.TestConstructor.AutowireMode; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -/** - * @author Oliver Drotbohm - */ -@ExtendWith(SpringExtension.class) -@TestConstructor(autowireMode = AutowireMode.ALL) -@RequiredArgsConstructor -public class JpaEventPublicationConfigurationIntegrationTests { - - private final ApplicationContext context; - - @Configuration - @Import(JpaEventPublicationConfiguration.class) - static class TestConfig { - - @Bean - EventSerializer eventSerializer() { - return mock(EventSerializer.class); - } - - @Bean - EntityManager entityManager() { - - EntityManager em = mock(EntityManager.class); - - // Mock API for query executed at bootstrap time - TypedQuery query = mock(TypedQuery.class); - doReturn(query).when(em).createQuery(any(String.class), any()); - - return em; - } - } - - @Test - void bootstrapsApplicationComponents() { - - assertThat(context.getBean(JpaEventPublicationRegistry.class)).isNotNull(); - assertThat(context.getBean(JpaEventPublicationRepository.class)).isNotNull(); - } -} diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepositoryIntegrationTests.java b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepositoryIntegrationTests.java deleted file mode 100644 index 870d5a58..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepositoryIntegrationTests.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.modulith.events.jpa; - -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; - -import jakarta.persistence.EntityManager; -import jakarta.persistence.EntityManagerFactory; -import lombok.RequiredArgsConstructor; - -import java.time.Instant; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.modulith.events.EventSerializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.SharedEntityManagerCreator; -import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.test.context.TestConstructor; -import org.springframework.test.context.TestConstructor.AutowireMode; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.transaction.annotation.Transactional; - -/** - * @author Oliver Drotbohm - */ -@ExtendWith(SpringExtension.class) -@TestConstructor(autowireMode = AutowireMode.ALL) -@Transactional -@RequiredArgsConstructor -class JpaEventPublicationRepositoryIntegrationTests { - - @Configuration - @Import(JpaEventPublicationConfiguration.class) - static class TestConfig { - - @Bean - EventSerializer eventSerializer() { - return mock(EventSerializer.class); - } - - // Database - - @Bean - EmbeddedDatabase hsqlDatabase() { - return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).build(); - } - - // JPA - - @Bean - LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { - - AbstractJpaVendorAdapter vendor = new HibernateJpaVendorAdapter(); - vendor.setGenerateDdl(true); - - LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); - factory.setJpaVendorAdapter(vendor); - factory.setDataSource(dataSource); - factory.setPackagesToScan(getClass().getPackage().getName()); - - return factory; - } - - @Bean - EntityManager entityManager(EntityManagerFactory factory) { - return SharedEntityManagerCreator.createSharedEntityManager(factory); - } - - @Bean - JpaTransactionManager transactionManager(EntityManagerFactory factory) { - return new JpaTransactionManager(factory); - } - } - - private final JpaEventPublicationRepository repository; - - @Test - void persistsJpaEventPublication() { - - JpaEventPublication publication = JpaEventPublication.of(Instant.now(), "listener", "", Object.class); - - // Store publication - repository.create(publication); - - assertThat(repository.findByCompletionDateIsNull()).containsExactly(publication); - assertThat(repository.findBySerializedEventAndListenerId("", "listener")).isPresent(); - - // Complete publication - repository.update(publication.markCompleted()); - - assertThat(repository.findByCompletionDateIsNull()).isEmpty(); - } -} diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/resources/logback.xml b/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/resources/logback.xml deleted file mode 100644 index 1200a71e..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/test/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - %d %5p %40.40c:%4L - %m%n - - - - - - - - - - diff --git a/spring-modulith-events/spring-modulith-events-jpa/pom.xml b/spring-modulith-events/spring-modulith-events-jpa/pom.xml index 6d8031ac..5aa3d6d9 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/pom.xml +++ b/spring-modulith-events/spring-modulith-events-jpa/pom.xml @@ -12,6 +12,7 @@ spring-modulith-events-jpa + 17 org.springframework.modulith.events.jpa @@ -23,11 +24,11 @@ ${project.version} - + - javax.persistence - javax.persistence-api + jakarta.persistence + jakarta.persistence-api @@ -37,13 +38,27 @@ - + - org.hibernate - hibernate-core + jakarta.xml.bind + jakarta.xml.bind-api test - + + + + org.hibernate.orm + hibernate-core + 6.1.1.Final + test + + + + jakarta.transaction + jakarta.transaction-api + test + + org.springframework.boot spring-boot-starter-test @@ -64,4 +79,14 @@ + + + spring-milestone + https://repo.spring.io/milestone + + false + + + + \ No newline at end of file diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublication.java b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublication.java index 74f501a9..92425f50 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublication.java +++ b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublication.java @@ -15,6 +15,9 @@ */ package org.springframework.modulith.events.jpa; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.Builder; import lombok.Data; @@ -24,10 +27,6 @@ import lombok.RequiredArgsConstructor; import java.time.Instant; import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; - /** * @author Oliver Gierke */ diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationAutoConfiguration.java b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationAutoConfiguration.java index d9f0384e..058bb5d4 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationAutoConfiguration.java +++ b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationAutoConfiguration.java @@ -23,6 +23,4 @@ import org.springframework.context.annotation.Configuration; */ @Configuration(proxyBeanMethods = false) @AutoConfigurationPackage -class JpaEventPublicationAutoConfiguration { - -} +class JpaEventPublicationAutoConfiguration {} diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfiguration.java b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfiguration.java index 4b7190b1..59affa96 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfiguration.java +++ b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfiguration.java @@ -17,7 +17,7 @@ package org.springframework.modulith.events.jpa; import lombok.RequiredArgsConstructor; -import javax.persistence.EntityManager; +import jakarta.persistence.EntityManager; import org.springframework.modulith.events.EventSerializer; import org.springframework.modulith.events.config.EventPublicationConfigurationExtension; diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRegistry.java b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRegistry.java index 3f1df1d2..82c01e3d 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRegistry.java +++ b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ class JpaEventPublicationRegistry implements EventPublicationRegistry, Disposabl Assert.notNull(listener, "Listener identifier must not be null!"); events.findBySerializedEventAndListenerId(serializer.serialize(event), listener.toString()) // - .map(JpaEventPublicationRegistry::logCompleted) // + .map(JpaEventPublicationRegistry::LOGCompleted) // .ifPresent(it -> events.update(it.markCompleted())); } @@ -130,7 +130,7 @@ class JpaEventPublicationRegistry implements EventPublicationRegistry, Disposabl return result; } - private static JpaEventPublication logCompleted(JpaEventPublication publication) { + private static JpaEventPublication LOGCompleted(JpaEventPublication publication) { LOG.debug("Marking publication of event {} with id {} to listener {} completed.", // publication.getEventType(), publication.getId(), publication.getListenerId()); @@ -145,20 +145,13 @@ class JpaEventPublicationRegistry implements EventPublicationRegistry, Disposabl private final JpaEventPublication publication; private final EventSerializer serializer; - private Object deserializedEvent; - /* * (non-Javadoc) * @see org.springframework.events.EventPublication#getEvent() */ @Override public Object getEvent() { - - if (deserializedEvent == null) { - this.deserializedEvent = serializer.deserialize(publication.getSerializedEvent(), publication.getEventType()); - } - - return deserializedEvent; + return serializer.deserialize(publication.getSerializedEvent(), publication.getEventType()); } /* diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java index c90afe40..57155e4c 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java +++ b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java @@ -15,14 +15,13 @@ */ package org.springframework.modulith.events.jpa; +import jakarta.persistence.EntityManager; +import jakarta.persistence.TypedQuery; import lombok.RequiredArgsConstructor; import java.util.List; import java.util.Optional; -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; - import org.springframework.transaction.annotation.Transactional; /** diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-modulith-events/spring-modulith-events-jpa/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index dc43aae2..00000000 --- a/spring-modulith-events/spring-modulith-events-jpa/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.modulith.events.jpa.JpaEventPublicationAutoConfiguration -org.springframework.modulith.events.jpa.JpaEventPublicationConfiguration diff --git a/spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.factories b/spring-modulith-events/spring-modulith-events-jpa/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.factories similarity index 100% rename from spring-modulith-events/spring-modulith-events-jpa-jakarta/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.factories rename to spring-modulith-events/spring-modulith-events-jpa/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.factories diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfigurationIntegrationTests.java b/spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfigurationIntegrationTests.java index ca2a59dd..5be78a68 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfigurationIntegrationTests.java +++ b/spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationConfigurationIntegrationTests.java @@ -19,11 +19,10 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import jakarta.persistence.EntityManager; +import jakarta.persistence.TypedQuery; import lombok.RequiredArgsConstructor; -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.modulith.events.EventSerializer; diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepositoryIntegrationTests.java b/spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepositoryIntegrationTests.java index 3d0ff48d..870d5a58 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepositoryIntegrationTests.java +++ b/spring-modulith-events/spring-modulith-events-jpa/src/test/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepositoryIntegrationTests.java @@ -18,12 +18,12 @@ package org.springframework.modulith.events.jpa; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; import lombok.RequiredArgsConstructor; import java.time.Instant; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.junit.jupiter.api.Test; @@ -102,14 +102,13 @@ class JpaEventPublicationRepositoryIntegrationTests { @Test void persistsJpaEventPublication() { - String listenerId = "listener"; - JpaEventPublication publication = JpaEventPublication.of(Instant.now(), listenerId, "", Object.class); + JpaEventPublication publication = JpaEventPublication.of(Instant.now(), "listener", "", Object.class); // Store publication repository.create(publication); assertThat(repository.findByCompletionDateIsNull()).containsExactly(publication); - assertThat(repository.findBySerializedEventAndListenerId("", listenerId)).isPresent(); + assertThat(repository.findBySerializedEventAndListenerId("", "listener")).isPresent(); // Complete publication repository.update(publication.markCompleted()); diff --git a/spring-modulith-events/spring-modulith-events-tests/pom.xml b/spring-modulith-events/spring-modulith-events-tests/pom.xml index 6a7dfb7e..693e39b0 100644 --- a/spring-modulith-events/spring-modulith-events-tests/pom.xml +++ b/spring-modulith-events/spring-modulith-events-tests/pom.xml @@ -34,8 +34,9 @@ - org.hibernate + org.hibernate.orm hibernate-core + 6.1.1.Final diff --git a/spring-modulith-events/spring-modulith-events-tests/src/test/java/example/events/InfrastructureConfiguration.java b/spring-modulith-events/spring-modulith-events-tests/src/test/java/example/events/InfrastructureConfiguration.java index cfb86bd4..0bf2c582 100644 --- a/spring-modulith-events/spring-modulith-events-tests/src/test/java/example/events/InfrastructureConfiguration.java +++ b/spring-modulith-events/spring-modulith-events-tests/src/test/java/example/events/InfrastructureConfiguration.java @@ -15,8 +15,9 @@ */ package example.events; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; + import javax.sql.DataSource; import org.springframework.context.annotation.Bean; diff --git a/spring-modulith-sample/src/main/java/com/acme/myproject/stereotypes/Stereotypes.java b/spring-modulith-sample/src/main/java/com/acme/myproject/stereotypes/Stereotypes.java index 0523dc05..c7d9fe4b 100644 --- a/spring-modulith-sample/src/main/java/com/acme/myproject/stereotypes/Stereotypes.java +++ b/spring-modulith-sample/src/main/java/com/acme/myproject/stereotypes/Stereotypes.java @@ -18,7 +18,6 @@ package com.acme.myproject.stereotypes; import lombok.Value; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller; @@ -67,7 +66,6 @@ public class Stereotypes { static class SomeAppInterfaceImplementation implements SomeAppInterface {} @Value - @ConstructorBinding @ConfigurationProperties("org.springframework.modulith.sample") static class SomeConfigurationProperties { diff --git a/spring-modulith-starter-jpa-jakarta/pom.xml b/spring-modulith-starter-jpa-jakarta/pom.xml deleted file mode 100644 index 01d0aba1..00000000 --- a/spring-modulith-starter-jpa-jakarta/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - 4.0.0 - - - org.springframework.experimental - spring-modulith - 0.1.0-SNAPSHOT - - - spring-modulith-starter-jpa-jakarta - Spring Modulith - Starter JPA (Jakarta) - - - org.springframework.modulith.starter.jpa.jakarta - - - - - - org.springframework.experimental - spring-modulith-api - 0.1.0-SNAPSHOT - - - org.springframework.experimental - spring-modulith-moments - 0.1.0-SNAPSHOT - - - - - - org.springframework.experimental - spring-modulith-events-core - 0.1.0-SNAPSHOT - - - org.springframework.experimental - spring-modulith-events-jackson - 0.1.0-SNAPSHOT - runtime - - - org.springframework.experimental - spring-modulith-events-jpa-jakarta - 0.1.0-SNAPSHOT - runtime - - - - - \ No newline at end of file