<commit_before>package com.devicehive.dao;

import com.devicehive.exceptions.HiveWebsocketException;
import com.devicehive.model.Device;
import com.devicehive.model.DeviceCommand;
import com.devicehive.model.User;

import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ssidorenko
 * Date: 20.06.13
 * Time: 15:36
 * To change this template use File | Settings | File Templates.
 */
public class DeviceCommandDAO {

    @PersistenceContext(unitName = "devicehive")
    private EntityManager em;


    @Transactional
    public void saveCommand(DeviceCommand deviceCommand) {
        em.persist(deviceCommand);
    }


    @Transactional
    public DeviceCommand updateCommand(DeviceCommand update, Device expectedDevice) {
        DeviceCommand cmd = em.find(DeviceCommand.class, update.getId(), LockModeType.WRITE);
        if (!cmd.getDevice().getId().equals(expectedDevice.getId())) {
            throw new HiveWebsocketException("Device tries to update incorrect command");
        }
        cmd.setCommand(update.getCommand());
        cmd.setParameters(update.getParameters());
        cmd.setLifetime(update.getLifetime());
        cmd.setFlags(update.getFlags());
        cmd.setStatus(update.getStatus());
        cmd.setResult(update.getResult());
        return em.merge(cmd);
    }


    @Transactional
    public DeviceCommand findById(Long id) {
        return em.find(DeviceCommand.class, id);
    }


    @Transactional
    public List<DeviceCommand> getNewerThan(Device device, Date timestamp) {
        TypedQuery<DeviceCommand> query = em.createNamedQuery("DeviceCommand.getNewerThan", DeviceCommand.class);
        query.setParameter("timestamp", timestamp);
        query.setParameter("device", device);
        return query.getResultList();
    }
}<commit_msg>DAO class should not throw HiveWebsocketException<commit_after>package com.devicehive.dao;

import com.devicehive.exceptions.HiveException;
import com.devicehive.exceptions.HiveWebsocketException;
import com.devicehive.model.Device;
import com.devicehive.model.DeviceCommand;
import com.devicehive.model.User;

import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ssidorenko
 * Date: 20.06.13
 * Time: 15:36
 * To change this template use File | Settings | File Templates.
 */
public class DeviceCommandDAO {

    @PersistenceContext(unitName = "devicehive")
    private EntityManager em;


    @Transactional
    public void saveCommand(DeviceCommand deviceCommand) {
        em.persist(deviceCommand);
    }


    @Transactional
    public DeviceCommand updateCommand(DeviceCommand update, Device expectedDevice) {
        DeviceCommand cmd = em.find(DeviceCommand.class, update.getId(), LockModeType.WRITE);
        if (!cmd.getDevice().getId().equals(expectedDevice.getId())) {
            throw new HiveException("Device tries to update incorrect command");
        }
        cmd.setCommand(update.getCommand());
        cmd.setParameters(update.getParameters());
        cmd.setLifetime(update.getLifetime());
        cmd.setFlags(update.getFlags());
        cmd.setStatus(update.getStatus());
        cmd.setResult(update.getResult());
        return em.merge(cmd);
    }


    @Transactional
    public DeviceCommand findById(Long id) {
        return em.find(DeviceCommand.class, id);
    }


    @Transactional
    public List<DeviceCommand> getNewerThan(Device device, Date timestamp) {
        TypedQuery<DeviceCommand> query = em.createNamedQuery("DeviceCommand.getNewerThan", DeviceCommand.class);
        query.setParameter("timestamp", timestamp);
        query.setParameter("device", device);
        return query.getResultList();
    }
}
{'fraction_non_alphanumeric': 0.10600534889375152, 'fraction_numerical': 0.004862630683199611, 'mean_word_length': 3.915173237753883, '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': '5155590', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1140, 'n_words': 231}