Uploaded image for project: 'iBatis for Java [READ ONLY]'
  1. iBatis for Java [READ ONLY]
  2. IBATIS-50

Ability to override the default bean creation mechanism

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.9
    • 2.2.0
    • Core
    • None

    Description

      Currently, iBatis is responsible for creating instances of classes used in result maps. It relies on the assumption that objects can be obtained using the Class.newInstance() method (or something equivalent).

      The assumption forces users of the framework to create classes with a no-arg default constructor. IMHO, this also has the effect of favoring implementation inheritance (extends) over interface inheritance.

      Although this is not a problem in most cases, the ability to plug in an external instance factory would provide more flexibility and favor good programming practices. Amongst other things, it would provide developers the ability write code in terms of interface.

      A simple solution is to provide an extension point where resultMap class instances are obtained from.

      The simplest form would be:

      public interface InstanceFactory {
      Object createInstance(Class resultMapClass);
      }

      The default implementation would do something along the lines of:

      [...]
      return resultMapClass.newInstance();
      [...]

      Developers could configure iBatis to either use the default implementation or their own custom implementation. The setting could be part of the sqlMapConfig file or even per resultMap.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              plaflamme Philippe Laflamme
              Votes:
              15 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: