List of usage examples for javax.persistence Query setHint
Query setHint(String hintName, Object value);
From source file:com.webbfontaine.valuewebb.action.pricedb.freight.FreightList.java
private void tuneQuery(Query query) { query.setHint("org.hibernate.readOnly", Boolean.TRUE); }
From source file:org.broadleafcommerce.common.locale.dao.LocaleDaoImpl.java
/** * Returns all supported BLC locales./*from www . j a v a 2 s . c o m*/ * @return */ public List<Locale> findAllLocales() { Query query = em.createNamedQuery("BC_READ_ALL_LOCALES"); query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true); return (List<Locale>) query.getResultList(); }
From source file:org.broadleafcommerce.common.locale.dao.LocaleDaoImpl.java
/** * Returns the page template with the passed in id. * * @return The default locale//from w w w .j ava 2 s . c om */ @Override public Locale findDefaultLocale() { Query query = em.createNamedQuery("BC_READ_DEFAULT_LOCALE"); query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true); List<Locale> localeList = (List<Locale>) query.getResultList(); if (localeList.size() >= 1) { if (localeList.size() > 1) { LOG.warn("There is more than one default locale configured"); } return localeList.get(0); } return null; }
From source file:com.devicehive.dao.rdbms.RdbmsGenericDao.java
public void cacheQuery(Query query, Optional<CacheConfig> cacheConfig) { if (cacheConfig.isPresent()) { query.setHint(CACHEABLE, true); query.setHint(RETRIEVE_MODE, cacheConfig.get().getRetrieveMode()); query.setHint(STORE_MODE, cacheConfig.get().getStoreMode()); }//from w w w . ja v a2 s . c o m }
From source file:Professor.java
public Professor findProfessorNoCache(int empId) { Query q = em.createQuery("SELECT e FROM Professor e WHERE e.id = ?1"); // force read from database q.setHint("cacheUsage", oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.DoNotCheckCache); q.setParameter(1, empId);// w w w .j a va2 s .c om try { return (Professor) q.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.broadleafcommerce.common.locale.dao.LocaleDaoImpl.java
/** * @return The locale for the passed in code *///from ww w . j a v a 2 s . c o m @Override public Locale findLocaleByCode(String localeCode) { Query query = em.createNamedQuery("BC_READ_LOCALE_BY_CODE"); query.setParameter("localeCode", localeCode); query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true); List<Locale> localeList = (List<Locale>) query.getResultList(); if (localeList.size() >= 1) { if (localeList.size() > 1) { LOG.warn("Locale code " + localeCode + " exists for more than one locale"); } return localeList.get(0); } return null; }
From source file:net.urlgrey.mythpodcaster.dao.MythRecordingsDAOImpl.java
@SuppressWarnings("unchecked") @Override/*from w ww . ja va2 s. c o m*/ public List<String> findRecordingDirectories() { List<String> resultsList; if ((resultsList = cache.get(RECORDING_DIRECTORIES_CACHE_LABEL)) == null) { final Query nativeQuery = entityManager.createNativeQuery("SELECT DISTINCT dirname FROM storagegroup"); nativeQuery.setHint("org.hibernate.comment", "MythPodcaster: findRecordingDirectories"); resultsList = nativeQuery.getResultList(); cache.put(RECORDING_DIRECTORIES_CACHE_LABEL, resultsList); } return resultsList; }
From source file:gwap.game.quiz.QuizSessionBean.java
/** * Creates a new game array for the Quiz Game with 15 images *//*w ww . j av a 2s. co m*/ private boolean createWoelfflinResource() { this.questions = new ArrayList<QuizQuestionBean>(15); Query query = entityManager.createNamedQuery("artResource.woelfflin"); query.setHint("org.hibernate.readOnly", true); query.setMaxResults(500); List<ArtResource> resultList = (List<ArtResource>) query.getResultList(); int numImagesFound = 0; int listCounter = 0; for (ArtResource a : resultList) { listCounter++; String dateCreated = validateYear(a.getDateCreated()); if (dateCreated != null) { String forename = a.getArtist().getForename(); String surname = a.getArtist().getSurname(); if (!(forename == null && surname == null)) { a.setDateCreated(dateCreated); QuizQuestionBean q = new QuizQuestionBean(numImagesFound, a); q.generateAnswers(); questions.add(q); numImagesFound++; if (numImagesFound == 15) { log.info("Found valid quiz game setup after observing " + listCounter + " ArtResources"); return true; } } } } log.error("Did not find 15 valid ArtResources out of 500 for a valid quiz game setup!"); return false; }
From source file:org.broadleafcommerce.openadmin.server.security.dao.AdminPermissionDaoImpl.java
@SuppressWarnings("unchecked") public List<AdminPermission> readAllAdminPermissions() { Query query = em.createNamedQuery("BC_READ_ALL_ADMIN_PERMISSIONS"); query.setHint(QueryHints.HINT_CACHEABLE, true); List<AdminPermission> permissions = query.getResultList(); return permissions; }
From source file:com.mothsoft.alexis.dao.TermDaoImpl.java
public Term find(String termValue, PartOfSpeech partOfSpeech) { final Query query = this.em .createQuery("FROM Term WHERE value = :termValue AND partOfSpeechEnumValue = :partOfSpeech"); query.setParameter("termValue", termValue); query.setParameter("partOfSpeech", (byte) partOfSpeech.getValue()); query.setHint("org.hibernate.cacheable", true); @SuppressWarnings("unchecked") final List<Term> results = query.getResultList(); final Term result = results != null && results.size() == 1 ? results.get(0) : null; return result; }