Skip to content

Conversation

@liyuj
Copy link

@liyuj liyuj commented Dec 2, 2016

In some scenarios, need to define a generic typehandler for some custom types, so typehandler can be search in a recursive manner,is very valuable.

In some scenarios, need to define a generic typehandler for some custom types, so typehandler can be search in a recursive manner,is very valuable.
@harawata
Copy link
Member

harawata commented Dec 2, 2016

This is basically a duplicate of #604 .
There seems to be a need for this feature, so I will look into it.
We need to be careful as this method affects performance.

@liyuj
Copy link
Author

liyuj commented Dec 3, 2016 via email

@harawata
Copy link
Member

harawata commented Dec 6, 2016

Is it a bad idea to add a new entry to TYPE_HANDLER_MAP when matching entry for a superclass is found?

  if (jdbcHandlerMap == null && type instanceof Class){
    Class c = ((Class)type).getSuperclass();
    while(c != null && c != Object.class){
      jdbcHandlerMap = TYPE_HANDLER_MAP.get(c);
      if (jdbcHandlerMap != null) {
+        TYPE_HANDLER_MAP.put(type, jdbcHandlerMap);
        break;
      } else {
        c = c.getSuperclass();
      }
    }
  }

Then the superclass-scanning is performed only once for a subclass and it would save a decent amount of time when dealing with a large number of rows.

@liyuj
Copy link
Author

liyuj commented Dec 6, 2016 via email

@harawata
Copy link
Member

harawata commented Dec 6, 2016

Assuming that the current version of MyBatis works fine with your solution, memory usage should not be a problem.
Because the value (jdbcHandlerMap) of a new entry is just a reference, memory usage will actually be smaller than the current version with the same type handler entries, at least.

If it still concerns you, give me some time and I will do some profiling.

@liyuj
Copy link
Author

liyuj commented Dec 6, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improve a feature or add a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants