I wish there was a whitespace removal feature for use in the cloud service.

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

I wish there was a whitespace removal feature for use in the cloud service.

HeeGu Lee
Many services are being provided through the cloud these days.
My system was also decided to service through AWS.
These cloud services cost even one packet.

So it would be nice if mybatis also had the option to automatically reduce the whitespace in the XML file to a minimum.

I tried to do this as a plugin.
I read several blogs through Google Ring.
However, since reflect is used every time, it is judged whether the performance of the computer will be slightly slower.
So it would be nice to be able to set the compression of the query using the whitespaceStripper function, which is called when the log is taken, even when running the actual log.

Please review.
Thank you.

@Intercepts ({@ Signature (type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class WhitespaceStripperPlugin implements Interceptor {

    private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory ();
    private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory ();
    private static final ReflectorFactory DEFAULT_REFLECTOR_FACTORY = new DefaultReflectorFactory ();

    @Override
    public Object intercept (Invocation invocation) throws Throwable {

        if (invocation.getTarget () instanceof StatementHandler) {
            StatementHandler statementHandler = (StatementHandler) invocation.getTarget ();
            MetaObject metaStatementHandler = MetaObject.forObject (statementHandler, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
            String originalSql = (String) metaStatementHandler.getValue ("delegate.boundSql.sql");
            metaStatementHandler.setValue ("delegate.boundSql.sql", removeBreakingWhitespace (originalSql));
        }

        return invocation.proceed ();
    }

    protected String removeBreakingWhitespace (String original) { // copy of BaseJdbcLogger
        StringTokenizer whitespaceStripper = new StringTokenizer (original);
        StringBuilder builder = new StringBuilder ();
        while (whitespaceStripper.hasMoreTokens ()) {
            builder.append (whitespaceStripper.nextToken ());
            builder.append ("");
        }
        return builder.toString ();
    }

    @Override
    public Object plugin (Object target) {
        return Plugin.wrap (target, this);
    }

    @Override
    public void setProperties (Properties properties) {
        // no op
    }
}

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: I wish there was a whitespace removal feature for use in the cloud service.

Iwao AVE!
Hello HeeGu,

This probably is the same request as #1126.

You might want to try this workaround using custom language driver (not thoroughly tested).

Regards,
Iwao

On Thu, Mar 26, 2020 at 6:43 PM HeeGu Lee <[hidden email]> wrote:
Many services are being provided through the cloud these days.
My system was also decided to service through AWS.
These cloud services cost even one packet.

So it would be nice if mybatis also had the option to automatically reduce the whitespace in the XML file to a minimum.

I tried to do this as a plugin.
I read several blogs through Google Ring.
However, since reflect is used every time, it is judged whether the performance of the computer will be slightly slower.
So it would be nice to be able to set the compression of the query using the whitespaceStripper function, which is called when the log is taken, even when running the actual log.

Please review.
Thank you.

@Intercepts ({@ Signature (type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class WhitespaceStripperPlugin implements Interceptor {

    private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory ();
    private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory ();
    private static final ReflectorFactory DEFAULT_REFLECTOR_FACTORY = new DefaultReflectorFactory ();

    @Override
    public Object intercept (Invocation invocation) throws Throwable {

        if (invocation.getTarget () instanceof StatementHandler) {
            StatementHandler statementHandler = (StatementHandler) invocation.getTarget ();
            MetaObject metaStatementHandler = MetaObject.forObject (statementHandler, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
            String originalSql = (String) metaStatementHandler.getValue ("delegate.boundSql.sql");
            metaStatementHandler.setValue ("delegate.boundSql.sql", removeBreakingWhitespace (originalSql));
        }

        return invocation.proceed ();
    }

    protected String removeBreakingWhitespace (String original) { // copy of BaseJdbcLogger
        StringTokenizer whitespaceStripper = new StringTokenizer (original);
        StringBuilder builder = new StringBuilder ();
        while (whitespaceStripper.hasMoreTokens ()) {
            builder.append (whitespaceStripper.nextToken ());
            builder.append ("");
        }
        return builder.toString ();
    }

    @Override
    public Object plugin (Object target) {
        return Plugin.wrap (target, this);
    }

    @Override
    public void setProperties (Properties properties) {
        // no op
    }
}

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CA%2Buep2Sp%2BK75xmtKoee%2B3cfngORAvoZBBc8y3SZRgd7__E0crw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: I wish there was a whitespace removal feature for use in the cloud service.

HeeGu Lee
Oh, It's a another view of solve my problem.
Thank you, Iwao!
Have a nice day!

2020년 3월 31일 화요일 오후 7시 19분 57초 UTC+9, Iwao AVE! 님의 말:
Hello HeeGu,

This probably is the same request as #1126.
<a href="https://github.com/mybatis/mybatis-3/issues/1126#issuecomment-564968197" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fissues%2F1126%23issuecomment-564968197\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTOKBhDoH75WePOAxHicwyXkbJDg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fissues%2F1126%23issuecomment-564968197\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTOKBhDoH75WePOAxHicwyXkbJDg&#39;;return true;">https://github.com/mybatis/mybatis-3/issues/1126

You might want to try this workaround using custom language driver (not thoroughly tested).
<a href="https://github.com/mybatis/mybatis-3/issues/1126#issuecomment-564968197" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fissues%2F1126%23issuecomment-564968197\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTOKBhDoH75WePOAxHicwyXkbJDg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fissues%2F1126%23issuecomment-564968197\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTOKBhDoH75WePOAxHicwyXkbJDg&#39;;return true;">https://github.com/mybatis/mybatis-3/issues/1126#issuecomment-564968197

Regards,
Iwao

On Thu, Mar 26, 2020 at 6:43 PM HeeGu Lee <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="PQHPRhf7AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">elfhaz...@...> wrote:
Many services are being provided through the cloud these days.
My system was also decided to service through AWS.
These cloud services cost even one packet.

So it would be nice if mybatis also had the option to automatically reduce the whitespace in the XML file to a minimum.

I tried to do this as a plugin.
I read several blogs through Google Ring.
However, since reflect is used every time, it is judged whether the performance of the computer will be slightly slower.
So it would be nice to be able to set the compression of the query using the whitespaceStripper function, which is called when the log is taken, even when running the actual log.

Please review.
Thank you.

@Intercepts ({@ Signature (type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class WhitespaceStripperPlugin implements Interceptor {

    private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory ();
    private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory ();
    private static final ReflectorFactory DEFAULT_REFLECTOR_FACTORY = new DefaultReflectorFactory ();

    @Override
    public Object intercept (Invocation invocation) throws Throwable {

        if (invocation.getTarget () instanceof StatementHandler) {
            StatementHandler statementHandler = (StatementHandler) invocation.getTarget ();
            MetaObject metaStatementHandler = MetaObject.forObject (statementHandler, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
            String originalSql = (String) metaStatementHandler.getValue ("delegate.boundSql.sql");
            metaStatementHandler.setValue ("delegate.boundSql.sql", removeBreakingWhitespace (originalSql));
        }

        return invocation.proceed ();
    }

    protected String removeBreakingWhitespace (String original) { // copy of BaseJdbcLogger
        StringTokenizer whitespaceStripper = new StringTokenizer (original);
        StringBuilder builder = new StringBuilder ();
        while (whitespaceStripper.hasMoreTokens ()) {
            builder.append (whitespaceStripper.nextToken ());
            builder.append ("");
        }
        return builder.toString ();
    }

    @Override
    public Object plugin (Object target) {
        return Plugin.wrap (target, this);
    }

    @Override
    public void setProperties (Properties properties) {
        // no op
    }
}

--
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="PQHPRhf7AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybati...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/58020f97-e669-4705-bc05-4430e22d950a%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: I wish there was a whitespace removal feature for use in the cloud service.

HeeGu Lee
In reply to this post by Iwao AVE!
I failed with 1126.
I don't know why I failed... OTL
Bye.

2020년 3월 31일 화요일 오후 7시 19분 57초 UTC+9, Iwao AVE! 님의 말:
Hello HeeGu,

This probably is the same request as #1126.
<a href="https://github.com/mybatis/mybatis-3/issues/1126#issuecomment-564968197" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fissues%2F1126%23issuecomment-564968197\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTOKBhDoH75WePOAxHicwyXkbJDg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fissues%2F1126%23issuecomment-564968197\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTOKBhDoH75WePOAxHicwyXkbJDg&#39;;return true;">https://github.com/mybatis/mybatis-3/issues/1126

You might want to try this workaround using custom language driver (not thoroughly tested).
<a href="https://github.com/mybatis/mybatis-3/issues/1126#issuecomment-564968197" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fissues%2F1126%23issuecomment-564968197\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTOKBhDoH75WePOAxHicwyXkbJDg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fmybatis-3%2Fissues%2F1126%23issuecomment-564968197\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHTOKBhDoH75WePOAxHicwyXkbJDg&#39;;return true;">https://github.com/mybatis/mybatis-3/issues/1126#issuecomment-564968197

Regards,
Iwao

On Thu, Mar 26, 2020 at 6:43 PM HeeGu Lee <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="PQHPRhf7AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">elfhaz...@...> wrote:
Many services are being provided through the cloud these days.
My system was also decided to service through AWS.
These cloud services cost even one packet.

So it would be nice if mybatis also had the option to automatically reduce the whitespace in the XML file to a minimum.

I tried to do this as a plugin.
I read several blogs through Google Ring.
However, since reflect is used every time, it is judged whether the performance of the computer will be slightly slower.
So it would be nice to be able to set the compression of the query using the whitespaceStripper function, which is called when the log is taken, even when running the actual log.

Please review.
Thank you.

@Intercepts ({@ Signature (type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class WhitespaceStripperPlugin implements Interceptor {

    private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory ();
    private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory ();
    private static final ReflectorFactory DEFAULT_REFLECTOR_FACTORY = new DefaultReflectorFactory ();

    @Override
    public Object intercept (Invocation invocation) throws Throwable {

        if (invocation.getTarget () instanceof StatementHandler) {
            StatementHandler statementHandler = (StatementHandler) invocation.getTarget ();
            MetaObject metaStatementHandler = MetaObject.forObject (statementHandler, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
            String originalSql = (String) metaStatementHandler.getValue ("delegate.boundSql.sql");
            metaStatementHandler.setValue ("delegate.boundSql.sql", removeBreakingWhitespace (originalSql));
        }

        return invocation.proceed ();
    }

    protected String removeBreakingWhitespace (String original) { // copy of BaseJdbcLogger
        StringTokenizer whitespaceStripper = new StringTokenizer (original);
        StringBuilder builder = new StringBuilder ();
        while (whitespaceStripper.hasMoreTokens ()) {
            builder.append (whitespaceStripper.nextToken ());
            builder.append ("");
        }
        return builder.toString ();
    }

    @Override
    public Object plugin (Object target) {
        return Plugin.wrap (target, this);
    }

    @Override
    public void setProperties (Properties properties) {
        // no op
    }
}

--
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="PQHPRhf7AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybati...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/8054292c-4668-4d55-b3b8-0ff29820ae50%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: I wish there was a whitespace removal feature for use in the cloud service.

Iwao AVE!
Could you explain how it didn't work?
Any example so that I can verify the issue?

On Tue, Apr 21, 2020 at 6:40 PM HeeGu Lee <[hidden email]> wrote:
I failed with 1126.
I don't know why I failed... OTL
Bye.

2020년 3월 31일 화요일 오후 7시 19분 57초 UTC+9, Iwao AVE! 님의 말:
Hello HeeGu,

This probably is the same request as #1126.

You might want to try this workaround using custom language driver (not thoroughly tested).

Regards,
Iwao

On Thu, Mar 26, 2020 at 6:43 PM HeeGu Lee <[hidden email]> wrote:
Many services are being provided through the cloud these days.
My system was also decided to service through AWS.
These cloud services cost even one packet.

So it would be nice if mybatis also had the option to automatically reduce the whitespace in the XML file to a minimum.

I tried to do this as a plugin.
I read several blogs through Google Ring.
However, since reflect is used every time, it is judged whether the performance of the computer will be slightly slower.
So it would be nice to be able to set the compression of the query using the whitespaceStripper function, which is called when the log is taken, even when running the actual log.

Please review.
Thank you.

@Intercepts ({@ Signature (type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class WhitespaceStripperPlugin implements Interceptor {

    private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory ();
    private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory ();
    private static final ReflectorFactory DEFAULT_REFLECTOR_FACTORY = new DefaultReflectorFactory ();

    @Override
    public Object intercept (Invocation invocation) throws Throwable {

        if (invocation.getTarget () instanceof StatementHandler) {
            StatementHandler statementHandler = (StatementHandler) invocation.getTarget ();
            MetaObject metaStatementHandler = MetaObject.forObject (statementHandler, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
            String originalSql = (String) metaStatementHandler.getValue ("delegate.boundSql.sql");
            metaStatementHandler.setValue ("delegate.boundSql.sql", removeBreakingWhitespace (originalSql));
        }

        return invocation.proceed ();
    }

    protected String removeBreakingWhitespace (String original) { // copy of BaseJdbcLogger
        StringTokenizer whitespaceStripper = new StringTokenizer (original);
        StringBuilder builder = new StringBuilder ();
        while (whitespaceStripper.hasMoreTokens ()) {
            builder.append (whitespaceStripper.nextToken ());
            builder.append ("");
        }
        return builder.toString ();
    }

    @Override
    public Object plugin (Object target) {
        return Plugin.wrap (target, this);
    }

    @Override
    public void setProperties (Properties properties) {
        // no op
    }
}

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/4c47bd4e-cc7a-4ca3-86ed-ade406aade2b%40googlegroups.com.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/8054292c-4668-4d55-b3b8-0ff29820ae50%40googlegroups.com.

--
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].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CA%2Buep2TCf%2BfrHJnNpfA2htT%3D%2BxNo%2BKR2mWmB7e12QX4YPEwsEA%40mail.gmail.com.