geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jb...@apache.org
Subject svn commit: r883783 - in /geronimo/sandbox/jbohn/daytrader-bp-new/modules: core/ core/src/main/java/org/apache/geronimo/samples/daytrader/core/ core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/ core/src/main/java/org/apache/geronimo/sa...
Date Tue, 24 Nov 2009 16:59:41 GMT
Author: jbohn
Date: Tue Nov 24 16:59:39 2009
New Revision: 883783

URL: http://svn.apache.org/viewvc?rev=883783&view=rev
Log:
centralize common DB processing in TradeDBManager and break the dependency between TradeJPADirect and TradeJDBCDirect

Added:
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeDBManagerImpl.java   (with props)
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeDBManager.java   (with props)
Removed:
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/util/
Modified:
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/pom.xml
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServiceUtilities.java
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServices.java
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServicesManager.java
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/pom.xml
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/src/main/java/org/apache/geronimo/samples/daytrader/persist/jdbc/TradeJDBCDirect.java
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/pom.xml
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/src/main/java/org/apache/geronimo/samples/daytrader/persist/jpa/TradeJPADirect.java
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeBuildDB.java
    geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/pom.xml?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/pom.xml (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/pom.xml Tue Nov 24 16:59:39 2009
@@ -107,6 +107,9 @@
                             <!--javax.persistence;version=1.0.0,-->
                             <!--javax.transaction-->
                         </Import-Package>
+                        <Private-Package>
+                            org.apache.geronimo.samples.daytrader.core
+                        </Private-Package>
                     </instructions>
                 </configuration>
             </plugin>

Added: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeDBManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeDBManagerImpl.java?rev=883783&view=auto
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeDBManagerImpl.java (added)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeDBManagerImpl.java Tue Nov 24 16:59:39 2009
@@ -0,0 +1,464 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.samples.daytrader.core;
+
+import javax.naming.InitialContext;
+
+import javax.sql.DataSource;
+
+import org.apache.geronimo.samples.daytrader.beans.*;
+import org.apache.geronimo.samples.daytrader.core.spi.RunStatsDataBean;
+import org.apache.geronimo.samples.daytrader.core.spi.TradeDBManager;
+import org.apache.geronimo.samples.daytrader.util.*;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+
+/**
+ * TradeDBManagerImpl centralizes and simplifies the DB
+ * configuartion methods that are shared by some TradeServices
+ * implementations.
+ * 
+ * @see
+ *      org.apache.geronimo.samples.daytrader.core.spi.TradeDBManager
+ */
+
+public class TradeDBManagerImpl implements TradeDBManager {
+
+    private static String dsName = TradeConfig.DATASOURCE;
+
+    private static DataSource datasource = null;
+
+    private static InitialContext context;
+
+    private static boolean initialized = false;
+
+    /**
+     * Zero arg constructor for TradeDBManagerImpl
+     */
+    public TradeDBManagerImpl() {
+        if (initialized == false)
+            init();
+    }
+
+    /**
+     * Return a String containing the DBProductName configured for
+     * the current DataSource
+     * 
+     * used by TradeBuildDB
+     *
+     * @return A String of the currently configured DataSource
+     * 
+     */
+    public String checkDBProductName() throws Exception {
+        Connection conn = null;
+        String dbProductName = null;
+
+        try {
+            if (Log.doTrace())
+                Log.traceEnter("TradeDBManagerImpl:checkDBProductName");
+
+            conn = getConn();
+            DatabaseMetaData dbmd = conn.getMetaData();
+            dbProductName = dbmd.getDatabaseProductName();
+        }
+        catch (SQLException e) {
+            Log.error(e, "TradeDBManagerImpl:checkDBProductName() -- Error checking the Daytrader Database Product Name");
+        }
+        finally {
+            releaseConn(conn);
+        }
+        return dbProductName;
+    }
+
+    /**
+     * Recreate DataBase Tables for DayTrader
+     * 
+     * used by TradeBuildDB
+     *
+     * @return boolean of success/failure in recreate of DB tables
+     * 
+     */
+    public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out) throws Exception {
+        // Clear MDB Statistics
+        MDBStats.getInstance().reset();
+
+        Connection conn = null;
+        boolean success = false;
+        try {
+            if (Log.doTrace())
+                Log.traceEnter("TradeDBManagerImpl:recreateDBTables");
+
+            conn = getConn();
+            Statement stmt = conn.createStatement();
+            int bufferLength = sqlBuffer.length;
+            for (int i = 0; i < bufferLength; i++) {
+                try {
+                    stmt.executeUpdate((String) sqlBuffer[i]);
+                }
+                catch (SQLException ex) {
+                    // Ignore DROP statements as tables won't always exist.
+                    if (((String) sqlBuffer[i]).indexOf("DROP TABLE") < 0) {
+                        Log.error("TradeDBManagerImpl:recreateDBTables SQL Exception thrown on executing the foll sql command: "
+                                  + sqlBuffer[i], ex);
+                        out.println("<BR>SQL Exception thrown on executing the foll sql command: <I>" + sqlBuffer[i]
+                                    + "</I> . Check log for details.</BR>");
+                    }
+                }
+            }
+            stmt.close();
+            commit(conn);
+            success = true;
+        }
+        catch (Exception e) {
+            Log.error(e, "TradeDBManagerImpl:recreateDBTables() -- Error dropping and recreating the database tables");
+        }
+        finally {
+            releaseConn(conn);
+        }
+        return success;
+    }
+
+    /**
+     * Reset the statistics for the Test Daytrader Scenario
+     * 
+     * used by TradeConfigServlet
+     *
+     * @return the RunStatsDataBean
+     * 
+     */
+    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
+        // Clear MDB Statistics
+        MDBStats.getInstance().reset();
+
+        // Reset Trade
+
+        RunStatsDataBean runStatsData = new RunStatsDataBean();
+        Connection conn = null;
+        try {
+            if (Log.doTrace())
+                Log.traceEnter("TradeJDBCDirect:resetTrade deleteAll rows=" + deleteAll);
+
+            conn = getConn();
+            PreparedStatement stmt = null;
+            ResultSet rs = null;
+
+            if (deleteAll) {
+                try {
+                    stmt = getStatement(conn, "delete from quoteejb");
+                    stmt.executeUpdate();
+                    stmt.close();
+                    stmt = getStatement(conn, "delete from accountejb");
+                    stmt.executeUpdate();
+                    stmt.close();
+                    stmt = getStatement(conn, "delete from accountprofileejb");
+                    stmt.executeUpdate();
+                    stmt.close();
+                    stmt = getStatement(conn, "delete from holdingejb");
+                    stmt.executeUpdate();
+                    stmt.close();
+                    stmt = getStatement(conn, "delete from orderejb");
+                    stmt.executeUpdate();
+                    stmt.close();
+                    // FUTURE: - DuplicateKeyException - For now, don't start at
+                    // zero as KeySequenceDirect and KeySequenceBean will still
+                    // give out
+                    // the cached Block and then notice this change. Better
+                    // solution is
+                    // to signal both classes to drop their cached blocks
+                    // stmt = getStatement(conn, "delete from keygenejb");
+                    // stmt.executeUpdate();
+                    // stmt.close();
+                    commit(conn);
+                }
+                catch (Exception e) {
+                    Log.error(e, "TradeJDBCDirect:resetTrade(deleteAll) -- Error deleting Trade users and stock from the Trade database");
+                }
+                return runStatsData;
+            }
+
+            stmt = getStatement(conn, "delete from holdingejb where holdingejb.account_accountid is null");
+            int x = stmt.executeUpdate();
+            stmt.close();
+
+            // Count and Delete newly registered users (users w/ id that start
+            // "ru:%":
+            stmt = getStatement(conn, "delete from accountprofileejb where userid like 'ru:%'");
+            int rowCount = stmt.executeUpdate();
+            stmt.close();
+
+            stmt = getStatement(conn,
+                                "delete from orderejb where account_accountid in (select accountid from accountejb a where a.profile_userid like 'ru:%')");
+            rowCount = stmt.executeUpdate();
+            stmt.close();
+
+            stmt = getStatement(conn,
+                                "delete from holdingejb where account_accountid in (select accountid from accountejb a where a.profile_userid like 'ru:%')");
+            rowCount = stmt.executeUpdate();
+            stmt.close();
+
+            stmt = getStatement(conn, "delete from accountejb where profile_userid like 'ru:%'");
+            int newUserCount = stmt.executeUpdate();
+            runStatsData.setNewUserCount(newUserCount);
+            stmt.close();
+
+            // Count of trade users
+            stmt = getStatement(conn,
+                                "select count(accountid) as \"tradeUserCount\" from accountejb a where a.profile_userid like 'uid:%'");
+            rs = stmt.executeQuery();
+            rs.next();
+            int tradeUserCount = rs.getInt("tradeUserCount");
+            runStatsData.setTradeUserCount(tradeUserCount);
+            stmt.close();
+
+            rs.close();
+            // Count of trade stocks
+            stmt = getStatement(conn,
+                                "select count(symbol) as \"tradeStockCount\" from quoteejb a where a.symbol like 's:%'");
+            rs = stmt.executeQuery();
+            rs.next();
+            int tradeStockCount = rs.getInt("tradeStockCount");
+            runStatsData.setTradeStockCount(tradeStockCount);
+            stmt.close();
+
+            // Count of trade users login, logout
+            stmt = getStatement(conn,
+                                "select sum(loginCount) as \"sumLoginCount\", sum(logoutCount) as \"sumLogoutCount\" from accountejb a where  a.profile_userID like 'uid:%'");
+            rs = stmt.executeQuery();
+            rs.next();
+            int sumLoginCount = rs.getInt("sumLoginCount");
+            int sumLogoutCount = rs.getInt("sumLogoutCount");
+            runStatsData.setSumLoginCount(sumLoginCount);
+            runStatsData.setSumLogoutCount(sumLogoutCount);
+            stmt.close();
+
+            rs.close();
+            // Update logoutcount and loginCount back to zero
+
+            stmt =
+            getStatement(conn, "update accountejb set logoutCount=0,loginCount=0 where profile_userID like 'uid:%'");
+            rowCount = stmt.executeUpdate();
+            stmt.close();
+
+            // count holdings for trade users
+            stmt = getStatement(conn,
+                               "select count(holdingid) as \"holdingCount\" from holdingejb h where h.account_accountid in "
+                               + "(select accountid from accountejb a where a.profile_userid like 'uid:%')");
+
+            rs = stmt.executeQuery();
+            rs.next();
+            int holdingCount = rs.getInt("holdingCount");
+            runStatsData.setHoldingCount(holdingCount);
+            stmt.close();
+            rs.close();
+
+            // count orders for trade users
+            stmt = getStatement(conn,
+                                "select count(orderid) as \"orderCount\" from orderejb o where o.account_accountid in "
+                                + "(select accountid from accountejb a where a.profile_userid like 'uid:%')");
+
+            rs = stmt.executeQuery();
+            rs.next();
+            int orderCount = rs.getInt("orderCount");
+            runStatsData.setOrderCount(orderCount);
+            stmt.close();
+            rs.close();
+
+            // count orders by type for trade users
+            stmt = getStatement(conn,
+                                "select count(orderid) \"buyOrderCount\"from orderejb o where (o.account_accountid in "
+                                + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
+                                + " (o.orderType='buy')");
+
+            rs = stmt.executeQuery();
+            rs.next();
+            int buyOrderCount = rs.getInt("buyOrderCount");
+            runStatsData.setBuyOrderCount(buyOrderCount);
+            stmt.close();
+            rs.close();
+
+            // count orders by type for trade users
+            stmt = getStatement(conn,
+                                "select count(orderid) \"sellOrderCount\"from orderejb o where (o.account_accountid in "
+                                + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
+                                + " (o.orderType='sell')");
+
+            rs = stmt.executeQuery();
+            rs.next();
+            int sellOrderCount = rs.getInt("sellOrderCount");
+            runStatsData.setSellOrderCount(sellOrderCount);
+            stmt.close();
+            rs.close();
+
+            // Delete cancelled orders
+            stmt = getStatement(conn, "delete from orderejb where orderStatus='cancelled'");
+            int cancelledOrderCount = stmt.executeUpdate();
+            runStatsData.setCancelledOrderCount(cancelledOrderCount);
+            stmt.close();
+            rs.close();
+
+            // count open orders by type for trade users
+            stmt = getStatement(conn,
+                                "select count(orderid) \"openOrderCount\"from orderejb o where (o.account_accountid in "
+                                + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
+                                + " (o.orderStatus='open')");
+
+            rs = stmt.executeQuery();
+            rs.next();
+            int openOrderCount = rs.getInt("openOrderCount");
+            runStatsData.setOpenOrderCount(openOrderCount);
+
+            stmt.close();
+            rs.close();
+            // Delete orders for holding which have been purchased and sold
+            stmt = getStatement(conn, "delete from orderejb where holding_holdingid is null");
+            int deletedOrderCount = stmt.executeUpdate();
+            runStatsData.setDeletedOrderCount(deletedOrderCount);
+            stmt.close();
+            rs.close();
+
+            commit(conn);
+
+            System.out.println("TradeJDBCDirect:reset Run stats data\n\n" + runStatsData);
+        }
+        catch (Exception e) {
+            Log.error(e, "Failed to reset Trade");
+            rollBack(conn, e);
+            throw e;
+        }
+        finally {
+            releaseConn(conn);
+        }
+        return runStatsData;
+
+    }
+
+    private void releaseConn(Connection conn) throws Exception {
+        try {
+            if (conn != null) {
+                conn.close();
+                if (Log.doTrace()) {
+                    synchronized (lock) {
+                        connCount--;
+                    }
+                    Log.trace("TradeDBManagerImpl:releaseConn -- connection closed, connCount=" + connCount);
+                }
+            }
+        }
+        catch (Exception e) {
+            Log.error("TradeDBManagerImpl:releaseConnection -- failed to close connection", e);
+        }
+    }
+
+    /*
+     * Lookup the TradeData datasource
+     */
+    private void getDataSource() throws Exception {
+        if (datasource == null)
+            datasource = (DataSource) context.lookup(dsName);
+    }
+
+    /*
+     * Allocate a new connection to the datasource
+     */
+    private static int connCount = 0;
+
+    private static Integer lock = new Integer(0);
+
+    private Connection getConn() throws Exception {
+
+        Connection conn = null;
+        getDataSource();
+        conn = datasource.getConnection();
+        conn.setAutoCommit(false);
+        if (Log.doTrace()) {
+            synchronized (lock) {
+                connCount++;
+            }
+            Log.trace("TradeDBManagerImpl:getConn -- new connection allocated, IsolationLevel="
+                      + conn.getTransactionIsolation() + " connectionCount = " + connCount);
+        }
+
+        return conn;
+    }
+
+    /*
+     * Commit the provided connection 
+     */
+    private void commit(Connection conn) throws Exception {
+        if (conn != null)
+            conn.commit();
+    }
+
+    /*
+     * Rollback the statement for the given connection
+     */
+    private void rollBack(Connection conn, Exception e) throws Exception {
+        Log.log("TradeDBManagerImpl:rollBack -- rolling back conn due to previously caught exception");
+        if (conn != null)
+            conn.rollback();
+        else
+            throw e; // Throw the exception
+    }
+
+    /*
+     * Allocate a new prepared statment for this connection
+     */
+    private PreparedStatement getStatement(Connection conn, String sql) throws Exception {
+        return conn.prepareStatement(sql);
+    }
+
+
+    public static synchronized void init() {
+        if (initialized)
+            return;
+        if (Log.doTrace())
+            Log.trace("TradeDBManagerImpl:init -- *** initializing");
+        try {
+            context = new InitialContext();
+            datasource = (DataSource) context.lookup(dsName);
+        }
+        catch (Exception e) {
+            Log.error("TradeDBManagerImpl:init -- error on JNDI lookups of DataSource -- TradeDBManagerImpl will not work", e);
+            return;
+        }
+
+        TradeConfig.setPublishQuotePriceChange(false);
+
+        if (Log.doTrace())
+            Log.trace("TradeDBManagerImpl:init -- +++ initialized");
+
+        initialized = true;
+    }
+
+    public static void destroy() {
+        try {
+            Log.trace("TradeDBManagerImpl:destroy");
+            if (!initialized)
+                return;
+        }
+        catch (Exception e) {
+            Log.error("TradeDBManagerImpl:destroy", e);
+        }
+    }
+
+}

Propchange: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeDBManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeDBManagerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/TradeDBManagerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeDBManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeDBManager.java?rev=883783&view=auto
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeDBManager.java (added)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeDBManager.java Tue Nov 24 16:59:39 2009
@@ -0,0 +1,58 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.samples.daytrader.core.spi;
+
+
+/**
+  * TradeDBManager interface centralizes and simplifies the DB
+  * configuartion methods that are shared by some TradeServices
+  * implementations.
+  *
+  */ 
+public interface TradeDBManager {
+
+    /**
+     * Return a String containing the DBProductName configured for
+     * the current DataSource
+     * 
+     * used by TradeBuildDB
+     *
+     * @return A String of the currently configured DataSource
+     * 
+     */
+    public String checkDBProductName() throws Exception;
+
+    /**
+     * Recreate DataBase Tables for DayTrader
+     * 
+     * used by TradeBuildDB
+     *
+     * @return boolean of success/failure in recreate of DB tables
+     * 
+     */
+    public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out) throws Exception;
+
+    /**
+     * Reset the statistics for the Test Daytrader Scenario
+     * 
+     * used by TradeConfigServlet
+     *
+     * @return the RunStatsDataBean
+     * 
+     */
+    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception;
+}   

Propchange: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeDBManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeDBManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeDBManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServiceUtilities.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServiceUtilities.java?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServiceUtilities.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServiceUtilities.java Tue Nov 24 16:59:39 2009
@@ -63,4 +63,16 @@
         return (TradeServicesManager) ServiceUtilities.getOSGIService(TradeServicesManager.class.getName());
     }
 
+    /**
+     * Lookup and return the TradeDBManager osgi service
+     * 
+     * @return TradeDBManager
+     * 
+     */
+    public static final TradeDBManager getTradeDBManager() {
+        if (Log.doTrace())
+            Log.trace("TradeServiceUtilities:getTradeDBManager()");
+        return (TradeDBManager) ServiceUtilities.getOSGIService(TradeDBManager.class.getName());
+    }
+
 }
\ No newline at end of file

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServices.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServices.java?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServices.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServices.java Tue Nov 24 16:59:39 2009
@@ -266,28 +266,6 @@
 								  String email,
 								  String creditcard,
 								  BigDecimal openBalance) throws Exception, RemoteException;  
-						  
-
-   /**
-	 * Reset the TradeData by
-	 * - removing all newly registered users by scenario servlet
-	 *    (i.e. users with userID's beginning with "ru:")	 * 
-	 * - removing all buy/sell order pairs 
-	 * - setting logoutCount = loginCount
-	 *  
- 	 *  return statistics for this benchmark run
-	 */
-    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception, RemoteException;
-    
-    /**
-     * TradeBuildDB needs this abstracted method
-     */
-    public String checkDBProductName() throws Exception;
-    
-    /**
-     * TradeBuildDB needs this abstracted method
-     */
-    public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out) throws Exception;
 
    /**
     * Get mode - returns the persistence mode

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServicesManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServicesManager.java?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServicesManager.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/java/org/apache/geronimo/samples/daytrader/core/spi/TradeServicesManager.java Tue Nov 24 16:59:39 2009
@@ -54,10 +54,11 @@
       * conditions.  This includes the TSIA - and index of the prive
       * of the top 100 Trade stock quotes.  Ths openTSIA(the index
       * at the open), The volune of shares traded, Top Stocks gain
-      * and loss.  Get the currently selected TradeServices
+      * and loss.
       * 
       * This is a special version of this function which will cache
-      * the results provided by TradeServices.
+      * the results provided by the currently selected
+      * TradeServices.
       * 
       * @return A snapshot of the current market summary
       */

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/core/src/main/resources/OSGI-INF/blueprint/blueprint.xml Tue Nov 24 16:59:39 2009
@@ -5,8 +5,14 @@
       <property name="tradeServices" ref="tradeServicesRefJDBC"/>
       <property name="tradeServicesJPA" ref="tradeServicesRefJPA"/>
   </bean>
-  
+
   <service id="TradeServicesManager" ref="tradeServicesManagerBean" interface="org.apache.geronimo.samples.daytrader.core.spi.TradeServicesManager"/>
+  
+  <bean id="tradeDBManagerBean" class="org.apache.geronimo.samples.daytrader.core.TradeDBManagerImpl" activation="lazy" init-method="init">
+  </bean>
+
+  <service id="TradeDBManager" ref="tradeDBManagerBean" interface="org.apache.geronimo.samples.daytrader.core.spi.TradeDBManager">
+  </service>
 
   <reference id="tradeServicesRefJDBC" availability="optional" interface="org.apache.geronimo.samples.daytrader.core.spi.TradeServices" filter="(mode=jdbc)">
     <reference-listener ref="tradeServicesManagerBean" bind-method="bindService" unbind-method="unbindService"/>

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/pom.xml?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/pom.xml (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/pom.xml Tue Nov 24 16:59:39 2009
@@ -118,7 +118,7 @@
                 <configuration>
                     <instructions>
                         <Export-Package>
-                            org.apache.geronimo.samples.daytrader.persist.jdbc;version=1.0.0
+                            <!--org.apache.geronimo.samples.daytrader.persist.jdbc;version=1.0.0-->
                         </Export-Package>
                         <Import-Package>
                             org.apache.geronimo.samples.daytrader.beans;version=1.0,
@@ -129,6 +129,9 @@
                             <!--javax.persistence;version=1.0.0,-->
                             <!--javax.transaction-->
                         </Import-Package>
+                        <Private-Package>
+                            org.apache.geronimo.samples.daytrader.persist.jdbc
+                        </Private-Package>
                     </instructions>
                 </configuration>
             </plugin>

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/src/main/java/org/apache/geronimo/samples/daytrader/persist/jdbc/TradeJDBCDirect.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/src/main/java/org/apache/geronimo/samples/daytrader/persist/jdbc/TradeJDBCDirect.java?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/src/main/java/org/apache/geronimo/samples/daytrader/persist/jdbc/TradeJDBCDirect.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jdbc/src/main/java/org/apache/geronimo/samples/daytrader/persist/jdbc/TradeJDBCDirect.java Tue Nov 24 16:59:39 2009
@@ -1491,280 +1491,6 @@
         return orderData;
     }
 
-    public String checkDBProductName() throws Exception {
-        Connection conn = null;
-        String dbProductName = null;
-
-        try {
-            if (Log.doTrace())
-                Log.traceEnter("TradeJDBCDirect:checkDBProductName");
-
-            conn = getConn();
-            DatabaseMetaData dbmd = conn.getMetaData();
-            dbProductName = dbmd.getDatabaseProductName();
-        } catch (SQLException e) {
-            Log.error(e, "TradeJDBCDirect:checkDBProductName() -- Error checking the Daytrader Database Product Name");
-        } finally {
-            releaseConn(conn);
-        }
-        return dbProductName;
-    }
-
-    public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out) throws Exception {
-        // Clear MDB Statistics
-        MDBStats.getInstance().reset();
-
-        Connection conn = null;
-        boolean success = false;
-        try {
-            if (Log.doTrace())
-                Log.traceEnter("TradeJDBCDirect:recreateDBTables");
-
-            conn = getConn();
-            Statement stmt = conn.createStatement();
-            int bufferLength = sqlBuffer.length;
-            for (int i = 0; i < bufferLength; i++) {
-                try {
-                    stmt.executeUpdate((String) sqlBuffer[i]);
-                    // commit(conn);
-                } catch (SQLException ex) {
-                    // Ignore DROP statements as tables won't always exist.
-                    if (((String) sqlBuffer[i]).indexOf("DROP TABLE") < 0) {
-                        Log.error(
-                            "TradeJDBCDirect:recreateDBTables SQL Exception thrown on executing the foll sql command: "
-                                + sqlBuffer[i], ex);
-                        out.println("<BR>SQL Exception thrown on executing the foll sql command: <I>" + sqlBuffer[i]
-                            + "</I> . Check log for details.</BR>");
-                    }
-                }
-            }
-            stmt.close();
-            commit(conn);
-            success = true;
-        } catch (Exception e) {
-            Log.error(e, "TradeJDBCDirect:recreateDBTables() -- Error dropping and recreating the database tables");
-        } finally {
-            releaseConn(conn);
-        }
-        return success;
-    }
-
-    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
-        // Clear MDB Statistics
-        MDBStats.getInstance().reset();
-        // Reset Trade
-
-        RunStatsDataBean runStatsData = new RunStatsDataBean();
-        Connection conn = null;
-        try {
-            if (Log.doTrace())
-                Log.traceEnter("TradeJDBCDirect:resetTrade deleteAll rows=" + deleteAll);
-
-            conn = getConn();
-            PreparedStatement stmt = null;
-            ResultSet rs = null;
-
-            if (deleteAll) {
-                try {
-                    stmt = getStatement(conn, "delete from quoteejb");
-                    stmt.executeUpdate();
-                    stmt.close();
-                    stmt = getStatement(conn, "delete from accountejb");
-                    stmt.executeUpdate();
-                    stmt.close();
-                    stmt = getStatement(conn, "delete from accountprofileejb");
-                    stmt.executeUpdate();
-                    stmt.close();
-                    stmt = getStatement(conn, "delete from holdingejb");
-                    stmt.executeUpdate();
-                    stmt.close();
-                    stmt = getStatement(conn, "delete from orderejb");
-                    stmt.executeUpdate();
-                    stmt.close();
-                    // FUTURE: - DuplicateKeyException - For now, don't start at
-                    // zero as KeySequenceDirect and KeySequenceBean will still
-                    // give out
-                    // the cached Block and then notice this change. Better
-                    // solution is
-                    // to signal both classes to drop their cached blocks
-                    // stmt = getStatement(conn, "delete from keygenejb");
-                    // stmt.executeUpdate();
-                    // stmt.close();
-                    commit(conn);
-                } catch (Exception e) {
-                    Log
-                        .error(e,
-                            "TradeJDBCDirect:resetTrade(deleteAll) -- Error deleting Trade users and stock from the Trade database");
-                }
-                return runStatsData;
-            }
-
-            stmt = getStatement(conn, "delete from holdingejb where holdingejb.account_accountid is null");
-            int x = stmt.executeUpdate();
-            stmt.close();
-
-            // Count and Delete newly registered users (users w/ id that start
-            // "ru:%":
-            stmt = getStatement(conn, "delete from accountprofileejb where userid like 'ru:%'");
-            int rowCount = stmt.executeUpdate();
-            stmt.close();
-
-            stmt =
-                getStatement(
-                    conn,
-                    "delete from orderejb where account_accountid in (select accountid from accountejb a where a.profile_userid like 'ru:%')");
-            rowCount = stmt.executeUpdate();
-            stmt.close();
-
-            stmt =
-                getStatement(
-                    conn,
-                    "delete from holdingejb where account_accountid in (select accountid from accountejb a where a.profile_userid like 'ru:%')");
-            rowCount = stmt.executeUpdate();
-            stmt.close();
-
-            stmt = getStatement(conn, "delete from accountejb where profile_userid like 'ru:%'");
-            int newUserCount = stmt.executeUpdate();
-            runStatsData.setNewUserCount(newUserCount);
-            stmt.close();
-
-            // Count of trade users
-            stmt =
-                getStatement(conn,
-                    "select count(accountid) as \"tradeUserCount\" from accountejb a where a.profile_userid like 'uid:%'");
-            rs = stmt.executeQuery();
-            rs.next();
-            int tradeUserCount = rs.getInt("tradeUserCount");
-            runStatsData.setTradeUserCount(tradeUserCount);
-            stmt.close();
-
-            rs.close();
-            // Count of trade stocks
-            stmt =
-                getStatement(conn,
-                    "select count(symbol) as \"tradeStockCount\" from quoteejb a where a.symbol like 's:%'");
-            rs = stmt.executeQuery();
-            rs.next();
-            int tradeStockCount = rs.getInt("tradeStockCount");
-            runStatsData.setTradeStockCount(tradeStockCount);
-            stmt.close();
-
-            // Count of trade users login, logout
-            stmt =
-                getStatement(
-                    conn,
-                    "select sum(loginCount) as \"sumLoginCount\", sum(logoutCount) as \"sumLogoutCount\" from accountejb a where  a.profile_userID like 'uid:%'");
-            rs = stmt.executeQuery();
-            rs.next();
-            int sumLoginCount = rs.getInt("sumLoginCount");
-            int sumLogoutCount = rs.getInt("sumLogoutCount");
-            runStatsData.setSumLoginCount(sumLoginCount);
-            runStatsData.setSumLogoutCount(sumLogoutCount);
-            stmt.close();
-
-            rs.close();
-            // Update logoutcount and loginCount back to zero
-
-            stmt =
-                getStatement(conn, "update accountejb set logoutCount=0,loginCount=0 where profile_userID like 'uid:%'");
-            rowCount = stmt.executeUpdate();
-            stmt.close();
-
-            // count holdings for trade users
-            stmt =
-                getStatement(conn,
-                    "select count(holdingid) as \"holdingCount\" from holdingejb h where h.account_accountid in "
-                        + "(select accountid from accountejb a where a.profile_userid like 'uid:%')");
-
-            rs = stmt.executeQuery();
-            rs.next();
-            int holdingCount = rs.getInt("holdingCount");
-            runStatsData.setHoldingCount(holdingCount);
-            stmt.close();
-            rs.close();
-
-            // count orders for trade users
-            stmt =
-                getStatement(conn,
-                    "select count(orderid) as \"orderCount\" from orderejb o where o.account_accountid in "
-                        + "(select accountid from accountejb a where a.profile_userid like 'uid:%')");
-
-            rs = stmt.executeQuery();
-            rs.next();
-            int orderCount = rs.getInt("orderCount");
-            runStatsData.setOrderCount(orderCount);
-            stmt.close();
-            rs.close();
-
-            // count orders by type for trade users
-            stmt =
-                getStatement(conn,
-                    "select count(orderid) \"buyOrderCount\"from orderejb o where (o.account_accountid in "
-                        + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
-                        + " (o.orderType='buy')");
-
-            rs = stmt.executeQuery();
-            rs.next();
-            int buyOrderCount = rs.getInt("buyOrderCount");
-            runStatsData.setBuyOrderCount(buyOrderCount);
-            stmt.close();
-            rs.close();
-
-            // count orders by type for trade users
-            stmt =
-                getStatement(conn,
-                    "select count(orderid) \"sellOrderCount\"from orderejb o where (o.account_accountid in "
-                        + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
-                        + " (o.orderType='sell')");
-
-            rs = stmt.executeQuery();
-            rs.next();
-            int sellOrderCount = rs.getInt("sellOrderCount");
-            runStatsData.setSellOrderCount(sellOrderCount);
-            stmt.close();
-            rs.close();
-
-            // Delete cancelled orders
-            stmt = getStatement(conn, "delete from orderejb where orderStatus='cancelled'");
-            int cancelledOrderCount = stmt.executeUpdate();
-            runStatsData.setCancelledOrderCount(cancelledOrderCount);
-            stmt.close();
-            rs.close();
-
-            // count open orders by type for trade users
-            stmt =
-                getStatement(conn,
-                    "select count(orderid) \"openOrderCount\"from orderejb o where (o.account_accountid in "
-                        + "(select accountid from accountejb a where a.profile_userid like 'uid:%')) AND "
-                        + " (o.orderStatus='open')");
-
-            rs = stmt.executeQuery();
-            rs.next();
-            int openOrderCount = rs.getInt("openOrderCount");
-            runStatsData.setOpenOrderCount(openOrderCount);
-
-            stmt.close();
-            rs.close();
-            // Delete orders for holding which have been purchased and sold
-            stmt = getStatement(conn, "delete from orderejb where holding_holdingid is null");
-            int deletedOrderCount = stmt.executeUpdate();
-            runStatsData.setDeletedOrderCount(deletedOrderCount);
-            stmt.close();
-            rs.close();
-
-            commit(conn);
-
-            System.out.println("TradeJDBCDirect:reset Run stats data\n\n" + runStatsData);
-        } catch (Exception e) {
-            Log.error(e, "Failed to reset Trade");
-            rollBack(conn, e);
-            throw e;
-        } finally {
-            releaseConn(conn);
-        }
-        return runStatsData;
-
-    }
 
     private void releaseConn(Connection conn) throws Exception {
         try {

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/pom.xml?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/pom.xml (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/pom.xml Tue Nov 24 16:59:39 2009
@@ -56,12 +56,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.geronimo.daytrader.modules</groupId>
-            <artifactId>daytrader-persist-jdbc</artifactId>
-            <version>${pom.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-jta_1.1_spec</artifactId>
             <scope>provided</scope>
@@ -113,19 +107,21 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <!--<Export-Package>-->
+                        <Export-Package>
                             <!--org.apache.geronimo.samples.daytrader.persist.jpa;version=1.0.0-->
-                        <!--</Export-Package>-->
+                        </Export-Package>
                         <Import-Package>
                             org.apache.geronimo.samples.daytrader.beans;version=1.0,
                             org.apache.geronimo.samples.daytrader.util;version=1.0,
                             org.apache.geronimo.samples.daytrader.core.spi;version=1.0,
-                            org.apache.geronimo.samples.daytrader.persist.jdbc;version=1.0,
                             javax.naming,
                             javax.sql,
                             javax.persistence;version=1.0.0,
                             javax.transaction
                         </Import-Package>
+                        <Export-Package>
+                            org.apache.geronimo.samples.daytrader.persist.jpa
+                        </Export-Package>
                     </instructions>
                 </configuration>
             </plugin>

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/src/main/java/org/apache/geronimo/samples/daytrader/persist/jpa/TradeJPADirect.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/src/main/java/org/apache/geronimo/samples/daytrader/persist/jpa/TradeJPADirect.java?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/src/main/java/org/apache/geronimo/samples/daytrader/persist/jpa/TradeJPADirect.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/persist-jpa/src/main/java/org/apache/geronimo/samples/daytrader/persist/jpa/TradeJPADirect.java Tue Nov 24 16:59:39 2009
@@ -35,7 +35,6 @@
 import org.apache.geronimo.samples.daytrader.core.spi.MarketSummaryDataBean;
 import org.apache.geronimo.samples.daytrader.core.spi.RunStatsDataBean;
 import org.apache.geronimo.samples.daytrader.core.spi.TradeServices;
-import org.apache.geronimo.samples.daytrader.persist.jdbc.TradeJDBCDirect;
 import org.apache.geronimo.samples.daytrader.util.Log;
 import org.apache.geronimo.samples.daytrader.util.TradeConfig;
 
@@ -671,13 +670,6 @@
         return account;
     }
 
-    public RunStatsDataBean resetTrade(boolean deleteAll) throws Exception {
-        if (Log.doTrace())
-            Log.trace("TradeJPADirect:resetTrade", deleteAll);
-
-        return(new TradeJDBCDirect(true)).resetTrade(deleteAll);
-    }
-
     /*
      * NO LONGER USE
      */
@@ -753,25 +745,6 @@
     }
 
     /**
-     * TradeBuildDB needs this abstracted method
-     */
-    public String checkDBProductName() throws Exception {
-        if (Log.doTrace())
-            Log.trace("TradeJPADirect:checkDBProductName");
-        return(new TradeJDBCDirect(true)).checkDBProductName();
-    }
-
-    /**
-     * TradeBuildDB needs this abstracted method
-     */
-    public boolean recreateDBTables(Object[] sqlBuffer, java.io.PrintWriter out)
-    throws Exception {
-        if (Log.doTrace())
-            Log.trace("TradeJPADirect:checkDBProductName");
-        return(new TradeJDBCDirect(true)).recreateDBTables(sqlBuffer, out);
-    }
-
-    /**
      * Get mode - returns the persistence mode (TradeConfig.JPA)
      * 
      * @return int mode

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeBuildDB.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeBuildDB.java?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeBuildDB.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeBuildDB.java Tue Nov 24 16:59:39 2009
@@ -23,6 +23,7 @@
 import java.math.BigDecimal;
 import java.util.ArrayList;
 
+import org.apache.geronimo.samples.daytrader.core.spi.TradeDBManager;
 import org.apache.geronimo.samples.daytrader.core.spi.TradeServices;
 import org.apache.geronimo.samples.daytrader.core.spi.TradeServicesManager;
 import org.apache.geronimo.samples.daytrader.core.spi.TradeServiceUtilities;
@@ -43,6 +44,7 @@
     private boolean verbose = true;
     private TradeConfig t = new TradeConfig();
     private static TradeServicesManager tradeServicesManager = null;
+    private static TradeDBManager tradeDBManager = null;
 
     /**
      * Populate a Trade DB using standard out as a log
@@ -64,6 +66,10 @@
         }
         TradeServices tradeServices = tradeServicesManager.getTradeServices();
 
+        if (tradeDBManager == null) {
+            tradeDBManager = TradeServiceUtilities.getTradeDBManager();
+        }
+
         // TradeStatistics.statisticsEnabled=false; // disable statistics
         out.println("<HEAD><BR><EM> TradeBuildDB: Building DayTrader Database...</EM><BR>"
             + "This operation will take several minutes. Please wait...</HEAD>");
@@ -77,7 +83,7 @@
 
             // Find out the Database being used
             try {
-                dbProductName = tradeServices.checkDBProductName();
+                dbProductName = tradeDBManager.checkDBProductName();
             } catch (Exception e) {
                 Log.error(e, "TradeBuildDB: Unable to check DB Product name");
             }
@@ -146,7 +152,7 @@
             // send the sql commands buffer to drop and recreate the Daytrader tables
             out.println("<BR>TradeBuildDB: **** Dropping and Recreating the DayTrader tables... ****</BR>");
             try {
-                success = tradeServices.recreateDBTables(sqlBuffer, out);
+                success = tradeDBManager.recreateDBTables(sqlBuffer, out);
             } catch (Exception e) {
                 Log.error(e,
                     "TradeBuildDB: Unable to drop and recreate DayTrader Db Tables, "+
@@ -167,7 +173,7 @@
             + TradeConfig.getMAX_QUOTES() + " Quotes ****</BR>");
         // Attempt to delete all of the Trade users and Trade Quotes first
         try {
-            tradeServices.resetTrade(true);
+            tradeDBManager.resetTrade(true);
         } catch (Exception e) {
             Log.error(e, "TradeBuildDB: Unable to delete Trade users "+
                 "(uid:0, uid:1, ...) and Trade Quotes (s:0, s:1, ...)");

Modified: geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java?rev=883783&r1=883782&r2=883783&view=diff
==============================================================================
--- geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java (original)
+++ geronimo/sandbox/jbohn/daytrader-bp-new/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java Tue Nov 24 16:59:39 2009
@@ -20,8 +20,7 @@
 import javax.servlet.http.*;
 
 import org.apache.geronimo.samples.daytrader.core.spi.RunStatsDataBean;
-import org.apache.geronimo.samples.daytrader.core.spi.TradeServices;
-import org.apache.geronimo.samples.daytrader.core.spi.TradeServicesManager;
+import org.apache.geronimo.samples.daytrader.core.spi.TradeDBManager;
 import org.apache.geronimo.samples.daytrader.core.spi.TradeServiceUtilities;
 import org.apache.geronimo.samples.daytrader.util.*;
 
@@ -35,7 +34,7 @@
  */
 public class TradeConfigServlet extends HttpServlet {
 	
-    private static TradeServices tradeServices = null;
+    private static TradeDBManager tradeDBManager = null;
 
    /**
 	* Servlet initialization method.
@@ -74,14 +73,13 @@
 		RunStatsDataBean runStatsData = new RunStatsDataBean();
 		TradeConfig currentConfig = new TradeConfig();		
 
-                if (tradeServices == null) {
-                    TradeServicesManager tradeServicesManager = TradeServiceUtilities.getTradeServicesManager();
-                    tradeServices = tradeServicesManager.getTradeServices();
+                if (tradeDBManager == null) {
+                    tradeDBManager = TradeServiceUtilities.getTradeDBManager();
                 }
 
 		try
 		{
-			runStatsData = tradeServices.resetTrade(false);
+			runStatsData = tradeDBManager.resetTrade(false);
 			
 			req.setAttribute("runStatsData", runStatsData);
 			req.setAttribute("tradeConfig", currentConfig);



Mime
View raw message