Example usage for org.hibernate Criteria setCacheable

List of usage examples for org.hibernate Criteria setCacheable

Introduction

In this page you can find the example usage for org.hibernate Criteria setCacheable.

Prototype

public Criteria setCacheable(boolean cacheable);

Source Link

Document

Enable caching of this query result, provided query caching is enabled for the underlying session factory.

Usage

From source file:com.mercatis.lighthouse3.persistence.environment.hibernate.EnvironmentRegistryImplementation.java

License:Apache License

@Override
protected Criteria entityToCriteria(Session session, Environment entityTemplate) {

    Criteria criteria = super.entityToCriteria(session, entityTemplate);

    if (entityTemplate.getLongName() != null)
        criteria.add(Restrictions.eq("longName", entityTemplate.getLongName()));

    if (entityTemplate.getDescription() != null)
        criteria.add(Restrictions.eq("description", entityTemplate.getDescription()));

    if (entityTemplate.getContact() != null)
        criteria.add(Restrictions.eq("contact", entityTemplate.getContact()));

    if (entityTemplate.getContactEmail() != null)
        criteria.add(Restrictions.eq("contactEmail", entityTemplate.getContactEmail()));

    criteria.setCacheable(true);

    return criteria;
}

From source file:com.mercatis.lighthouse3.persistence.environment.hibernate.ProcessTaskRegistryImplementation.java

License:Apache License

@Override
protected Criteria entityToCriteria(Session session, ProcessTask entityTemplate) {
    Criteria criteria = super.entityToCriteria(session, entityTemplate);

    if (entityTemplate.getLongName() != null)
        criteria.add(Restrictions.eq("longName", entityTemplate.getLongName()));

    if (entityTemplate.getVersion() != null)
        criteria.add(Restrictions.eq("version", entityTemplate.getVersion()));

    if (entityTemplate.getDescription() != null)
        criteria.add(Restrictions.eq("description", entityTemplate.getDescription()));

    if (entityTemplate.getContact() != null)
        criteria.add(Restrictions.eq("contact", entityTemplate.getContact()));

    if (entityTemplate.getContactEmail() != null)
        criteria.add(Restrictions.eq("contactEmail", entityTemplate.getContactEmail()));

    for (Entry<String, String> swimlane : entityTemplate.getSwimlaneData().entrySet()) {
        criteria.add(Restrictions.sqlRestriction(
                "exists (select psl.* from PROCESS_SWIMLANES psl where {alias}.STC_ID = psl.PRO_ID and psl.SWIMLANE = ? and psl.PRO_CODE = ?)",
                new String[] { swimlane.getValue(), swimlane.getKey() },
                new Type[] { StringType.INSTANCE, StringType.INSTANCE }));
    }//from  ww  w .ja v a2  s  .com

    for (Tuple<String, String> transition : entityTemplate.getTransitionData()) {
        criteria.add(Restrictions.sqlRestriction(
                "exists (select pst.* from PROCESS_TRANSITIONS pst where {alias}.STC_ID = pst.PRO_ID and pst.FROM_PRO_CODE = ? and pst.TO_PRO_CODE = ?)",
                new String[] { transition.getA(), transition.getB() },
                new Type[] { StringType.INSTANCE, StringType.INSTANCE }));
    }

    criteria.setCacheable(true);

    return criteria;
}

From source file:com.mercatis.lighthouse3.persistence.environment.hibernate.SoftwareComponentRegistryImplementation.java

License:Apache License

@Override
protected Criteria entityToCriteria(Session session, SoftwareComponent entityTemplate) {

    Criteria criteria = super.entityToCriteria(session, entityTemplate);

    if (entityTemplate.getLongName() != null)
        criteria.add(Restrictions.eq("longName", entityTemplate.getLongName()));

    if (entityTemplate.getVersion() != null)
        criteria.add(Restrictions.eq("version", entityTemplate.getVersion()));

    if (entityTemplate.getDescription() != null)
        criteria.add(Restrictions.eq("description", entityTemplate.getDescription()));

    if (entityTemplate.getContact() != null)
        criteria.add(Restrictions.eq("contact", entityTemplate.getContact()));

    if (entityTemplate.getContactEmail() != null)
        criteria.add(Restrictions.eq("contactEmail", entityTemplate.getContactEmail()));

    if (entityTemplate.getCopyright() != null)
        criteria.add(Restrictions.eq("copyright", entityTemplate.getCopyright()));

    criteria.setCacheable(true);

    return criteria;
}

From source file:com.mercatis.lighthouse3.persistence.environment.hibernate.SoftwareComponentRegistryImplementation.java

License:Apache License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from   ww w. j  a v a  2 s  . co  m
public void delete(SoftwareComponent sc) {
    SoftwareComponent component = findByCode(sc.getCode());
    if (component == null)
        throw new PersistenceException("Entity not persistent", null);

    Criteria crit = this.unitOfWork.getCurrentSession().createCriteria(Deployment.class);
    crit.add(Restrictions.eq("deployedComponent", component));
    List<Deployment> deployments = crit.setCacheable(true).list();

    for (Deployment deployment : deployments) {
        List<DeploymentCarryingDomainModelEntity> attachedTo = this.unitOfWork.getCurrentSession()
                .createCriteria(DeploymentCarryingDomainModelEntity.class).createCriteria("attachedDeployments")
                .add(Restrictions.eq("id", deployment.getId())).setCacheable(true).list();

        for (DeploymentCarryingDomainModelEntity entity : attachedTo) {
            entity.detachDeployment(deployment);
            this.unitOfWork.getCurrentSession().saveOrUpdate(entity);
        }

        try {
            this.unitOfWork.getCurrentSession().createSQLQuery(
                    "delete from STATUS_METADATA where MD_STATUS_ID in (select distinct STA_ID from STATUS where STA_CONTEXT_ID = :entityToDelete_id)")
                    .setParameter("entityToDelete_id", deployment.getId()).executeUpdate();
            this.unitOfWork.getCurrentSession().createSQLQuery(
                    "delete from STATUS_NOTIFICATION_CHANNELS where SNC_STATUS_ID in (select distinct STA_ID from STATUS where STA_CONTEXT_ID = :entityToDelete_id)")
                    .setParameter("entityToDelete_id", deployment.getId()).executeUpdate();
            this.unitOfWork.getCurrentSession().createSQLQuery(
                    "update STATUS set LATEST_STATUS_CHANGE = null where STA_CONTEXT_ID = :entityToDelete_id")
                    .setParameter("entityToDelete_id", deployment.getId()).executeUpdate();
            this.unitOfWork.getCurrentSession().createSQLQuery(
                    "update STATUS_CHANGES set NEXT_STATUS_CHANGE = null where SCH_STATUS_ID in (select distinct STA_ID from STATUS where STA_CONTEXT_ID = :entityToDelete_id)")
                    .setParameter("entityToDelete_id", deployment.getId()).executeUpdate();
            this.unitOfWork.getCurrentSession().createSQLQuery(
                    "update STATUS_CHANGES set PREVIOUS_STATUS_CHANGE = null where SCH_STATUS_ID in (select distinct STA_ID from STATUS where STA_CONTEXT_ID = :entityToDelete_id)")
                    .setParameter("entityToDelete_id", deployment.getId()).executeUpdate();
            this.unitOfWork.getCurrentSession().createSQLQuery(
                    "delete from STATUS_CHANGES where SCH_STATUS_ID in (select distinct STA_ID from STATUS where STA_CONTEXT_ID = :entityToDelete_id)")
                    .setParameter("entityToDelete_id", deployment.getId()).executeUpdate();
            this.unitOfWork.getCurrentSession()
                    .createSQLQuery("delete from STATUS where STA_CONTEXT_ID = :entityToDelete_id")
                    .setParameter("entityToDelete_id", deployment.getId()).executeUpdate();
        } catch (Exception ex) {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed to cleanup status tables for softwareComponent: " + sc.getCode(), ex);
            }
        }
        this.unitOfWork.getCurrentSession().delete(deployment);
    }

    HashSet<SoftwareComponent> directSubEntities = new HashSet<SoftwareComponent>(
            component.getDirectSubEntities());

    for (SoftwareComponent childComponent : directSubEntities) {
        component.removeSubEntity(childComponent);
        this.delete(childComponent);
    }

    super.delete(component);
}

From source file:com.mercatis.lighthouse3.persistence.status.hibernate.StatusRegistryImplementation.java

License:Apache License

@Override
protected Criteria entityToCriteria(Session session, Status entityTemplate) {
    Criteria criteria = super.entityToCriteria(session, entityTemplate);

    if (entityTemplate.getLongName() != null) {
        criteria.add(Restrictions.eq("longName", entityTemplate.getLongName()));
    }// w  w  w .j av  a  2 s  .  c o m

    if (entityTemplate.getDescription() != null) {
        criteria.add(Restrictions.eq("description", entityTemplate.getDescription()));
    }

    if (entityTemplate.getContact() != null) {
        criteria.add(Restrictions.eq("contact", entityTemplate.getContact()));
    }

    if (entityTemplate.getContactEmail() != null) {
        criteria.add(Restrictions.eq("contactEmail", entityTemplate.getContactEmail()));
    }

    criteria.setCacheable(true);

    return criteria;
}

From source file:com.purebred.core.dao.EntityDao.java

License:Open Source License

/**
 * Find entity by natural id, or business key. This method only works for entities that have a single property
 * marked as @NaturalId. The benefit of calling this method is that Hibernate will try to look up the entity
 * in the secondary cache.//from  ww w  .j  a  v a2 s  .  c o m
 *
 * @param propertyName name of the property in the entity that is marked @NaturalId
 * @param propertyValue value to search for
 *
 * @return  entity
 */
public T findByNaturalId(String propertyName, Object propertyValue) {
    Session session = (Session) getEntityManager().getDelegate();

    Criteria criteria = session.createCriteria(getEntityType());
    criteria.add(Restrictions.naturalId().set(propertyName, propertyValue));
    criteria.setCacheable(true);

    return (T) criteria.uniqueResult();
}

From source file:com.qcadoo.model.internal.search.SearchCriteriaImpl.java

License:Open Source License

@Override
public void addCacheable(Criteria criteria) {
    if (cacheable) {
        criteria.setCacheable(cacheable);
    }
}

From source file:com.quix.aia.cn.imo.mapper.AamDataMaintenance.java

License:Open Source License

/**
 * <p>/*ww w .  ja v  a 2s .c om*/
 * This method retrieves single Model for particular agentId
 * </p>
 * 
 * @param agentId
 * @return AamData Class Object
 * 
 */
public static AamData retrieveDataToModel(String agentId, String coBranch) {

    ArrayList<AamData> list = new ArrayList();
    AamData aamData = new AamData();
    try {
        session = clientSessionFactory.openSession();
        transaction = session.beginTransaction();

        Criteria crit = session.createCriteria(AamData.class);
        if (null != agentId && !"".equals(agentId)) {
            crit.add(Restrictions.eq("agentCode", agentId));
        }
        if (null != coBranch && !"".equals(coBranch)) {
            crit.add(Restrictions.eq("branch", coBranch));
        }

        list = (ArrayList) crit.setCacheable(true).list();
    } catch (Exception he) {
        he.printStackTrace();

        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        he.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("AamDataMaintenance", Level.SEVERE + "", errors.toString());
    } finally {
        session.close();
    }

    if (!list.isEmpty()) {
        aamData = list.get(0);
        aamData = retrieveOtherData(aamData);
    }

    return aamData;
}

From source file:com.quix.aia.cn.imo.mapper.AamDataMaintenance.java

License:Open Source License

/**
 * <p>/*  w  ww. ja  v  a2s . c o  m*/
 * This method retrieves list of data for matching bu, district, city, ssc
 * </p>
 * @param office 
 * 
 * @param bu, district, city, ssc
 *            
 * @return List (List of Class Object)
 * 
 */
//   public static List retrieveDataToList(String bu, String district, String city, String ssc) {
public static List retrieveDataToList(String city, String ssc, String branch, String office) {
    ArrayList list = new ArrayList();

    try {
        session = clientSessionFactory.openSession();
        transaction = session.beginTransaction();

        Criteria crit = session.createCriteria(AamData.class);
        //         if (null != bu && !"".equals(bu)) {
        //            crit.add(Restrictions.eq("bu", bu));
        //         }
        //         if (null != district && !"".equals(district)) {
        //            crit.add(Restrictions.eq("district", district));
        //         }
        if (null != branch && !"".equals(branch)) {
            crit.add(Restrictions.eq("branch", branch));
        }

        if (null != city && !"".equals(city)) {
            crit.add(Restrictions.eq("city", city));
        }
        if (null != ssc && !"".equals(ssc)) {
            crit.add(Restrictions.eq("ssc", ssc));
        }

        if (null != office && !"".equals(office)) {
            crit.add(Restrictions.eq("officeCode", office));
        }

        list = (ArrayList) crit.setCacheable(true).list();
    } catch (Exception he) {
        he.printStackTrace();
        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        he.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("AamDataMaintenance", Level.SEVERE + "", errors.toString());
    } finally {
        session.close();
    }

    return list;
}

From source file:com.quix.aia.cn.imo.mapper.AamDataMaintenance.java

License:Open Source License

/**
 * <p>/*from   w  w  w  .  j  a  va2s.  c  om*/
 * This method retrieves agentName for particular agentId
 * </p>
 * 
 * @param agentId
 * @return String 
 * 
 */
public static String retrieveAgentName(String agentId) {
    String agentName = "";
    try {
        session = clientSessionFactory.openSession();
        transaction = session.beginTransaction();

        Criteria crit = session.createCriteria(AamData.class);
        if (null != agentId && !"".equals(agentId)) {
            crit.setProjection(Projections.property("agentName"));
            crit.add(Restrictions.eq("agentCode", agentId));
        }

        ArrayList list = (ArrayList) crit.setCacheable(true).list();
        if (list != null && list.size() > 0)
            agentName = (String) list.get(0);
    } catch (Exception he) {
        he.printStackTrace();

        LogsMaintenance logsMain = new LogsMaintenance();
        StringWriter errors = new StringWriter();
        he.printStackTrace(new PrintWriter(errors));
        logsMain.insertLogs("AamDataMaintenance", Level.SEVERE + "", errors.toString());
    } finally {
        session.close();
    }

    return agentName;
}