Example usage for org.hibernate.criterion DetachedCriteria forClass

List of usage examples for org.hibernate.criterion DetachedCriteria forClass

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria forClass.

Prototype

public static DetachedCriteria forClass(Class clazz) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity, by its Class.

Usage

From source file:com.headstrong.teevra.services.component.dao.impl.ComponentTemplateDAOImpl.java

License:Open Source License

public void saveComponentTemplate(ComponentTemplateEO compTemplateToSave) throws ComponentServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(ComponentTemplateEO.class);
    criteria.add(Restrictions.eq("compId", compTemplateToSave.getCompId()));
    criteria.add(Restrictions.eq("templateName", compTemplateToSave.getTemplateName()));

    // fetch the template if it already exists and update it, else insert a
    // new record
    List<ComponentTemplateEO> compTemplateList = super.getByCriteria(criteria);

    if (!compTemplateList.isEmpty()) {
        // matching template exists already. Hence update it with just the
        // serialized configurations
        ComponentTemplateEO existingTemplate = compTemplateList.get(0);
        existingTemplate.setConfigurations(compTemplateToSave.getConfigurations());
        existingTemplate.setModifiedBy(System.getProperty("user.name"));
        existingTemplate.setModifiedDate(new Timestamp(System.currentTimeMillis()));
        compTemplateToSave = existingTemplate;
    } else {/* ww  w  .j a va2  s .  c o  m*/
        // given template is a fresh one for the component
        compTemplateToSave.setCreatedBy(System.getProperty("user.name"));
        compTemplateToSave.setCreatedDate(new Timestamp(System.currentTimeMillis()));
    }
    super.saveOrUpdate(compTemplateToSave);
}

From source file:com.headstrong.teevra.services.process.dao.impl.ProcessDAOImpl.java

License:Open Source License

public List<ProcessEO> getProcesses(ProcessEO criteria) throws ProcessServiceException {

    return super.getByCriteria(
            DetachedCriteria.forClass(ProcessEO.class).add(Restrictions.eq("prcsId", criteria.getPrcsId())));
}

From source file:com.headstrong.teevra.services.process.dao.impl.ProcessDAOImpl.java

License:Open Source License

public void saveProcess(ProcessEO processToSave) throws ProcessServiceException {

    DetachedCriteria criteria = DetachedCriteria.forClass(ProcessEO.class);
    criteria.add(Restrictions.eq("prcsName", processToSave.getPrcsName()));
    // processToSave.getPrcsId() != null, it means the process is not new so
    // we set the modified details whenever the process is to be saved
    if (processToSave.getPrcsId() != null) {
        criteria.add(Restrictions.ne("prcsId", processToSave.getPrcsId()));
        // set process modified details
        processToSave.setModifiedBy(System.getProperty("user.name"));
        processToSave.setModifiedDate(new Timestamp(System.currentTimeMillis()));
    }// ww w. jav  a 2s  .  c  o  m

    List<ProcessEO> processList = super.getByCriteria(criteria);

    if (!processList.isEmpty()) {
        logger.error("Couldn't save process: " + processToSave.getPrcsName()
                + ". A process with the same name already exists in the system");
        throw new UniqueProcessException("A process with the name " + "'" + processToSave.getPrcsName() + "'"
                + " already exists in the system");
    } else {
        super.saveOrUpdate(processToSave);
    }

}

From source file:com.headstrong.teevra.services.processadmin.dao.impl.ProcessRuntimeEventlogDAOImpl.java

License:Open Source License

public List<ProcessRuntimeEventlogEO> getProcessEventLogs(ProcessRuntimeEventlogEO criteria)
        throws ProcessAdminServiceException {
    // TODO citeria specifications to be defined properly
    return super.getByCriteria(DetachedCriteria.forClass(ProcessRuntimeEventlogEO.class)
            .add(Restrictions.eq("prcsRunId", criteria.getPrcsRunId())));
}

From source file:com.headstrong.teevra.services.processadmin.dao.impl.ProcessScheduleDAOImpl.java

License:Open Source License

public void deleteProcessSchedule(Long prcsId) throws ProcessAdminServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(ProcessScheduleEO.class);
    criteria.add(Restrictions.eq("prcsId", prcsId));

    // fetch the schedule to delete
    List<ProcessScheduleEO> prcsScheduleList = super.getByCriteria(criteria);
    // delete the process schedule if it exits
    if (!prcsScheduleList.isEmpty()) {
        super.delete(prcsScheduleList.get(0));
    }/*from  w  w w.  j a  va 2 s.c  o m*/

}

From source file:com.headstrong.teevra.services.processadmin.dao.impl.ProcessScheduleDAOImpl.java

License:Open Source License

public ProcessScheduleEO getProcessSchedule(Long prcsId) throws ProcessAdminServiceException {
    if ((prcsId == null)) {
        return null;
    }/*from  w w  w .  j  av a2 s  . co  m*/

    List<ProcessScheduleEO> scheduleList = super.getByCriteria(
            DetachedCriteria.forClass(ProcessScheduleEO.class).add(Restrictions.eq("prcsId", prcsId)));
    return (scheduleList.size() > 0) ? scheduleList.get(0) : null;
}

From source file:com.headstrong.teevra.services.processadmin.dao.impl.ProcessScheduleDAOImpl.java

License:Open Source License

public void saveProcessSchedule(ProcessScheduleEO processScheduleToSave) throws ProcessAdminServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(ProcessScheduleEO.class);
    criteria.add(Restrictions.eq("prcsId", processScheduleToSave.getPrcsId()));

    // fetch the schedule, if it already exists update it, else insert a
    // new record
    List<ProcessScheduleEO> prcsScheduleList = super.getByCriteria(criteria);

    if (!prcsScheduleList.isEmpty()) {
        // matching schedule exists already. update the modified fields
        ProcessScheduleEO temp = prcsScheduleList.get(0);
        temp.setRecurrenceType(processScheduleToSave.getRecurrenceType());
        temp.setRecurrence(processScheduleToSave.getRecurrence());
        temp.setModifiedBy(System.getProperty("user.name"));
        temp.setModifiedDate(new Timestamp(System.currentTimeMillis()));
        processScheduleToSave = temp;//from   w w  w  .  j a  v a2  s .  c om
    } else {
        // given schedule is a fresh one, hence update the created fileds
        processScheduleToSave.setCreatedBy(System.getProperty("user.name"));
        processScheduleToSave.setCreatedDate(new Timestamp(System.currentTimeMillis()));
    }
    // save or update the schedule
    super.saveOrUpdate(processScheduleToSave);
}

From source file:com.headstrong.teevra.services.refdata.dao.impl.CacheReloadScheduleDAOImpl.java

License:Open Source License

public void deleteCacheReloadSchedule(String cacheName) throws SchedulingException {
    DetachedCriteria criteria = DetachedCriteria.forClass(CacheReloadScheduleEO.class);
    criteria.add(Restrictions.eq("cacheName", cacheName));

    // fetch the schedule to delete
    List<CacheReloadScheduleEO> cacheReloadScheduleList = super.getByCriteria(criteria);
    // delete the cache schedule if it exits
    if (!cacheReloadScheduleList.isEmpty()) {
        super.delete(cacheReloadScheduleList.get(0));
    }//  w w w .  j  a  v  a 2 s  .  c om

}

From source file:com.headstrong.teevra.services.refdata.dao.impl.CacheReloadScheduleDAOImpl.java

License:Open Source License

public CacheReloadScheduleEO getCacheReloadSchedule(String cacheName) throws SchedulingException {
    if ((cacheName == null)) {
        return null;
    }//from   w ww.j a v  a  2 s  .c o  m

    List<CacheReloadScheduleEO> scheduleList = super.getByCriteria(DetachedCriteria
            .forClass(CacheReloadScheduleEO.class).add(Restrictions.eq("cacheName", cacheName)));
    return (scheduleList.size() > 0) ? scheduleList.get(0) : null;
}

From source file:com.headstrong.teevra.services.refdata.dao.impl.CacheReloadScheduleDAOImpl.java

License:Open Source License

public void saveCacheReloadSchedule(CacheReloadScheduleEO scheduleToSave) throws SchedulingException {
    DetachedCriteria criteria = DetachedCriteria.forClass(CacheReloadScheduleEO.class);
    criteria.add(Restrictions.eq("cacheName", scheduleToSave.getCacheName()));

    // fetch the schedule, if it already exists update it, else insert a
    // new record
    List<CacheReloadScheduleEO> scheduleList = super.getByCriteria(criteria);

    if (!scheduleList.isEmpty()) {
        // matching schedule exists already. update the modified fields
        CacheReloadScheduleEO temp = scheduleList.get(0);
        temp.setRecurrenceType(scheduleToSave.getRecurrenceType());
        temp.setRecurrence(scheduleToSave.getRecurrence());
        temp.setModifiedBy(System.getProperty("user.name"));
        temp.setModifiedDate(new Timestamp(System.currentTimeMillis()));
        scheduleToSave = temp;/*  w  w  w .  j  a  v a  2s. c o  m*/
    } else {
        // given schedule is a fresh one, hence update the created fields
        scheduleToSave.setCreatedBy(System.getProperty("user.name"));
        scheduleToSave.setCreatedDate(new Timestamp(System.currentTimeMillis()));
    }
    // save or update the schedule
    super.saveOrUpdate(scheduleToSave);
}