Menu

Enhancement proposal: plug in external bean

Tak
2004-10-30
2013-04-11
  • Tak

    Tak - 2004-10-30

    Hello SQLMap development team,

    My name is Tak Yoshida.
    I am start coding deeply with SQLMap for my project.
    And I found one thing I should ask, that is external service bean plug in feature
    for the complex object query.

    In my project, I need to use Oracle Object Cache Service for disributed
    application environment.
    and this cache will be managed outside of SQLMap framework, which mean I
    cannot use SQLMap cache plugin mechanism where SQLMap manage cache object itself.

    So I would like to have SQLMap call external service for complex object's sub query.

    Here is my proposal:
    Summary:
    Inject ServiceLocator to make SQLMap be able to call the service managed
    outside of SQLMap.

    1: To make use of external object, SqlMapClient has UserServiceBeanLocator object property.

    public interface SqlMapClient extends SqlMapExecutor,
    SqlMapTransactionManager {
      public void setUserServiceBeanLocator(UserServiceBeanLocator serviceBeanLocator);
      public UserServiceBeanLocator getUserServiceBeanLocator();
      ....
    }
    And SqlMapClientImpl has this imlementation.

    public interface UserServiceBeanLocator {
      // locator method
      public Object getUserServiceBean(String name) throws SqlMapException;
    }

    2: Extends resultMap's "result" tag attribute to specify the external bean and the method name.

    <result property="shipMode" column="SMODE" javaType="string" bean="shipModeDao" method="getShipModeById"/>
    instead of
    <result property="shipMode" column="SMODE" select="shipModeSqlMap.getShipModeById"/>

    3: To support 2, DTD must be enhanced for new two attributes, and
    XmlSqlMapClientBuilder must support it.

    4: And to hold these external bean info in mapping object created by XmlSqlMapClientBuilder,
    I introduce UserServiceBeanInfo.
    public class UserServiceBeanInfo {
      private String beanName;
      private String methodName;
      private Method method;
      ...
    }

    5: Utilizing aboves, BasicResultMap.getResults() method can do nested quesry for the complex property by calling external service.

    Here is a snippet of the codes
    } else if (mapping.getUserServiceBeanInfo() != null) {
    // get key for complex property
    Object rawValue = getPrimitiveResultMappingValue(rs, mapping);
    // get complex property via external service
    UserServiceBeanLocator serviceBeanLocator =
    request.getSession().getSqlMapClient().getUserServiceBeanLocator();
    UserServiceBeanInfo serviceBeanInfo = mapping.getUserServiceBeanInfo();
    try {
      Object service =  serviceBeanLocator.getUserServiceBean(serviceBeanInfo.getBeanName());
      Method method = serviceBeanInfo.getMethod(); // check cacheed one.
      if (method == null) {
        method = service.getClass().getMethod(serviceBeanInfo.getMethodName(),  new Class[] {mapping.getJavaType()});
        serviceBeanInfo.setMethod(method); // cache it.
      }
      columnValues[i] = method.invoke(service, new Object[] {rawValue});
    ... exception handling...
    } else {

    6: Application is fully responsible to set this up at startup time.
    I am injecting spring ApplicationContext object to SqlMapClient via ApplicationListener,

    I believe this is not only for my case in real world,
    and makes SQLMap more flexible.

    I have done experimental work already, and it works fine.
    If you would reflect my proposal in the future SQLMap, that would be great.

    I would like to attach my patch, so please let me know where I should post it.

    thanks,
    Tak

     
    • Brandon Goodin

      Brandon Goodin - 2004-10-30

      That sounds pretty cool. I think this points to a bigger topic on how to make the population of complex properties more flexible and extensible. There is also a post that was recently asking about passing a calling select's parameter object to a called select in cases where there are more than one parameter needed as selection criteria or in cases where a complex key exists.

      We are in the process of transitioning over to Apache Incubator and we (IBatis team) have been exceptionally busy on the payed work front. So, we might not get to this quickly. Once we get the code base under the Apache umbrella we can get  back on the task of improving and developing IBatis.

      Thanks for the submission.

      Brandon

       
    • Brandon Goodin

      Brandon Goodin - 2004-10-30

      Also, if you have not written any unit tests please do so. Then you can submit a patch to the patch section on the sourceforge site.

      http://sourceforge.net/tracker/?group_id=61326&atid=496913

      Brandon

       
    • Tak

      Tak - 2004-10-31

      Thanks for considering my post.

      Sure, I will start thinking about uunit testing, but is there any unit testing codes for existing complex query mechanism? I would like to follow the testing stragegy.

      Yes, you're right, and I have noticed it. I haven't invnstigate complex key situation, yet. I will take a look at it.

      Tak

       
      • Brandon Goodin

        Brandon Goodin - 2004-10-31

        We have unit tests. But, I wouldn't say that we have a uniform manner of testing. Feel free to checkout ibatis from the cvs repository. You will find the test classes there. But, they can be a little confusing.

        Brandon

         
    • Tak

      Tak - 2004-11-10

      I have submit a patch to the patch section on the sourceforge site.
      This patch only includes what I mentioned in my first post.
      Sorry, I couldn't squeeze my time to checked mutiple keys senario, yet.

      I would really appreciate it if you would review it.
      Thanks,
      Tak

       

Log in to post a comment.