Skip to content

Customize object construction when select the raw. (Feature request) #1678

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

Closed
kazuki-ma opened this issue Sep 30, 2019 · 3 comments
Closed

Comments

@kazuki-ma
Copy link
Contributor

Object construction in ObjectFactory is not customizable in user side.

Users need all result ret (column name and value) instead of List<Class<?>> constructorArgTypes, List<Object> constructorArgs.

Background

We want get result by immutable class.
There are few implementations in MyBatis.
Current implementation flow is following.

  • Gets constructor.getParameterTypes().
  • Gets rsw.getColumnNames()

If not match parameter order, runtime exception is occurred.

boolean foundValues = false;
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
Class<?> parameterType = constructor.getParameterTypes()[i];
String columnName = rsw.getColumnNames().get(i);
TypeHandler<?> typeHandler = rsw.getTypeHandler(parameterType, columnName);
Object value = typeHandler.getResult(rsw.getResultSet(), columnName);
constructorArgTypes.add(parameterType);
constructorArgs.add(value);
foundValues = value != null || foundValues;

There are many cases when database column order changes or constructor parameter order changes.

It is more flexible to create customize point of matching strategy by user.

@harawata
Copy link
Member

Hi @kazuki-ma ,

I am not sure if I understand correctly, but it is already possible to map constructor arguments by name.
Please see #721 and the test in this directory for how it works.

If it is not what you are looking for, please explain the mapping you are trying to achieve using some concrete examples (result set, Java classes, etc.).

@harawata
Copy link
Member

harawata commented Jan 2, 2020

No reply.
ObjectFactory should not rely on the column name, I think.

@harawata harawata closed this as completed Jan 2, 2020
@harawata
Copy link
Member

harawata commented Mar 6, 2021

Hello @GoldSubmarine ,

It's not supported at the moment, but there might be room for improvement.
Could you create a new issue?
As your proposal does not include 'customizable' part, it is different than this request, I would think.

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

No branches or pull requests

3 participants