Skip to content

Commit

Permalink
Release v0.3.3 | spring-multi-data-source Java 17+ support (#26)
Browse files Browse the repository at this point in the history
* Added support for Java 17+ by abstracting away all usages of `javax.persistence`.

* Removed `javax.persistence` from Docs as well
  • Loading branch information
Dhi13man authored Aug 5, 2024
1 parent 13deed2 commit d51caac
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Releases

## [0.3.3] - 5th August 2024

- Java 17+ Support: Added support for Java 17+ by abstracting away all usages
of `javax.persistence`. This is to ensure that the library is compatible with the latest Java
versions.
- This is a minor change and should not affect any existing implementations.

## [0.3.2] - 4th August 2024

- **HOTFIX:** Replaced the use of native entity manager factory
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,5 @@
</scm>

<url>http://www.github.com/dhi13man/spring-multi-data-source</url>
<version>0.3.2</version>
<version>0.3.3</version>
</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.dhi13man.spring.datasource.config;

import java.util.Properties;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
Expand Down Expand Up @@ -62,8 +61,11 @@ LocalContainerEntityManagerFactoryBean entityManagerFactory(
/**
* Get the transaction manager to be used for the data source.
*
* @param entityManagerFactory The entity manager factory used to create the transaction manager
* @param entityManagerFactoryBean The entity manager factory bean whose EntityManagerFactory
* object is used to create the transaction manager
* @return The transaction manager.
*/
PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory);
PlatformTransactionManager transactionManager(
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Properties;
import javax.annotation.Nonnull;
import javax.lang.model.element.Modifier;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
Expand Down Expand Up @@ -238,9 +237,10 @@ public MultiDataSourceConfigGenerator(
* the data source are located (to be included in the
* {@link EnableJpaRepositories} annotation)
* @param entityManagerFactoryBeanNameField the {@link FieldSpec} for the
* {@link EntityManagerFactory} bean name constant. This
* is used to reference the {@link EntityManagerFactory}
* bean in the {@link EnableJpaRepositories} annotation
* {@link LocalContainerEntityManagerFactoryBean} bean
* name constant. This is used to reference the
* {@link LocalContainerEntityManagerFactoryBean} bean in
* the {@link EnableJpaRepositories} annotation
* @param transactionManagerBeanNameField the {@link FieldSpec} for the
* {@link PlatformTransactionManager} bean name constant.
* This is used to reference the
Expand Down Expand Up @@ -431,10 +431,11 @@ public MultiDataSourceConfigGenerator(
}

/**
* Create the {@link MethodSpec} builder for the {@link EntityManagerFactory} bean.
* Create the {@link MethodSpec} builder for the {@link LocalContainerEntityManagerFactoryBean}
* bean.
* <p>
* {@link EntityManagerFactory} will determine the {@link javax.persistence.EntityManager}
* implementation to use based on the {@link DataSource} implementation for complex queries.
* {@link LocalContainerEntityManagerFactoryBean} will determine the EntityManager implementation
* to use based on the {@link DataSource} implementation for complex queries.
*
* @param beanNameFieldSpece the {@link FieldSpec} for this bean name
* constant
Expand All @@ -446,7 +447,8 @@ public MultiDataSourceConfigGenerator(
* dependency bean name constant
* @param hibernateBeanContainerPropertyFieldSpec the {@link FieldSpec} for the hibernate bean
* container property constant
* @return the {@link MethodSpec} builder for the {@link EntityManagerFactory} bean
* @return the {@link MethodSpec} builder for the {@link LocalContainerEntityManagerFactoryBean}
* bean
*/
private @Nonnull MethodSpec.Builder createEntityManagerFactoryBeanMethod(
@Nonnull FieldSpec beanNameFieldSpece,
Expand Down Expand Up @@ -514,7 +516,8 @@ public MultiDataSourceConfigGenerator(
*
* @param beanNamefieldSpec the {@link FieldSpec} for this bean name constant
* @param entityManagerFactoryBeanNameFieldSpec the {@link FieldSpec} for the
* {@link EntityManagerFactory} dependency bean
* {@link LocalContainerEntityManagerFactoryBean}
* dependency bean
* @return the {@link MethodSpec} builder for the {@link PlatformTransactionManager} bean
*/
private @Nonnull MethodSpec.Builder createTransactionManagerBeanMethod(
Expand All @@ -533,7 +536,7 @@ public MultiDataSourceConfigGenerator(

// Create the method parameters (EntityManagerFactory dependency)
final ParameterSpec entityManagerFactoryParameter = ParameterSpec
.builder(EntityManagerFactory.class, "entityManagerFactory")
.builder(LocalContainerEntityManagerFactoryBean.class, "entityManagerFactoryBean")
.addAnnotation(qualifierAnnotation)
.build();

Expand All @@ -545,7 +548,7 @@ public MultiDataSourceConfigGenerator(
.returns(PlatformTransactionManager.class)
.addParameter(entityManagerFactoryParameter)
.addStatement(
"return new $T($N)",
"return new $T($N.getObject())",
JpaTransactionManager.class,
entityManagerFactoryParameter
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Properties;
import java.util.Set;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -103,8 +102,10 @@ void generateMultiDataSourceConfigTypeElementGetEntityManagerFactory() {
void generateMultiDataSourceConfigTypeElementGetTransactionManager() {
for (final IMultiDataSourceConfig generatedConfig : generatedConfigs) {
// Arrange
final EntityManagerFactory mockEntityManagerFactory = Mockito
.mock(EntityManagerFactory.class);
final LocalContainerEntityManagerFactoryBean mockEntityManagerFactory = Mockito
.mock(LocalContainerEntityManagerFactoryBean.class);
Mockito.when(mockEntityManagerFactory.getObject())
.thenReturn(Mockito.mock());

// Act
final PlatformTransactionManager transactionManager = generatedConfig
Expand Down

0 comments on commit d51caac

Please sign in to comment.