Generator plugin: add new select element to mappers.

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Generator plugin: add new select element to mappers.

Iwao AVE!
Hi,

I am writing a generator plugin to add a project-specific query
(selectByXxx) to mappers.
It was easy to add a new method to the java mapper interfaces, but I
couldn't figure out how to add a new 'select' element to the xml
mapper files.
PluginAdapter#sqlMapGenerated() seemed to be the one I should
override, but it doesn't expose XML elements of the generated XML
file.
Any hints?

Thanks,
Iwao
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Generator plugin: add new select element to mappers.

Jeff Butler
That method will work (GeneratedXMLFile#getDocument), or you can use
PluginAdapter#sqlMapDocumentGenerated

Jeff Butler


On Thu, Feb 3, 2011 at 4:32 AM, Iwao AVE! <[hidden email]> wrote:

> Hi,
>
> I am writing a generator plugin to add a project-specific query
> (selectByXxx) to mappers.
> It was easy to add a new method to the java mapper interfaces, but I
> couldn't figure out how to add a new 'select' element to the xml
> mapper files.
> PluginAdapter#sqlMapGenerated() seemed to be the one I should
> override, but it doesn't expose XML elements of the generated XML
> file.
> Any hints?
>
> Thanks,
> Iwao
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Generator plugin: add new select element to mappers.

Iwao AVE!
Jeff,

PluginAdapter#sqlMapDocumentGenerated is what I was looking for.
Thank you!

# In version 1.3.1, GeneratedXMLFile#getDocument() doesn't seem to
exist.

// Iwao

On 2月4日, 午後12:23, Jeff Butler <[hidden email]> wrote:

> That method will work (GeneratedXMLFile#getDocument), or you can use
> PluginAdapter#sqlMapDocumentGenerated
>
> Jeff Butler
>
> On Thu, Feb 3, 2011 at 4:32 AM, Iwao AVE! <[hidden email]> wrote:
> > Hi,
>
> > I am writing a generator plugin to add a project-specific query
> > (selectByXxx) to mappers.
> > It was easy to add a new method to the java mapper interfaces, but I
> > couldn't figure out how to add a new 'select' element to the xml
> > mapper files.
> > PluginAdapter#sqlMapGenerated() seemed to be the one I should
> > override, but it doesn't expose XML elements of the generated XML
> > file.
> > Any hints?
>
> > Thanks,
> > Iwao
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Generator plugin: add new select element to mappers.

Jeff Butler
Sorry - you are right about GeneratedXMLFile#getDocument().  I was
working from memory (dangerous).

Jeff Butler


On Fri, Feb 4, 2011 at 1:43 AM, Iwao AVE! <[hidden email]> wrote:

> Jeff,
>
> PluginAdapter#sqlMapDocumentGenerated is what I was looking for.
> Thank you!
>
> # In version 1.3.1, GeneratedXMLFile#getDocument() doesn't seem to
> exist.
>
> // Iwao
>
> On 2月4日, 午後12:23, Jeff Butler <[hidden email]> wrote:
>> That method will work (GeneratedXMLFile#getDocument), or you can use
>> PluginAdapter#sqlMapDocumentGenerated
>>
>> Jeff Butler
>>
>> On Thu, Feb 3, 2011 at 4:32 AM, Iwao AVE! <[hidden email]> wrote:
>> > Hi,
>>
>> > I am writing a generator plugin to add a project-specific query
>> > (selectByXxx) to mappers.
>> > It was easy to add a new method to the java mapper interfaces, but I
>> > couldn't figure out how to add a new 'select' element to the xml
>> > mapper files.
>> > PluginAdapter#sqlMapGenerated() seemed to be the one I should
>> > override, but it doesn't expose XML elements of the generated XML
>> > file.
>> > Any hints?
>>
>> > Thanks,
>> > Iwao
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Generator plugin: add new select element to mappers.

Sully
Hi Jeff, I want  the generated xml file excluding all 'jdbcType=xxxx', so I tried to do this task with globally replacing in PluginAdapter.sqlMapGenerated(), but I can only get the short file name of the xml file via PluginAdapter.sqlMapGenerated().
Or I can change the MyBatis3FormattingUtilities.getParameterClause() method directly, I wonder whether there is an alternative option without breaking the original code?

On Saturday, February 5, 2011 at 3:53:12 AM UTC+8, Jeff Butler wrote:
Sorry - you are right about GeneratedXMLFile#getDocument().  I was
working from memory (dangerous).

Jeff Butler


On Fri, Feb 4, 2011 at 1:43 AM, Iwao AVE! <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="G4vlMf6De0EJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">hara...@...> wrote:


> Jeff,
>
> PluginAdapter#sqlMapDocumentGenerated is what I was looking for.
> Thank you!
>
> # In version 1.3.1, GeneratedXMLFile#getDocument() doesn't seem to
> exist.
>
> // Iwao
>
> On 2月4日, 午後12:23, Jeff Butler <[hidden email]> wrote:
>> That method will work (GeneratedXMLFile#getDocument), or you can use
>> PluginAdapter#sqlMapDocumentGenerated
>>
>> Jeff Butler
>>
>> On Thu, Feb 3, 2011 at 4:32 AM, Iwao AVE! <[hidden email]> wrote:
>> > Hi,
>>
>> > I am writing a generator plugin to add a project-specific query
>> > (selectByXxx) to mappers.
>> > It was easy to add a new method to the java mapper interfaces, but I
>> > couldn't figure out how to add a new 'select' element to the xml
>> > mapper files.
>> > PluginAdapter#sqlMapGenerated() seemed to be the one I should
>> > override, but it doesn't expose XML elements of the generated XML
>> > file.
>> > Any hints?
>>
>> > Thanks,
>> > Iwao

--
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
|  
Report Content as Inappropriate

Re: Generator plugin: add new select element to mappers.

Jeff Butler
I think there's an easier way - remove the attribute before the file is generated.  In your plugin, override sqlMapResultMapWithoutBLOBsElementGenerated and sqlMapResultMapWithBLOBsElementGenerated.  In both, call a method like this:

    private void removeJdbcType(XmlElement element) {
        for (Iterator<Attribute> iterator = element.getAttributes().iterator(); iterator.hasNext();) {
            Attribute attribute = iterator.next();
            if ("jdbcType".equals(attribute.getName())) {
                iterator.remove();
            }
        }
    }

Jeff Butler


On Thu, Apr 27, 2017 at 3:03 AM Sully <[hidden email]> wrote:
Hi Jeff, I want  the generated xml file excluding all 'jdbcType=xxxx', so I tried to do this task with globally replacing in PluginAdapter.sqlMapGenerated(), but I can only get the short file name of the xml file via PluginAdapter.sqlMapGenerated().
Or I can change the MyBatis3FormattingUtilities.getParameterClause() method directly, I wonder whether there is an alternative option without breaking the original code?

On Saturday, February 5, 2011 at 3:53:12 AM UTC+8, Jeff Butler wrote:
Sorry - you are right about GeneratedXMLFile#getDocument().  I was
working from memory (dangerous).

Jeff Butler


On Fri, Feb 4, 2011 at 1:43 AM, Iwao AVE! <[hidden email]> wrote:


> Jeff,
>
> PluginAdapter#sqlMapDocumentGenerated is what I was looking for.
> Thank you!
>
> # In version 1.3.1, GeneratedXMLFile#getDocument() doesn't seem to
> exist.
>
> // Iwao
>
> On 2月4日, 午後12:23, Jeff Butler <[hidden email]> wrote:
>> That method will work (GeneratedXMLFile#getDocument), or you can use
>> PluginAdapter#sqlMapDocumentGenerated
>>
>> Jeff Butler
>>
>> On Thu, Feb 3, 2011 at 4:32 AM, Iwao AVE! <[hidden email]> wrote:
>> > Hi,
>>
>> > I am writing a generator plugin to add a project-specific query
>> > (selectByXxx) to mappers.
>> > It was easy to add a new method to the java mapper interfaces, but I
>> > couldn't figure out how to add a new 'select' element to the xml
>> > mapper files.
>> > PluginAdapter#sqlMapGenerated() seemed to be the one I should
>> > override, but it doesn't expose XML elements of the generated XML
>> > file.
>> > Any hints?
>>
>> > Thanks,
>> > Iwao

--
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
|  
Report Content as Inappropriate

Re: Generator plugin: add new select element to mappers.

Sully
In fact, this will remove all attributes named 'jdbcType'. But what I want to remove is the 'jdbcType' string in sql scripts, like ",jdbcType=BIGINT" in 
 "select 
<include refid="Base_Column_List" />
from test.user
where id = #{id,jdbcType=BIGINT}".
This small piece of sql code is actually the content of "<select>" element. Will this kind operation be also possible?

On Thursday, April 27, 2017 at 5:54:27 PM UTC+8, Jeff Butler wrote:
I think there's an easier way - remove the attribute before the file is generated.  In your plugin, override sqlMapResultMapWithoutBLOBsElementGenerated and sqlMapResultMapWithBLOBsElementGenerated.  In both, call a method like this:

    private void removeJdbcType(XmlElement element) {
        for (Iterator<Attribute> iterator = element.getAttributes().iterator(); iterator.hasNext();) {
            Attribute attribute = iterator.next();
            if ("jdbcType".equals(attribute.getName())) {
                iterator.remove();
            }
        }
    }

Jeff Butler


On Thu, Apr 27, 2017 at 3:03 AM Sully <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="FtW01NdoBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">huge...@...> wrote:
Hi Jeff, I want  the generated xml file excluding all 'jdbcType=xxxx', so I tried to do this task with globally replacing in PluginAdapter.sqlMapGenerated(), but I can only get the short file name of the xml file via PluginAdapter.sqlMapGenerated().
Or I can change the MyBatis3FormattingUtilities.getParameterClause() method directly, I wonder whether there is an alternative option without breaking the original code?

On Saturday, February 5, 2011 at 3:53:12 AM UTC+8, Jeff Butler wrote:
Sorry - you are right about GeneratedXMLFile#getDocument().  I was
working from memory (dangerous).

Jeff Butler


On Fri, Feb 4, 2011 at 1:43 AM, Iwao AVE! <[hidden email]> wrote:


> Jeff,
>
> PluginAdapter#sqlMapDocumentGenerated is what I was looking for.
> Thank you!
>
> # In version 1.3.1, GeneratedXMLFile#getDocument() doesn't seem to
> exist.
>
> // Iwao
>
> On 2月4日, 午後12:23, Jeff Butler <[hidden email]> wrote:
>> That method will work (GeneratedXMLFile#getDocument), or you can use
>> PluginAdapter#sqlMapDocumentGenerated
>>
>> Jeff Butler
>>
>> On Thu, Feb 3, 2011 at 4:32 AM, Iwao AVE! <[hidden email]> wrote:
>> > Hi,
>>
>> > I am writing a generator plugin to add a project-specific query
>> > (selectByXxx) to mappers.
>> > It was easy to add a new method to the java mapper interfaces, but I
>> > couldn't figure out how to add a new 'select' element to the xml
>> > mapper files.
>> > PluginAdapter#sqlMapGenerated() seemed to be the one I should
>> > override, but it doesn't expose XML elements of the generated XML
>> > file.
>> > Any hints?
>>
>> > Thanks,
>> > Iwao

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="FtW01NdoBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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
|  
Report Content as Inappropriate

Re: Generator plugin: add new select element to mappers.

Jeff Butler
There's not an easy way to do that.  You would need to override the methods for the generated select elements and then do the regex replace thing on each line of generated SQL.

Is there some problem you are trying to solve, or is this just a style thing?

Jeff Butler


On Fri, Apr 28, 2017 at 12:14 AM Sully <[hidden email]> wrote:
In fact, this will remove all attributes named 'jdbcType'. But what I want to remove is the 'jdbcType' string in sql scripts, like ",jdbcType=BIGINT" in 
 "select 
<include refid="Base_Column_List" />
from test.user
where id = #{id,jdbcType=BIGINT}".
This small piece of sql code is actually the content of "<select>" element. Will this kind operation be also possible?

On Thursday, April 27, 2017 at 5:54:27 PM UTC+8, Jeff Butler wrote:
I think there's an easier way - remove the attribute before the file is generated.  In your plugin, override sqlMapResultMapWithoutBLOBsElementGenerated and sqlMapResultMapWithBLOBsElementGenerated.  In both, call a method like this:

    private void removeJdbcType(XmlElement element) {
        for (Iterator<Attribute> iterator = element.getAttributes().iterator(); iterator.hasNext();) {
            Attribute attribute = iterator.next();
            if ("jdbcType".equals(attribute.getName())) {
                iterator.remove();
            }
        }
    }

Jeff Butler


On Thu, Apr 27, 2017 at 3:03 AM Sully <[hidden email]> wrote:
Hi Jeff, I want  the generated xml file excluding all 'jdbcType=xxxx', so I tried to do this task with globally replacing in PluginAdapter.sqlMapGenerated(), but I can only get the short file name of the xml file via PluginAdapter.sqlMapGenerated().
Or I can change the MyBatis3FormattingUtilities.getParameterClause() method directly, I wonder whether there is an alternative option without breaking the original code?

On Saturday, February 5, 2011 at 3:53:12 AM UTC+8, Jeff Butler wrote:
Sorry - you are right about GeneratedXMLFile#getDocument().  I was
working from memory (dangerous).

Jeff Butler


On Fri, Feb 4, 2011 at 1:43 AM, Iwao AVE! <[hidden email]> wrote:


> Jeff,
>
> PluginAdapter#sqlMapDocumentGenerated is what I was looking for.
> Thank you!
>
> # In version 1.3.1, GeneratedXMLFile#getDocument() doesn't seem to
> exist.
>
> // Iwao
>
> On 2月4日, 午後12:23, Jeff Butler <[hidden email]> wrote:
>> That method will work (GeneratedXMLFile#getDocument), or you can use
>> PluginAdapter#sqlMapDocumentGenerated
>>
>> Jeff Butler
>>
>> On Thu, Feb 3, 2011 at 4:32 AM, Iwao AVE! <[hidden email]> wrote:
>> > Hi,
>>
>> > I am writing a generator plugin to add a project-specific query
>> > (selectByXxx) to mappers.
>> > It was easy to add a new method to the java mapper interfaces, but I
>> > couldn't figure out how to add a new 'select' element to the xml
>> > mapper files.
>> > PluginAdapter#sqlMapGenerated() seemed to be the one I should
>> > override, but it doesn't expose XML elements of the generated XML
>> > file.
>> > Any hints?
>>
>> > Thanks,
>> > Iwao

--
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.

--
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
|  
Report Content as Inappropriate

Re: Generator plugin: add new select element to mappers.

Sully
In that case, I will have to change implementation of all corresponding elements if I also want to remove the 'javaType' in select/update/delete/insert elements.
No, I am trying to keep the scripts in xml file simple. I think that complexity cover the essence of the sql clause in xml file. I will fork the repository and change the source code directly instead.
Thanks again.

On Friday, April 28, 2017 at 4:51:34 PM UTC+8, Jeff Butler wrote:
There's not an easy way to do that.  You would need to override the methods for the generated select elements and then do the regex replace thing on each line of generated SQL.

Is there some problem you are trying to solve, or is this just a style thing?

Jeff Butler


On Fri, Apr 28, 2017 at 12:14 AM Sully <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ew0O7_2zBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">huge...@...> wrote:
In fact, this will remove all attributes named 'jdbcType'. But what I want to remove is the 'jdbcType' string in sql scripts, like ",jdbcType=BIGINT" in 
 "select 
<include refid="Base_Column_List" />
from test.user
where id = #{id,jdbcType=BIGINT}".
This small piece of sql code is actually the content of "<select>" element. Will this kind operation be also possible?

On Thursday, April 27, 2017 at 5:54:27 PM UTC+8, Jeff Butler wrote:
I think there's an easier way - remove the attribute before the file is generated.  In your plugin, override sqlMapResultMapWithoutBLOBsElementGenerated and sqlMapResultMapWithBLOBsElementGenerated.  In both, call a method like this:

    private void removeJdbcType(XmlElement element) {
        for (Iterator<Attribute> iterator = element.getAttributes().iterator(); iterator.hasNext();) {
            Attribute attribute = iterator.next();
            if ("jdbcType".equals(attribute.getName())) {
                iterator.remove();
            }
        }
    }

Jeff Butler


On Thu, Apr 27, 2017 at 3:03 AM Sully <[hidden email]> wrote:
Hi Jeff, I want  the generated xml file excluding all 'jdbcType=xxxx', so I tried to do this task with globally replacing in PluginAdapter.sqlMapGenerated(), but I can only get the short file name of the xml file via PluginAdapter.sqlMapGenerated().
Or I can change the MyBatis3FormattingUtilities.getParameterClause() method directly, I wonder whether there is an alternative option without breaking the original code?

On Saturday, February 5, 2011 at 3:53:12 AM UTC+8, Jeff Butler wrote:
Sorry - you are right about GeneratedXMLFile#getDocument().  I was
working from memory (dangerous).

Jeff Butler


On Fri, Feb 4, 2011 at 1:43 AM, Iwao AVE! <[hidden email]> wrote:


> Jeff,
>
> PluginAdapter#sqlMapDocumentGenerated is what I was looking for.
> Thank you!
>
> # In version 1.3.1, GeneratedXMLFile#getDocument() doesn't seem to
> exist.
>
> // Iwao
>
> On 2月4日, 午後12:23, Jeff Butler <[hidden email]> wrote:
>> That method will work (GeneratedXMLFile#getDocument), or you can use
>> PluginAdapter#sqlMapDocumentGenerated
>>
>> Jeff Butler
>>
>> On Thu, Feb 3, 2011 at 4:32 AM, Iwao AVE! <[hidden email]> wrote:
>> > Hi,
>>
>> > I am writing a generator plugin to add a project-specific query
>> > (selectByXxx) to mappers.
>> > It was easy to add a new method to the java mapper interfaces, but I
>> > couldn't figure out how to add a new 'select' element to the xml
>> > mapper files.
>> > PluginAdapter#sqlMapGenerated() seemed to be the one I should
>> > override, but it doesn't expose XML elements of the generated XML
>> > file.
>> > Any hints?
>>
>> > Thanks,
>> > Iwao

--
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 mybatis-user...@googlegroups.com.

For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ew0O7_2zBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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.
Loading...