Writing blob type handler for paging

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

Writing blob type handler for paging

Mariu sz
Hi everyone!
I need to write mybatis handler similar to this:
https://stackoverflow.com/questions/27522589/how-to-handle-blob-with-mybatis/27522590#27522590
which will replace old jdbc code that was used for paging:

            final byte[] fixedSizeBuf = new byte[CONTENT_PAGE_SIZE];
            byte[] buf = null;

            final ResultSet rset = stmt.executeQuery(
                    "SELECT sth from table "'");
            if (rset.next()) {
                try {
                    if (rset.getBlob(1) != null) {
                        final InputStream is = rset.getBlob(1).getBinaryStream();
                        is.skip(page * CONTENT_PAGE_SIZE);
                        final int count = is.read(fixedSizeBuf, 0, CONTENT_PAGE_SIZE);
                        if (count == STREAM_AT_END_OF_FILE) {
                            buf = new byte[0];
                        } else if (count < CONTENT_PAGE_SIZE) {
                            buf = Arrays.copyOfRange(fixedSizeBuf, 0, count);
                        } else {
                            buf = fixedSizeBuf;
                        }
                    }
                } catch (IOException e) {
                   // catch
                }
            }

Anyone have an idea if myBatis will handle such an example?

--
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: Writing blob type handler for paging

Iwao AVE!
Hi,

Type handler is not suitable for such task and it's inefficient as well.
Depending on the database you are using, there is a way to select partial data out of BLOB column, usually.

Regards,
Iwao

On Thu, Jan 31, 2019 at 11:39 PM Mariu sz <[hidden email]> wrote:
Hi everyone!
I need to write mybatis handler similar to this:
which will replace old jdbc code that was used for paging:

            final byte[] fixedSizeBuf = new byte[CONTENT_PAGE_SIZE];
            byte[] buf = null;

            final ResultSet rset = stmt.executeQuery(
                    "SELECT sth from table "'");
            if (rset.next()) {
                try {
                    if (rset.getBlob(1) != null) {
                        final InputStream is = rset.getBlob(1).getBinaryStream();
                        is.skip(page * CONTENT_PAGE_SIZE);
                        final int count = is.read(fixedSizeBuf, 0, CONTENT_PAGE_SIZE);
                        if (count == STREAM_AT_END_OF_FILE) {
                            buf = new byte[0];
                        } else if (count < CONTENT_PAGE_SIZE) {
                            buf = Arrays.copyOfRange(fixedSizeBuf, 0, count);
                        } else {
                            buf = fixedSizeBuf;
                        }
                    }
                } catch (IOException e) {
                   // catch
                }
            }

Anyone have an idea if myBatis will handle such an example?

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