com.fhs.trans.config.EasyTransJPA2Config Maven / Gradle / Ivy
package com.fhs.trans.config;
import com.fhs.core.trans.util.ReflectUtils;
import com.fhs.trans.extend.JPA2SimpleTransDiver;
import com.fhs.trans.extend.JPA2TransableRegister;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.persistence.EntityManager;
import javax.persistence.Id;
/**
* JPA2适配器
*
* @author wanglei
*/
@Slf4j
@Configuration
@ConditionalOnClass(EntityManager.class)
public class EasyTransJPA2Config {
/**
* service的包路径
*/
@Value("${easy-trans.autotrans.package:com.*.*.service.impl}")
private String packageNames;
@Bean
@ConditionalOnProperty(name = "easy-trans.is-enable-auto", havingValue = "true")
public JPA2TransableRegister jpaTransableRegister() {
JPA2TransableRegister result = new JPA2TransableRegister();
result.setPackageNames(packageNames);
return result;
}
@Bean
public JPA2SimpleTransDiver jpaSimpleTransDiver(EntityManager em) {
ReflectUtils.ID_ANNO.add(Id.class);
JPA2SimpleTransDiver result = new JPA2SimpleTransDiver(em);
return result;
}
}