临时表和连接池 [英] Temporary tables and connection pool

查看:631
本文介绍了临时表和连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JBoss 7提供的连接池,每次执行操作后都执行connection.close().

I use connection pooling provided by JBoss 7 and I do a connection.close() after every action.

但是当我创建一个临时表时,当前用户不会保留它,因为他正在使用数据库中的新会话(由于connection.close()和缓冲池的影响).

But when I create a temporary table, it does not remain for the current user because he is using a new session from the database (due to connection.close() and pooling).

例如,我在一个动作中创建一个临时表.用户更改页面.新操作必须在临时表中进行查询,但此查询已不存在.

For example, I create a temp table in an action. The user changes page. The new action has to do queries in temp table but this does not exist anymore.

所以,我真的不知道如何使用这种架构来提供临时表.

So, I really don't know how to provide temporary tables with this kind of architecture.

推荐答案

临时表与连接池的组合意味着临时表的请求范围.您想拥有会话范围临时表.

Temporary tables in combination with connection pooling means request scope for the temporary tables. You'd like to have session scope temporary tables.

我不知道一个现成的解决方案.所以选项是

I am not aware of an out-of-the box solution. So options are

  1. 使用前缀/后缀创建普通表,以与用户关联
  2. 在整个会话过程中为用户使用相同的连接
  3. 重写应用程序:完整读取数据,而不是临时表,并将其存储在 HTTP会话中.可能数据库可以分页,因此不需要缓存中间结果等.
  1. Create normal tables with a prefix/suffix to associate these with a user
  2. Use the same connection for a user throughout the whole session
  3. Rewrite the application: Instead of temporary tables, read the data completely, and store it in the HTTP session. Possibly the database can paginate so there is no need to cache intermediate results etc.

选项1和2需要清理,尤其是在会话未正确关闭的情况下.选项2可能需要很多资源.因此,即使它似乎是最笨拙的一种,我也将对其进行研究.

Options 1 and 2 require cleanup, especially if the session is not shut down properly. Option 2 possibly requires many resources. So I would investigate the 3rd option, even if it seems to be the most cumbersone one.

这篇关于临时表和连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆