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

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

There is a newer version: 1.0.6
Show newest version
package com.jfireframework.jfireSqlStarter;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import com.jfireframework.jfire.support.BeanInstanceResolver.LoadByBeanInstanceResolver.BeanLoadFactory;
import com.jfireframework.sql.dao.Dao;
import com.jfireframework.sql.resultsettransfer.ResultsetTransferStore;
import com.jfireframework.sql.session.SessionFactory;
import com.jfireframework.sql.session.SessionfactoryConfig;
import com.jfireframework.sql.session.SqlSession;

public class MapperLoadFactory implements BeanLoadFactory, SessionFactory
{
    private SessionFactory sessionFactory;
    private DataSource     dataSource;
    private ClassLoader    classLoader;
    private String         tableMode = "none";
    private String         scanPackage;
    
    @PostConstruct
    public void init()
    {
        SessionfactoryConfig config = new SessionfactoryConfig();
        config.setClassLoader(classLoader);
        config.setScanPackage(scanPackage);
        config.setTableMode(tableMode);
        config.setDataSource(dataSource);
        sessionFactory = config.build();
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public  E load(Class ckass)
    {
        return (E) sessionFactory.getMapper(ckass);
    }
    
    @Override
    public  Dao getDao(Class ckass)
    {
        return sessionFactory.getDao(ckass);
    }
    
    @Override
    public  T getMapper(Class entityClass)
    {
        return sessionFactory.getMapper(entityClass);
    }
    
    @Override
    public SqlSession getCurrentSession()
    {
        return sessionFactory.getCurrentSession();
    }
    
    @Override
    public SqlSession getOrCreateCurrentSession()
    {
        return sessionFactory.getOrCreateCurrentSession();
    }
    
    @Override
    public SqlSession openSession()
    {
        return sessionFactory.openSession();
    }
    
    @Override
    public void cleanAllData()
    {
        sessionFactory.cleanAllData();
    }
    
    public void setTableMode(String tableMode)
    {
        this.tableMode = tableMode;
    }
    
    public void setScanPackage(String scanPackage)
    {
        this.scanPackage = scanPackage;
    }
    
    public void setDataSource(DataSource dataSource)
    {
        this.dataSource = dataSource;
    }
    
    public void setClassLoader(ClassLoader classLoader)
    {
        this.classLoader = classLoader;
    }
    
    @Override
    public ResultsetTransferStore getResultSetTransferStore()
    {
        return sessionFactory.getResultSetTransferStore();
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy