<commit_before>package modelLayer;

import tools.QuickHash;
import tools.databaseQuery;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

// Static import the dbQuery tools
import static tools.databaseQuery.dbQuery;
import static tools.databaseQuery.dbQueryRow;
import static tools.databaseQuery.dbQueryField;
import static tools.databaseQuery.dbExecute;

public class Rooms {
    // Not really used for anything, just reminders what fields are in the database
    private int roomID; // the room ID
    private String roomDescription; // the room description
    private int roomSize; // Type of room, 1 for 1 person room, 2 for 2 person room, 3 for 3 person room etc.
    private int roomStatus; // 0 free, 1 taken
    private float roomDiscount; // the discount applied to this room by default (if it's a haunted room for example)
    private float roomPricePerNight; // the price of the room pr. night

    // Get all data for all rooms
    public ArrayList<LinkedHashMap> getAllRooms() {
        Map<String, String> parameters = new QuickHash();
        try {
            return dbQuery("SELECT * FROM rooms", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    // Get all data for a single room by roomID
    public LinkedHashMap getRoomByRoomID(int roomID) {
        Map<String, String> parameters = new QuickHash(":roomID", String.valueOf(roomID));
        try {
            return dbQueryRow("SELECT * FROM rooms WHERE roomID = :roomID", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    // Get all rooms by size..
    public ArrayList<LinkedHashMap> getRoomByRoomSize(int roomSize) {
        Map<String, String> parameters = new QuickHash(":roomSize", String.valueOf(roomSize));
        try {
            return dbQuery("SELECT * FROM rooms WHERE roomSize = :roomSize", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    public ArrayList<LinkedHashMap> getRoomByRoomStatus(int roomStatus) {
        Map<String, String> parameters = new QuickHash(":roomStatus", String.valueOf(roomStatus));
        try {
            return dbQuery("SELECT * FROM rooms WHERE roomStatus = :roomStatus", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    public ArrayList<LinkedHashMap> getRoomByRoomPricePerNight(float roomPricePerNight) {
        Map<String, String> parameters = new QuickHash(":roomPricePerNight", String.valueOf(roomPricePerNight));
        try {
            return dbQuery("SELECT * FROM rooms WHERE roomPricePerNight = :roomPricePerNight", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    public int insertUpdateRoom(String roomDescription, int roomSize, int roomStatus, float roomDiscount, float roomPricePerNight) {
        // check if it exists, if it doesn't update it.. also fuck microsoft sql server so hard..
        // MySQL: INSERT INTO table () VALUES () ON DUPLICATE KEY UPDATE key = value ....
        // MSSQL: http://i.imgur.com/zT1VT4L.png <- that.. tha... wow..
        // Also: http://i.imgur.com/NiyJuVg.png - seriously, upgrade your shitty mssql server you useless pieces of shit
        // Fucking mickey mouse education...

        int id;
        // Get ID
        Map<String, String> parameters = new QuickHash(":roomDescription", String.valueOf(roomDescription), ":roomSize", String.valueOf(roomSize), ":roomStatus", String.valueOf(roomStatus), ":roomDiscount", String.valueOf(roomDiscount), ":roomPricePerNight", String.valueOf(roomPricePerNight));
        try {
            id = Integer.parseInt(dbQueryField("SELECT roomID FROM rooms WHERE roomDescription = :roomDescription AND roomSize = :roomSize AND roomStatus = :roomStatus AND roomDiscount = :roomDiscount AND roomPricePerNight = :roomPricePerNight", "roomID", parameters));
        } catch (SQLException e) {
            id = 0;
        }
        
        // If id is larger than 0 then we update, else we insert
        if(id > 0) {
            Map<String, String> updateParameters = new QuickHash(":roomID", String.valueOf(id), ":roomDescription", String.valueOf(roomDescription), ":roomSize", String.valueOf(roomSize), ":roomStatus", String.valueOf(roomStatus), ":roomDiscount", String.valueOf(roomDiscount), ":roomPricePerNight", String.valueOf(roomPricePerNight));
            try {
                dbExecute("UPDATE rooms SET roomDescription = :roomDescription, roomSize = :roomSize, roomStatus = :roomStatus, roomDiscount = :roomDiscount, roomPricePerNight = :roomPricePerNight WHERE roomID = :roomID", updateParameters);
            } catch (SQLException e) {<commit_msg>more comments with more rage<commit_after>package modelLayer;

import tools.QuickHash;
import tools.databaseQuery;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

// Static import the dbQuery tools
import static tools.databaseQuery.dbQuery;
import static tools.databaseQuery.dbQueryRow;
import static tools.databaseQuery.dbQueryField;
import static tools.databaseQuery.dbExecute;

public class Rooms {
    // Not really used for anything, just reminders what fields are in the database
    private int roomID; // the room ID
    private String roomDescription; // the room description
    private int roomSize; // Type of room, 1 for 1 person room, 2 for 2 person room, 3 for 3 person room etc.
    private int roomStatus; // 0 free, 1 taken
    private float roomDiscount; // the discount applied to this room by default (if it's a haunted room for example)
    private float roomPricePerNight; // the price of the room pr. night

    // Get all data for all rooms
    public ArrayList<LinkedHashMap> getAllRooms() {
        Map<String, String> parameters = new QuickHash();
        try {
            return dbQuery("SELECT * FROM rooms", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    // Get all data for a single room by roomID
    public LinkedHashMap getRoomByRoomID(int roomID) {
        Map<String, String> parameters = new QuickHash(":roomID", String.valueOf(roomID));
        try {
            return dbQueryRow("SELECT * FROM rooms WHERE roomID = :roomID", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    // Get all rooms by size..
    public ArrayList<LinkedHashMap> getRoomByRoomSize(int roomSize) {
        Map<String, String> parameters = new QuickHash(":roomSize", String.valueOf(roomSize));
        try {
            return dbQuery("SELECT * FROM rooms WHERE roomSize = :roomSize", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    public ArrayList<LinkedHashMap> getRoomByRoomStatus(int roomStatus) {
        Map<String, String> parameters = new QuickHash(":roomStatus", String.valueOf(roomStatus));
        try {
            return dbQuery("SELECT * FROM rooms WHERE roomStatus = :roomStatus", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    public ArrayList<LinkedHashMap> getRoomByRoomPricePerNight(float roomPricePerNight) {
        Map<String, String> parameters = new QuickHash(":roomPricePerNight", String.valueOf(roomPricePerNight));
        try {
            return dbQuery("SELECT * FROM rooms WHERE roomPricePerNight = :roomPricePerNight", parameters);
        } catch (SQLException e) {
            return null;
        }
    }

    public int insertUpdateRoom(String roomDescription, int roomSize, int roomStatus, float roomDiscount, float roomPricePerNight) {
        // check if it exists, if it doesn't update it.. also fuck microsoft sql server so hard.
        // MySQL: INSERT INTO table () VALUES () ON DUPLICATE KEY UPDATE key = value ....
        // MSSQL: http://i.imgur.com/zT1VT4L.png <- that.. tha... wow..
        // Also: http://i.imgur.com/NiyJuVg.png - seriously, upgrade your shitty mssql server you useless assholes.
        // Fucking mickey mouse education.
        // Ps. MSSQL is the ISIS of the database server world.

        int id;
        // Get ID
        Map<String, String> parameters = new QuickHash(":roomDescription", String.valueOf(roomDescription), ":roomSize", String.valueOf(roomSize), ":roomStatus", String.valueOf(roomStatus), ":roomDiscount", String.valueOf(roomDiscount), ":roomPricePerNight", String.valueOf(roomPricePerNight));
        try {
            id = Integer.parseInt(dbQueryField("SELECT roomID FROM rooms WHERE roomDescription = :roomDescription AND roomSize = :roomSize AND roomStatus = :roomStatus AND roomDiscount = :roomDiscount AND roomPricePerNight = :roomPricePerNight", "roomID", parameters));
        } catch (SQLException e) {
            id = 0;
        }

        // If id is larger than 0 then we update, else we insert
        if(id > 0) {
            Map<String, String> updateParameters = new QuickHash(":roomID", String.valueOf(id), ":roomDescription", String.valueOf(roomDescription), ":roomSize", String.valueOf(roomSize), ":roomStatus", String.valueOf(roomStatus), ":roomDiscount", String.valueOf(roomDiscount), ":roomPricePerNight", String.valueOf(roomPricePerNight));
            try {
                dbExecute("UPDATE rooms SET roomDescription = :roomDescription, roomSize = :roomSize, roomStatus = :roomStatus, roomDiscount = :roomDiscount, roomPricePerNight = :roomPricePerNight WHERE roomID = :roomID", updateParameters);
            } catch (SQLException e) {
{'fraction_non_alphanumeric': 0.09897682188348299, 'fraction_numerical': 0.002714554186677803, 'mean_word_length': 3.0588983050847456, 'pattern_counts': {'":': 30, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2959358', 'n_tokens_mistral': 2581, 'n_tokens_neox': 2490, 'n_words': 830}