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

io.robe.admin.quartz.hibernate.HibernateJobProvider Maven / Gradle / Ivy

There is a newer version: 0.5.0.0-1039
Show newest version
package io.robe.admin.quartz.hibernate;

import io.robe.admin.dto.JobEntityDTO;
import io.robe.hibernate.RobeHibernateBundle;
import io.robe.quartz.common.JobInfo;
import io.robe.quartz.common.JobProvider;
import io.robe.quartz.common.TriggerInfo;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.quartz.Job;

import java.util.Iterator;
import java.util.List;

public class HibernateJobProvider extends JobProvider {

    @Override
    public JobInfo getJob(Class clazz) {
        Session session = RobeHibernateBundle.getInstance().getSessionFactory().openSession();
        JobEntity quartzJob = (JobEntity) session.createCriteria(JobEntity.class).add(Restrictions.eq("jobClass", clazz)).uniqueResult();
        if (quartzJob == null)
            return null;

        List triggerEntities = session.createCriteria(TriggerEntity.class).add(Restrictions.eq("jobOid", quartzJob.getOid())).list();
        session.close();

        JobEntityDTO dto = new JobEntityDTO(quartzJob);

        dto.setTriggers(triggerEntities);

        Iterator iterator = triggerEntities.iterator();

        while (iterator.hasNext()) {
            TriggerInfo info = iterator.next();
            if (info instanceof TriggerEntity) {
                TriggerEntity triggerEntity = (TriggerEntity) info;
                if (triggerEntity.getType().equals(TriggerInfo.Type.CRON)) {
                    if (!triggerEntity.isActive()) {
                        iterator.remove();
                    }
                }
            }
        }

        return dto;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy