Commons-dbUtils开发应用和研究(四)

 private boolean isCompatibleType(Object value, Class type) {

        // Do object check first, then primitives

        if (value == null || type.isInstance(value)) {

            return true;

 

        } else if (

            type.equals(Integer.TYPE) && Integer.class.isInstance(value)) {

            return true;

        } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) {

            return true;

 

        } else if (

            type.equals(Double.TYPE) && Double.class.isInstance(value)) {

            return true;

 

        } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) {

            return true;

        } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) {

            return true;

        } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) {

            return true;

 

        } else if (

            type.equals(Character.TYPE) && Character.class.isInstance(value)) {

            return true;

 

        } else if (

            type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) {

            return true;

 

        } else {

            return false;

        }

 

    }

 

    /**

     *创建一个对象

     */

    protected Object newInstance(Class c) throws SQLException {

        try {

            return c.newInstance();

 

        } catch (InstantiationException e) {

            throw new SQLException(

                "Cannot create " + c.getName() + ": " + e.getMessage());

 

        } catch (IllegalAccessException e) {

            throw new SQLException(

                "Cannot create " + c.getName() + ": " + e.getMessage());

        }

    }

     /**

     * 返回一个类的属性描述的信息

     */

    private PropertyDescriptor[] propertyDescriptors(Class c)

        throws SQLException {

        // Introspector caches BeanInfo classes for better performance

        BeanInfo beanInfo = null;

        try {

            beanInfo = Introspector.getBeanInfo(c);

 

        } catch (IntrospectionException e) {

            throw new SQLException(

                "Bean introspection failed: " + e.getMessage());

        }

         return beanInfo.getPropertyDescriptors();

    }

   

你可能感兴趣的:(C++,c,bean,C#,performance)