Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 55664 invoked from network); 28 Mar 2008 07:04:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Mar 2008 07:04:45 -0000 Received: (qmail 99228 invoked by uid 500); 28 Mar 2008 07:04:44 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 99087 invoked by uid 500); 28 Mar 2008 07:04:43 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 99078 invoked by uid 99); 28 Mar 2008 07:04:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Mar 2008 00:04:43 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Mar 2008 07:03:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7E0841A9832; Fri, 28 Mar 2008 00:04:17 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r642104 - in /geronimo/samples/branches/1.0/migration-jdbc: src/com/dev/trade/ src/org/ src/org/apache/ src/org/apache/geronimo/ src/org/apache/geronimo/demo/ src/org/apache/geronimo/demo/jdbc/ src/org/apache/geronimo/demo/jdbc/bo/ src/org/... Date: Fri, 28 Mar 2008 07:04:16 -0000 To: scm@geronimo.apache.org From: ecraig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080328070417.7E0841A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ecraig Date: Fri Mar 28 00:04:14 2008 New Revision: 642104 URL: http://svn.apache.org/viewvc?rev=642104&view=rev Log: GERONIMO-3910 Cleaned up samples/branches/1.0/migration-jdbc Added: geronimo/samples/branches/1.0/migration-jdbc/src/org/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/Stock.java geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/User.java geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/dao/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/dao/TradeDAO.java geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/exception/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/exception/DBException.java geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/servlet/ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/servlet/TradeDispatcherServlet.java Removed: geronimo/samples/branches/1.0/migration-jdbc/src/com/dev/trade/ Modified: geronimo/samples/branches/1.0/migration-jdbc/web/descriptors/web.xml geronimo/samples/branches/1.0/migration-jdbc/web/jsps/register.jsp geronimo/samples/branches/1.0/migration-jdbc/web/jsps/stocks.jsp geronimo/samples/branches/1.0/migration-jdbc/web/jsps/userstocks.jsp Added: geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/Stock.java URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/Stock.java?rev=642104&view=auto ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/Stock.java (added) +++ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/Stock.java Fri Mar 28 00:04:14 2008 @@ -0,0 +1,56 @@ +/* +* 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.demo.jdbc.bo; + +public class Stock { + private String id = null; + private String name = null; + private float price = 0.0f; + private int quantity = 0; + + public Stock(String id, String name, float price, int quantity) { + this.id = id; + this.name = name; + this.price = price; + this.quantity = quantity; + } + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public float getPrice() { + return price; + } + public void setPrice(float price) { + this.price = price; + } + public int getQuantity() { + return quantity; + } + public void setQuantity(int quantity) { + this.quantity = quantity; + } + +} Added: geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/User.java URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/User.java?rev=642104&view=auto ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/User.java (added) +++ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/bo/User.java Fri Mar 28 00:04:14 2008 @@ -0,0 +1,68 @@ +/* +* 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.demo.jdbc.bo; + +public class User { + + private String userId = null; + private String name = null; + private String password = null; + private String address = null; + private float cash = 0f; + + public User(String userId,String name,String password,String address,float cash){ + this.userId = userId; + this.name = name; + this.password = password; + this.address = address; + this.cash = cash; + } + + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + public String getUserId() { + return userId; + } + public void setUserId(String userId) { + this.userId = userId; + } + + public float getCash() { + return cash; + } + + public void setCash(float cash) { + this.cash = cash; + } + +} Added: geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/dao/TradeDAO.java URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/dao/TradeDAO.java?rev=642104&view=auto ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/dao/TradeDAO.java (added) +++ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/dao/TradeDAO.java Fri Mar 28 00:04:14 2008 @@ -0,0 +1,355 @@ +/* +* 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.demo.jdbc.dao; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.sql.DataSource; + +import org.apache.geronimo.demo.jdbc.bo.Stock; +import org.apache.geronimo.demo.jdbc.bo.User; +import org.apache.geronimo.demo.jdbc.exception.DBException; + + +public class TradeDAO { + private Connection con; + + public TradeDAO() throws Exception { + try { + InitialContext initialContext = new InitialContext(); + Context envCtx = (Context) initialContext.lookup("java:comp/env"); + DataSource ds = (DataSource) envCtx.lookup("jdbc/TradeDB"); + con = ds.getConnection(); + } catch (Exception ex) { + throw new Exception("Couldn't open connection to database: " + + ex.getMessage()); + } + } + + public User getUserByUserId(String userId) throws DBException { + + User user = null; + try { + String query = "select * from users where userid = ?"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setString(1, userId); + ResultSet rs = pStmt.executeQuery(); + while (rs.next()) { + user = new User(rs.getString(1), rs.getString(2), rs + .getString(3), rs.getString(4), rs.getFloat(5)); + } + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + + return user; + } + + public List getUserStocks(String userId) throws DBException { + List stocks = new ArrayList(); + try { + String query = "select A.quantity,A.stockid,B.name,B.price from TradingAccount A,stocks B where A.userid = ? and A.stockid = B.id"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setString(1, userId); + Stock stock = null; + ResultSet rs = pStmt.executeQuery(); + while (rs.next()) { + stock = new Stock(rs.getString(2), rs.getString(3), rs + .getFloat(4), rs.getInt(1)); + stocks.add(stock); + } + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + return stocks; + } + + public List getStocks() throws DBException { + List stocks = new ArrayList(); + try { + String query = "select * from stocks"; + PreparedStatement pStmt = con.prepareStatement(query); + + Stock stock = null; + ResultSet rs = pStmt.executeQuery(); + while (rs.next()) { + stock = new Stock(rs.getString(1), rs.getString(2), rs + .getFloat(3), 0); + stocks.add(stock); + } + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + return stocks; + } + + public float getUserCash(String userId) throws DBException { + float cash = 0; + try { + String query = "select cash from users where userid = ?"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setString(1, userId); + ResultSet rs = pStmt.executeQuery(); + while (rs.next()) { + cash = rs.getFloat("cash"); + } + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + return cash; + } + + public boolean buyStock(String userId, String stockId, int quantity) + throws DBException { + float cashAvailable = getUserCash(userId); + float costOfStock = getStockPrice(stockId); + float totalCost = costOfStock * quantity; + int availableStock = getStockQuantityForUser(userId, stockId); + cashAvailable = cashAvailable - totalCost; + availableStock = availableStock + quantity; + if (cashAvailable >= 0 && (availableStock != quantity)) { + try { + con.setAutoCommit(false); + if (setUserCash(userId, cashAvailable) + && setUserStock(userId, stockId, availableStock)) { + con.commit(); + } else { + con.rollback(); + } + con.setAutoCommit(true); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new DBException(e.getMessage()); + } + } else if (cashAvailable >= 0 && (availableStock == quantity)) { + try { + con.setAutoCommit(false); + if (setUserCash(userId, cashAvailable) + && addUserStock(userId, stockId, availableStock)) { + con.commit(); + } else { + con.rollback(); + } + con.setAutoCommit(true); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new DBException(e.getMessage()); + } + } else { + return false; + } + return true; + } + + public boolean sellStock(String userId, String stockId, int quantity) + throws DBException { + float cashAvailable = getUserCash(userId); + float costOfStock = getStockPrice(stockId); + float totalCost = costOfStock * quantity; + int availableStock = getStockQuantityForUser(userId, stockId); + cashAvailable = cashAvailable + totalCost; + availableStock = availableStock - quantity; + if (availableStock >= 0) { + try { + con.setAutoCommit(false); + if (setUserCash(userId, cashAvailable) + && setUserStock(userId, stockId, availableStock)) { + con.commit(); + } else { + con.rollback(); + } + con.setAutoCommit(true); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new DBException(e.getMessage()); + } + + } else { + return false; + } + return true; + } + + public float getStockPrice(String stockId) throws DBException { + float stockPrice = 0f; + try { + String query = "select price from stocks where id = ?"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setString(1, stockId); + ResultSet rs = pStmt.executeQuery(); + while (rs.next()) { + stockPrice = rs.getFloat("price"); + } + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + + return stockPrice; + } + + private boolean setUserCash(String userId, float cash) throws DBException { + int status = 0; + try { + String query = "update users set cash = ? where userid = ?"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setFloat(1, cash); + pStmt.setString(2, userId); + status = pStmt.executeUpdate(); + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + if (status == 0) { + return false; + } else { + return true; + } + } + + // buy = true sell = false + private boolean setUserStock(String userId, String stockId, int quantity) + throws DBException { + int existingQuantity = 0; + int status = 0; + + try { + String query = "update TradingAccount set quantity = ? where stockid = ? and userid = ?"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setInt(1, quantity); + pStmt.setString(2, stockId); + pStmt.setString(3, userId); + status = pStmt.executeUpdate(); + pStmt.close(); + query = "delete from TradingAccount where quantity = ?"; + pStmt = con.prepareStatement(query); + pStmt.setInt(1, 0); + pStmt.executeUpdate(); + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + if (status == 0) { + return false; + } else { + return true; + } + + } + + private boolean addUserStock(String userId, String stockId, int quantity) + throws DBException { + + int status = 0; + try { + String query = "insert into TradingAccount values (?,?,?)"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setInt(3, quantity); + pStmt.setString(2, stockId); + pStmt.setString(1, userId); + status = pStmt.executeUpdate(); + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + if (status == 0) { + return false; + } else { + return true; + } + + } + + public int getStockQuantityForUser(String userId, String stockId) + throws DBException { + int existingQuantity = 0; + + try { + String query = "select quantity from TradingAccount where userid = ? and stockid = ?"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setString(1, userId); + pStmt.setString(2, stockId); + ResultSet rs = pStmt.executeQuery(); + while (rs.next()) { + existingQuantity = rs.getInt("quantity"); + } + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + return existingQuantity; + } + + public boolean addUser(String userId, String name, String password, + String address, float cash) throws DBException { + int status = 0; + + try { + String query = "insert into users values (?,?,?,?,?)"; + PreparedStatement pStmt = con.prepareStatement(query); + pStmt.setString(1, userId); + pStmt.setString(2, name); + pStmt.setString(3, password); + pStmt.setString(4, address); + pStmt.setFloat(5, cash); + status = pStmt.executeUpdate(); + pStmt.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + throw new DBException(ex.getMessage()); + } + if (status == 0) { + return false; + } else { + return true; + } + + } + + public void remove() throws DBException { + try { + con.close(); + } catch (SQLException ex) { + + throw new DBException(ex.getMessage()); + } + } + +} Added: geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/exception/DBException.java URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/exception/DBException.java?rev=642104&view=auto ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/exception/DBException.java (added) +++ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/exception/DBException.java Fri Mar 28 00:04:14 2008 @@ -0,0 +1,26 @@ +/* +* 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.demo.jdbc.exception; + +public class DBException extends Exception { +public DBException(){ +super(); +} +public DBException(String message){ + super(message); + } +} Added: geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/servlet/TradeDispatcherServlet.java URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/servlet/TradeDispatcherServlet.java?rev=642104&view=auto ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/servlet/TradeDispatcherServlet.java (added) +++ geronimo/samples/branches/1.0/migration-jdbc/src/org/apache/geronimo/demo/jdbc/servlet/TradeDispatcherServlet.java Fri Mar 28 00:04:14 2008 @@ -0,0 +1,184 @@ +/* +* 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.demo.jdbc.servlet; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.geronimo.demo.jdbc.bo.User; +import org.apache.geronimo.demo.jdbc.dao.TradeDAO; +import org.apache.geronimo.demo.jdbc.exception.DBException; + + +public class TradeDispatcherServlet extends HttpServlet { + + private TradeDAO tradeDAO = null; + + private HttpSession session = null; + + public void init() throws ServletException { + // TODO Auto-generated method stub + super.init(); + try { + tradeDAO = new TradeDAO(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + try { + session = request.getSession(true); + session.removeAttribute("status"); + String page = request.getServletPath(); + if ("/login".equals(page)) { + String userId = (String) request.getParameter("user"); + String password = (String) request.getParameter("password"); + if (userId != null && password != null) { + User user = tradeDAO.getUserByUserId(userId); + session.setAttribute("user", user); + if (user != null && password.equals(user.getPassword())) { + page = "/stocks"; + session.setAttribute("userId", userId); + session.setAttribute("password", password); + List stocks = tradeDAO.getStocks(); + session.setAttribute("stocks", stocks); + } else { + page = "/login"; + session.setAttribute("status", + "Logon Failed Please Try Again!"); + } + } else { + page = "/login"; + } + + } else if ("/stocks".equals(page)) { + List stocks = tradeDAO.getStocks(); + session.setAttribute("stocks", stocks); + } else if ("/userstocks".equals(page)) { + String userId = (String) session.getAttribute("userId"); + List userStocks = tradeDAO.getUserStocks(userId); + session.setAttribute("userStocks", userStocks); + } else if ("/register".equals(page)) { + String userId = request.getParameter("user"); + String name = request.getParameter("name"); + String password = request.getParameter("password"); + String address = request.getParameter("address"); + float cash = Float + .parseFloat((request.getParameter("cash") == null) ? "0" + : request.getParameter("cash")); + if (userId != null && name != null && password != null + && address != null && cash != 0) { + User user = tradeDAO.getUserByUserId(userId); + if (user == null) { + boolean status = tradeDAO.addUser(userId, name, + password, address, cash); + if (status) { + page = "/login"; + } else { + page = "/register"; + session.setAttribute("status", + "Registration Failed Please Try Again!"); + } + } else { + page = "/register"; + session.setAttribute("status", + "Registration Failed User Already Exists!"); + } + + }else if (userId != null && name != null && password != null + && address != null && cash == 0) { + session.setAttribute("status", + "Registration Failed Not enough Cash!"); + page = "/register"; + + }else { + page = "/register"; + } + + } else if ("/sell".equals(page)) { + page = "/userstocks"; + String userId = (String) session.getAttribute("userId"); + String stockId = request.getParameter("select"); + int quantity = Integer.parseInt(request + .getParameter("sellQuantity")); + boolean status = tradeDAO.sellStock(userId, stockId, quantity); + if (!status) { + session + .setAttribute("status", + "Not Enough Stocks or Operation Failed Please Try Again!"); + } + List userStocks = tradeDAO.getUserStocks(userId); + session.setAttribute("userStocks", userStocks); + User user = tradeDAO.getUserByUserId(userId); + session.setAttribute("user", user); + } else if ("/buy".equals(page)) { + page = "/stocks"; + String userId = (String) session.getAttribute("userId"); + String stockId = request.getParameter("select"); + int quantity = Integer.parseInt(request + .getParameter("buyQuantity")); + boolean status = tradeDAO.buyStock(userId, stockId, quantity); + if (!status) { + session + .setAttribute("status", + "Not Enough Money or Operation Failed Please Try Again!"); + } + List userStocks = tradeDAO.getUserStocks(userId); + session.setAttribute("userStocks", userStocks); + User user = tradeDAO.getUserByUserId(userId); + session.setAttribute("user", user); + } + + request.getRequestDispatcher(page + ".jsp").forward(request, + response); + } catch (DBException e) { + throw new ServletException(e.getMessage()); + } catch (Exception ex) { + throw new ServletException(ex.getMessage()); + } + + } + + protected void doPost(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + + doGet(request, response); + } + + public void destroy() { + // TODO Auto-generated method stub + super.destroy(); + try { + tradeDAO.remove(); + } catch (DBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} Modified: geronimo/samples/branches/1.0/migration-jdbc/web/descriptors/web.xml URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/web/descriptors/web.xml?rev=642104&r1=642103&r2=642104&view=diff ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/web/descriptors/web.xml (original) +++ geronimo/samples/branches/1.0/migration-jdbc/web/descriptors/web.xml Fri Mar 28 00:04:14 2008 @@ -20,7 +20,7 @@ Trade-Dispatcher TradeDispatcher -com.dev.trade.servlet.TradeDispatcherServlet +org.apache.geronimo.demo.jdbc.servlet.TradeDispatcherServlet TradeDispatcher Modified: geronimo/samples/branches/1.0/migration-jdbc/web/jsps/register.jsp URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/web/jsps/register.jsp?rev=642104&r1=642103&r2=642104&view=diff ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/web/jsps/register.jsp (original) +++ geronimo/samples/branches/1.0/migration-jdbc/web/jsps/register.jsp Fri Mar 28 00:04:14 2008 @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> -<%@page language="java" import="com.dev.trade.bo.*" %> +<%@page language="java" import="org.apache.geronimo.demo.jdbc.bo.*" %> Trader Registration Modified: geronimo/samples/branches/1.0/migration-jdbc/web/jsps/stocks.jsp URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/web/jsps/stocks.jsp?rev=642104&r1=642103&r2=642104&view=diff ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/web/jsps/stocks.jsp (original) +++ geronimo/samples/branches/1.0/migration-jdbc/web/jsps/stocks.jsp Fri Mar 28 00:04:14 2008 @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> -<%@page language="java" import="java.util.List,com.dev.trade.bo.Stock" %> +<%@page language="java" import="java.util.List,org.apache.geronimo.demo.jdbc.bo.Stock" %> Available Stocks Modified: geronimo/samples/branches/1.0/migration-jdbc/web/jsps/userstocks.jsp URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jdbc/web/jsps/userstocks.jsp?rev=642104&r1=642103&r2=642104&view=diff ============================================================================== --- geronimo/samples/branches/1.0/migration-jdbc/web/jsps/userstocks.jsp (original) +++ geronimo/samples/branches/1.0/migration-jdbc/web/jsps/userstocks.jsp Fri Mar 28 00:04:14 2008 @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> -<%@page language="java" import="java.util.List,com.dev.trade.bo.*" %> +<%@page language="java" import="java.util.List,org.apache.geronimo.demo.jdbc.bo.*" %> Portfolio