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

com.silentgo.orm.kit.PropertyKit Maven / Gradle / Ivy

There is a newer version: 0.3.2
Show newest version
package com.silentgo.orm.kit;

import com.silentgo.orm.base.BaseTableInfo;
import com.silentgo.orm.base.TableModel;
import com.silentgo.utils.log.Log;
import com.silentgo.utils.log.LogFactory;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Project : SilentGo
 * Package : com.silentgo.core.plugin.db.util
 *
 * @author teddyzhu
 *         

* Created by teddyzhu on 2016/10/10. */ public class PropertyKit { public static final Log LOGGER = LogFactory.get(); private static final Map, BeanInfo> beanMap = new ConcurrentHashMap<>(); private static final Map, Map> cachedPropMap = new ConcurrentHashMap<>(); public static BeanInfo getBeanInfo(Class t) { BeanInfo beanInfo = null; if (beanMap.containsKey(t)) { beanInfo = beanMap.get(t); } else { try { beanInfo = Introspector.getBeanInfo(t); beanMap.put(t, beanInfo); } catch (IntrospectionException e) { LOGGER.debug("create bean :{} failed", t); e.printStackTrace(); } } return beanInfo; } public static Map getCachedProps(BaseTableInfo tableInfo) { BeanInfo beanInfo = getBeanInfo(tableInfo.getClazz()); if (cachedPropMap.containsKey(tableInfo.getClazz())) { return cachedPropMap.get(tableInfo.getClazz()); } else { Map propertyDescriptors = getProps(beanInfo, tableInfo); cachedPropMap.put(tableInfo.getClazz(), propertyDescriptors); return propertyDescriptors; } } public static Map getProps(BeanInfo beanInfo, BaseTableInfo tableInfo) { Map propsMap = new HashMap<>(); for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { if (tableInfo.getColumnInfo().containsKey(propertyDescriptor.getName())) { propsMap.put(propertyDescriptor.getName(), propertyDescriptor); } } return propsMap; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy