fixed file parsing cancelation problem due to encountering an order that already exists

This commit is contained in:
2011-01-10 04:10:33 +00:00
parent 0420f11fa1
commit f8d9eb7281
3 changed files with 61 additions and 61 deletions

View File

@@ -70,30 +70,23 @@ public class OrderDB {
} }
/** /**
* returns the row count * added the order to the database
* @return number orders in the database * @param order
* @throws SQLException * @throws OrderExistsException
* @author ricky barrette * @throws ClassNotFoundException
* @throws IOException
* @throws SQLException
*/ */
public int getCount() throws SQLException{ public void addOrder(Order order) throws OrderExistsException, SQLException, IOException, ClassNotFoundException {
int count = -1;
Connection conn = getConnection();
ResultSet rs = conn.createStatement().executeQuery("select COUNT(*) from Orders;");
if(rs.next()) /*
count = rs.getInt(1); * check the current database for an orders with a matching order number
conn.close(); */
return count; for(Order item : getAllOrders())
} if(item.getGoogleOrderNumber() == order.getGoogleOrderNumber())
throw new OrderExistsException(order.toString());
/**
* gets the connection to the data base saveOrder(order);
* @return
* @throws SQLException
* @author ricky barrette
*/
private Connection getConnection() throws SQLException{
return DriverManager.getConnection("jdbc:sqlite:"+ dbLocation+".db");
} }
/** /**
@@ -128,6 +121,33 @@ public class OrderDB {
return list; 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 * loads the orders from the specified *.CSV file
* @param file to be parsed * @param file to be parsed
@@ -137,7 +157,7 @@ public class OrderDB {
* @throws ClassNotFoundException * @throws ClassNotFoundException
* @throws OrderExistsException * @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); Scanner scan = new Scanner(file);
int line = 1; int line = 1;
isLoadingFile = true; isLoadingFile = true;
@@ -160,12 +180,15 @@ public class OrderDB {
e.printStackTrace(); e.printStackTrace();
} catch (InvalidDateFormatException e) { } catch (InvalidDateFormatException e) {
e.printStackTrace(); e.printStackTrace();
} catch (OrderExistsException e) {
e.printStackTrace();
} }
} }
conn.close(); conn.close();
isLoadingFile = false; isLoadingFile = false;
} }
/** /**
* saves an order to the database * saves an order to the database
* @param order * @param order
@@ -183,17 +206,7 @@ public class OrderDB {
bos.close(); bos.close();
prep.setBytes(1, bos.toByteArray()); prep.setBytes(1, bos.toByteArray());
prep.execute(); prep.executeUpdate();
}
/**
* sets a listener for db progress updates
* @param listener
* @author ricky barrette
*/
public void setOnProgressListerner(ProgressListener listener) {
mListener = listener;
} }
/** /**
@@ -228,26 +241,6 @@ public class OrderDB {
return list; 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 * Searches for a specific string in between specific dates
* @param search string to search for * @param search string to search for
@@ -270,4 +263,13 @@ public class OrderDB {
} }
return list; return list;
} }
/**
* sets a listener for db progress updates
* @param listener
* @author ricky barrette
*/
public void setOnProgressListerner(ProgressListener listener) {
mListener = listener;
}
} }

View File

@@ -22,7 +22,6 @@ import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import com.TwentyCodes.java.OrderProcessor.Date; import com.TwentyCodes.java.OrderProcessor.Date;
import com.TwentyCodes.java.OrderProcessor.InvalidDateFormatException;
import com.TwentyCodes.java.OrderProcessor.Months; import com.TwentyCodes.java.OrderProcessor.Months;
/** /**
@@ -49,8 +48,11 @@ public class GetStatsDialog extends JFrame implements ActionListener {
private JRadioButton mOct; private JRadioButton mOct;
private JTextField textField; private JTextField textField;
private JButton mOkButton; private JButton mOkButton;
@SuppressWarnings("unused")
private Months mTimeFrame = Months.JAN; private Months mTimeFrame = Months.JAN;
@SuppressWarnings("unused")
private Date mStartDate; private Date mStartDate;
@SuppressWarnings("unused")
private Date mEndDate; private Date mEndDate;
/** /**

View File

@@ -23,10 +23,9 @@ import javax.swing.JPanel;
import javax.swing.JProgressBar; import javax.swing.JProgressBar;
import com.TwentyCodes.java.OrderProcessor.FileFilter; 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.ProgressListener;
import com.TwentyCodes.java.OrderProcessor.UncaughtExceptionHandler; import com.TwentyCodes.java.OrderProcessor.UncaughtExceptionHandler;
import com.TwentyCodes.java.OrderProcessor.DB.OrderDB;
/** /**
* this is the main window and class of this application * 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) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (OrderExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();