List of usage examples for org.hibernate Query setReadOnly
Query<R> setReadOnly(boolean readOnly);
From source file:edu.harvard.med.screensaver.db.CherryPickRequestDAO.java
License:Open Source License
public Map<WellKey, Number> findDuplicateCherryPicksForScreen(final Screen screen) { Query query = getHibernateSession().createQuery("select sw.wellId, count(*) " + "from Screen s left join s.cherryPickRequests cpr left join cpr.screenerCherryPicks scp join scp.screenedWell sw " + "where s." + Screen.facilityId.getPropertyName() + " = :screenId " + "group by sw.wellId having count(*) > 1"); query.setReadOnly(true); query.setParameter("screenId", screen.getFacilityId()); Map<WellKey, Number> result = new HashMap<WellKey, Number>(); for (Iterator iter = query.list().iterator(); iter.hasNext();) { Object[] row = (Object[]) iter.next(); result.put(new WellKey(row[0].toString()), (Number) row[1]); }/*www . j av a 2s . c o m*/ return result; }
From source file:edu.harvard.med.screensaver.db.hqlbuilder.HqlBuilder.java
License:Open Source License
public Query toQuery(Session session, boolean isReadOnly) { org.hibernate.Query query = session.createQuery(toHql()); for (Map.Entry<String, Object> arg : args().entrySet()) { if (arg.getKey().endsWith(SET_ARG_SUFFIX)) { // HACK: handle 'list' type parameters, used with the 'IN (?)' operator query.setParameterList(arg.getKey(), (Set<?>) arg.getValue()); } else {/*from w w w.j av a 2 s . c o m*/ query.setParameter(arg.getKey(), arg.getValue()); } } if (_isDistinctRootEntities) { query.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); } query.setReadOnly(isReadOnly); return query; }
From source file:edu.ur.hibernate.file.mime.HbSubTypeDAO.java
License:Apache License
@SuppressWarnings("unchecked") public List<SubType> getSubTypes(final Long topMediaTypeId, final int rowStart, final int numberOfResultsToShow, final String sortType) { List<SubType> subTypes = (List<SubType>) hbCrudDAO.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = null; if (sortType.equalsIgnoreCase("asc")) { q = session.getNamedQuery("getSubTypesOrderByNameAsc"); } else { q = session.getNamedQuery("getSubTypesOrderByNameDesc"); }/*from w ww .j a v a2 s.com*/ q.setParameter("topMediaTypeId", topMediaTypeId); q.setFirstResult(rowStart); q.setMaxResults(numberOfResultsToShow); q.setReadOnly(true); q.setFetchSize(numberOfResultsToShow); return q.list(); } }); return subTypes; }
From source file:edu.ur.hibernate.file.mime.HbSubTypeExtensionDAO.java
License:Apache License
/** * @see edu.ur.file.mime.SubTypeExtensionDAO#getSubTypeExtensions(Long, int, int, String) *//*from w w w . j a va 2s .co m*/ @SuppressWarnings("unchecked") public List<SubTypeExtension> getSubTypeExtensions(final Long subTypeId, final int rowStart, final int numberOfResultsToShow, final String sortType) { List<SubTypeExtension> subTypeExtensions = (List<SubTypeExtension>) hbCrudDAO.getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = null; if (sortType.equalsIgnoreCase("asc")) { q = session.getNamedQuery("getSubTypeExtensionsOrderByNameAsc"); } else { q = session.getNamedQuery("getSubTypeExtensionsOrderByNameDesc"); } q.setParameter("subTypeId", subTypeId); q.setFirstResult(rowStart); q.setMaxResults(numberOfResultsToShow); q.setReadOnly(true); q.setFetchSize(numberOfResultsToShow); return q.list(); } }); return subTypeExtensions; }
From source file:edu.ur.hibernate.file.mime.HbTopMediaTypeDAO.java
License:Apache License
/** * @see edu.ur.file.mime.TopMediaTypeDAO#getTopMediaTypes(int, int, String) *//*www . j ava 2 s .c om*/ @SuppressWarnings("unchecked") public List<TopMediaType> getTopMediaTypes(final int rowStart, final int numberOfResultsToShow, final String sortType) { List<TopMediaType> topMediaTypes = (List<TopMediaType>) hbCrudDAO.getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = null; if (sortType.equalsIgnoreCase("asc")) { q = session.getNamedQuery("getTopMediaTypesOrderByNameAsc"); } else { q = session.getNamedQuery("getTopMediaTypesOrderByNameDesc"); } q.setFirstResult(rowStart); q.setMaxResults(numberOfResultsToShow); q.setReadOnly(true); q.setFetchSize(numberOfResultsToShow); return q.list(); } }); return topMediaTypes; }
From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalCollectionDAO.java
License:Apache License
/** * Get the sub or child institutional collections. * /*from w ww. j av a 2 s . co m*/ * @see edu.ur.ir.institution.InstitutionalCollectionDAO#getSubInstituionalCollections(java.lang.Long, java.lang.Long, int, int, String) */ @SuppressWarnings("unchecked") public List<InstitutionalCollection> getSubInstituionalCollections(final Long repositoryId, final Long parentCollectionId, final int rowStart, final int maxNumToFetch, final String orderType) { List<InstitutionalCollection> institutionalCollections = (List<InstitutionalCollection>) hbCrudDAO .getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = null; if (orderType.equalsIgnoreCase("asc")) { q = session.getNamedQuery("getSubCollectionsByNameAsc"); } else { q = session.getNamedQuery("getSubCollectionsByNameDesc"); } q.setParameter("repositoryId", repositoryId); q.setParameter("parentCollectionId", parentCollectionId); q.setFirstResult(rowStart); q.setMaxResults(maxNumToFetch); q.setReadOnly(true); q.setFetchSize(maxNumToFetch); return q.list(); } }); return institutionalCollections; }
From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalCollectionDAO.java
License:Apache License
/** * Get the root institutional collections. * /*from w w w.j av a 2 s . c o m*/ * @see edu.ur.ir.institution.InstitutionalCollectionDAO#getRootInstituionalCollections(java.lang.Long, int, int, String) */ @SuppressWarnings("unchecked") public List<InstitutionalCollection> getRootInstituionalCollections(final Long repositoryId, final int rowStart, final int maxNumToFetch, final String orderType) { List<InstitutionalCollection> institutionalCollections = (List<InstitutionalCollection>) hbCrudDAO .getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = null; if (orderType.equalsIgnoreCase("asc")) { q = session.getNamedQuery("getRootCollectionsByNameAsc"); } else { q = session.getNamedQuery("getRootCollectionsByNameDesc"); } q.setParameter("repositoryId", repositoryId); q.setFirstResult(rowStart); q.setMaxResults(maxNumToFetch); q.setReadOnly(true); q.setFetchSize(maxNumToFetch); return q.list(); } }); return institutionalCollections; }
From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java
License:Apache License
/** * Get a list of items for a specified repository by name. * //from w w w. j a v a 2s . c o m * @param rowStart - Start row to fetch the data from * @param maxResulsts - maximum number of results to fetch * @param repositoryId - id of the collection to get items * @param orderType - The order to sort by (ascending/descending) * * @return List of institutional items */ @SuppressWarnings("unchecked") public List<InstitutionalItem> getRepositoryItemsByName(final int rowStart, final int maxResults, final Long repositoryId, final OrderType orderType) { Session session = hbCrudDAO.getSessionFactory().getCurrentSession(); Query q = null; if (orderType.equals(OrderType.DESCENDING_ORDER)) { q = session.getNamedQuery("getRepositoryItemsByNameOrderDesc"); } else { q = session.getNamedQuery("getRepositoryItemsByNameOrderAsc"); } q.setLong("repositoryId", repositoryId); q.setFirstResult(rowStart); q.setMaxResults(maxResults); q.setCacheable(false); q.setReadOnly(true); q.setFetchSize(maxResults); return q.list(); }
From source file:edu.ur.hibernate.ir.institution.db.HbInstitutionalItemDAO.java
License:Apache License
/** * Get a list of items for a specified repository by publication date. * //from w w w . j a v a 2 s . com * @param rowStart - Start row to fetch the data from * @param maxResulsts - maximum number of results to fetch * @param repositoryId - id of the collection to get items * @param orderType - The order to sort by (ascending/descending) * * @return List of institutional items */ @SuppressWarnings("unchecked") public List<InstitutionalItem> getRepositoryItemsPublicationDateOrder(int rowStart, int maxResults, Long repositoryId, OrderType orderType) { Query q = null; if (orderType.equals(OrderType.DESCENDING_ORDER)) { q = hbCrudDAO.getSessionFactory().getCurrentSession() .getNamedQuery("getRepositoryItemsByPublicationDateOrderDesc"); } else { q = hbCrudDAO.getSessionFactory().getCurrentSession() .getNamedQuery("getRepositoryItemsByPublicationDateOrderAsc"); } q.setLong("repositoryId", repositoryId); q.setFirstResult(rowStart); q.setMaxResults(maxResults); q.setCacheable(false); q.setReadOnly(true); q.setFetchSize(maxResults); return (List<InstitutionalItem>) q.list(); }
From source file:edu.ur.hibernate.ir.item.db.HbContentTypeDAO.java
License:Apache License
/** * Get the content type order by name./*from w w w .j a v a 2 s. c o m*/ * * @see edu.ur.ir.item.ContentTypeDAO#getContentTypesOrderByName(int, int, String) */ @SuppressWarnings("unchecked") public List<ContentType> getContentTypesOrderByName(final int rowStart, final int numberOfResultsToShow, final String sortType) { List<ContentType> contentTypes = (List<ContentType>) hbCrudDAO.getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = null; if (sortType.equalsIgnoreCase("asc")) { q = session.getNamedQuery("getContentTypesOrderByNameAsc"); } else { q = session.getNamedQuery("getContentTypesOrderByNameDesc"); } q.setFirstResult(rowStart); q.setMaxResults(numberOfResultsToShow); q.setReadOnly(true); q.setFetchSize(numberOfResultsToShow); return q.list(); } }); return contentTypes; }