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

link.jfire.sql.util.MapBeanFactory Maven / Gradle / Ivy

package link.jfire.sql.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import link.jfire.sql.annotation.TableEntity;
import link.jfire.sql.function.MapBean;
import link.jfire.sql.function.impl.MapBeanImpl;
import link.jfire.sql.metadata.MetaData;

public class MapBeanFactory
{
    private static Map, MapBeanImpl> mapBeans    = new HashMap<>();
    private static Map         metaDataMap = new HashMap<>();
    
    /**
     * 获取对应类型的MapBean
     * 
     * @param entityClass
     * @return
     */
    @SuppressWarnings({ "unchecked" })
    public static  MapBean getBean(Class entityClass)
    {
        return (MapBeanImpl) mapBeans.get(entityClass);
    }
    
    public static void build(Set set)
    {
        for (String each : set)
        {
            Class ckass;
            try
            {
                ckass = Class.forName(each);
                if (ckass.isAnnotationPresent(TableEntity.class))
                {
                    metaDataMap.put(ckass.getSimpleName(), new MetaData(ckass));
                    mapBeans.put(ckass, new MapBeanImpl<>(ckass));
                }
            }
            catch (ClassNotFoundException e)
            {
                throw new RuntimeException(e);
            }
            
        }
    }
    
    public static MetaData getMetaData(String name)
    {
        return metaDataMap.get(name);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy