org.midao.jdbc.core.handlers.utils
Class MappingUtils

java.lang.Object
  extended by org.midao.jdbc.core.handlers.utils.MappingUtils

public class MappingUtils
extends java.lang.Object

Collection of utilities used to map values from one type into another (Bean->Map, Map->Bean)


Constructor Summary
MappingUtils()
           
 
Method Summary
static java.lang.Object callGetter(java.lang.Object target, java.beans.PropertyDescriptor prop)
          Invokes Property Descriptor Getter and returns value returned by that function.
static void callSetter(java.lang.Object target, java.beans.PropertyDescriptor prop, java.lang.Object value)
          Invokes Property Descriptor Setter and sets value @value into it.
static java.util.List<QueryParameters> convertResultSet(java.sql.ResultSet rs)
          Converts java.sql.ResultSet into List of QueryParameters.
static boolean hasFunction(java.lang.Object object, java.lang.String functionName, java.lang.Class[] parameters)
          Checks if Instance has specified function
static void invokeConnectionSetter(java.sql.Connection conn, java.lang.String functionName, java.lang.Object value)
          Invocation of Connection setter functions This function provides flexibility which required to use Connection with different Java versions: 5/6 etc.
static java.lang.Object invokeFunction(java.lang.Object object, java.lang.String functionName, java.lang.Class[] parameters, java.lang.Object[] values)
          Invokes class function using Reflection
static java.lang.Object invokeStaticFunction(java.lang.Class clazz, java.lang.String functionName, java.lang.Class[] parameters, java.lang.Object[] values)
          Invokes class function using Reflection
static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> mapPropertyDescriptors(java.lang.Class<?> clazz)
          Reads property descriptors of class and puts them into Map.
static
<T> T
newInstance(java.lang.Class<T> clazz)
          Creates new Instance of class specified.
static boolean objectAssignableTo(java.lang.Object object, java.lang.String className)
          Checks if instance can be cast to specified Class
static boolean objectExtends(java.lang.Object object, java.lang.String superClassName)
          Checks if Instance extends specified Class Class.isAssignableFrom(Class) is not used as Class might not be available and String representation can only be used
static boolean objectImplements(java.lang.Object object, java.lang.String interfaceClass)
          Checks if Instance implements specified Interface Class.isAssignableFrom(Class) is not used as Interface might not be available and String representation can only be used
static boolean objectInstanceOf(java.lang.Object object, java.lang.String className)
          Checks if instance is of specified class
static java.beans.PropertyDescriptor[] propertyDescriptors(java.lang.Class<?> clazz)
          Reads property descriptors of class
static java.lang.Object returnStaticField(java.lang.Class clazz, java.lang.String fieldName)
          Returns class static field value Is used to return Constants
static java.util.Map<java.lang.String,java.lang.Object> toMap(java.lang.Object inputParameter, java.beans.PropertyDescriptor[] propertyDescriptors)
          Converts Java Object into Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MappingUtils

public MappingUtils()
Method Detail

toMap

public static java.util.Map<java.lang.String,java.lang.Object> toMap(java.lang.Object inputParameter,
                                                                     java.beans.PropertyDescriptor[] propertyDescriptors)
Converts Java Object into Map. Keys and Values are read from PropertyDescriptors

Parameters:
inputParameter - Object which would be converted into Map
propertyDescriptors - Array of Class PropertyDescriptors
Returns:
Map with values from Object

propertyDescriptors

public static java.beans.PropertyDescriptor[] propertyDescriptors(java.lang.Class<?> clazz)
Reads property descriptors of class

Parameters:
clazz - Class for which we are getting property descriptors
Returns:
Array of Class PropertyDescriptors

mapPropertyDescriptors

public static java.util.Map<java.lang.String,java.beans.PropertyDescriptor> mapPropertyDescriptors(java.lang.Class<?> clazz)
Reads property descriptors of class and puts them into Map. Key for map is read from property descriptor.

Parameters:
clazz - Class for which Property Descriptors would be read
Returns:
Map of Property Descriptors for specified class

callGetter

public static java.lang.Object callGetter(java.lang.Object target,
                                          java.beans.PropertyDescriptor prop)
Invokes Property Descriptor Getter and returns value returned by that function.

Parameters:
target - Object Getter of which would be executed
prop - Property Descriptor which would be used to invoke Getter
Returns:
Value returned from Getter

callSetter

public static void callSetter(java.lang.Object target,
                              java.beans.PropertyDescriptor prop,
                              java.lang.Object value)
Invokes Property Descriptor Setter and sets value @value into it.

Parameters:
target - Object Getter of which would be executed
prop - Property Descriptor which would be used to invoke Getter
value - Value which should be set into @target

convertResultSet

public static java.util.List<QueryParameters> convertResultSet(java.sql.ResultSet rs)
                                                        throws java.sql.SQLException
Converts java.sql.ResultSet into List of QueryParameters. Used for caching purposes to allow ResultSet to be closed and disposed.

Parameters:
rs - ResultSet values from which would be read
Returns:
List of QueryParameters (one for each row)
Throws:
java.sql.SQLException - propagates SQLException sent from ResultSet

newInstance

public static <T> T newInstance(java.lang.Class<T> clazz)
                     throws MidaoException
Creates new Instance of class specified. Default Constructor should be visible in order to create new Instance

Parameters:
clazz - Class which should be instantiated
Returns:
Empty Object
Throws:
java.sql.SQLException - in case of instantiation error
MidaoException

invokeConnectionSetter

public static void invokeConnectionSetter(java.sql.Connection conn,
                                          java.lang.String functionName,
                                          java.lang.Object value)
                                   throws MidaoException
Invocation of Connection setter functions This function provides flexibility which required to use Connection with different Java versions: 5/6 etc.

Parameters:
conn - SQL Connection
functionName - SQL Connection parameter name
value - value which would be set
Throws:
MidaoException - if property wasn't found

invokeFunction

public static java.lang.Object invokeFunction(java.lang.Object object,
                                              java.lang.String functionName,
                                              java.lang.Class[] parameters,
                                              java.lang.Object[] values)
                                       throws MidaoException
Invokes class function using Reflection

Parameters:
object - Instance which function would be invoked
functionName - function name
parameters - function parameters (array of Class)
values - function values (array of Object)
Returns:
function return
Throws:
MidaoException - in case function doesn't exists

invokeStaticFunction

public static java.lang.Object invokeStaticFunction(java.lang.Class clazz,
                                                    java.lang.String functionName,
                                                    java.lang.Class[] parameters,
                                                    java.lang.Object[] values)
                                             throws MidaoException
Invokes class function using Reflection

Parameters:
clazz - Class which function would be invoked
functionName - function name
parameters - function parameters (array of Class)
values - function values (array of Object)
Returns:
function return
Throws:
MidaoException - in case function doesn't exists

hasFunction

public static boolean hasFunction(java.lang.Object object,
                                  java.lang.String functionName,
                                  java.lang.Class[] parameters)
Checks if Instance has specified function

Parameters:
object - Instance which function would be checked
functionName - function name
parameters - function parameters (array of Class)
Returns:
true if function is present in Instance

objectImplements

public static boolean objectImplements(java.lang.Object object,
                                       java.lang.String interfaceClass)
Checks if Instance implements specified Interface Class.isAssignableFrom(Class) is not used as Interface might not be available and String representation can only be used

Parameters:
object - Instance which would be checked
interfaceClass - Interface with which it would be checked
Returns:
true if Instance implements specified Interface

objectExtends

public static boolean objectExtends(java.lang.Object object,
                                    java.lang.String superClassName)
Checks if Instance extends specified Class Class.isAssignableFrom(Class) is not used as Class might not be available and String representation can only be used

Parameters:
object - Instance which would be checked
superClassName - Class with which it would be checked
Returns:
true if Instance extends specified Parent

objectInstanceOf

public static boolean objectInstanceOf(java.lang.Object object,
                                       java.lang.String className)
Checks if instance is of specified class

Parameters:
object - Instance which would be checked
className - Class name with which it would be checked
Returns:
true if Instance is of specified class

objectAssignableTo

public static boolean objectAssignableTo(java.lang.Object object,
                                         java.lang.String className)
                                  throws MidaoException
Checks if instance can be cast to specified Class

Parameters:
object - Instance which would be checked
className - Class name with which it would be checked
Returns:
true if Instance can be cast to specified class
Throws:
MidaoException

returnStaticField

public static java.lang.Object returnStaticField(java.lang.Class clazz,
                                                 java.lang.String fieldName)
                                          throws MidaoException
Returns class static field value Is used to return Constants

Parameters:
clazz - Class static field of which would be returned
fieldName - field name
Returns:
field value
Throws:
MidaoException - if field is not present or access is prohibited


Copyright © 2013. All Rights Reserved.