geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hogst...@apache.org
Subject svn commit: r426057 - in /geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader: direct/TradeDirect.java ejb/TradeBean.java
Date Thu, 27 Jul 2006 13:05:48 GMT
Author: hogstrom
Date: Thu Jul 27 06:05:47 2006
New Revision: 426057

URL: http://svn.apache.org/viewvc?rev=426057&view=rev
Log:
DAYTRADER-9 Correct NPE when DB cardinality is too low.

Modified:
    geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java
    geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/TradeBean.java

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java?rev=426057&r1=426056&r2=426057&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java
(original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java
Thu Jul 27 06:05:47 2006
@@ -119,9 +119,15 @@
 			
 			stmt.close();
 			
+            BigDecimal TSIA = ZERO;
+            BigDecimal openTSIA = ZERO;
+            double volume=0.0;
+
+            if ( (topGainersData.size() > 0) || (topLosersData.size() > 0)){ 
+			
 			stmt = getStatement(conn, getTSIASQL);
 			rs = stmt.executeQuery();
-			BigDecimal TSIA=ZERO;
+
 			if (!rs.next() )  
 				Log.error("TradeDirect:getMarketSummary -- error w/ getTSIASQL -- no results");
 			else 
@@ -131,7 +137,7 @@
 			
 			stmt = getStatement(conn, getOpenTSIASQL);
 			rs = stmt.executeQuery();
-			BigDecimal openTSIA = ZERO;
+
 			if (!rs.next() )  
 				Log.error("TradeDirect:getMarketSummary -- error w/ getOpenTSIASQL -- no results");
 			else 
@@ -140,13 +146,13 @@
 
 			stmt = getStatement(conn, getTSIATotalVolumeSQL);
 			rs = stmt.executeQuery();
-			double volume=0.0;
+
 			if (!rs.next() ) 
 				Log.error("TradeDirect:getMarketSummary -- error w/ getTSIATotalVolumeSQL -- no results");
 			else 
 				volume = rs.getDouble("totalVolume");
 			stmt.close();
-			
+            }
 			commit(conn);
 				
 			marketSummaryData = new MarketSummaryDataBean(TSIA, openTSIA, volume, topGainersData,
topLosersData);

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/TradeBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/TradeBean.java?rev=426057&r1=426056&r2=426057&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/TradeBean.java
(original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb/TradeBean.java
Thu Jul 27 06:05:47 2006
@@ -169,15 +169,18 @@
 		    Object[] quoteArray = quotes.toArray();
 		    ArrayList topGainers = new ArrayList(5);
 		    ArrayList topLosers = new ArrayList(5);		    
-		    for (int i=0; i<5; i++) topGainers.add(quoteArray[i]);
-		    for (int i=quoteArray.length-1; i>=quoteArray.length-5; i--) topLosers.add(quoteArray[i]);
-		    
 			BigDecimal TSIA = FinancialUtils.ZERO;
 			BigDecimal openTSIA = FinancialUtils.ZERO;			
 			double totalVolume = 0.0;
-			for (int i=0; i<quoteArray.length; i++) 
-			{
-				LocalQuote quote = (LocalQuote)quoteArray[i];
+
+		   if (quoteArray.length > 5) {
+  			    for (int i = 0; i < 5; i++)
+					topGainers.add(quoteArray[i]);
+				for (int i = quoteArray.length - 1; i >= quoteArray.length - 5; i--)
+					topLosers.add(quoteArray[i]);
+ 
+  			   for (int i = 0; i < quoteArray.length; i++) {
+				LocalQuote quote = (LocalQuote) quoteArray[i];
 			  	BigDecimal price = quote.getPrice();
 			  	BigDecimal open  = quote.getOpen();
 			  	double volume = quote.getVolume();
@@ -185,9 +188,11 @@
 			  	openTSIA = openTSIA.add(open);			  	
 			  	totalVolume += volume;
 			}
-			TSIA = TSIA.divide(new BigDecimal(quoteArray.length), FinancialUtils.ROUND);
-			openTSIA = openTSIA.divide(new BigDecimal(quoteArray.length), FinancialUtils.ROUND);
-			
+				TSIA = TSIA.divide(new BigDecimal(quoteArray.length),
+						FinancialUtils.ROUND);
+				openTSIA = openTSIA.divide(new BigDecimal(quoteArray.length),
+						FinancialUtils.ROUND);
+			}
 			/* This is an alternate approach using ejbSelect methods
 			 *   In this approach an ejbSelect is used to select only the 
 			 *   current price and open price values for the TSIA



Mime
View raw message