<commit_before>package de.stups.slottool.data.dao

import de.stups.slottool.data.entities.Log
import groovy.sql.Sql

class LogDAO extends AbstractDAO {

    Set<String> log

    LogDAO(def sql) {
        super(sql)
        this.log= new HashSet<Log>()
    }

    @Override
    protected loadRow(def row) {
        log.add(new Log(row['session_id'] as int, row['src_day'], row['src_time'] as int,
                row['target_day'], row['target_time'] as int, Date.parse(DATE_FORMAT, row['created_at'])))
    }

    @Override
    def getById(def id) {
        throw new UnsupportedOperationException()
    }

    @Override
    String getTableName() {
        return "log"
    }

    @Override
    Iterator iterator() {
        throw new UnsupportedOperationException()
    }

    def addEntry(String session_id, String src_day, String src_time, String target_day, String target_time) {
        log.add(new Log(session_id as int, src_day, src_time as int, target_day, target_time as int, new Date()))
    }

    def persist(Sql sql) {
        for (Log l in log) {
            String query = "INSERT INTO log (session_id, src_day, src_time, target_day, target_time, created_at)" +
                    "VALUES (${l.created_at}, '${l.src_day}', ${l.src_time}, '${l.target_day}', ${l.target_time}, ${l.created_at})"
            sql.executeUpdate(query)
        }
    }
}<commit_msg>Log from Set to Map in order to access entry and update it easily; update method<commit_after>package de.stups.slottool.data.dao

import de.stups.slottool.data.entities.Log
import groovy.sql.Sql

class LogDAO extends AbstractDAO {

    Map<Integer, Log> log

    LogDAO(def sql) {
        super(sql)
        this.log= new HashMap<Integer, Log>()
    }

    @Override
    protected loadRow(def row) {
        log.put(row['session_id'], new Log(row['session_id'] as int, row['src_day'], row['src_time'] as int,
                row['target_day'], row['target_time'] as int, Date.parse(DATE_FORMAT, row['created_at'])))
    }

    @Override
    def getById(def id) {
        throw new UnsupportedOperationException()
    }

    @Override
    String getTableName() {
        return "log"
    }

    @Override
    Iterator iterator() {
        throw new UnsupportedOperationException()
    }

    def addEntry(int session_id, String src_day, int src_time, String target_day, int target_time) {
        if (log[session_id]) {
            updateLog(session_id, target_day, target_time)
        } else {
            log.put(session_id, new Log(session_id, src_day, src_time, target_day, target_time, new Date()))
        }
    }

    def updateLog(int session_id, String target_day, int target_time) {
        log[session_id].target_day = target_day
        log[session_id].target_time = target_time
        log[session_id].created_at = new Date()
    }

    def persist(Sql sql) {
        for (Log l in log) {
            String query = "INSERT INTO log (session_id, src_day, src_time, target_day, target_time, created_at)" +
                    "VALUES (${l.created_at}, '${l.src_day}', ${l.src_time}, '${l.target_day}', ${l.target_time}, ${l.created_at})"
            sql.executeUpdate(query)
        }
    }
}
{'fraction_non_alphanumeric': 0.12173639509279648, 'fraction_numerical': 0.0, 'mean_word_length': 2.745583038869258, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6957544', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1014, 'n_words': 245}