Feature request: Constant (enum) references refactor friendly

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Feature request: Constant (enum) references refactor friendly

Сергей Каримов
Hi all!
There is one feature I think mybatis is lacking...
as for now you can reference enum value in xml like @com.company.project.model.enums.MyEnum@MY_ENUM_VALUE. But this is very refactoring unfriendly. When you rename package/enum/constant you have to manually update all scripts.
I suggest something like this:

@ConstantReference(name = "MyEnum", value = MyEnum.class)
public interface Mapper {
  @Select("SELECT * FROM SOME_TABLE WHERE TYPE_ID = @[hidden email]"
  List<...> run1()

  @ConstantReference(name = "MyEnumValue1", value = MyEnum.MY_ENUM_VALUE)
  @Select("SELECT * FROM SOME_TABLE WHERE TYPE_ID = @MyEnumValue1.id"
  List<...> run1()
}

@ConstantReference may contain Map<String, Object> or allow multiple annotations. If value is a class then you may access public static fields via @<reference name>@<field name>. if value is some object, you may access public nonstatic members.
@ConstantReference may be placed on the whole mapper or particular method.
you may choose whichever annotation you like #{<reference name>.<field name>} or @<reference name>@<field name>


Sergey.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Feature request: Constant (enum) references refactor friendly

Iwao AVE!
Hi Sergey,

Please see the workaround that I posted on another thread.

By the way, in Eclipse, there is 'Update fully qualified names in non-Java text files' option in the refactoring dialog.
NetBeans does not have such refactoring option (in 2013, at least) [1].
IntelliJ seems to do this by default [2].

p.s.
It may be a matter of preference, but I kind of prefer writing FQN because it's easier to search the references even though it's a little bit verbose.


Regards,
Iwao


2018-03-15 5:43 GMT+09:00 Сергей Каримов <[hidden email]>:
Hi all!
There is one feature I think mybatis is lacking...
as for now you can reference enum value in xml like @com.company.project.model.enums.MyEnum@MY_ENUM_VALUE. But this is very refactoring unfriendly. When you rename package/enum/constant you have to manually update all scripts.
I suggest something like this:

@ConstantReference(name = "MyEnum", value = MyEnum.class)
public interface Mapper {
  @Select("SELECT * FROM SOME_TABLE WHERE TYPE_ID = @[hidden email]"
  List<...> run1()

  @ConstantReference(name = "MyEnumValue1", value = MyEnum.MY_ENUM_VALUE)
  @Select("SELECT * FROM SOME_TABLE WHERE TYPE_ID = @MyEnumValue1.id"
  List<...> run1()
}

@ConstantReference may contain Map<String, Object> or allow multiple annotations. If value is a class then you may access public static fields via @<reference name>@<field name>. if value is some object, you may access public nonstatic members.
@ConstantReference may be placed on the whole mapper or particular method.
you may choose whichever annotation you like #{<reference name>.<field name>} or @<reference name>@<field name>


Sergey.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Feature request: Constant (enum) references refactor friendly

Сергей Каримов
Hi Iwao!

You wrote:
Please see the workaround that I posted on another thread.

Yes, it reduces number of references, but you still need at least one fully qualified reference.

You wrote:
By the way, in Eclipse, there is 'Update fully qualified names in non-Java text files' option in the refactoring dialog.
NetBeans does not have such refactoring option (in 2013, at least) [1].
IntelliJ seems to do this by default [2].

Yes, there is such an option and it would probably work if you rename foo.MyFooMapper to something else. But it surely wouldn't work if you rename enum constant foo.MyFooMapper.MY_CONSTANT 
referenced as @foo.MyFooMapper@MY_CONSTANT
or worse:
<property name="myFooMapper" value="@foo.MyFooMapper@"/>
<if test="params[${myFooMapper}.MY_CONSTANT]">

Regards, Sergey

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.