Commit cac8a940 authored by Daniel Kim's avatar Daniel Kim
Browse files

quick fix

parent 45680578
......@@ -220,29 +220,8 @@ public class ClientApplication {
String searchQueryString = "";
String sort = "";
boolean exitLoop = false;
while (!exitLoop) {
System.out.println("Type \"t\" to sort by title. Type \"p\" to sort by popularity. Press enter to sort default.");
sort = input.nextLine();
if (!sort.equals("t") && !sort.equals("p")) {
if (sort.equals("")) {
exitLoop = true;
} else {
System.out.println("Invalid command.");
}
} else {
exitLoop = true;
}
}
String sortString = "";
switch (sort) {
case "t":
sortString = "order by title";
break;
case "p":
sortString = "order by totalRating desc";
break;
default: break;
}
try {
// PreparedStatement query = null;
......@@ -293,12 +272,36 @@ public class ClientApplication {
HashSet<String> basicAttributes = new HashSet<String>();
switch (type) {
case "movie":
while (!exitLoop) {
System.out.println("Type \"t\" to sort by title. Type \"p\" to sort by popularity. Press enter to sort default.");
sort = input.nextLine();
if (!sort.equals("t") && !sort.equals("p")) {
if (sort.equals("")) {
exitLoop = true;
} else {
System.out.println("Invalid command.");
}
} else {
exitLoop = true;
}
}
switch (sort) {
case "t":
sortString = "order by title";
break;
case "p":
sortString = "order by totalRating desc";
break;
default: break;
}
basicAttributes.add("title");
basicAttributes.add("genre");
basicAttributes.add("releaseDate");
basicAttributes.add("description");
basicAttributes.add("averageRating");
basicAttributes.add("totalRating");
searchQueryString = searchMovieQueryString + "title like '%%%s%%' group by movieID %s limit 10";
keywords = keywords.replace("\'", "\\'");
......@@ -324,11 +327,36 @@ public class ClientApplication {
break;
case "genre":
while (!exitLoop) {
System.out.println("Type \"t\" to sort by title. Type \"p\" to sort by popularity. Press enter to sort default.");
sort = input.nextLine();
if (!sort.equals("t") && !sort.equals("p")) {
if (sort.equals("")) {
exitLoop = true;
} else {
System.out.println("Invalid command.");
}
} else {
exitLoop = true;
}
}
System.out.println();
switch (sort) {
case "t":
sortString = "order by title";
break;
case "p":
sortString = "order by totalRating desc";
break;
default: break;
}
basicAttributes.add("title");
basicAttributes.add("genre");
basicAttributes.add("releaseDate");
basicAttributes.add("description");
basicAttributes.add("averageRating");
basicAttributes.add("totalRating");
searchQueryString = "select "
+ "movieID, "
......@@ -336,7 +364,7 @@ public class ClientApplication {
+ "group_concat(genre separator ', ') AS genre, "
+ "releaseDate, "
+ "description, "
+ "averageRating "
+ "totalRating "
+ "from Movies left outer join GenresInMovies using (movieID) where genre like '%%%s%%' group by movieID %s limit 10";
query = String.format(searchQueryString, keywords, sortString);
......@@ -372,6 +400,30 @@ public class ClientApplication {
break;
case "person":
while (!exitLoop) {
System.out.println("Type \"n\" to sort by name. Type \"d\" to sort by date of birth. Press enter to sort default.");
sort = input.nextLine();
if (!sort.equals("n") && !sort.equals("d")) {
if (sort.equals("")) {
exitLoop = true;
} else {
System.out.println("Invalid command.");
}
} else {
exitLoop = true;
}
}
switch (sort) {
case "n":
sortString = "order by name";
break;
case "d":
sortString = "order by dateOfBirth desc";
break;
default: break;
}
basicAttributes.add("name");
basicAttributes.add("birthName");
basicAttributes.add("height");
......@@ -1202,10 +1254,10 @@ public class ClientApplication {
query = c.prepareStatement("insert into People values (?, ?, ?, ?, ?, ?, ?)");
query.setString(1, "nm" + maxId);
query.setString(2, values.get(name));
query.setString(3, values.get(birthName));
query.setInt(4, Integer.parseInt(values.get(height)));
query.setString(5, values.get(biography));
query.setString(6, values.get(birthDetails));
query.setString(3, values.containsKey(birthName) ? values.get(birthName) : "");
query.setInt(4, values.containsKey(height) ? Integer.parseInt(values.get(height)) : 0);
query.setString(5, values.containsKey(biography) ? values.get(biography) : "");
query.setString(6, values.containsKey(birthDetails) ? values.get(birthDetails) : "");
query.setTimestamp(7, values.containsKey(dateOfBirth) ? new java.sql.Timestamp(format.parse(values.get(dateOfBirth) + " 00:00:00").getTime()) : null);
query.execute();
......@@ -1213,8 +1265,8 @@ public class ClientApplication {
query = c.prepareStatement("insert into DeadPeople values (?, ?, ?, ?)");
query.setString(1, "nm" + maxId);
query.setTimestamp(2, values.containsKey(dateOfDeath) ? new java.sql.Timestamp(format.parse(values.get(dateOfDeath) + " 00:00:00").getTime()) : null);
query.setString(3, values.get(placeOfDeath));
query.setString(4, values.get(reasonOfDeath));
query.setString(3, values.containsKey(placeOfDeath) ? values.get(placeOfDeath) : "");
query.setString(4, values.containsKey(reasonOfDeath) ? values.get(reasonOfDeath) : "");
query.execute();
}
} catch (Exception e) {
......@@ -1350,6 +1402,7 @@ public class ClientApplication {
query2.setString(7, personID);
query2.executeUpdate();
System.out.println("Successfully updated person with personID = " + personID);
System.out.println();
break;
case "x":
exitLoop = true;
......
public class Constants {
public static final String db_url = "jdbc:mysql://marmoset03.shoshin.uwaterloo.ca";
public static final String db_user = "";
public static final String db_pwd = "";
}
import java.sql.Date;
public class Movie {
private String movieID;
private String title;
private String originalTitle;
private int year;
private Date releaseDate;
private int duration;
private String description;
private float averageRating;
private int totalRating;
private float metascore;
public Movie(String movieID, String title, String originalTitle, int year, Date releaseDate, int duration, String description, float averageRating, int totalRating, float metascore) {
this.movieID = movieID;
this.title = title;
this.originalTitle = originalTitle;
this.year = year;
this.releaseDate = releaseDate;
this.duration = duration;
this.description = description;
this.averageRating = averageRating;
this.totalRating = totalRating;
this.metascore = metascore;
}
public String getMovieID() {
return this.movieID;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getOriginalTitle() {
return this.originalTitle;
}
public void setOriginalTitle(String originalTitle) {
this.originalTitle = originalTitle;
}
public int getYear() {
return this.year;
}
public void setYear(int year) {
this.year = year;
}
public Date getReleaseDate() {
return this.releaseDate;
}
public void setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
}
public int getDuration() {
return this.duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public float getAverageRating() {
return this.averageRating;
}
public void setAverageRating(float averageRating) {
this.averageRating = averageRating;
}
public int getTotalRating() {
return this.totalRating;
}
public void setTotalRating(int totalRating) {
this.totalRating = totalRating;
}
public float getMetascore() {
return this.metascore;
}
public void setMetascore(float metascore) {
this.metascore = metascore;
}
}
import java.sql.Date;
public class Person {
private String name;
private String originalName;
private int height;
private String biography;
private String birthDetails;
private Date dateOfBirth;
private Date dateOfDeath;
private String placeOfDeath;
private String reasonOfDeath;
public Person(String name, String originalName, int height, String biography, String birthDetails, Date dateOfBirth, Date dateOfDeath, String placeOfDeath, String reasonOfDeath) {
this.name = name;
this.originalName = originalName;
this.height = height;
this.biography = biography;
this.birthDetails = birthDetails;
this.dateOfBirth = dateOfBirth;
this.dateOfDeath = dateOfDeath;
this.placeOfDeath = placeOfDeath;
this.reasonOfDeath = reasonOfDeath;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getOriginalName() {
return this.originalName;
}
public void setOriginalName(String originalName) {
this.originalName = originalName;
}
public int getHeight() {
return this.height;
}
public void setHeight(int height) {
this.height = height;
}
public String getBiography() {
return this.biography;
}
public void setBiography(String biography) {
this.biography = biography;
}
public String getBirthDetails() {
return this.birthDetails;
}
public void setBirthDetails(String birthDetails) {
this.birthDetails = birthDetails;
}
public Date getDateOfBirth() {
return this.dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public Date getDateOfDeath() {
return this.dateOfDeath;
}
public void setDateOfDeath(Date dateOfDeath) {
this.dateOfDeath = dateOfDeath;
}
public String getPlaceOfDeath() {
return this.placeOfDeath;
}
public void setPlaceOfDeath(String placeOfDeath) {
this.placeOfDeath = placeOfDeath;
}
public String getReasonOfDeath() {
return this.reasonOfDeath;
}
public void setReasonOfDeath(String reasonOfDeath) {
this.reasonOfDeath = reasonOfDeath;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment