fixed file parsing cancelation problem due to encountering an order that already exists
This commit is contained in:
@@ -70,30 +70,23 @@ public class OrderDB {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the row count
|
||||
* @return number orders in the database
|
||||
* added the order to the database
|
||||
* @param order
|
||||
* @throws OrderExistsException
|
||||
* @throws ClassNotFoundException
|
||||
* @throws IOException
|
||||
* @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;");
|
||||
public void addOrder(Order order) throws OrderExistsException, SQLException, IOException, ClassNotFoundException {
|
||||
|
||||
if(rs.next())
|
||||
count = rs.getInt(1);
|
||||
conn.close();
|
||||
return count;
|
||||
}
|
||||
/*
|
||||
* 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());
|
||||
|
||||
/**
|
||||
* 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");
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user