I would like to add an option to select sqlSession when executing the very long query.

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

I would like to add an option to select sqlSession when executing the very long query.

HeeGu Lee
Hi, Mybatis!

My predecessor made a query that was close to 1000 lines and left the company.
The problem was a query with transactions tied up, but I only had to service the results of doing a simple query.
The solution is simple. Just create a new slave mapper and copy it.
However, this causes a situation where the source needs to be modified twice.
So I thought that I would like to have the option to force SqlSession to be specified when executing a query in Mybatis.
Basically, it uses A session, but puts the option as below to use B session connected to Slave DB.

ex) 

A.java

@Options(sqlSessionRef="slaveSqlSession")
public int updateVeryLongQuery();

A.xml
<select id="updateVeryLongQuery">
... very long query ...
</select>

Is there any way to do this?

Thank you for reading.

Have a nice day! And please be safe from corona-19.

--
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/c3a2f166-0305-4842-919a-beccd2459502%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: I would like to add an option to select sqlSession when executing the very long query.

Iwao AVE!
Hello HeeGu,

Adding sqlSessionRef to @Options may be difficult, but there might be a decent solution.
Could you elaborate on the problem you are having?
I understand that there was/is a very large query, but I am not sure what you needed to achieve (=requirement).

Regards,
Iwao

On Tue, Mar 17, 2020 at 6:46 PM HeeGu Lee <[hidden email]> wrote:
Hi, Mybatis!

My predecessor made a query that was close to 1000 lines and left the company.
The problem was a query with transactions tied up, but I only had to service the results of doing a simple query.
The solution is simple. Just create a new slave mapper and copy it.
However, this causes a situation where the source needs to be modified twice.
So I thought that I would like to have the option to force SqlSession to be specified when executing a query in Mybatis.
Basically, it uses A session, but puts the option as below to use B session connected to Slave DB.

ex) 

A.java

@Options(sqlSessionRef="slaveSqlSession")
public int updateVeryLongQuery();

A.xml
<select id="updateVeryLongQuery">
... very long query ...
</select>

Is there any way to do this?

Thank you for reading.

Have a nice day! And please be safe from corona-19.

--
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/c3a2f166-0305-4842-919a-beccd2459502%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%2Buep2Qy84v7FYegcPnS%3DuS4%2BaB4jrgyEJ0tgskaSUMMBM_7jg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: I would like to add an option to select sqlSession when executing the very long query.

HeeGu Lee
Hello Iwao!

In our project, there is a query to get the balance of points that the customer has, so we set it to read from the Slave DB.

However, because the transaction takes place in the logic that uses points, even if you try to return the balance by calling the logic at the end, the balance has not been committed and the balance does not change even when read from the slave.

I can also copy the query to the master mapper and read it in the master DB session.
However, the query was a bit complicated, so it was difficult to fix it twice each time, so I thought about a good way. Then I thought about what I could do if I could specify SqlSession.

Is there a good way to do this?

2020년 3월 20일 금요일 오전 12시 32분 12초 UTC+9, Iwao AVE! 님의 말:
Hello HeeGu,

Adding sqlSessionRef to @Options may be difficult, but there might be a decent solution.
Could you elaborate on the problem you are having?
I understand that there was/is a very large query, but I am not sure what you needed to achieve (=requirement).

Regards,
Iwao

On Tue, Mar 17, 2020 at 6:46 PM HeeGu Lee <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VEqSysNnAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">elfhaz...@...> wrote:
Hi, Mybatis!

My predecessor made a query that was close to 1000 lines and left the company.
The problem was a query with transactions tied up, but I only had to service the results of doing a simple query.
The solution is simple. Just create a new slave mapper and copy it.
However, this causes a situation where the source needs to be modified twice.
So I thought that I would like to have the option to force SqlSession to be specified when executing a query in Mybatis.
Basically, it uses A session, but puts the option as below to use B session connected to Slave DB.

ex) 

A.java

@Options(sqlSessionRef="slaveSqlSession")
public int updateVeryLongQuery();

A.xml
<select id="updateVeryLongQuery">
... very long query ...
</select>

Is there any way to do this?

Thank you for reading.

Have a nice day! And please be safe from corona-19.

--
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="VEqSysNnAwAJ" 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/c3a2f166-0305-4842-919a-beccd2459502%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/c3a2f166-0305-4842-919a-beccd2459502%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/c3a2f166-0305-4842-919a-beccd2459502%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/mybatis-user/c3a2f166-0305-4842-919a-beccd2459502%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/b00ec238-c9a2-49a7-a935-169d56d0bedd%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: I would like to add an option to select sqlSession when executing the very long query.

Iwao AVE!
So, you want to execute the query sometimes against master, other times against slave, is that correct?
Then you can move the complex query to a new mapper and register the mapper to both SqlSessionFactory.

masterSqlSessionFactory.getConfiguration().addMapper(SharedMapper.class); 
slaveSqlSessionFactory.getConfiguration().addMapper(SharedMapper.class);

When you want to execute the query against master, get the mapper from the master's SqlSession.

try (SqlSession sqlSession = masterSqlSessionFactory.openSession()) {
  SharedMapper mapper = sqlSession.getMapper(SharedMapper.class);
  int result = mapper.updateVeryLongQuery()
}

Regards,
Iwao

On Fri, Mar 20, 2020 at 4:21 PM HeeGu Lee <[hidden email]> wrote:
Hello Iwao!

In our project, there is a query to get the balance of points that the customer has, so we set it to read from the Slave DB.

However, because the transaction takes place in the logic that uses points, even if you try to return the balance by calling the logic at the end, the balance has not been committed and the balance does not change even when read from the slave.

I can also copy the query to the master mapper and read it in the master DB session.
However, the query was a bit complicated, so it was difficult to fix it twice each time, so I thought about a good way. Then I thought about what I could do if I could specify SqlSession.

Is there a good way to do this?

2020년 3월 20일 금요일 오전 12시 32분 12초 UTC+9, Iwao AVE! 님의 말:
Hello HeeGu,

Adding sqlSessionRef to @Options may be difficult, but there might be a decent solution.
Could you elaborate on the problem you are having?
I understand that there was/is a very large query, but I am not sure what you needed to achieve (=requirement).

Regards,
Iwao

On Tue, Mar 17, 2020 at 6:46 PM HeeGu Lee <[hidden email]> wrote:
Hi, Mybatis!

My predecessor made a query that was close to 1000 lines and left the company.
The problem was a query with transactions tied up, but I only had to service the results of doing a simple query.
The solution is simple. Just create a new slave mapper and copy it.
However, this causes a situation where the source needs to be modified twice.
So I thought that I would like to have the option to force SqlSession to be specified when executing a query in Mybatis.
Basically, it uses A session, but puts the option as below to use B session connected to Slave DB.

ex) 

A.java

@Options(sqlSessionRef="slaveSqlSession")
public int updateVeryLongQuery();

A.xml
<select id="updateVeryLongQuery">
... very long query ...
</select>

Is there any way to do this?

Thank you for reading.

Have a nice day! And please be safe from corona-19.

--
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/c3a2f166-0305-4842-919a-beccd2459502%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/b00ec238-c9a2-49a7-a935-169d56d0bedd%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%2Buep2QWYQVJkkg3%2BQm4DF_vtZ8mVLBFn16OvZfrt8FoC1XkQA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: I would like to add an option to select sqlSession when executing the very long query.

HeeGu Lee
It's really amazing that you can add a mapper by taking the configuration out of the SqlSessionFactory.
I'll do it right now.
Thanks for the help.

Have a nice day.

2020년 3월 21일 토요일 오전 12시 43분 10초 UTC+9, Iwao AVE! 님의 말:
So, you want to execute the query sometimes against master, other times against slave, is that correct?
Then you can move the complex query to a new mapper and register the mapper to both SqlSessionFactory.

masterSqlSessionFactory.getConfiguration().addMapper(SharedMapper.class); 
slaveSqlSessionFactory.getConfiguration().addMapper(SharedMapper.class);

When you want to execute the query against master, get the mapper from the master's SqlSession.

try (SqlSession sqlSession = masterSqlSessionFactory.openSession()) {
  SharedMapper mapper = sqlSession.getMapper(SharedMapper.class);
  int result = mapper.updateVeryLongQuery()
}

Regards,
Iwao

On Fri, Mar 20, 2020 at 4:21 PM HeeGu Lee <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="bKTlaPG2AwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">elfhaz...@...> wrote:
Hello Iwao!

In our project, there is a query to get the balance of points that the customer has, so we set it to read from the Slave DB.

However, because the transaction takes place in the logic that uses points, even if you try to return the balance by calling the logic at the end, the balance has not been committed and the balance does not change even when read from the slave.

I can also copy the query to the master mapper and read it in the master DB session.
However, the query was a bit complicated, so it was difficult to fix it twice each time, so I thought about a good way. Then I thought about what I could do if I could specify SqlSession.

Is there a good way to do this?

2020년 3월 20일 금요일 오전 12시 32분 12초 UTC+9, Iwao AVE! 님의 말:
Hello HeeGu,

Adding sqlSessionRef to @Options may be difficult, but there might be a decent solution.
Could you elaborate on the problem you are having?
I understand that there was/is a very large query, but I am not sure what you needed to achieve (=requirement).

Regards,
Iwao

On Tue, Mar 17, 2020 at 6:46 PM HeeGu Lee <[hidden email]> wrote:
Hi, Mybatis!

My predecessor made a query that was close to 1000 lines and left the company.
The problem was a query with transactions tied up, but I only had to service the results of doing a simple query.
The solution is simple. Just create a new slave mapper and copy it.
However, this causes a situation where the source needs to be modified twice.
So I thought that I would like to have the option to force SqlSession to be specified when executing a query in Mybatis.
Basically, it uses A session, but puts the option as below to use B session connected to Slave DB.

ex) 

A.java

@Options(sqlSessionRef="slaveSqlSession")
public int updateVeryLongQuery();

A.xml
<select id="updateVeryLongQuery">
... very long query ...
</select>

Is there any way to do this?

Thank you for reading.

Have a nice day! And please be safe from corona-19.

--
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 <a href="https://groups.google.com/d/msgid/mybatis-user/c3a2f166-0305-4842-919a-beccd2459502%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/c3a2f166-0305-4842-919a-beccd2459502%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/c3a2f166-0305-4842-919a-beccd2459502%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/mybatis-user/c3a2f166-0305-4842-919a-beccd2459502%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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="bKTlaPG2AwAJ" 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/b00ec238-c9a2-49a7-a935-169d56d0bedd%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/b00ec238-c9a2-49a7-a935-169d56d0bedd%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/mybatis-user/b00ec238-c9a2-49a7-a935-169d56d0bedd%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/mybatis-user/b00ec238-c9a2-49a7-a935-169d56d0bedd%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/a7d3d6dc-f09a-4a14-a304-402a7ae7a7c1%40googlegroups.com.