Skip to content

Issue 652 - Parametrized include #331

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

Merged
merged 11 commits into from
Mar 2, 2015
Merged

Issue 652 - Parametrized include #331

merged 11 commits into from
Mar 2, 2015

Conversation

kmoco2am
Copy link
Contributor

This code changes implements static placeholders to be able to parametrize SQL fragments during parsing phase.

@harawata
Copy link
Member

Thank you @kmoco2am !

Looking at the test case, I think this is achievable using mybatis-velocity.
Please see my comment on another pull request.
The sample directive that I posted on Gist is a simple column list enhancement, but you should be able to modify it to suit your needs.

What do you think?

Regards,
Iwao

@lrfsat
Copy link

lrfsat commented Jan 21, 2015

From my point of view: parametrized include is more understandable, flexible and predictable than columnalias directive, or something based on columnalias.

@harawata
Copy link
Member

columnalias is just an example.
My point is that velocity custom directives is very flexible, powerful and less intrusive.

I wrote a new custom directive substitute and post it on Gist.
As an usage example, I rewrote the test case in this pull request using the directive.

p.s.
MyBatis already has ${var} expression, so I used @var@ instead.

@kmoco2am
Copy link
Contributor Author

Thank you for pointing me to the velocity integration project - I did not know about that before.

I think that Velocity can solve almost any issue because it is full templating engine. I just don't need all this functionality. Parametrized include is something missing in the whole mechanism of MyBatis statement construction by XML. Generally, I would be able to replace all , and others by Velocity. However, I don't want to add another syntax to our project just to be able to have this functionality (combining XML include and Velocity syntax). Some of the examples using Velocity for parametrized include are more complex (from syntax perspective), may be too much.

@harawata
Copy link
Member

We have discussed this addition on the dev list and decided it's a good addition to MyBatis :-)

Could you please add the following changes to this PR before merging?

  1. Documentation. The source of the doc is src/site/xdoc/sqlmap-xml.xml in xdoc format.
  2. Independent test case. Current test case in the PR does not fail even if the name/value of the placeholder is modified, so please create a new test case which actually validates the behavior.

Thank you both for your contribution!

@kmoco2am
Copy link
Contributor Author

kmoco2am commented Feb 2, 2015

That's great it has been accepted ;-)

Let me add more tests and documentation.

@kmoco2am
Copy link
Contributor Author

I have updated test cases and also added documentation for this feature.

@harawata
Copy link
Member

Thank you very much!
I will look into it as soon as I have time.

import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.session.Configuration;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Remove unused imports and 2) import each class explicitly instead of a package.
    Please see some other classes for reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I have changed IDE configuration to fix that,

@harawata harawata merged commit 4df0298 into mybatis:master Mar 2, 2015
harawata added a commit that referenced this pull request Mar 2, 2015
@harawata
Copy link
Member

harawata commented Mar 4, 2015

Hi, @kmoco2am

It's merged. Thanks again for your contribution!
Note that it might take a while until the DTD file to be updated.

I also added some tests that verify the expected behavior of this feature.
Please let me know if I am misunderstanding something.

Regards,
Iwao

harawata added a commit that referenced this pull request Mar 18, 2015
@emacarron emacarron added this to the 3.3.0 milestone Apr 25, 2015
@emacarron emacarron added the enhancement Improve a feature or add a new feature label Apr 25, 2015
harawata added a commit to harawata/mybatis-3 that referenced this pull request Jul 24, 2019
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
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.

4 participants