Re: The wisdom of the object mentors (Was: Searching OO Associations with RDBMS Persistence Models)

From: Robert Martin <unclebob_at_objectmentor.com>
Date: Tue, 20 Jun 2006 15:50:51 -0400
Message-ID: <2006062015505171490-unclebob_at_objectmentorcom>


On 2006-06-02 14:05:37 -0400, "Mikito Harakiri" <mikharakiri_nospaum_at_yahoo.com> said:

> 
> Robert Martin wrote:

>> Could you show me how you would construct a credit request packet from
>> a customer record and send it to the credit service, and then process
>> the response? Just for the sake of argument we'll keep the packet
>> simple. The request packet is just a simple SSN encoded in BCD in five
>> bytes. The response is two bytes that contain a binary number whose
>> value ranges from 0-999. You send the request to port 884 of
>> 124.132.4.23, and it will reply within 2 seconds. If it doesn't reply
>> within 2 seconds you need to retry. After the third attempt, you need
>> to declare an error in the current transaction and create a log file
>> entry. Given a valid reply, you set a flag in the customer record to
>> ACCEPTED if the returned value is > 500, otherwise you set the flat to
>> REJECTED.
> 
> Big Deal:
> 
> boolean querySSN ( int ssn ) {
>         PreparedStatement pstmt = conn.prepareStatement(
>         	"select count(*) from people where ssn = :0"
>         );
>         pstmt.setString(1,ssn);
>         ResultSet rs = pstmt.executeQuery();
>         rs.next();
>         return rs.getInt(1)==1? true : false
> }
> 
> boolean checkSSN ( int ssn ) {
>     boolean[] ret = new boolean[1];
>     Thread check1 = new Thread() {
>                     public void run() {
>                             ret[0] = checkSSN(ssn);
>                     }
>     };
>     check1.start();
>     final int tick = 10;
>     long startTime = System.currentTimeMillis();
>     while( check1.isAlive() ) {
>                     try {
>                         Thread.currentThread().sleep(tick,0);
>                         if(  System.currentTimeMillis()-startTime >
> timeoutMin*60*1000 ) {
>                             break;
>                         }
>                     } catch( InterruptedException e ) {
>                         throw new Exception("SHOULD NEVER HAPPEN");
>                     }
>     }
>     if( ret[0] ) return true;
>     Thread check2 = new Thread() {
>                     public void run() {
>                             checkSSN(ssn);
>                     }
>     };
>     check2.start();
>     startTime = System.currentTimeMillis();
>     while( check2.isAlive() ) {
>                     try {
>                         Thread.currentThread().sleep(tick,0);
>                         if(  System.currentTimeMillis()-startTime >
> timeoutMin*60*1000 ) {
>                             break;
>                         }
>                     } catch( InterruptedException e ) {
>                         throw new Exception("SHOULD NEVER HAPPEN");
>                     }
>     }
>     return ret[0];
> }

This is java. I believe I was asking for this to be done in a database language.

-- 
Robert C. Martin (Uncle Bob)  | email: unclebob_at_objectmentor.com
Object Mentor Inc.            | blog:  www.butunclebob.com
The Agile Transition Experts  | web:   www.objectmentor.com
800-338-6716                  |
Received on Tue Jun 20 2006 - 21:50:51 CEST

Original text of this message