<commit_before>package fi.otavanopisto.kuntaapi.server.persistence.dao;

import java.time.OffsetDateTime;

import javax.enterprise.context.ApplicationScoped;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import fi.otavanopisto.kuntaapi.server.persistence.model.Task;
import fi.otavanopisto.kuntaapi.server.persistence.model.TaskQueue;
import fi.otavanopisto.kuntaapi.server.persistence.model.Task_;

/**
 * DAO class for Task entity
 * 
 * @author <NAME>
 */
@ApplicationScoped
public class TaskDAO extends AbstractDAO<Task> {
  
  /**
   * Creates new task entity
   * 
   * @param queue queue the task belongs to
   * @param uniqueId unique id for the task. Property is used to ensure that task is added only once to the queue
   * @param priority whether the task is a priority task or not
   * @param data serialized task data
   * @param created creation time
   * @return created task
   */
  public Task create(TaskQueue queue, String uniqueId, Boolean priority, byte[] data, OffsetDateTime created) {
    Task task = new Task();
    task.setUniqueId(uniqueId);
    task.setCreated(created);
    task.setData(data);
    task.setPriority(priority);
    task.setQueue(queue);
    return persist(task);<commit_msg>Changed TaskDAO to flush JPA state on create so the database would receive the task as soon as possible <commit_after>package fi.otavanopisto.kuntaapi.server.persistence.dao;

import java.time.OffsetDateTime;

import javax.enterprise.context.ApplicationScoped;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import fi.otavanopisto.kuntaapi.server.persistence.model.Task;
import fi.otavanopisto.kuntaapi.server.persistence.model.TaskQueue;
import fi.otavanopisto.kuntaapi.server.persistence.model.Task_;

/**
 * DAO class for Task entity
 * 
 * @author <NAME>
 */
@ApplicationScoped
public class TaskDAO extends AbstractDAO<Task> {
  
  /**
   * Creates new task entity
   * 
   * @param queue queue the task belongs to
   * @param uniqueId unique id for the task. Property is used to ensure that task is added only once to the queue
   * @param priority whether the task is a priority task or not
   * @param data serialized task data
   * @param created creation time
   * @return created task
   */
  public Task create(TaskQueue queue, String uniqueId, Boolean priority, byte[] data, OffsetDateTime created) {
    Task task = new Task();
    task.setUniqueId(uniqueId);
    task.setCreated(created);
    task.setData(data);
    task.setPriority(priority);
    task.setQueue(queue);
    Task result = persist(task);
    flush();
    return result;
{'fraction_non_alphanumeric': 0.08831615120274915, 'fraction_numerical': 0.0, 'mean_word_length': 4.400742115027829, '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': '4825935', 'n_tokens_mistral': 833, 'n_tokens_neox': 846, 'n_words': 248}