Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: converted SQL statements to uppercase
  • Loading branch information
Priyanjoli-Mukherjee committed Aug 3, 2025
commit 284a90cfaf3e95fa1a90ccb2b97a4cbbcfc0d947
32 changes: 16 additions & 16 deletions src/main/java/com/heroku/java/concerto/ConcertoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ConcertoService(DataSource dataSource, AuthenticationService authenticati
}

private void saveArtists(Connection connection, Artist[] artists) throws SQLException {
String query = "insert into artist (id, name, genre, image, image_offset, description, tour) values ";
String query = "INSERT INTO artist (id, name, genre, image, image_offset, description, tour) VALUES ";
String[] values = new String[artists.length];
for (int i = 0; i < artists.length; i++) {
Artist artist = artists[i];
Expand Down Expand Up @@ -71,7 +71,7 @@ private Artist[] generateArtists(Connection connection) throws SQLException {
}

private void saveCities(Connection connection, City[] cities) throws SQLException {
String query = "insert into city (id, image, image_offset, name, state, locations) values ";
String query = "INSERT INTO city (id, image, image_offset, name, state, locations) VALUES ";
String[] values = new String[cities.length];
for (int i = 0; i < cities.length; i++) {
City city = cities[i];
Expand Down Expand Up @@ -127,7 +127,7 @@ private City[] generateCities(Connection connection) throws SQLException {
}

private void saveTickets(Connection connection, Ticket[] tickets) throws SQLException {
String query = "insert into ticket (id, amount_available, price, seat_group) values ";
String query = "INSERT INTO ticket (id, amount_available, price, seat_group) VALUES ";
String[] values = new String[tickets.length];
for (int i = 0; i < tickets.length; i++) {
Ticket ticket = tickets[i];
Expand All @@ -153,7 +153,7 @@ private Ticket[] generateTickets(Connection connection) throws SQLException {
}

private void saveVenues(Connection connection, Venue[] venues) throws SQLException {
String query = "insert into venue (id, city_id, location, timestamp) values ";
String query = "INSERT INTO venue (id, city_id, location, timestamp) VALUES ";
String[] values = new String[venues.length];
for (int i = 0; i < venues.length; i++) {
Venue venue = venues[i];
Expand Down Expand Up @@ -188,7 +188,7 @@ private Venue[] generateVenues(Connection connection, City[] cities) throws SQLE
}

private void saveEvents(Connection connection, Event[] events) throws SQLException {
String query = "insert into event (id, artist_id, ticket_ids, title, venue_id) values ";
String query = "INSERT INTO event (id, artist_id, ticket_ids, title, venue_id) VALUES ";
String[] values = new String[events.length];
for (int i = 0; i < events.length; i++) {
Event event = events[i];
Expand Down Expand Up @@ -224,17 +224,17 @@ public void generateData(String password) throws SQLException {
if (authenticationService.checkAdminPrivilege(password)) {
Connection connection = dataSource.getConnection();
final var statement = connection.createStatement();
statement.executeUpdate("drop table if exists event cascade");
statement.executeUpdate("drop table if exists venue cascade");
statement.executeUpdate("drop table if exists ticket cascade");
statement.executeUpdate("drop table if exists city cascade");
statement.executeUpdate("drop table if exists artist cascade");

statement.executeUpdate("create table artist (id uuid primary key, name text, genre text, image text, image_offset int, description text, tour text)");
statement.executeUpdate("create table city (id uuid primary key, image text, image_offset int, locations text[], name text, state text)");
statement.executeUpdate("create table ticket (id uuid primary key, amount_available int, price decimal, seat_group text)");
statement.executeUpdate("create table venue (id uuid primary key, city_id uuid references city(id), location text, timestamp timestamptz)");
statement.executeUpdate("create table event (id uuid primary key, artist_id uuid references artist(id), ticket_ids uuid[], title text, venue_id uuid references venue(id))");
statement.executeUpdate("DROP TABLE IF EXISTS event CASCADE");
statement.executeUpdate("DROP TABLE IF EXISTS venue CASCADE");
statement.executeUpdate("DROP TABLE IF EXISTS ticket CASCADE");
statement.executeUpdate("DROP TABLE IF EXISTS city CASCADE");
statement.executeUpdate("DROP TABLE IF EXISTS artist CASCADE");

statement.executeUpdate("CREATE TABLE artist (id UUID PRIMARY KEY, name TEXT, genre TEXT, image TEXT, image_offset INT, description TEXT, tour TEXT)");
statement.executeUpdate("CREATE TABLE city (id UUID PRIMARY KEY, image TEXT, image_offset INT, locations TEXT[], name TEXT, state TEXT)");
statement.executeUpdate("CREATE TABLE ticket (id UUID PRIMARY KEY, amount_available INT, price DECIMAL, seat_group TEXT)");
statement.executeUpdate("CREATE TABLE venue (id UUID PRIMARY KEY, city_id UUID REFERENCES city(id), location TEXT, timestamp TIMESTAMPTZ)");
statement.executeUpdate("CREATE TABLE event (id UUID PRIMARY KEY, artist_id UUID REFERENCES artist(id), ticket_ids UUID[], title TEXT, venue_id UUID REFERENCES venue(id))");

Artist[] artists = generateArtists(connection);
City[] cities = generateCities(connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AuthenticationService(DataSource dataSource) {
public boolean checkAdminPrivilege(String password) throws SQLException {
Connection connection = dataSource.getConnection();
final var statement = connection.createStatement();
final var resultSet = statement.executeQuery("select * from role where permission = 'admin'");
final var resultSet = statement.executeQuery("SELECT * FROM role WHERE permission = 'admin'");

while (resultSet.next()) {
String pwd = resultSet.getString("password");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/heroku/java/utils/SQLFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static String formatStringArray(String[] arr) {
for (int i = 0; i < arr.length; i++) {
values[i] = formatString(arr[i]);
}
return "Array [ " + String.join(", ", values) + " ]";
return "ARRAY [ " + String.join(", ", values) + " ]";
}

public static String formatUUIDArray(UUID[] arr) {
Expand Down