Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeHandler support the recursive search. #859

Merged
merged 1 commit into from
Dec 8, 2016
Merged

TypeHandler support the recursive search. #859

merged 1 commit into from
Dec 8, 2016

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