<commit_before>package system;

import org.apache.commons.io.FileUtils;
import rss.Feed;
import rss.Item;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

/**
 * Class DatabaseAccessObject
 *
 * @author <NAME> (axnion)
 */
public class DatabaseAccessObject {
    private String path;

    DatabaseAccessObject() {
        path = "temp.db";
        try {
            load();
        }
        catch(Exception expt) {
            expt.printStackTrace();
        }
    }

    DatabaseAccessObject(String path) {
        this.path = path;
        try {
            load();
        }
        catch(Exception expt) {
            expt.printStackTrace();
        }
    }

    ArrayList<FeedList> load() throws Exception {
        Statement statement = loadPreparation();
        ArrayList<FeedList> feedLists = loadFeedLists(statement);
        loadFeeds(statement, feedLists);
        loadItems(statement, feedLists);

        return feedLists;
    }

    private Statement loadPreparation() throws Exception {
        if(path.equals("temp.db")) {
            File tempDatabase = new File("temp.db");
            tempDatabase.delete();
        }

        Class.forName("org.sqlite.JDBC");
        Connection connection = DriverManager.getConnection("jdbc:sqlite:" + path);
        Statement statement = connection.createStatement();

        String createFeedListSaveDataTable = "CREATE TABLE IF NOT EXISTS save_data_feed_lists(" +
                "FEEDLISTNAME TEXT PRIMARY KEY UNIQUE NOT NULL, " +
                "SORTING VARCHAR(16)  DEFAULT DATE_DEC NOT NULL);";

        String createFeedSaveDataTable = "CREATE TABLE IF NOT EXISTS save_data_feeds" +
                " (URLTOXML     TEXT    NOT NULL," +
                " FEEDLISTNAME  TEXT    NOT NULL);";

        statement.executeUpdate(createFeedListSaveDataTable);
        statement.executeUpdate(createFeedSaveDataTable);

        return statement;
    }

    private ArrayList<FeedList> loadFeedLists(Statement statement) throws Exception {
        ArrayList<FeedList> feedLists = new ArrayList<>();
        String query = "SELECT * FROM save_data_feed_lists;";

        ResultSet results = statement.executeQuery(query);
        while(results.next()) {
            feedLists.add(new FeedList(results.getString("feedlistname"),
                    results.getString("sorting")));
        }

        return feedLists;
    }

    private void loadFeeds(Statement statement, ArrayList<FeedList> feedLists) throws Exception {
        for(FeedList feedList : feedLists) {
            String query = "SELECT * FROM save_data_feeds WHERE FEEDLISTNAME='" +
                    feedList.getName() + "';";

            ResultSet results = statement.executeQuery(query);
            while(results.next()) {
                feedList.add(results.getString("urltoxml"));
            }
        }
    }

    private void loadItems(Statement statement, ArrayList<FeedList> feedLists) throws Exception  {
        String query;

        for(FeedList feedList : feedLists) {
            for(Item item : feedList.getAllItems()) {
                query = "SELECT * FROM '" + feedList.getName() + "' WHERE ID='" +
                        item.getId() + "';";

                ResultSet results = statement.executeQuery(query);
                results.next();
                item.setVisited(results.getBoolean("VISITED"));
                item.setStarred(results.getBoolean("STARRED"));
            }
        }
    }

    void save() {

    }

    void copy(String destination) throws Exception {
        FileUtils.copyFile(new File(path), new File(destination));
        path = destination;
    }

    String getPath() {
        return path;
    }

    void setPath(String newPath) {
        path = newPath;
    }
}
<commit_msg>Implemented save functionallity in DAO<commit_after>package system;

import org.apache.commons.io.FileUtils;
import rss.Feed;
import rss.Item;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

/**
 * Class DatabaseAccessObject
 *
 * @author <NAME> (axnion)
 */
public class DatabaseAccessObject {
    private String path;

    DatabaseAccessObject() {
        path = "temp.db";
        try {
            load();
        }
        catch(Exception expt) {
            expt.printStackTrace();
        }
    }

    DatabaseAccessObject(String path) {
        this.path = path;
        try {
            load();
        }
        catch(Exception expt) {
            expt.printStackTrace();
        }
    }

    /*
    ------------------------------------ LOAD FROM DATABASE ----------------------------------------
    */

    ArrayList<FeedList> load() throws Exception {
        Connection connection = loadPrep();
        Statement statement = connection.createStatement();

        ArrayList<FeedList> feedLists = loadFeedLists(statement);
        loadFeeds(statement, feedLists);
        loadItems(statement, feedLists);

        connection.commit();
        statement.close();
        connection.close();

        return feedLists;
    }

    private Connection loadPrep() throws Exception {
        if(path.equals("temp.db")) {
            File tempDatabase = new File("temp.db");
            tempDatabase.delete();
        }

        Class.forName("org.sqlite.JDBC");
        Connection connection = DriverManager.getConnection("jdbc:sqlite:" + path);
        connection.setAutoCommit(false);
        Statement statement = connection.createStatement();

        String createFeedListSaveDataTable = "CREATE TABLE IF NOT EXISTS save_data_feed_lists(" +
                "FEEDLISTNAME TEXT PRIMARY KEY UNIQUE NOT NULL, " +
                "SORTING VARCHAR(16)  DEFAULT DATE_DEC NOT NULL);";

        String createFeedSaveDataTable = "CREATE TABLE IF NOT EXISTS save_data_feeds" +
                " (URLTOXML     TEXT    NOT NULL," +
                " FEEDLISTNAME  TEXT    NOT NULL);";

        statement.executeUpdate(createFeedListSaveDataTable);
        statement.executeUpdate(createFeedSaveDataTable);
        statement.close();

        return connection;
    }

    private ArrayList<FeedList> loadFeedLists(Statement statement) throws Exception {
        ArrayList<FeedList> feedLists = new ArrayList<>();
        String query = "SELECT * FROM save_data_feed_lists;";

        ResultSet results = statement.executeQuery(query);
        while(results.next()) {
            feedLists.add(new FeedList(results.getString("feedlistname"),
                    results.getString("sorting")));
        }

        return feedLists;
    }

    private void loadFeeds(Statement statement, ArrayList<FeedList> feedLists) throws Exception {
        for(FeedList feedList : feedLists) {
            String query = "SELECT * FROM save_data_feeds WHERE FEEDLISTNAME='" +
                    feedList.getName() + "';";

            ResultSet results = statement.executeQuery(query);
            while(results.next()) {
                feedList.add(results.getString("urltoxml"));
            }
        }
    }

    private void loadItems(Statement statement, ArrayList<FeedList> feedLists) throws Exception  {
        String query;

        for(FeedList feedList : feedLists) {
            for(Item item : feedList.getAllItems()) {
                query = "SELECT * FROM '" + feedList.getName() + "' WHERE ID='" +
                        item.getId() + "';";

                ResultSet results = statement.executeQuery(query);
                results.next();
                item.setVisited(results.getBoolean("VISITED"));
                item.setStarred(results.getBoolean("STARRED"));
            }
        }
    }

    /*
    ------------------------------------ SAVE TO DATABASE ------------------------------------------
    */

    void save(ArrayList<FeedList> feedLists) throws Exception {
        Connection connection = savePrep();
        Statement statement = connection.createStatement();

        saveFeedLists(statement, feedLists);
        saveFeeds(statement, feedLists);
        saveItems(statement, feedLists);

        connection.commit();
        statement.close();
        connection.close();
    }

    private Connection savePrep() throws Exception {
        Class.forName("org.sqlite.JDBC");
        Connection connection = DriverManager.getConnection("jdbc:sqlite:" + path);
        connection.setAutoCommit(false);
        return connection;
    }

    private void saveFeedLists(Statement statement, ArrayList<FeedList> feedLists) throws Exception {
        for(FeedList feedList : feedLists) {
            String createFeedListTableQuery =  "CREATE TABLE IF NOT EXISTS" + feedList.getName() +
                    " (ID           TEXT        PRIMARY KEY     UNIQUE     NOT NULL," +
                    " VISITED       BOOLEAN     NOT NULL," +
                    " STARRED       BOOLEAN     NOT NULL);";

            String addFeedListToSortTable = "INSERT INTO save_data_feed_lists (FEEDLISTNAME) " +
                    "VALUES ('" + feedList.getName() + "')";

            statement.executeUpdate(createFeedListTableQuery);
            statement.executeUpdate(addFeedListToSortTable);
        }
    }

    private void saveFeeds(Statement statement, ArrayList<FeedList> feedLists) throws Exception {
        for(FeedList feedList : feedLists) {
            for(Feed feed : feedList.getFeeds()) {
                String addFeedQuery = "INSERT INTO save_data_feeds (URLTOXML,FEEDLISTNAME) " +
                        "VALUES ('" + feed.getUrlToXML() + "','" + feedList.getName() + "');";

                statement.executeUpdate(addFeedQuery);
            }
        }
    }

    private void saveItems(Statement statement, ArrayList<FeedList> feedLists) throws Exception {
        for(FeedList feedList : feedLists) {
            for(Item item : feedList.getAllItems()) {
                String addItemQuery = "INSERT OR IGNORE INTO " + feedList.getName() +
                        " (ID,VISITED,STARRED) VALUES ('" + item.getId() + "','" +
                        item.isVisited() + "','" + item.isStarred() + "');";

                statement.executeUpdate(addItemQuery);
            }
        }
    }

    void copy(String destination) throws Exception {
        FileUtils.copyFile(new File(path), new File(destination));
        path = destination;
    }

    String getPath() {
        return path;
    }

    void setPath(String newPath) {
        path = newPath;
    }
}

{'fraction_non_alphanumeric': 0.1174804041930305, 'fraction_numerical': 0.00037775049579752575, 'mean_word_length': 2.0829694323144103, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6638567', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2680, 'n_words': 590}