Example usage for javax.persistence Query setHint

List of usage examples for javax.persistence Query setHint

Introduction

In this page you can find the example usage for javax.persistence Query setHint.

Prototype

Query setHint(String hintName, Object value);

Source Link

Document

Set a query property or hint.

Usage

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteCollectDataByDateTimeAndMonitorId(Long dateTime, int timeout, String monitorId) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("CollectData.deleteByDateTimeAndMonitorId")
            .setParameter("dateTime", dateTime).setParameter("monitorId", monitorId);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }/*from  ww w  .  j av  a2s  . c o  m*/
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteSummaryHourByDateTimeAndMonitorId(Long dateTime, int timeout, String monitorId) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("SummaryHour.deleteByDateTimeAndMonitorId")
            .setParameter("dateTime", dateTime).setParameter("monitorId", monitorId);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }/* w w  w.jav  a 2 s .  c o m*/
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteSummaryMonthByDateTimeAndMonitorId(Long dateTime, int timeout, String monitorId) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("SummaryMonth.deleteByDateTimeAndMonitorId")
            .setParameter("dateTime", dateTime).setParameter("monitorId", monitorId);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }//from  w  ww  .j  av  a2  s .com
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteCollectStringDataByDateTimeAndMonitorId(Long dateTime, int timeout, String monitorId) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("CollectStringData.deleteByDateTimeAndMonitorId")
            .setParameter("dateTime", dateTime).setParameter("monitorId", monitorId);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }/*w  w  w  .  j a v a  2s . c o m*/
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteEventLogByGenerationDateAndOwnerRoleId(Long generationDate, int timeout,
        String roleId) {//from  ww  w.  ja va 2  s . c  o m
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();

    Query query = em.createNamedQuery("EventLogEntity.deleteByGenerationDateAndOwnerRoleId")
            .setParameter("generationDate", generationDate).setParameter("ownerRoleId", roleId);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteEventLogByGenerationDateConfigFlgAndOwnerRoleId(Long generationDate, int timeout,
        String roleId) {/*  www.  j  a  va2s .  c  o m*/
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("EventLogEntity.deleteByGenerationDateConfigFlgAndOwnerRoleId")
            .setParameter("generationDate", generationDate).setParameter("ownerRoleId", roleId);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }
    return query.executeUpdate();
}

From source file:com.webbfontaine.valuewebb.model.util.Utils.java

public static Query setCacheBypass(Query query) {
    return query.setHint("org.hibernate.cacheMode", CacheMode.IGNORE);
}

From source file:com.webbfontaine.valuewebb.model.util.Utils.java

public static Query setReadOnlyFlag(Query query, boolean value) {
    return query.setHint("org.hibernate.readOnly", value);
}

From source file:com.webbfontaine.valuewebb.model.util.Utils.java

public static Query setCacheableFlag(Query query, boolean value) {
    return query.setHint("org.hibernate.cacheable", value);
}

From source file:org.springframework.orm.jpa.EntityManagerFactoryUtils.java

/**
 * Apply the current transaction timeout, if any, to the given JPA Query object.
 * <p>This method sets the JPA 2.0 query hint "javax.persistence.query.timeout" accordingly.
 * @param query the JPA Query object/*w  w w .j av a  2s.  c om*/
 * @param emf JPA EntityManagerFactory that the Query was created for
 */
public static void applyTransactionTimeout(Query query, EntityManagerFactory emf) {
    EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource(emf);
    if (emHolder != null && emHolder.hasTimeout()) {
        int timeoutValue = (int) emHolder.getTimeToLiveInMillis();
        try {
            query.setHint("javax.persistence.query.timeout", timeoutValue);
        } catch (IllegalArgumentException ex) {
            // oh well, at least we tried...
        }
    }
}