我正在尝试在Spring Boot项目中将记录保存到Oracle DB。我正在从其余服务中获取输入,运行逻辑并将结果保存到DB中。在搜索日志时,我看到一些记录在10到20毫秒内被保存,但是有些记录在千毫秒内保存。我怀疑数据源池化,但我不确定。这里有什么错误吗?
@Configuration
@PropertySource({"classpath:application.properties"})
@EnableJpaRepositories(
basePackages = "com.ykb.frd.fraudbase.repository.hibernate.fraud",
entityManagerFactoryRef = "fraudEntityManager",
transactionManagerRef = "fraudTransactionManager")
public class FraudConfiguration {
@Autowired
private DataSourceProperties dataSourceProperties;
@Autowired
private Environment env;
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean fraudEntityManager() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(fraudDataSource());
em.setPackagesToScan("com.ykb.frd.fraudbase.entity.fraud");
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
return em;
}
@Primary
@Bean
public DataSource fraudDataSource() {
DataSourceBuilder factory = DataSourceBuilder
.create(this.dataSourceProperties.getClassLoader())
.driverClassName(env.getProperty("driver-class-name"))
.url(env.getProperty("fraud.url"))
.username(env.getProperty("fraud.username"))
.password(env.getProperty("fraud.password"));
return factory.build();
}
@Primary
@Bean
public PlatformTransactionManager fraudTransactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(fraudEntityManager().getObject());
return transactionManager;
}
}
@Repository
public interface FraudRequestTransactionsRepository extends CrudRepository<FraudRequestTransactionsEntity, Long> {
}
long start = System.currentTimeMillis();
BaseService service = baseServices.length > 0 ? baseServices[0] : null;
FraudRequestTransactionsEntity fraudRequestTransactionsEntity = new FraudRequestTransactionsEntity();
fraudRequestTransactionsEntity.setLuc(0);
fraudRequestTransactionsEntity.setTransactionId(fraudActionsRestRequest.getTransactionId());
if (fraudActionsRestRequest.getSenderClientNo() != null)
fraudRequestTransactionsEntity.setClientNo(Integer.parseInt(fraudActionsRestRequest.getSenderClientNo()));
fraudRequestTransactionsEntity.setTransactionId(fraudActionsRestRequest.getTransactionId());
fraudRequestTransactionsEntity.setUserId(fraudActionsRestRequest.getUserId());
fraudRequestTransactionsEntity.setChannelName(fraudActionsRestRequest.getChannel());
fraudRequestTransactionsEntity.setProcessCode(fraudActionsRestRequest.getProcessCode());
fraudRequestTransactionsEntity.setProcessName(fraudActionsRestRequest.getProcessName());
fraudRequestTransactionsEntity.setRequest(requestMessage);
fraudRequestTransactionsEntity.setTransactionStatus("FINISHED");
fraudRequestTransactionsEntity.setSessionId(fraudActionsRestRequest.getSessionId());
Calendar date = Calendar.getInstance();
fraudRequestTransactionsEntity.setTransactionDate(date.getTime());
fraudRequestTransactionsEntity.setTransactionMillisecond(date.get(Calendar.MILLISECOND));
fraudRequestTransactionsEntity.setAmount(fraudActionsRestRequest.getTlAmount());
fraudRequestTransactionsEntity.setCurrency(fraudActionsRestRequest.getSenderCurrencyCode());
fraudRequestTransactionsEntity.setDeviceId(fraudActionsRestRequest.getDeviceId());
fraudRequestTransactionsEntity.setReceiverAccountNo(fraudActionsRestRequest.getReceiverAccountNo());
fraudRequestTransactionsEntity.setTransactionType(fraudActionsRestRequest.getFraudTransactionsMapEntity().getTransactionType());
fraudRequestTransactionsEntity.setSenderCardNo(fraudActionsRestRequest.getSenderCreditCardNumber());
fraudRequestTransactionsEntity.setTransactionSequenceNo(Long.toString(fraudActionsRestRequest.getTransactionSequenceNo()));
//TODO zeynep & berkin : bu alanları almamız gereken yerlere bakılacak
/*fraudRequestTransactionsEntity.setSubScriberNo(fraudActionsRestRequest.get);
if(fraudActionsRestRequest.getFraudTransactionsMapEntity().getTransactionType().equalsIgnoreCase(FalconUtil.RBTRAN)){
fraudRequestTransactionsEntity.setReceiverClientNo(((RbtranServiceInputModel)service).);
fraudRequestTransactionsEntity.setReceiverCardNo(((RbtranServiceInputModel)service).);
fraudRequestTransactionsEntity.setReceiverPhoneNo(((RbtranServiceInputModel)service).);
}*/
fraudRequestTransactionsRepository.save(fraudRequestTransactionsEntity);
log.info("[{}] REQ DB Yazma Süresi {}", fraudActionsRestRequest.getTransactionId(), System.currentTimeMillis() - start);
> 2019-02-01 09:31:03,671 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-3] [1550097604112] REQ DB Yazma Süresi 33
> 2019-02-01 09:32:04,338 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-8] [1548428179551] REQ DB Yazma Süresi 23
> 2019-02-01 09:32:38,260 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-8] [1549819439559] REQ DB Yazma Süresi 39
> 2019-02-01 09:33:41,725 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-3] [1548871854756] REQ DB Yazma Süresi 654
> 2019-02-01 09:34:04,093 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-9] [1551123829603] REQ DB Yazma Süresi 7841
> 2019-02-01 09:34:04,104 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-4] [1548256231753] REQ DB Yazma Süresi 18835
> 2019-02-01 09:34:50,452 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-1] [1550169566966] REQ DB Yazma Süresi 100
> 2019-02-01 09:35:52,729 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-8] [1548634610667] REQ DB Yazma Süresi 17
> 2019-02-01 09:36:48,676 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-9] [1548513532722] REQ DB Yazma Süresi 26
> 2019-02-01 09:37:29,116 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-10] [1547445362906] REQ DB Yazma Süresi 17
> 2019-02-01 09:39:09,091 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-4] [1548339052481] REQ DB Yazma Süresi 19
> 2019-02-01 09:39:53,977 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-2] [1547701783551] REQ DB Yazma Süresi 51
> 2019-02-01 09:40:31,429 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-2] [1550619321669] REQ DB Yazma Süresi 20
> 2019-02-01 09:41:12,516 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-2] [1549734992552] REQ DB Yazma Süresi 31
> 2019-02-01 09:42:42,585 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-2] [1550174884815] REQ DB Yazma Süresi 38
> 2019-02-01 09:44:10,962 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-2] [1547618724242] REQ DB Yazma Süresi 40
> 2019-02-01 09:47:26,009 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-5] [1548172574161] REQ DB Yazma Süresi 53
> 2019-02-01 09:47:57,171 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-1] [1548842916526] REQ DB Yazma Süresi 33
> 2019-02-01 09:47:58,080 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-5] [1547521859756] REQ DB Yazma Süresi 27
> 2019-02-01 09:49:13,696 INFO com.ykb.frd.fraudcommon.CommonApplication [http-nio-8080-exec-1] [1550270365545] REQ DB Yazma Süresi 974
谢谢。