Download
Magazine
Develop
Account
Download
Magazine
Develop
Login
Forgot Account/Password
Create Account
Language
Help
Language
Help
×
Login
Login Name
Password
×
Forgot Account/Password
Category:
Software
People
PersonalForge
Magazine
Wiki
Search
OSDN
>
Find Software
>
System
>
TERASOLUNA Framework
>
Forums
>
Open Discussion
>
リスナークラスからのDB更新について
TERASOLUNA Framework
Description
Project Summary
Developer Dashboard
Web Page
Developers
Image Gallery
List of RSS Feeds
Activity
Statistics
History
Downloads
List of Releases
Stats
Source Code
Code Repository list
Subversion
View Repository
Ticket
Ticket List
Milestone List
Type List
Component List
List of frequently used tickets/RSS
Submit New Ticket
Documents
Wiki
FrontPage
Title index
Recent changes
Doc Mgr
List Docs
Communication
Forums
List of Forums
Open Discussion (1277)
Mailing Lists
list of ML
terasoluna-information
News
Forums:
Open Discussion
(Thread #19858)
Return to Thread list
RSS
リスナークラスからのDB更新について (2008-09-08 16:58 by
Anonymous
#38747)
Reply
Create ticket
現在Server Framework for Java WEB版を使用して下記の処理を作成しております。。。
【処理】
HttpSessionAttributeListener等でセッションリスナークラスを実装し、あるセッションが破棄された時にDBに対して更新を行う処理を作成しています。
【疑問】
この時のDBに対して更新を行う処理の実装方法なのですが、applicationContext.xml等を使用して容易にDB更新を行う方法というのは可能でしょうか?
セッションリスナー実装クラスにオブジェクトをインジェクトすることが可能なのでしょうか。。
何かいい方法をご教授いただければ、幸いです。
以上、宜しくお願いいたしま
Reply to #38747
×
Subject
Body
Reply To Message #38747 > 現在Server Framework for Java WEB版を使用して下記の処理を作成しております。。。 > > 【処理】 > HttpSessionAttributeListener等でセッションリスナークラスを実装し、あるセッションが破棄された時にDBに対して更新を行う処理を作成しています。 > > 【疑問】 > この時のDBに対して更新を行う処理の実装方法なのですが、applicationContext.xml等を使用して容易にDB更新を行う方法というのは可能でしょうか? > セッションリスナー実装クラスにオブジェクトをインジェクトすることが可能なのでしょうか。。 > > 何かいい方法をご教授いただければ、幸いです。 > 以上、宜しくお願いいたしま
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel
RE: リスナークラスからのDB更新について (2008-09-08 19:51 by
kimumasa
#38755)
Reply
Create ticket
疑問がListenerにDIしたいのか、DB更新したいだけなのかよく分りませんが。。。
とりあえず一時回答をすると
ご希望と思われる動きを実現するにはHttpSessionListener内で
DIコンテナから管理しているDAOを取得する事になると思います。
ご参考までにサンプルコードとしては以下のような感じです。
「あるセッション」という記述がさらに謎な感じですが
特定のsessionIdに対してのみListenerを走らせると言う事は無理ですので
HttpSessionEvent.getSession()をコールして条件分岐させてもらえればと
思います。
====
package jp.terasoluna.sample;
import java.util.Map;
import javax.servlet.http.HttpSessionEvent;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.web.HttpSessionListenerImpl;
/**
* 蛇足ですがサンプルコードでは一時セッションディレクトリ機能を
* 利用している前提でHttpSessionListenerImplを継承しています。
* 不要であれば、随時読み替えてください。
**/
public class SampleSessionListener extends HttpSessionListenerImpl {
@Override
public void sessionDestroyed(HttpSessionEvent event) {
super.sessionDestroyed(event);
WebApplicationContext ctx =
WebApplicationContextUtils.getRequiredWebApplicationContext(event.getSession().getServletContext());
// 例えばQueryDAOを取得する場合
// QueryDAO queryDAO = (QueryDAO) ctx.getBean("queryDAO");
// Map<String, Object> map = queryDAO.executeForMap("test", null);
}
}
====
Reply to
#38747
Reply to #38755
×
Subject
Body
Reply To Message #38755 > > 疑問がListenerにDIしたいのか、DB更新したいだけなのかよく分りませんが。。。 > > とりあえず一時回答をすると > ご希望と思われる動きを実現するにはHttpSessionListener内で > DIコンテナから管理しているDAOを取得する事になると思います。 > ご参考までにサンプルコードとしては以下のような感じです。 > > 「あるセッション」という記述がさらに謎な感じですが > 特定のsessionIdに対してのみListenerを走らせると言う事は無理ですので > HttpSessionEvent.getSession()をコールして条件分岐させてもらえればと > 思います。 > > ==== > > package jp.terasoluna.sample; > > import java.util.Map; > > import javax.servlet.http.HttpSessionEvent; > > import org.springframework.web.context.WebApplicationContext; > import org.springframework.web.context.support.WebApplicationContextUtils; > > import jp.terasoluna.fw.dao.QueryDAO; > import jp.terasoluna.fw.web.HttpSessionListenerImpl; > > /** > * 蛇足ですがサンプルコードでは一時セッションディレクトリ機能を > * 利用している前提でHttpSessionListenerImplを継承しています。 > * 不要であれば、随時読み替えてください。 > **/ > public class SampleSessionListener extends HttpSessionListenerImpl { > > @Override > public void sessionDestroyed(HttpSessionEvent event) { > super.sessionDestroyed(event); > WebApplicationContext ctx = > WebApplicationContextUtils.getRequiredWebApplicationContext(event.getSession().getServletContext()); > // 例えばQueryDAOを取得する場合 > // QueryDAO queryDAO = (QueryDAO) ctx.getBean("queryDAO"); > // Map<String, Object> map = queryDAO.executeForMap("test", null); > } > } > > ====
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel
RE: リスナークラスからのDB更新について (2008-09-08 19:58 by
kimumasa
#38756)
Reply
Create ticket
HttpSessionListenerではなく
HttpSessionAttributeListenerでしたか・・
とはいえ、回答としてはあまり変わらないと思いますので
ご参考まで。
Reply to
#38755
Reply to #38756
×
Subject
Body
Reply To Message #38756 > HttpSessionListenerではなく > HttpSessionAttributeListenerでしたか・・ > > とはいえ、回答としてはあまり変わらないと思いますので > ご参考まで。
You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.)
Login
Nickname
Preview
Post
Cancel