From: JT S. <jt...@pl...> - 2004-07-09 15:34:58
|
I've been struggling over the last week with how to implement the ability to use a replicated database as a read source. I've experimented with about 10 different ways of doing this and all either didn't work or were way too convoluted to be useful. I've come down to two ways to implement this, but I need about 2 seconds of feedback from a couple of people on this list to make sure I'm on the right track. Way #1: Refactor WebGUI::SQL Change WebGUI::SQL to not use all those class methods, but instead instance methods. So we'd add several constructors and remove the ability to pass in a new database handler on each seperate method. The new constructors would be: new ( [ dbh ] ) This would default to the WebGUI db handler, but you could override it by passing in a dbh. This would be the common one everyone would use. newReplicant ( ) This would use a random one of the defined replicated databases, except if the user was in admin mode. newHandler ( dsn, user, pass [ , options ] ) This would create a new DBH and set it in the object instance. And would require the use of a disconnect() method to destroy it. So to use any of these you'd do something like this: my $db = WebGUI::SQL->newReplicant; my @arr = $db->quickArray($sql); Way #2: Progie does more work, but gets more control We leave WebGUI::SQL as is, except for adding one method like: WebGUI::SQL->getReplicant() Then the programmer in his code would write something like (when he wants to use a replicant): my $dbh = $session{dbh}; unless ($session{var}{adminOn} || $shouldntUseReplicant) { $dbh = WebGUI::SQL->getReplicant; } my @arr = WebGUI::SQL->quickAarry($sql,$dbh); Way #1 is cleaner, but requires refactoring all of WebGUI. (which I'll do if you guys think this is the best way to go) Way #2 is not nearly as clean, but requires no change to the rest of WebGUI. I hope to implement one of these in a few hours, so quick feedback is appreciated. JT ~ Plain Black Create like a god, command like a king, work like a slave. |