1 package org.paneris.messageboard.model;
2
3 import java.sql.Connection;
4 import java.sql.ResultSet;
5 import java.sql.Statement;
6 import java.util.Stack;
7
8 import org.paneris.jal.model.DBConnectionManager;
9 import org.paneris.jal.model.DDField;
10
11
12
13
14
15
16 public class MessageThread extends Stack {
17
18 private static final long serialVersionUID = 1L;
19 String database;
20 private DBConnectionManager connMgr;
21
22
23
24
25
26 public MessageThread(String db) {
27 super();
28 database = db;
29 }
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public Message getNext(Message m) throws Exception {
44 connMgr = DBConnectionManager.getInstance();
45 Connection conn = connMgr.getConnection("MessageThread",database);
46 Statement s = conn.createStatement();
47 DDField idField = (DDField) m.get("id");
48 String sqlString = new String("SELECT * FROM messages WHERE parent = " + (Integer)idField.getValue() + " ORDER BY messagedate DESC");
49 ResultSet rs = s.executeQuery(sqlString);
50 while (rs.next()) {
51 Message n = new Message(database,rs);
52 n.setIndentation(m.getIndentation() + 1);
53 push(n);
54 }
55 connMgr.freeConnection(database, conn);
56 if (empty()) {
57 return null;
58 } else {
59 return (Message) pop();
60 }
61 }
62 }
63