package com.tzy.framework.bee;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.teasoft.bee.osql.PreparedSql;
import org.teasoft.bee.osql.Suid;
import org.teasoft.bee.osql.SuidRich;
import org.teasoft.honey.osql.core.BeeFactory;
import org.teasoft.honey.osql.core.BeeFactoryHelper;

import javax.annotation.Resource;

/**
 * @author by po'yi
 * @Classname BeeConfig
 * @Description 通用dao,实体类尽量使用pojo包下,其他实体类个别字段未和表对应
 * @Date 2021/12/8 13:01
 */
@Configuration
@Slf4j
public class BeeConfig {
	//@Value("${logging.bee.enabled:false}")
	//private boolean showSql;
	@Resource
	private DruidDataSource druidDataSource;

	@Bean
	public BeeFactory beeFactory() throws Exception {
		BeeFactory beeFactory = BeeFactory.getInstance();
		//DataSource dataSource = applicationContext.getBean(DataSource.class);
		beeFactory.setDataSource(druidDataSource);
		return beeFactory;
	}

	@Bean("suid")
	public Suid beeSuid() {
		return BeeFactoryHelper.getSuid();
	}

	@Bean("suidRich")
	public SuidRich beeSuidRich() {
		return BeeFactory.getHoneyFactory().getSuidRich();
	}

	@Bean("preparedSql")
	public PreparedSql beePreparedSql() {
		return BeeFactory.getHoneyFactory().getPreparedSql();
	}
}
