<commit_before>package edu.kit.ipd.crowdcontrol.objectservice.database.operations;

import edu.kit.ipd.crowdcontrol.objectservice.database.model.Tables;
import edu.kit.ipd.crowdcontrol.objectservice.database.model.tables.records.TaskRecord;
import org.jooq.DSLContext;
import org.jooq.impl.DSL;

import java.util.Optional;

/**
 * Responsible for the operations involving the creation of tasks.
 * @author LeanderK
 * @version 1.0
 */
public class TasksOperations extends AbstractOperations {
    protected TasksOperations(DSLContext create) {
        super(create);
    }

    /**
     * Inserts the TaskRecord into the database.
     * @param taskRecord the task to create
     * @return the resulting TaskRecord existing in the DB
     */
    public TaskRecord createTask(TaskRecord taskRecord) {
        taskRecord.setIdTask(null);
        return doIfNotRunning(taskRecord.getExperiment(), trans ->
                DSL.using(trans)
                        .insertInto(Tables.TASK)
                        .set(taskRecord)
                        .returning()
                        .fetchOne());
    }

    /**
     * Updates a Task.
     * @param taskRecord the update
     * @return whether the update was successful
     * @throws IllegalArgumentException if the record has no primary key
     */
    public boolean updateTask(TaskRecord taskRecord) throws IllegalArgumentException {
        assertHasPrimaryKey(taskRecord);
        return create.executeUpdate(taskRecord) == 1;
    }

    /**
     * Searches for a task specified by platform and experimentId.
     * @param platform the string of the platform
     * @param experimentId the primary key of the experiment
     * @return the found task or empty if not found
     */
    public Optional<TaskRecord> getTask(String platform, int experimentId) {
        return create.selectFrom(Tables.TASK)
                .where(Tables.TASK.CROWD_PLATFORM.eq(platform))
                .and(Tables.TASK.EXPERIMENT.eq(experimentId))
                .fetchOptional();
    }

    public void deleteTask(TaskRecord result) {
        //TODO leander
    }
}<commit_msg>database: added deleteTask<commit_after>package edu.kit.ipd.crowdcontrol.objectservice.database.operations;

import edu.kit.ipd.crowdcontrol.objectservice.database.model.Tables;
import edu.kit.ipd.crowdcontrol.objectservice.database.model.tables.records.TaskRecord;
import org.jooq.DSLContext;
import org.jooq.impl.DSL;

import java.util.Optional;

import static edu.kit.ipd.crowdcontrol.objectservice.database.model.Tables.*;

/**
 * Responsible for the operations involving the creation of tasks.
 * @author LeanderK
 * @version 1.0
 */
public class TasksOperations extends AbstractOperations {
    protected TasksOperations(DSLContext create) {
        super(create);
    }

    /**
     * Inserts the TaskRecord into the database.
     * @param taskRecord the task to create
     * @return the resulting TaskRecord existing in the DB
     */
    public TaskRecord createTask(TaskRecord taskRecord) {
        taskRecord.setIdTask(null);
        return doIfNotRunning(taskRecord.getExperiment(), trans ->
                DSL.using(trans)
                        .insertInto(TASK)
                        .set(taskRecord)
                        .returning()
                        .fetchOne());
    }

    /**
     * Updates a Task.
     * @param taskRecord the update
     * @return whether the update was successful
     * @throws IllegalArgumentException if the record has no primary key
     */
    public boolean updateTask(TaskRecord taskRecord) throws IllegalArgumentException {
        assertHasPrimaryKey(taskRecord);
        return create.executeUpdate(taskRecord) == 1;
    }

    /**
     * Searches for a task specified by platform and experimentId.
     * @param platform the string of the platform
     * @param experimentId the primary key of the experiment
     * @return the found task or empty if not found
     */
    public Optional<TaskRecord> getTask(String platform, int experimentId) {
        return create.selectFrom(TASK)
                .where(TASK.CROWD_PLATFORM.eq(platform))
                .and(TASK.EXPERIMENT.eq(experimentId))
                .fetchOptional();
    }

    /**
     * deletes a TaskRecord matching the primary key of the passed TaskRecord
     * @param result a TaskRecord with the primary key set
     */
    public void deleteTask(TaskRecord result) {
        assertHasPrimaryKey(result);
        create.deleteFrom(TASK)
                .where(TASK.ID_TASK.eq(result.getIdTask()));
    }
}
{'fraction_non_alphanumeric': 0.08501314636283962, 'fraction_numerical': 0.0013146362839614374, 'mean_word_length': 2.56640625, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3638733', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1218, 'n_words': 324}