List of usage examples for org.hibernate Query setReadOnly
Query<R> setReadOnly(boolean readOnly);
From source file:org.openspaces.persistency.hibernate.iterator.DefaultScrollableDataIterator.java
License:Open Source License
protected ScrollableResults createCursor() { session = sessionFactory.openSession(); session.setFlushMode(FlushMode.MANUAL); transaction = session.beginTransaction(); if (entityName != null) { Criteria criteria = session.createCriteria(entityName); criteria.setCacheable(false);//from ww w . j av a 2 s . c o m criteria.setFlushMode(FlushMode.MANUAL); criteria.setFetchSize(fetchSize); if (perfromOrderById) { ClassMetadata metadata = sessionFactory.getClassMetadata(entityName); String idPropName = metadata.getIdentifierPropertyName(); if (idPropName != null) { criteria.addOrder(Order.asc(idPropName)); } } if (from >= 0) { if (from > 0) criteria.setFirstResult(from); criteria.setMaxResults(size); } return criteria.scroll(ScrollMode.FORWARD_ONLY); } else if (sqlQuery != null) { Query query = HibernateIteratorUtils.createQueryFromSQLQuery(sqlQuery, session); query.setFetchSize(fetchSize); if (from >= 0) { if (from > 0) query.setFirstResult(from); query.setMaxResults(size); } return query.scroll(ScrollMode.FORWARD_ONLY); } else if (hQuery != null) { Query query = session.createQuery(hQuery); query.setFetchSize(fetchSize); if (from >= 0) { if (from > 0) query.setFirstResult(from); query.setMaxResults(size); } query.setCacheMode(CacheMode.IGNORE); query.setCacheable(false); query.setReadOnly(true); return query.scroll(ScrollMode.FORWARD_ONLY); } else { throw new IllegalStateException("No SQLQuery, entity, or Hibernate Query provided"); } }
From source file:org.openspaces.persistency.hibernate.iterator.HibernateIteratorUtils.java
License:Open Source License
public static Query createQueryFromSQLQuery(SQLQuery<?> sqlQuery, Session session) { String select = sqlQuery.getFromQuery(); Query query = session.createQuery(select); Object[] preparedValues = sqlQuery.getParameters(); if (preparedValues != null) { for (int i = 0; i < preparedValues.length; i++) { query.setParameter(i, preparedValues[i]); }/* w ww . j ava2 s . c om*/ } query.setCacheMode(CacheMode.IGNORE); query.setCacheable(false); query.setReadOnly(true); return query; }
From source file:org.openspaces.persistency.hibernate.iterator.HibernateIteratorUtils.java
License:Open Source License
public static Query createQueryFromSQLQuery(SQLQuery<?> sqlQuery, StatelessSession session) { String select = sqlQuery.getFromQuery(); Query query = session.createQuery(select); Object[] preparedValues = sqlQuery.getParameters(); if (preparedValues != null) { for (int i = 0; i < preparedValues.length; i++) { query.setParameter(i, preparedValues[i]); }/*from w ww. java 2 s . com*/ } query.setReadOnly(true); return query; }
From source file:org.openspaces.persistency.hibernate.iterator.HibernateIteratorUtils.java
License:Open Source License
public static Query createQueryFromDataSourceSQLQuery(DataSourceSQLQuery dataSourceSQLQuery, Session session) { String select = dataSourceSQLQuery.getFromQuery(); Query query = session.createQuery(select); Object[] preparedValues = dataSourceSQLQuery.getQueryParameters(); if (preparedValues != null) { for (int i = 0; i < preparedValues.length; i++) { query.setParameter(i, preparedValues[i]); }//from w w w .j av a 2 s. com } query.setReadOnly(true); return query; }
From source file:org.openspaces.persistency.hibernate.iterator.HibernateIteratorUtils.java
License:Open Source License
public static Query createQueryFromDataSourceSQLQuery(DataSourceSQLQuery dataSourceSQLQuery, StatelessSession session) {//from w w w . j a v a2 s . co m String select = dataSourceSQLQuery.getFromQuery(); Query query = session.createQuery(select); Object[] preparedValues = dataSourceSQLQuery.getQueryParameters(); if (preparedValues != null) { for (int i = 0; i < preparedValues.length; i++) { query.setParameter(i, preparedValues[i]); } } query.setReadOnly(true); return query; }
From source file:org.openspaces.persistency.hibernate.iterator.StatelessScrollableDataIterator.java
License:Open Source License
protected ScrollableResults createCursor() { session = sessionFactory.openStatelessSession(); transaction = session.beginTransaction(); if (entityName != null) { Criteria criteria = session.createCriteria(entityName); criteria.setFetchSize(fetchSize); if (perfromOrderById) { ClassMetadata metadata = sessionFactory.getClassMetadata(entityName); String idPropName = metadata.getIdentifierPropertyName(); if (idPropName != null) { criteria.addOrder(Order.asc(idPropName)); }/*from ww w .j a va 2 s .co m*/ } if (from >= 0) { if (from > 0) criteria.setFirstResult(from); criteria.setMaxResults(size); } return criteria.scroll(ScrollMode.FORWARD_ONLY); } else if (sqlQuery != null) { Query query = HibernateIteratorUtils.createQueryFromSQLQuery(sqlQuery, session); query.setFetchSize(fetchSize); if (from >= 0) { if (from > 0) query.setFirstResult(from); query.setMaxResults(size); } return query.scroll(ScrollMode.FORWARD_ONLY); } else if (hQuery != null) { Query query = session.createQuery(hQuery); query.setFetchSize(fetchSize); if (from >= 0) { if (from > 0) query.setFirstResult(from); query.setMaxResults(size); } query.setReadOnly(true); return query.scroll(ScrollMode.FORWARD_ONLY); } else { throw new IllegalStateException("Either SQLQuery or entity must be provided"); } }
From source file:org.openxma.dsl.platform.hibernate.NamedQueryFilter.java
License:Open Source License
protected Collection list(QueryObject queryObject, String rewrittenHqlString) throws HibernateException { if (logger.isDebugEnabled()) { logger.debug(rewrittenHqlString); }//from w w w . ja v a 2 s.c o m Query query = createQuery(queryObject, rewrittenHqlString); query.setReadOnly(true); if (rewritingHqlParser.isPropertiesSelect()) { return namedQueryMapper.createAndMapMany(query.list(), null, Collections.singletonMap(GenericDaoHibernateImpl.QUERY_NAME, queryObject.getQueryName())); } return rewritingHqlParser.getJoinAliasMap().isEmpty() ? query.list() : new LinkedHashSet(query.list()); }
From source file:org.ow2.bonita.persistence.db.DbSessionImpl.java
License:Open Source License
@Override public int getCasesNumberWithTwoLabels(final String ownerName, final String label1Name, final String label2Name) { final Query query = getSession().getNamedQuery("getCasesNumberWithTwoLabels"); query.setString("label1", CaseImpl.buildLabel(ownerName, label1Name)); query.setString("label2", CaseImpl.buildLabel(ownerName, label2Name)); query.setReadOnly(true); return ((Long) query.uniqueResult()).intValue(); }
From source file:org.ow2.bonita.persistence.db.DbSessionImpl.java
License:Open Source License
@Override public int getCasesNumber(final String ownerName, final String labelName) { final Query query = getSession().getNamedQuery("getCasesNumber"); query.setString("ownerName", ownerName); query.setString("label", labelName); query.setReadOnly(true); return ((Long) query.uniqueResult()).intValue(); }
From source file:org.ow2.bonita.persistence.db.DbSessionImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public Set<CaseImpl> getCasesWithTwoLabels(final String ownerName, final String label1Name, final String label2Name, final int limit) { final Query query = getSession().getNamedQuery("getCasesWithTwoLabelsWithLimit"); query.setString("label1", CaseImpl.buildLabel(ownerName, label1Name)); query.setString("label2", CaseImpl.buildLabel(ownerName, label2Name)); query.setReadOnly(true); query.setMaxResults(limit);// www. ja v a 2 s.c o m final List<CaseImpl> results = query.list(); if (results != null) { return new HashSet<CaseImpl>(results); } else { return new HashSet<CaseImpl>(); } }