Jive notes 6 - Database package below the Double Diablo
JIVE Note 6 - Database Package The following Dark World Written By Shyguy2002 / 12 / 27Jive Cow B, go to the end or deal with Database. Not to call getConnection (), createstatement (), resultSet.next (). So, how is the coupling between the low-level operation class (DBFORMMESSAGE / DBFORUMTHREAD / DBFORUM)? Due to Cache, the relationship between these classes between DBForumFactory / DBCachemanager / DBForumxxx can be described as complex. (1) How do we complete the loading of a ForumMessageObject? And how to add message to the addition of the message? Open dbForumMessage.java, found that in addition to completing the method of completing the ForumMessage Interface, there are several private methods and protected methods. They are: private void loadingfromDB (); private void savetoDB (); protected void insertodu ();, etc. The above three functions are used to complete the SELECT / UPDATE / INSERT operation to the JiveMessage table. Therefore, it can be determined that the operation of the JiveMessage table is basically included in DBForumMessage. But not all, why? Slow down. a. Loading DBForumMessage is very simple, the code of the earth knows. Call LoadFromDB () in a constructor, then execute SELECT XXX, XXX, .. where id = ..., if the RS throws MessageNotFoundException, otherwise, one one is copied to the member variable of DBForumMessage. (By the way, the member variables of these mapping database fields are private, some are protected, why? Oh.) For this loading method, if there is no Cache, it will be very slow. Imagine, every time you display a message, you have to select. When I browse the Thread page, I will display N thread / message once, .... Don't have a database for the database. In the process of my cloning, since the Cache mechanism will be implemented later, a compromise approach has been taken. Remove the dbmessageiterator () class, change the original only ID for all the content other than Body, and directly on the ground New DBforumMessage, then copy to ArrayList. As for Body, use LazyLoad method, etc. to go to SELECT BODY from ... This is handled, because there is a resultfilter limit, the maximum copy dozens of DBForumMessAg objects, this for Appserver, I want to affect Big? b. Increasing DBForumMessage is also calling INSERT INTO JIVEMESSAGE. However, notice that when inserting a new ForumMessage record, ThreadID is a must, so it seems to be only let DBForumThread call this method. No wonder !! With protected insertosis !! It turns out that Class in a packet is a method of accessing protected each other.
Even Java is basically good, huh, I've been discovered today. c. Delete DBForumMessage This is more interesting. DBForumMessage does not have any code that executes Delete from JiveMessage. It seems that it must be implemented outside DBTHREAD. After all, this is THREAD. If you don't have it, DBForumthread :: DeleteMessage () directly executed DELETE SQL. I did a small change in Clone Jive, I added a protected deleteFromDB () method to dbForumMessage, put the execution of SQL to Message finished. During the add / delete operation for Message, you can not forget the update of cache list, so you must remember to update cache in dbForumMessage to update cache, although in my system, these functions are empty :) . I understand the "father and child relationship" between Thread / Message, the relationship between Forum / Thread Category / Forum is almost. Oh, the category in jive seems to be a bit special, and then I will report another detailed report next time. (2) What is DBFORumFactory? After jive2.1.1, DBForumFactory did not give Source, and Jad is still difficult to compile because JAD can't refact with code such as Synchronized (Object) {}. Fortunately, we have a code of JIVE 2.1.1. Haha. Look and say it. First, the identity of DBForumFactory will be exposed. In fact, DBForumFactory is a general manager. Tubing forum / Thread / Message. So, when we call the API, we have obtained those objects through Factory.Getforum () / getthread () / getMessage (). JIVE uses Singleton to ensure that DBForumFactory () is unique, that is, the static method dbforumfactory.getInstance (). At the same time, DBForumFactory has a DatabaseCacheManager in the constructor. Therefore, Factory and CacheManager have colluded like this. All call getforum (), getthread (), getMessage (), is to call the relevant method of the DatabaseCacheManager to be implemented. Example: dbforumfactory :: getthread () ==> DatabaseCacheManager.getthread () ==> Search Cache or New DBTHREAD OBJECT
Conclusion, DBForumFactory is not something. In addition to checking if the lice is legal, the other is basically a two vendors. (3) In fact, there are those Thread / Message's Dbitrator, which has been mentioned in Jive Notes 4. Don't have to come again. I have written so much, I feel that there is still a lot of things. I hope everyone can carefully taste the protected attribute / method in the inside, I think that these things are similar to the friend, and some of them break the package, but it has got a lot of flexibility. If you think about it, we just have to limit those things in the Database package, and there is no impact on the overall package. Oh, a speech, please don't care about Shyguy