adm/app 계정 관련 하이버네이트 대응

This commit is contained in:
Rinjae
2025-09-11 16:38:50 +09:00
parent a83bb20934
commit 8d07897e42
7 changed files with 122 additions and 47 deletions
@@ -14,5 +14,6 @@ public class EmsDatasourceProperties {
private String password;
private String databaseName;
private String serverName;
private String schema;
private int portNumber;
}
@@ -14,5 +14,6 @@ public class GatewayDataSourceProperties {
private String password;
private String databaseName;
private String serverName;
private String schema;
private int portNumber;
}
@@ -3,7 +3,12 @@ package com.eactive.apim.portal.config;
import com.eactive.eai.data.jpa.BaseRepositoryImpl;
import java.util.HashMap;
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.jta.atomikos.AtomikosDataSourceBean;
@@ -19,36 +24,71 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
repositoryBaseClass = BaseRepositoryImpl.class,
entityManagerFactoryRef = "gatewayEntityManagerFactory")
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
@Slf4j
public class PortalConfigGatewayDatasource {
@Autowired
private GatewayDataSourceProperties gatewayDataSourceProperties;
@PostConstruct
public void init() {
if (StringUtils.isEmpty(gatewayDataSourceProperties.getSchema())) {
log.error("Profile property 'schema' is empty. Please check your configuration.");
throw new IllegalArgumentException("GatewayDataSourceProperties schema is empty. Please check your configuration.");
}
}
// @Bean
// public DataSource gatewayDataSource() {
// AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
// dataSource.setBeanName("gatewayDataSource");
// dataSource.setUniqueResourceName("gatewayDataSource");
// dataSource.setMinPoolSize(5);
// dataSource.setMaxPoolSize(10);
// dataSource.setMaxIdleTime(60); // seconds
// dataSource.setBorrowConnectionTimeout(30); // seconds
// dataSource.setTestQuery("SELECT 1 FROM DUAL");
// dataSource.setMaintenanceInterval(60);
// dataSource.setXaDataSourceClassName("oracle.jdbc.xa.client.OracleXADataSource");
//
// Properties xaProperties = new Properties();
// String url = String.format("jdbc:oracle:thin:@//%s:%d/%s",
// gatewayDataSourceProperties.getServerName(), // HOST
// gatewayDataSourceProperties.getPortNumber(), // PORT
// gatewayDataSourceProperties.getDatabaseName()); // SERVICE_NAME 또는 SID
// // SID를 사용하는 경우: "jdbc:oracle:thin:@host:port:SID"
//
// xaProperties.setProperty("URL", url);
// xaProperties.setProperty("user", gatewayDataSourceProperties.getUsername());
// xaProperties.setProperty("password", gatewayDataSourceProperties.getPassword());
//
// dataSource.setXaProperties(xaProperties);
// return dataSource;
// }
@Bean
public DataSource gatewayDataSource() {
AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
dataSource.setBeanName("gatewayDataSource");
dataSource.setUniqueResourceName("gatewayDataSource");
dataSource.setMinPoolSize(5);
dataSource.setMaxPoolSize(10);
dataSource.setMaxIdleTime(60); // seconds
dataSource.setBorrowConnectionTimeout(30); // seconds
dataSource.setTestQuery("SELECT 1 FROM DUAL");
dataSource.setMaintenanceInterval(60);
dataSource.setXaDataSourceClassName("oracle.jdbc.xa.client.OracleXADataSource");
HikariDataSource dataSource = new HikariDataSource();
Properties xaProperties = new Properties();
String url = String.format("jdbc:oracle:thin:@//%s:%d/%s",
gatewayDataSourceProperties.getServerName(), // HOST
gatewayDataSourceProperties.getPortNumber(), // PORT
gatewayDataSourceProperties.getDatabaseName()); // SERVICE_NAME 또는 SID
// SID를 사용하는 경우: "jdbc:oracle:thin:@host:port:SID"
gatewayDataSourceProperties.getServerName(), // HOST
gatewayDataSourceProperties.getPortNumber(), // PORT
gatewayDataSourceProperties.getDatabaseName()); // SERVICE_NAME 또는 SID
xaProperties.setProperty("URL", url);
xaProperties.setProperty("user", gatewayDataSourceProperties.getUsername());
xaProperties.setProperty("password", gatewayDataSourceProperties.getPassword());
dataSource.setJdbcUrl(url);
dataSource.setUsername(gatewayDataSourceProperties.getUsername());
dataSource.setPassword(gatewayDataSourceProperties.getPassword());
dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
// 커넥션 풀 세팅
dataSource.setMinimumIdle(5);
dataSource.setMaximumPoolSize(10);
dataSource.setIdleTimeout(60000); // 60초
dataSource.setConnectionTimeout(30000); // 30초
dataSource.setConnectionTestQuery("SELECT 1 FROM DUAL");
dataSource.setXaProperties(xaProperties);
return dataSource;
}
@@ -62,6 +102,7 @@ public class PortalConfigGatewayDatasource {
properties.put("hibernate.connection.handling_mode", "DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION");
properties.put("hibernate.transaction.jta.platform", "org.hibernate.engine.transaction.jta.platform.internal.AtomikosJtaPlatform");
properties.put("hibernate.physical_naming_strategy", "com.eactive.apim.portal.common.entity.CustomPhysicalNamingStrategy");
properties.put("hibernate.default_schema", gatewayDataSourceProperties.getSchema());
properties.put("javax.persistence.validation.mode", "none");
properties.put("javax.persistence.transactionType", "JTA");
@@ -1,11 +1,12 @@
package com.eactive.apim.portal.config;
import com.eactive.eai.data.jpa.BaseRepositoryImpl;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.jta.atomikos.AtomikosDataSourceBean;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -19,9 +20,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Properties;
/**
* @author Sungpil Hyun
@@ -56,35 +55,59 @@ public class PortalConfigPortalDatasource {
@PostConstruct
public void checkProfile() {
log.warn("Active profiles: {}", Arrays.toString(env.getActiveProfiles()));
if (StringUtils.isEmpty(emsDatasourceProperties.getSchema())) {
log.error("Profile property 'schema' is empty. Please check your configuration.");
throw new IllegalArgumentException("'ems.datasource.schema' is not configured.");
}
}
@Primary
@Primary
@Bean
public DataSource portalDataSource() {
AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
dataSource.setBeanName("portalDataSource");
dataSource.setUniqueResourceName("portalDataSource");
dataSource.setMinPoolSize(5);
dataSource.setMaxPoolSize(10);
dataSource.setMaxIdleTime(60); // seconds
dataSource.setBorrowConnectionTimeout(30); // seconds
dataSource.setTestQuery("SELECT 1 FROM DUAL");
dataSource.setMaintenanceInterval(60);
dataSource.setXaDataSourceClassName("oracle.jdbc.xa.client.OracleXADataSource");
// AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
// dataSource.setBeanName("portalDataSource");
// dataSource.setUniqueResourceName("portalDataSource");
// dataSource.setMinPoolSize(5);
// dataSource.setMaxPoolSize(10);
// dataSource.setMaxIdleTime(60); // seconds
// dataSource.setBorrowConnectionTimeout(30); // seconds
// dataSource.setTestQuery("SELECT 1 FROM DUAL");
// dataSource.setMaintenanceInterval(60);
// dataSource.setXaDataSourceClassName("oracle.jdbc.xa.client.OracleXADataSource");
//
// Properties xaProperties = new Properties();
// String url = String.format("jdbc:oracle:thin:@//%s:%d/%s",
// emsDatasourceProperties.getServerName(), // HOST
// emsDatasourceProperties.getPortNumber(), // PORT
// emsDatasourceProperties.getDatabaseName()); // SERVICE_NAME 또는 SID
// // SID를 사용하는 경우: "jdbc:oracle:thin:@host:port:SID"
//
// xaProperties.setProperty("URL", url);
// xaProperties.setProperty("user", emsDatasourceProperties.getUsername());
// xaProperties.setProperty("password", emsDatasourceProperties.getPassword());
//
// dataSource.setXaProperties(xaProperties);
// return dataSource;
HikariDataSource dataSource = new HikariDataSource();
Properties xaProperties = new Properties();
String url = String.format("jdbc:oracle:thin:@//%s:%d/%s",
emsDatasourceProperties.getServerName(), // HOST
emsDatasourceProperties.getPortNumber(), // PORT
emsDatasourceProperties.getDatabaseName()); // SERVICE_NAME 또는 SID
// SID를 사용하는 경우: "jdbc:oracle:thin:@host:port:SID"
emsDatasourceProperties.getServerName(), // HOST
emsDatasourceProperties.getPortNumber(), // PORT
emsDatasourceProperties.getDatabaseName()); // SERVICE_NAME 또는 SID
xaProperties.setProperty("URL", url);
xaProperties.setProperty("user", emsDatasourceProperties.getUsername());
xaProperties.setProperty("password", emsDatasourceProperties.getPassword());
dataSource.setJdbcUrl(url);
dataSource.setUsername(emsDatasourceProperties.getUsername());
dataSource.setPassword(emsDatasourceProperties.getPassword());
dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
// 커넥션 풀 설정
dataSource.setMinimumIdle(5);
dataSource.setMaximumPoolSize(10);
dataSource.setIdleTimeout(60000); // 60s
dataSource.setConnectionTimeout(30000); // 30s
dataSource.setConnectionTestQuery("SELECT 1 FROM DUAL");
dataSource.setXaProperties(xaProperties);
return dataSource;
}
@@ -106,6 +129,7 @@ public class PortalConfigPortalDatasource {
properties.put("hibernate.show_sql", "true");
properties.put("hibernate.transaction.jta.platform", "org.hibernate.engine.transaction.jta.platform.internal.AtomikosJtaPlatform");
properties.put("hibernate.use_sql_comments", "true");
properties.put("hibernate.default_schema", emsDatasourceProperties.getSchema());
properties.put("javax.persistence.validation.mode", "none");
properties.put("javax.persistence.transactionType", "JTA");
+6 -4
View File
@@ -20,16 +20,18 @@ ems:
serverName: 192.168.240.177
portNumber: 1599
databaseName: DAPM
username: EMSADM
password: EMSADM123!
username: EMSAPP
password: EMSAPP123!
schema: EMSADM
gateway:
datasource:
serverName: 192.168.240.177
portNumber: 1599
databaseName: DAPM
username: AGWADM
password: AGWADM123!
username: AGWAPP
password: AGWAPP123!
schema: AGWADM
proxy:
+2
View File
@@ -22,6 +22,7 @@ ems:
databaseName: DAPM
username: EMSAPP
password: EMSAPP123!
schema: EMSADM
gateway:
datasource:
@@ -30,6 +31,7 @@ gateway:
databaseName: DAPM
username: AGWAPP
password: AGWAPP123!
schema: AGWADM
#proxy:
# targets:
+4
View File
@@ -40,6 +40,10 @@
<logger name="org.apache" level="INFO" additivity="false"/>
<logger name="sun.rmi" level="WARN" additivity="false"/>
<logger name="javax" level="WARN" additivity="false"/>
<logger name="jdk.event.security" level="WARN" additivity="false"/>
<logger name="com.zaxxer.hikari" level="INFO" additivity="false"/>
<logger name="_org.springframework.web" level="INFO" additivity="false"/>
<logger name="com.atomikos" level="INFO" additivity="false"/>
<root level="DEBUG">
<appender-ref ref="ROLLING"/>