Skip to content

LanguageDriver interface added method for scriptings sql source #1715

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
stepjacky opened this issue Nov 4, 2019 · 9 comments
Closed

LanguageDriver interface added method for scriptings sql source #1715

stepjacky opened this issue Nov 4, 2019 · 9 comments

Comments

@stepjacky
Copy link

in using mybatis scripting language ,like freemarker ,usually define mapper interface like below:

interface SomeTypeMapper{
     @Select("some-type/findBySome.ftl") 
     List<SomeType> findByBySome();  
}

as you know , In @select value style like namespace/method+'.ftl',it always has much more methods in mappers ,developer must write many of this style code for mybatis LanguageDriver to creating SqlSource, this style of Annotation is more common templated,think to add overload a method in LanguageDriver like below :

public interface LanguageDriver {
     SqlSource createSqlSource(Configuration configuration,Class<?> mapperType, Method mapperMethod, Class<?> parameterType);
}

to help find the sql templated styling ,current method in interface LanguageDriver is not friendly for annotation style by scripting sql template found!
THANKS

@kazuki43zoo
Copy link
Member

I think you can resolve this with using the TemplateFilePathProvider.

  • mybatis-freemarker.properties
templateFile.pathProvider.includesMapperNameWhenSeparateDirectory = false

It find a template file from namespace/method+'.ftl' (e.g. /com/example/SampleMapper/findById.ftl) .

@stepjacky
Copy link
Author

@kazuki43zoo

-Not only this , the class TemplateFilePathProvider you provided is in fact a SqlProvider ,isn't it?

-Actually ,it just convert declaring a @select Annotation to a @SelectProvider Annotation,I was always defined the common CURD operation of every POJO entity by this way ,but there usually has amount of other mapper methods need be load scripting file from some agreed path .

-I thought to create its SqlSource without declaring any Annotation to a method but use Mapper class and Mapper method to get it at LanguageDriver createSqlSource method from som called "The appointment is greater than configuration".

@kazuki43zoo
Copy link
Member

@stepjacky

Please refer to the previous discussion similar to this issue(#1492).
In that discussion, we decided to not passed a source informations(e.g. statement id, mapper type and method, etc...) to the LanguageDriver.

@harawata Please comment if you have any supplements.

@stepjacky
Copy link
Author

stepjacky commented Nov 6, 2019

LanguageDriver's task is to process an already loaded SQL script and I think it's better to keep this separation.
@harawata @kazuki43zoo
I dont think it is suitable for any scenes above ,and in xml sql source ,this statement is suitable,but annotation, because of xml sql source is configed by multi-way ,the property mapper location on configuration can clearly located mapper.xml file from variable way and without any other extra step,while annotationd mapper can't ,there has no way apart from adding sql annotation or sql provider annotation on a mapper method to locate the scripting template , so i think there need some way to do it , for every mapper method assign every scripting template location is troubled and unnecessary!
in issue (#1492), give LanguageDriver method a context maybe a good idea!

@harawata
Copy link
Member

harawata commented Nov 6, 2019

Hi @stepjacky ,

My English is not very good, so please let me clarify.
You want to load some .ftl file without writing annotation on a method, is that correct?

@stepjacky
Copy link
Author

@harawata
It's almost my opinion. it make code more concision ,and if writing annotation use it , otherwise,use default action we previous discussed.

@harawata
Copy link
Member

harawata commented Nov 9, 2019

Hi @stepjacky ,

Thank you for the clarification.
When there is no annotation, MyBatis looks for a mapped statement loaded from XML mappers and LanguageDriver is not used in this process.
There may be a way to achieve what you want, but using LanguageDriver is not the right approach.

@stepjacky
Copy link
Author

@harawata
yes i agree with you ,may be in global configuration,may be in somewhere needed .thanks for focusing on it,and waiting for more idea!
And i have viewed the source of mybatis about SqlSource building, it looks like just only in LanguageDriver to load scripting template source.
hoping to more...

@harawata
Copy link
Member

As @kazuki43zoo and I explained, we don't plan to pass method related information to language driver at present.

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