Java Reference
In-Depth Information
system stays up, we'll retrieve a row once for every new post or update, per server,
resulting in tremendous savings.
1!
These are our get and set methods. The value of encapsulating them is clear: We
won't have to change the interface for the command even though we've changed
the implementation of our instance variables. For the most part, for the interface
attributes for ShowBoardCommand we simply pass through to the get and set
methods of the imbedded commands.
1@
Because board is the key, we have that one on hand and pass it back directly.
Continuing with the next part of our program, we need to modify AddPost-
Command to invalidate the appropriate cache when a new post is added. Here
are the changes, which are added to the execute method in our new class,
called FastAddPostCommand:
query =
"INSERT INTO POSTS values ('"
+ getSubject()
+ "', (select max(number) from posts) + 1, '"
+ getAuthor()
+ "', '"
+ getPostText()
+ "', current timestamp, "
+ getParent()
+ ", '"
+ getBoard()
+ "')";
Statement statement = connection.createStatement();
result = statement.executeQuery(query);
result.close();
statement.close();
connection.close();
The query and its execution remain unchanged:
// If it's a top-level post, we must invalidate the board cache
// because the board list will be different.
if(getParent()=="0") {
BoardCacheCommand boardCache = new BoardCacheCommand();
boardCache.invalidate(getBoard());
} else {
// otherwise, we must invalidate the thread cache
// because the message content has changed.
ThreadCacheCommand threadCache = new ThreadCacheCommand();
threadCache.invalidate(getParent());
}
Search WWH ::




Custom Search