All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.evasion.plugin.common.dao.EventDataDaoImpl Maven / Gradle / Ivy

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evasion.plugin.common.dao;

import com.evasion.dao.api.AbstractJPAGenericDAO;
import com.evasion.plugin.common.entity.EventData;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.persistence.Query;
import javax.persistence.TemporalType;
import org.apache.commons.lang.StringUtils;

/**
 *
 * @author sebastien
 */
public class EventDataDaoImpl extends AbstractJPAGenericDAO {

    public List selectEventSince(Date since, String code, String plugin) {
        StringBuilder queryString = new StringBuilder("select e from "+EventData.ENTITY_NAME+" e where");
        queryString.append(" e.dateRecordInternal >= :since");
        if (StringUtils.isNotBlank(code)) {
            queryString.append(" and e.code=:code");
        }
        if (StringUtils.isNotBlank(plugin)) {
        queryString.append(" and e.plugin=:plugin");
        }
        queryString.append(" order by e.dateRecordInternal asc");

        Query query= getEntityManager().createQuery(queryString.toString());
        if (StringUtils.isNotBlank(code)) {
        query.setParameter("code", code);
        }
        if (StringUtils.isNotBlank(plugin)) {
        query.setParameter("plugin", plugin);
        }
        Calendar calendar =new GregorianCalendar();
        calendar.setTime(since);
        query.setParameter("since", calendar, TemporalType.TIMESTAMP);

        return query.getResultList();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy