org.locomotive.module.discuss
Class DiscussionLib

java.lang.Object
  |
  +--org.locomotive.module.discuss.DiscussionLib

public class DiscussionLib
extends java.lang.Object

This class provides a series of static methods which return Database information used by the Locomotive Discussion system. Each of the methods return the data in a org.locomotive.util.SortableTable format, which then may be altered by the handler and displayed using the [table ] expression in the Steam template language. All database connectivity for the Discussion system is provided in the class; if support for new databases is required, then only this class should be altered!

Note that any reference to 'deleting' topics, posts, or discussions via the handlers only changes their status to 'DEAD'. To actually remove them from the database, use the deleteDeadTopics(), deleteDeadPosts(), and deleteDeadDiscussions() methods. The main method for this class does just this.


Field Summary
static int AUTHOR
          used by the getPostSummaries method specify sorting
static int DATE
          used by the getPostSummaries method specify sorting
static int TITLE
          used by the getPostSummaries method specify sorting
 
Constructor Summary
DiscussionLib(java.sql.Connection conn)
          Initializes a DiscussionLib instance, with the correct database type.
 
Method Summary
 SortableTable addCategory(java.sql.Connection conn, java.lang.String title, java.lang.String body, java.lang.String status)
          adds a new category.
 boolean addPost(java.sql.Connection conn, int topicId, java.lang.String title, java.lang.String postBody, java.lang.String firstname, java.lang.String lastname, java.lang.String email)
          adds a post with the specified into to list of posts for the topic specified by the id.
 SortableTable addTopic(java.sql.Connection conn, int catId, java.lang.String title)
          adds a topic for the category specified by the id whose title is the specified title.
 void changeCategoryStatus(java.sql.Connection conn, int id, java.lang.String status)
          Changes a topic's status to the specified parameter.
 boolean changePostStatus(java.sql.Connection conn, int postId, java.lang.String status)
          changes a post status.
 void changeTopicStatus(java.sql.Connection conn, int id, java.lang.String status)
          Changes a topic's status to the specified parameter.
 SortableTable cleanTopics(java.sql.Connection conn)
          Delete all topics which don't have any posts.
 int deleteDeadDiscussions(java.sql.Connection conn)
          Get rid of the 'DEAD' discussions.
 int deleteDeadPosts(java.sql.Connection conn)
          Get rid of the 'DEAD' posts.
 int deleteDeadTopics(java.sql.Connection conn)
          Get rid of the 'DEAD' topics.
 SortableTable getCategoryInfo(java.sql.Connection conn, int id)
          retrieves a single category's information
 SortableTable getCategoryList(java.sql.Connection conn, java.lang.String status)
          returns the list of categories available for the community
 SortableTable getPost(java.sql.Connection conn, int postId)
          returns a post
 SortableTable getPostIds(java.sql.Connection conn, int id)
          returns the entire list of posts from the database for the topic specified by the id
 SortableTable getPostList(java.sql.Connection conn, int topicId, int start, int num)
          returns a list of posts for a topic specified by the id.
 SortableTable getPostSummaries(java.sql.Connection conn, int id, int order)
          this method returns a summary of all the posts related to a particular topic.
 SortableTable getTopicInfo(java.sql.Connection conn, int topicId)
          returns the information for the topic whose id is specified
 SortableTable getTopicList(java.sql.Connection conn, int catId, java.lang.String status)
          returns a list of topics for the category whose id is specified
 void getUserInfo(java.sql.Connection conn, User user, java.util.Hashtable steam_vars)
           
static void main(java.lang.String[] args)
          This sample app will go ahead and delete all the discussions, topics and posts marked as 'DEAD'.
 void modifyCategory(java.sql.Connection conn, int id, java.lang.String title, java.lang.String body, java.lang.String status)
          Modify the topic.
 boolean modifyPost(java.sql.Connection conn, int postId, int topicId, java.lang.String title, java.lang.String postBody, java.lang.String firstname, java.lang.String lastname, java.lang.String email, java.lang.String status)
          modifies an existing post with the new fields passed in as parameters.
 void modifyTopic(java.sql.Connection conn, int id, java.lang.String title, java.lang.String status)
          Modify the topic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE

public static final int DATE
used by the getPostSummaries method specify sorting

AUTHOR

public static final int AUTHOR
used by the getPostSummaries method specify sorting

TITLE

public static final int TITLE
used by the getPostSummaries method specify sorting
Constructor Detail

DiscussionLib

public DiscussionLib(java.sql.Connection conn)
              throws java.sql.SQLException
Initializes a DiscussionLib instance, with the correct database type.
Method Detail

getUserInfo

public void getUserInfo(java.sql.Connection conn,
                        User user,
                        java.util.Hashtable steam_vars)
                 throws java.sql.SQLException

getCategoryList

public SortableTable getCategoryList(java.sql.Connection conn,
                                     java.lang.String status)
returns the list of categories available for the community
Parameters:
status - the status of the list of communities to return
Returns:
a SortableTable with the following columns:
   0  id                  Integer
   1  name                String
   2  description         String
   3  status              string 
   4  topic_count         Integer 
   5  post_count          Integer 
   6  last_post_date      Integer
  

getCategoryInfo

public SortableTable getCategoryInfo(java.sql.Connection conn,
                                     int id)
retrieves a single category's information
Parameters:
id - the id of the category to return.
Returns:
a SortableTable with the following columns:
   0  id                  Integer
   1  name                String
   2  description         String
   3  status              string 
   4  topic_count         Integer 
   5  post_count          Integer 
   6  last_post_date      Integer
  

getTopicList

public SortableTable getTopicList(java.sql.Connection conn,
                                  int catId,
                                  java.lang.String status)
returns a list of topics for the category whose id is specified
Parameters:
catId - the id of the category to return topics for
Returns:
a SortableTable with the following columns:
   0  topicid             int
   1  communityid         int
   2  topicname           String
   3  post_count          Integer
   4  last_post_date      Integer

getTopicInfo

public SortableTable getTopicInfo(java.sql.Connection conn,
                                  int topicId)
returns the information for the topic whose id is specified
Parameters:
topicId - the id of the topic to return. If -1, all topics are returned.
Returns:
a SortableTable with the following columns:
   0  topicid             int
   1  communityid         int
   2  topicname           String
   3  post_count          Integer
   4  last_post_date      Integer
   5  topicstatus         String
 

getPostList

public SortableTable getPostList(java.sql.Connection conn,
                                 int topicId,
                                 int start,
                                 int num)
returns a list of posts for a topic specified by the id.
Parameters:
start - the post number to start counting back from. In other words, return the first num posts whose postid is less than or equal to this number. If the number is -1, return the last num posts.
num - the number of posts to return
Returns:
a SortableTable with the following columns:
    0  postid              int
    1  posttitle           String
    2  postbody            String
    3  postauthorfn        String
    4  postauthorln        String
    5  postemail           String
    6  postdate            Date

getPost

public SortableTable getPost(java.sql.Connection conn,
                             int postId)
returns a post
Parameters:
postId - the post id
num - the number of posts to return
Returns:
a SortableTable with the following columns:
    0  postid              int
    1  posttitle           String
    2  postbody            String
    3  postauthorfn        String
    4  postauthorln        String
    5  postemail           String
    6  postdate            Date
    7  topicid             int
 

getPostIds

public SortableTable getPostIds(java.sql.Connection conn,
                                int id)
returns the entire list of posts from the database for the topic specified by the id
Returns:
a SortableTable with the following columns:
    0  postid              int

getPostSummaries

public SortableTable getPostSummaries(java.sql.Connection conn,
                                      int id,
                                      int order)
this method returns a summary of all the posts related to a particular topic. These summaries may be sorted in three ways: by date, by Author, and by Title.
Parameters:
id - the topic's id to summarize the posts for
order - one of either of the class constants DiscussionLib.DATE, DiscussionLib.AUTHOR, DiscussionLib.TITLE
Returns:
a SortableTable with the following columns:
    0  postid              int
    1  posttitle           String
    2  postauthorfn        String
    3  postauthorln        String
    4  postemail           String
    5  postdate            Date

addPost

public boolean addPost(java.sql.Connection conn,
                       int topicId,
                       java.lang.String title,
                       java.lang.String postBody,
                       java.lang.String firstname,
                       java.lang.String lastname,
                       java.lang.String email)
adds a post with the specified into to list of posts for the topic specified by the id.
Returns:
whether the update was successful

changePostStatus

public boolean changePostStatus(java.sql.Connection conn,
                                int postId,
                                java.lang.String status)
changes a post status. Use this to 'delete' a post- just set post status to 'DEAD'

modifyPost

public boolean modifyPost(java.sql.Connection conn,
                          int postId,
                          int topicId,
                          java.lang.String title,
                          java.lang.String postBody,
                          java.lang.String firstname,
                          java.lang.String lastname,
                          java.lang.String email,
                          java.lang.String status)
modifies an existing post with the new fields passed in as parameters. To 'delete' a post- just set post status to 'DEAD'

addTopic

public SortableTable addTopic(java.sql.Connection conn,
                              int catId,
                              java.lang.String title)
adds a topic for the category specified by the id whose title is the specified title.
Returns:
a SortableTable with the following columns:
   0  topicid             int
   1  communityid         int
   2  topicname           String

changeTopicStatus

public void changeTopicStatus(java.sql.Connection conn,
                              int id,
                              java.lang.String status)
Changes a topic's status to the specified parameter.
Parameters:
conn - the Connection to use
id - the topicid of the topic to change
status - the status to change the topic to. Should be either LIVE or DEAD.

modifyTopic

public void modifyTopic(java.sql.Connection conn,
                        int id,
                        java.lang.String title,
                        java.lang.String status)
Modify the topic.
Parameters:
conn - the Connection to use
id - the topicid of the topic to change
title - the new title for the topic. Set this to null if you don't want to update the title.
status - the status to change the topic to. Should be either 'LIVE' or 'DEAD'.

addCategory

public SortableTable addCategory(java.sql.Connection conn,
                                 java.lang.String title,
                                 java.lang.String body,
                                 java.lang.String status)
adds a new category. Returns a table containing the category's info:
Returns:
a SortableTable with the following columns:
   0  id                  int
   1  name                String
   2  description         String
 
Return null if there was an error

changeCategoryStatus

public void changeCategoryStatus(java.sql.Connection conn,
                                 int id,
                                 java.lang.String status)
Changes a topic's status to the specified parameter.
Parameters:
conn - the Connection to use
id - the topicid of the topic to change
status - the status to change the topic to. Should be either LIVE or DEAD.

modifyCategory

public void modifyCategory(java.sql.Connection conn,
                           int id,
                           java.lang.String title,
                           java.lang.String body,
                           java.lang.String status)
Modify the topic.
Parameters:
conn - the Connection to use
id - the topicid of the topic to change
title - the new title for the topic. Set this to null if you don't want to update the title.
status - the status to change the topic to. Should be either 'LIVE' or 'DEAD'.

deleteDeadPosts

public int deleteDeadPosts(java.sql.Connection conn)
Get rid of the 'DEAD' posts. This is an administration helper method that can be used to clean out deleted posts. Run this before deleteDeadTopics().
Returns:
the number of topics we deleted, or -1 if error

deleteDeadTopics

public int deleteDeadTopics(java.sql.Connection conn)
Get rid of the 'DEAD' topics. This is an administration method that can be used by an administration handler to clean out all deleted topics. Run this after deleteDeadPosts().
Returns:
the number of topics we deleted, or -1 if error

deleteDeadDiscussions

public int deleteDeadDiscussions(java.sql.Connection conn)
Get rid of the 'DEAD' discussions. This is an administration method that can be used by an administration handler to clean out all deleted discussions. Run this after deleteDeadPosts() and deleteDeadTopics().
Returns:
the number of discussions we deleted, or -1 if error

cleanTopics

public SortableTable cleanTopics(java.sql.Connection conn)
Delete all topics which don't have any posts. Another administration method.
Returns:
a SortableTable containing all the topics we deleted, or null if there were no topics to delete or if there was an error.

main

public static void main(java.lang.String[] args)
This sample app will go ahead and delete all the discussions, topics and posts marked as 'DEAD'. It will remove all the topics without posts too. This may remove data you want to hold on to, so use it with care. You'll have to go into the source yourself to edit the database user, password, driver, and URL. It wouldn't be bad to run this as a cron job occasionally...