Class ResultObjectFactoryUtil
java.lang.Object
com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactoryUtil
This class is used to create instances of result objects. It will use the configured ResultObjectFactory if there is
one, otherwise it will use iBATIS' normal methods.
Note that this class is somewhat tightly coupled with SqlExecuter - SqlExecute must call the setStatementId() and setResultObjectFactory() methods before executing a statement. This is a result of using a ThreadLocal to hold the current configuration for the statement under execution. Using a ThreadLocal is a solution for IBATIS-366. Without a ThreadLocal, the current factory and statement id would have to be added to many method signatures - often in inappropriate places.
- Author:
- Jeff Butler
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Removes the FactorySettings bound to the current thread to avoid classloader leak issues.static Object
createObjectThroughFactory
(Class clazz) Algorithm: If factory is null, then create object internally() Otherwise try to create object through factory If null returned from factory, then create object internally This allows the factory to selectively create objects, also allows for the common possibility that a factory is not configured.static void
setupResultObjectFactory
(ResultObjectFactory resultObjectFactory, String statementId) This method pushes a new result object factory configuration onto the stack.
-
Method Details
-
createObjectThroughFactory
public static Object createObjectThroughFactory(Class clazz) throws InstantiationException, IllegalAccessException Algorithm:- If factory is null, then create object internally()
- Otherwise try to create object through factory
- If null returned from factory, then create object internally
- Parameters:
clazz
- the type of object to create- Returns:
- a new instance of the specified class. The instance must be castable to the specified class.
- Throws:
InstantiationException
- if the instance cannot be created. If you throw this Exception, iBATIS will throw a runtime exception in response and will end.IllegalAccessException
- if the constructor cannot be accessed. If you throw this Exception, iBATIS will throw a runtime exception in response and will end.
-
setupResultObjectFactory
public static void setupResultObjectFactory(ResultObjectFactory resultObjectFactory, String statementId) This method pushes a new result object factory configuration onto the stack. We use a stack because the method can be called in a "nested" fashion if there are sub-selects. Calls to this method should be equally balanced with calls to cleanupResultObjectFactory().- Parameters:
resultObjectFactory
- the result object factorystatementId
- the statement id
-
cleanupResultObjectFactory
public static void cleanupResultObjectFactory()Removes the FactorySettings bound to the current thread to avoid classloader leak issues. This method pops the top item off the stack, and kills the stack if there are no items left.
-