KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > pages > MemberPage


1 package org.ashkelon.pages;
2
3 import org.ashkelon.*;
4 import org.ashkelon.util.*;
5 import org.ashkelon.db.*;
6
7 import java.util.*;
8 import java.sql.*;
9
10 import org.apache.oro.util.*;
11
12 /**
13  * @author Eitan Suez
14  */

15 public class MemberPage extends Page
16 {
17    public MemberPage()
18    {
19       super();
20    }
21    
22    public String JavaDoc handleRequest() throws SQLException
23    {
24       //int memberId = Integer.parseInt(ServletUtils.getRequestParam(request, "member_id"));
25
int memberId = 0;
26
27       try
28       {
29          memberId = Integer.parseInt(ServletUtils.getRequestParam(request, "member_id"));
30       }
31       catch (NumberFormatException JavaDoc ex)
32       {
33          String JavaDoc memberName = ServletUtils.getRequestParam(request, "member_name");
34          
35          String JavaDoc sql = DBMgr.getInstance().getStatement("getmemberid");
36          PreparedStatement pstmt = conn.prepareStatement(sql);
37          pstmt.setString(1, memberName);
38          ResultSet rset = pstmt.executeQuery();
39          if (rset.next())
40             memberId = rset.getInt(1);
41          rset.close();
42          pstmt.close();
43       }
44       
45       Integer JavaDoc memberId_obj = new Integer JavaDoc(memberId);
46
47       Object JavaDoc members_cache_obj = app.getAttribute("members_cache");
48       CacheLRU members_cache = null;
49       if (members_cache_obj == null)
50       {
51          members_cache = new CacheLRU(3000);
52       }
53       else
54       {
55          members_cache = (CacheLRU) members_cache_obj;
56          Object JavaDoc member_object = members_cache.getElement(memberId_obj);
57          if (member_object != null)
58          {
59             List members = (List) member_object;
60             request.setAttribute("members", members);
61             request.setAttribute("member", members.get(0));
62             return null;
63          }
64       }
65       
66       List members = Member.makeMembersFor(conn, memberId);
67       members_cache.addElement(memberId_obj, members);
68       app.setAttribute("members_cache", members_cache);
69       
70       request.setAttribute("members", members);
71       request.setAttribute("member", members.get(0));
72       return null;
73    }
74    
75 }
76
77
Popular Tags