Re: The wisdom of the object mentors (Was: Searching OO Associations with RDBMS Persistence Models)
Date: 2 Jun 2006 11:05:37 -0700
Message-ID: <1149271537.880851.94760_at_y43g2000cwc.googlegroups.com>
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];
} Received on Fri Jun 02 2006 - 20:05:37 CEST