List of usage examples for org.hibernate SQLQuery setCacheable
@Override
NativeQuery<T> setCacheable(boolean cacheable);
From source file:org.yamj.core.hibernate.HibernateDao.java
License:Open Source License
/** * Execute a SQL update statement./*from ww w.j av a 2 s . c om*/ * * @param queryCharSequence the query string * @return number of affected rows */ public int executeSqlUpdate(CharSequence queryCharSequence) { SQLQuery query = currentSession().createSQLQuery(queryCharSequence.toString()); query.setCacheable(true); return query.executeUpdate(); }
From source file:org.yamj.core.hibernate.HibernateDao.java
License:Open Source License
/** * Execute an update statement.//from www .java 2s . c o m * * @param queryCharSequence the query string * @param params the named parameters * @return number of affected rows */ public int executeSqlUpdate(CharSequence queryCharSequence, Map<String, Object> params) { SQLQuery query = currentSession().createSQLQuery(queryCharSequence.toString()); query.setCacheable(true); for (Entry<String, Object> param : params.entrySet()) { applyNamedParameterToQuery(query, param.getKey(), param.getValue()); } return query.executeUpdate(); }
From source file:org.yamj.core.hibernate.HibernateDao.java
License:Open Source License
/** * Execute a query to return the results * * Gets the options from the wrapper for start and max * * Puts the total count returned from the query into the wrapper * * @param <T>//from w ww.j a v a 2 s . c o m * @param T The class to return the transformed results of. * @param sqlScalars * @param wrapper * @return */ @SuppressWarnings("rawtypes") public <T> List<T> executeQueryWithTransform(Class T, SqlScalars sqlScalars, IApiWrapper wrapper) { SQLQuery query = sqlScalars.createSqlQuery(currentSession()); query.setReadOnly(true); query.setCacheable(true); if (T != null) { if (T.equals(String.class)) { // no transformer needed } else if (T.equals(Long.class)) { // no transformer needed } else if (T.equals(Object[].class)) { // no transformer needed } else { query.setResultTransformer(Transformers.aliasToBean(T)); } } // Add the scalars to the query sqlScalars.populateScalars(query); List<T> queryResults = query.list(); // If the wrapper is populated, then run the query to get the maximum results if (wrapper != null) { wrapper.setTotalCount(queryResults.size()); // If there is a start or max set, we will need to re-run the query after setting the options IOptions options = wrapper.getOptions(); if (options != null) { if (options.getStart() > 0 || options.getMax() > 0) { if (options.getStart() > 0) { query.setFirstResult(options.getStart()); } if (options.getMax() > 0) { query.setMaxResults(options.getMax()); } // This will get the trimmed list queryResults = query.list(); } } } return queryResults; }