partial implementation of conference management; rewrote the whole servlets
layer to eliminate duplicate code and make error checking more efficient (we now use a system that relies on Throwables to do interesting things)
This commit is contained in:
@@ -117,4 +117,6 @@ public interface ConferenceContext
|
||||
|
||||
public abstract HTMLChecker getNewTopicPreviewChecker();
|
||||
|
||||
public abstract void fixSeen() throws DataException;
|
||||
|
||||
} // end interface ConferenceContext
|
||||
|
||||
@@ -74,6 +74,48 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
|
||||
|
||||
} // end class ConfCache
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class used in the implementation of fixSeen()
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static class FixSeenHelper
|
||||
{
|
||||
private int topicid;
|
||||
private int top_message;
|
||||
private boolean do_insert;
|
||||
|
||||
public FixSeenHelper(int topicid, int top_message, boolean do_insert)
|
||||
{
|
||||
this.topicid = topicid;
|
||||
this.top_message = top_message;
|
||||
this.do_insert = do_insert;
|
||||
|
||||
} // end constructor
|
||||
|
||||
public void doFix(Statement stmt, int uid) throws SQLException
|
||||
{
|
||||
StringBuffer sql = new StringBuffer();
|
||||
if (do_insert)
|
||||
{ // construct an SQL INSERT statement
|
||||
sql.append("INSERT INTO topicsettings (topicid, uid, last_message) VALUES (").append(topicid);
|
||||
sql.append(", ").append(uid).append(", ").append(top_message).append(");");
|
||||
|
||||
} // end if
|
||||
else
|
||||
{ // construct an SQL UPDATE statement
|
||||
sql.append("UPDATE topicsettings SET last_message = ").append(top_message).append(" WHERE topicid = ");
|
||||
sql.append(topicid).append(" AND uid = ").append(uid).append(';');
|
||||
|
||||
} // end else
|
||||
|
||||
// now execute the update
|
||||
stmt.executeUpdate(sql.toString());
|
||||
|
||||
} // end doFix
|
||||
|
||||
} // end class FixSeenHelper
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
@@ -908,6 +950,68 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
|
||||
|
||||
} // end getNewTopicPreviewChecker
|
||||
|
||||
public void fixSeen() throws DataException
|
||||
{
|
||||
Connection conn = null;
|
||||
|
||||
try
|
||||
{ // retrieve a connection from the datapool
|
||||
conn = datapool.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
|
||||
// lock the tables that we need
|
||||
stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;");
|
||||
|
||||
try
|
||||
{ // get the existing topic list and its top messages list
|
||||
StringBuffer sql =
|
||||
new StringBuffer("SELECT topics.topicid, topics.top_message, ISNULL(topicsettings.last_message) "
|
||||
+ "FROM topics LEFT JOIN topicsettings ON topics.topicid = topicsettings.topicid "
|
||||
+ "AND topicsettings.uid = ");
|
||||
sql.append(sig.realUID()).append(" WHERE topics.confid = ").append(confid).append(';');
|
||||
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||
|
||||
// use the results to build up a list of FixSeenHelpers
|
||||
Vector tmp = new Vector();
|
||||
while (rs.next())
|
||||
tmp.add(new FixSeenHelper(rs.getInt(1),rs.getInt(2),rs.getBoolean(3)));
|
||||
|
||||
// now iterate over the list and call doFix on each one
|
||||
Iterator it = tmp.iterator();
|
||||
while (it.hasNext())
|
||||
{ // just hit each one in turn
|
||||
FixSeenHelper fsh = (FixSeenHelper)(it.next());
|
||||
fsh.doFix(stmt,sig.realUID());
|
||||
|
||||
} // end while
|
||||
|
||||
// update our last-read indicator, too
|
||||
touchRead(conn);
|
||||
|
||||
} // end try
|
||||
finally
|
||||
{ // make sure we unlock everything before we go
|
||||
Statement ulk_stmt = conn.createStatement();
|
||||
ulk_stmt.executeUpdate("UNLOCK TABLES;");
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // this becomes a DataException
|
||||
logger.error("DB error updating user information: " + e.getMessage(),e);
|
||||
throw new DataException("unable to update user information: " + e.getMessage(),e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // make sure we release the connection before we go
|
||||
if (conn!=null)
|
||||
datapool.releaseConnection(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end fixSeen
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface UserBackend
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user