From f8d9eb72812ebbfbcd5d674431646c23db0502be Mon Sep 17 00:00:00 2001 From: ricky barrette Date: Mon, 10 Jan 2011 04:10:33 +0000 Subject: [PATCH] fixed file parsing cancelation problem due to encountering an order that already exists --- .../java/OrderProcessor/DB/OrderDB.java | 112 +++++++++--------- .../OrderProcessor/UI/GetStatsDialog.java | 4 +- .../java/OrderProcessor/UI/MainWindow.java | 6 +- 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/DB/OrderDB.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/DB/OrderDB.java index a83741b..d892b24 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/DB/OrderDB.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/DB/OrderDB.java @@ -70,30 +70,23 @@ public class OrderDB { } /** - * returns the row count - * @return number orders in the database - * @throws SQLException - * @author ricky barrette + * added the order to the database + * @param order + * @throws OrderExistsException + * @throws ClassNotFoundException + * @throws IOException + * @throws SQLException */ - public int getCount() throws SQLException{ - int count = -1; - Connection conn = getConnection(); - ResultSet rs = conn.createStatement().executeQuery("select COUNT(*) from Orders;"); + public void addOrder(Order order) throws OrderExistsException, SQLException, IOException, ClassNotFoundException { - if(rs.next()) - count = rs.getInt(1); - conn.close(); - return count; - } - - /** - * gets the connection to the data base - * @return - * @throws SQLException - * @author ricky barrette - */ - private Connection getConnection() throws SQLException{ - return DriverManager.getConnection("jdbc:sqlite:"+ dbLocation+".db"); + /* + * check the current database for an orders with a matching order number + */ + for(Order item : getAllOrders()) + if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber()) + throw new OrderExistsException(order.toString()); + + saveOrder(order); } /** @@ -128,6 +121,33 @@ public class OrderDB { return list; } + /** + * gets the connection to the data base + * @return + * @throws SQLException + * @author ricky barrette + */ + private Connection getConnection() throws SQLException{ + return DriverManager.getConnection("jdbc:sqlite:"+ dbLocation+".db"); + } + + /** + * returns the row count + * @return number orders in the database + * @throws SQLException + * @author ricky barrette + */ + public int getCount() throws SQLException{ + int count = -1; + Connection conn = getConnection(); + ResultSet rs = conn.createStatement().executeQuery("select COUNT(*) from Orders;"); + + if(rs.next()) + count = rs.getInt(1); + conn.close(); + return count; + } + /** * loads the orders from the specified *.CSV file * @param file to be parsed @@ -137,7 +157,7 @@ public class OrderDB { * @throws ClassNotFoundException * @throws OrderExistsException */ - public void load(File file) throws SQLException, IOException, OrderExistsException, ClassNotFoundException{ + public void load(File file) throws SQLException, IOException, ClassNotFoundException{ Scanner scan = new Scanner(file); int line = 1; isLoadingFile = true; @@ -160,12 +180,15 @@ public class OrderDB { e.printStackTrace(); } catch (InvalidDateFormatException e) { e.printStackTrace(); + } catch (OrderExistsException e) { + e.printStackTrace(); } } conn.close(); isLoadingFile = false; } - + + /** * saves an order to the database * @param order @@ -183,17 +206,7 @@ public class OrderDB { bos.close(); prep.setBytes(1, bos.toByteArray()); - prep.execute(); - } - - - /** - * sets a listener for db progress updates - * @param listener - * @author ricky barrette - */ - public void setOnProgressListerner(ProgressListener listener) { - mListener = listener; + prep.executeUpdate(); } /** @@ -228,26 +241,6 @@ public class OrderDB { return list; } - /** - * added the order to the database - * @param order - * @throws OrderExistsException - * @throws ClassNotFoundException - * @throws IOException - * @throws SQLException - */ - public void addOrder(Order order) throws OrderExistsException, SQLException, IOException, ClassNotFoundException { - - /* - * check the current database for an orders with a matching order number - */ - for(Order item : getAllOrders()) - if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber()) - throw new OrderExistsException(order.toString()); - - saveOrder(order); - } - /** * Searches for a specific string in between specific dates * @param search string to search for @@ -270,4 +263,13 @@ public class OrderDB { } return list; } + + /** + * sets a listener for db progress updates + * @param listener + * @author ricky barrette + */ + public void setOnProgressListerner(ProgressListener listener) { + mListener = listener; + } } \ No newline at end of file diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/GetStatsDialog.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/GetStatsDialog.java index fada503..d4e29bc 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/GetStatsDialog.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/GetStatsDialog.java @@ -22,7 +22,6 @@ import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.border.EmptyBorder; import com.TwentyCodes.java.OrderProcessor.Date; -import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException; import com.TwentyCodes.java.OrderProcessor.Months; /** @@ -49,8 +48,11 @@ public class GetStatsDialog extends JFrame implements ActionListener { private JRadioButton mOct; private JTextField textField; private JButton mOkButton; + @SuppressWarnings("unused") private Months mTimeFrame = Months.JAN; + @SuppressWarnings("unused") private Date mStartDate; + @SuppressWarnings("unused") private Date mEndDate; /** diff --git a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/MainWindow.java b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/MainWindow.java index b77a2b8..e771c5f 100644 --- a/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/MainWindow.java +++ b/Order Processor/src/com/TwentyCodes/java/OrderProcessor/UI/MainWindow.java @@ -23,10 +23,9 @@ import javax.swing.JPanel; import javax.swing.JProgressBar; import com.TwentyCodes.java.OrderProcessor.FileFilter; -import com.TwentyCodes.java.OrderProcessor.DB.OrderDB; -import com.TwentyCodes.java.OrderProcessor.OrderExistsException; import com.TwentyCodes.java.OrderProcessor.ProgressListener; import com.TwentyCodes.java.OrderProcessor.UncaughtExceptionHandler; +import com.TwentyCodes.java.OrderProcessor.DB.OrderDB; /** * this is the main window and class of this application @@ -126,9 +125,6 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (OrderExistsException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace();