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

org.smallframework.spring.mapper.DaoMapperFactoryBean Maven / Gradle / Ivy

The newest version!
package org.smallframework.spring.mapper;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.Assert;
import sf.database.dao.DBClient;

/**
 * 对工厂Bean的实现用于构建Mapper,一次只对一个接口进行扫描,构建Mapper
 * 要获取FactoryBean本身 需要加&
 * @param 
 */
public class DaoMapperFactoryBean implements FactoryBean {
    private Class mapperInterface;
    private DBClient client;

    public DaoMapperFactoryBean(Class mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    public DaoMapperFactoryBean() {
    }

    protected void checkDaoConfig() throws IllegalArgumentException {
        Assert.notNull(this.mapperInterface, " 'mapperInterface' 属性是必须的");
    }

    @Override
    public T getObject() throws Exception {
        return this.client.getMapper(mapperInterface);
    }

    @Override
    public Class getObjectType() {
        return this.mapperInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    //在扫描时会注入该属性
    public void setMapperInterface(Class mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    public void setClient(DBClient client) {
        this.client = client;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy