Skip to content

Commit

Permalink
chore: testing native
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Dec 20, 2024
1 parent 0e0a9db commit 2503da8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
import com.zaxxer.hikari.HikariDataSource;
import jakarta.persistence.EntityManagerFactory;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes;
import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypesScanner;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

Expand All @@ -31,22 +33,30 @@ public class OracleJpaConfiguration {
@Bean(name = "oracleEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean oracleEntityManagerFactory(
@Qualifier("oracleDataSource") HikariDataSource dataSource,
@Qualifier("oracleManagedTypes") PersistenceManagedTypes persistenceManagedTypes,
EntityManagerFactoryBuilder builder
) {
return builder
.dataSource(dataSource)
.properties(Map.of(
"hibernate.dialect", "org.hibernate.dialect.OracleDialect",
"hibernate.boot.allow_jdbc_metadata_access","false",
"hibernate.boot.allow_jdbc_metadata_access", "false",
"hibernate.hikari.connection.provider_class",
"org.hibernate.hikaricp.internal.HikariCPConnectionProvider",
"hibernate.connection.datasource", dataSource
))
.packages("ca.bc.gov.restapi.results.oracle")
.managedTypes(persistenceManagedTypes)
.persistenceUnit("oracle")
.build();
}

@Bean(name = "oracleManagedTypes")
public PersistenceManagedTypes oracleManagedTypes(ResourceLoader resourceLoader) {
return new PersistenceManagedTypesScanner(resourceLoader)
.scan("ca.bc.gov.restapi.results.oracle");
}

@Bean(name = "oracleDataSource")
@ConfigurationProperties(prefix = "spring.oracle.hikari")
public HikariDataSource oracleDataSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import com.zaxxer.hikari.HikariDataSource;
import jakarta.persistence.EntityManagerFactory;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes;
import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypesScanner;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

Expand All @@ -32,6 +34,7 @@ public class PostgresJpaConfiguration {
@Bean(name = "postgresEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean postgresEntityManagerFactory(
@Qualifier("postgresHikariDataSource") HikariDataSource dataSource,
@Qualifier("postgresManagedTypes") PersistenceManagedTypes persistenceManagedTypes,
EntityManagerFactoryBuilder builder
) {
return builder
Expand All @@ -44,10 +47,18 @@ public LocalContainerEntityManagerFactoryBean postgresEntityManagerFactory(
"hibernate.connection.datasource", dataSource
))
.packages("ca.bc.gov.restapi.results.postgres")
.managedTypes(persistenceManagedTypes)
.persistenceUnit("postgres")
.build();
}

@Bean(name = "postgresManagedTypes")
@Primary
public PersistenceManagedTypes postgresManagedTypes(ResourceLoader resourceLoader) {
return new PersistenceManagedTypesScanner(resourceLoader)
.scan("ca.bc.gov.restapi.results.postgres");
}

@Bean(name = "postgresHikariDataSource")
@ConfigurationProperties(prefix = "spring.datasource.hikari")
@Primary
Expand Down

0 comments on commit 2503da8

Please sign in to comment.