org.accesointeligente.server.robots.RequestUpdater.java Source code

Java tutorial

Introduction

Here is the source code for org.accesointeligente.server.robots.RequestUpdater.java

Source

/**
 * Acceso Inteligente
 *
 * Copyright (C) 2010-2012 Fundacin Ciudadano Inteligente
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.accesointeligente.server.robots;

import org.accesointeligente.model.Request;
import org.accesointeligente.server.HibernateUtil;
import org.accesointeligente.shared.RequestStatus;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import java.util.List;

public class RequestUpdater {
    private static final Logger logger = Logger.getLogger(RequestUpdater.class);

    public void updateRequests() {
        Session hibernate = null;

        try {
            hibernate = HibernateUtil.getSession();
            hibernate.beginTransaction();
            Criteria criteria = hibernate.createCriteria(Request.class);
            criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
            criteria.setFetchMode("institution", FetchMode.JOIN);
            criteria.add(Restrictions.eq("status", RequestStatus.ERROR));
            criteria.createAlias("institution", "ins").add(Restrictions.eq("ins.masterEnabled", true));
            List<Request> newRequests = criteria.list();
            hibernate.getTransaction().commit();

            for (Request request : newRequests) {
            }
        } catch (Exception ex) {
            if (hibernate != null && hibernate.isOpen() && hibernate.getTransaction().isActive()) {
                hibernate.getTransaction().rollback();
                logger.error("Failure", ex);
            }
        }
    }
}