All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jfireframework.jfireSqlStarter.AutoConfigAllSql Maven / Gradle / Ivy

package com.jfireframework.jfireSqlStarter;

import javax.annotation.Resource;
import javax.sql.DataSource;
import com.jfireframework.jfire.kernel.Jfire;
import com.jfireframework.jfire.kernel.Order;
import com.jfireframework.jfire.support.BeanInstanceResolver.extend.bean.annotation.field.PropertyRead;
import com.jfireframework.jfire.support.JfirePrepared.Configuration;
import com.jfireframework.jfire.support.JfirePrepared.Configuration.Bean;
import com.jfireframework.jfire.support.JfirePrepared.condition.provide.ConditionOnBean;
import com.jfireframework.jfire.support.JfirePrepared.condition.provide.ConditionOnProperty;
import com.jfireframework.sql.session.SessionFactory;
import com.jfireframework.sql.session.SqlSession;

@Configuration
public class AutoConfigAllSql
{
    @Resource
    private DataSource  dataSource;
    @Resource
    private ClassLoader classLoader;
    @PropertyRead("sessionFactory.tableMode")
    private String      tableMode = "none";
    @PropertyRead("sessionFactory.scanPackage")
    private String      scanPackage;
    @Resource
    private Jfire       jfire;
    
    @Order(1)
    @ConditionOnProperty({ "sessionFactory.scanPackage" })
    @Bean(name = "com.jfireframework.jfireSqlStarter.MapperLoadFactory")
    public SessionFactory sessionFactory()
    {
        MapperLoadFactory factory = new MapperLoadFactory();
        factory.setClassLoader(classLoader);
        factory.setDataSource(dataSource);
        factory.setScanPackage(scanPackage);
        factory.setTableMode(tableMode);
        factory.init();
        return factory;
    }
    
    @Order(2)
    @ConditionOnBean(SessionFactory.class)
    @Bean
    public AutoSession autoSession()
    {
        AutoSession autoSession = new AutoSession();
        autoSession.setSessionFactory(jfire.getBean(SessionFactory.class));
        return autoSession;
    }
    
    @Order(2)
    @ConditionOnBean(SessionFactory.class)
    @Bean
    public TxManager txManager()
    {
        TxManager txManager = new TxManager();
        txManager.setSessionFactory(jfire.getBean(SessionFactory.class));
        return txManager;
    }
    
    @Order(2)
    @ConditionOnBean(SessionFactory.class)
    @Bean
    public SqlSession sqlSession()
    {
        SqlSessionProxy proxy = new SqlSessionProxy();
        proxy.setSessionFactory(jfire.getBean(SessionFactory.class));
        return proxy;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy