main
Sunguin Peng 9 years ago
commit 8fb7a36d80

Binary file not shown.

@ -139,6 +139,7 @@ public class App extends Application
c.close(); c.close();
} catch ( Exception e ) { } catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
e.printStackTrace();
} }
} }

@ -375,7 +375,7 @@ public class Dataset {
ArrayList<Airline> airlinesToImport = parser.getResult(); ArrayList<Airline> airlinesToImport = parser.getResult();
//check for dup //check for dup
int numOfDuplicates = 0; int numOfDuplicates = 0;
int nextID = -1; int nextID = 1;
//query database. //query database.
Connection c = null; Connection c = null;
Statement stmt = null; Statement stmt = null;
@ -448,7 +448,7 @@ public class Dataset {
ArrayList<Country> countriesToImport = parser.getCountryResult(); ArrayList<Country> countriesToImport = parser.getCountryResult();
//check for dup //check for dup
int numOfDuplicates = 0; int numOfDuplicates = 0;
int nextID = -1; int nextID = 1;
//query database. //query database.
Connection c = null; Connection c = null;
Statement stmt = null; Statement stmt = null;
@ -580,7 +580,7 @@ public class Dataset {
ArrayList<Route> routesToImport = parser.getResult(); ArrayList<Route> routesToImport = parser.getResult();
//check for dup //check for dup
int numOfDuplicates = 0; int numOfDuplicates = 0;
int nextID = -1; int nextID = 1;
//query database. //query database.
Connection c = null; Connection c = null;
Statement stmt = null; Statement stmt = null;
@ -654,7 +654,7 @@ public class Dataset {
String message = parser.parse(); String message = parser.parse();
ArrayList<FlightPoint> flightPointsToImport = parser.getResult(); ArrayList<FlightPoint> flightPointsToImport = parser.getResult();
//check for dup //check for dup
int nextID = -1; int nextID = 1;
//query database. //query database.
Connection c = null; Connection c = null;
Statement stmt = null; Statement stmt = null;
@ -662,12 +662,13 @@ public class Dataset {
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
stmt = c.createStatement(); stmt = c.createStatement();
String queryName = this.name.replace("'", "''"); String queryName = this.name.replace("\"", "\"\"");
String IDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = '"+queryName+"_Flight_Points' LIMIT 1;"; String IDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+queryName+"_Flight_Points\" LIMIT 1;";
ResultSet IDResult = stmt.executeQuery(IDQuery); ResultSet IDResult = stmt.executeQuery(IDQuery);
while(IDResult.next()){ while(IDResult.next()){
nextID = Integer.parseInt(IDResult.getString("seq")) + 1;//for some reason sqlite3 stores incremental values as a string... nextID = Integer.parseInt(IDResult.getString("seq")) + 1;//for some reason sqlite3 stores incremental values as a string...
} }
System.out.println(nextID);
stmt.close(); stmt.close();
stmt = c.createStatement(); stmt = c.createStatement();
//ADDED //ADDED
@ -728,10 +729,12 @@ public class Dataset {
c.close(); c.close();
flightPaths.add(flightPathToAdd); flightPaths.add(flightPathToAdd);
System.out.println(flightPathToAdd.getFlightPoints().get(0).getID());
updateFlightPointInfo(flightPathToAdd); updateFlightPointInfo(flightPathToAdd);
flightPathDictionary.put(flightPathToAdd.getID(), flightPathToAdd); flightPathDictionary.put(flightPathToAdd.getID(), flightPathToAdd);
} catch ( Exception e ) { } catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
e.printStackTrace();
System.exit(0); System.exit(0);
} }
createDataLinks(); createDataLinks();
@ -1225,7 +1228,7 @@ public class Dataset {
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
stmt = c.createStatement(); stmt = c.createStatement();
String flightPointIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name+"_Flight_Points\" LIMIT 1;"; String flightPointIDQuery = "SELECT * FROM `sqlite_sequence` WHERE `name` = \""+this.name.replace("\"", "\"\"")+"_Flight_Points\" LIMIT 1;";
ResultSet pointIDRes= stmt.executeQuery(flightPointIDQuery); ResultSet pointIDRes= stmt.executeQuery(flightPointIDQuery);
while (pointIDRes.next()){ while (pointIDRes.next()){
pointID = Integer.parseInt(pointIDRes.getString("seq")); pointID = Integer.parseInt(pointIDRes.getString("seq"));

@ -32,6 +32,11 @@ public class DatasetTest {
fail("The sample file is missing"); fail("The sample file is missing");
} }
assertTrue(dataset.getAirlines().size() == dataset.getAirlineDictionary().size()); assertTrue(dataset.getAirlines().size() == dataset.getAirlineDictionary().size());
try {
assertTrue(dataset.getAirlines().get(0).getID() == 1);
} catch (DataException e) {
fail("The first index of Airlines should have an id of 1 as there has been no tampering with the data yet");
}
try { try {
dataset.importAirport("res/Reduced Samples/Airports.txt"); dataset.importAirport("res/Reduced Samples/Airports.txt");
@ -41,6 +46,11 @@ public class DatasetTest {
assertTrue(dataset.getAirports().size() == dataset.getAirportDictionary().size()); assertTrue(dataset.getAirports().size() == dataset.getAirportDictionary().size());
assertTrue(dataset.getCities().size() == dataset.getCityDictionary().size()); assertTrue(dataset.getCities().size() == dataset.getCityDictionary().size());
assertTrue(dataset.getCountries().size() == dataset.getCountryDictionary().size()); assertTrue(dataset.getCountries().size() == dataset.getCountryDictionary().size());
try {
assertTrue(dataset.getAirports().get(0).getID() == 1);
} catch (DataException e) {
fail("The first index of Airports should have an id of 1 as there has been no tampering with the data yet");
}
try { try {
dataset.importRoute("res/Reduced Samples/Routes.txt"); dataset.importRoute("res/Reduced Samples/Routes.txt");
@ -48,6 +58,11 @@ public class DatasetTest {
fail("The sample file is missing"); fail("The sample file is missing");
} }
assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size()); assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size());
try {
assertTrue(dataset.getRoutes().get(0).getID() == 1);
} catch (DataException e) {
fail("The first index of Routes should have an id of 1 as there has been no tampering with the data yet");
}
try { try {
dataset.importFlight("res/Reduced Samples/NZCH-WSSS.csv"); dataset.importFlight("res/Reduced Samples/NZCH-WSSS.csv");
@ -55,6 +70,11 @@ public class DatasetTest {
fail("The sample file is missing"); fail("The sample file is missing");
} }
assertTrue(dataset.getFlightPaths().size() == dataset.getFlightPathDictionary().size()); assertTrue(dataset.getFlightPaths().size() == dataset.getFlightPathDictionary().size());
try {
assertTrue(dataset.getFlightPaths().get(0).getID() == 1);
} catch (DataException e) {
fail("The first index of Flight Paths should have an id of 1 as there has been no tampering with the data yet");
}
dataset.createDataLinks(); dataset.createDataLinks();
@ -185,6 +205,8 @@ public class DatasetTest {
fail("The sample file is missing"); fail("The sample file is missing");
} }
assertTrue(dataset.getFlightPaths().get(0).getFlightPoints().get(0).getID() == 1);
FlightPoint flightPoint = dataset.getFlightPaths().get(0).getFlightPoints().get(6); FlightPoint flightPoint = dataset.getFlightPaths().get(0).getFlightPoints().get(6);
FlightPoint flightPoint1 = dataset.getFlightPaths().get(0).getFlightPoints().get(5); FlightPoint flightPoint1 = dataset.getFlightPaths().get(0).getFlightPoints().get(5);
dataset.deleteFlightPoint(1, 5); dataset.deleteFlightPoint(1, 5);

Loading…
Cancel
Save