/** * Compile the query (generate the SQL). * * @throws org.hibernate.MappingException Indicates problems resolving things referenced in the * query. * @throws org.hibernate.QueryException Generally some form of syntatic failure. */ private void compile() throws QueryException, MappingException { LOG.trace("Compiling query"); try { ParserHelper.parse( new PreprocessingParser(tokenReplacements), queryString, ParserHelper.HQL_SEPARATORS, this); renderSQL(); } catch (QueryException qe) { qe.setQueryString(queryString); throw qe; } catch (MappingException me) { throw me; } catch (Exception e) { LOG.debug("Unexpected query compilation problem", e); e.printStackTrace(); QueryException qe = new QueryException("Incorrect query syntax", e); qe.setQueryString(queryString); throw qe; } postInstantiate(); compiled = true; }
public int[] getNamedParameterLocs(String name) throws QueryException { Object o = namedParameters.get(name); if (o == null) { QueryException qe = new QueryException(ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name); qe.setQueryString(queryString); throw qe; } if (o instanceof Integer) { return new int[] {((Integer) o).intValue()}; } else { return ArrayHelper.toIntArray((ArrayList) o); } }
@MethodContract( pre = @Expression("session != null"), post = {}) public <_PersistentBean_ extends PersistentBean<?>> Set<_PersistentBean_> retrieveAllPersistentBeans( final Class<_PersistentBean_> persistentBeanType, final boolean retrieveSubClasses) { LOG.debug("Retrieving all records of type \"" + persistentBeanType + "\" ..."); dependency(getSession(), "session"); preArgumentNotNull(persistentBeanType, "persistentBeanType"); Set<_PersistentBean_> results = new HashSet<_PersistentBean_>(); try { if (retrieveSubClasses) { @SuppressWarnings("unchecked") List<_PersistentBean_> list = getSession().createCriteria(persistentBeanType).list(); results.addAll(list); } else { try { @SuppressWarnings("unchecked") List<_PersistentBean_> list = getSession() .createQuery( "FROM " + persistentBeanType.getName() + " as persistentObject WHERE persistentObject.class = " + persistentBeanType.getName()) .list(); results.addAll(list); } catch (QueryException qExc) { if (qExc.getMessage().matches("could not resolve property: class of: .*")) { @SuppressWarnings("unchecked") List<_PersistentBean_> list = getSession().createCriteria(persistentBeanType).list(); results.addAll(list); } } } } catch (HibernateException hExc) { throw new ExternalError( "problem getting all instances of " + persistentBeanType.getName(), hExc); } assert results != null; LOG.debug("Retrieval succeeded (" + results.size() + " objects retrieved)"); // $NON-NLS-2$ return results; }
public HibernateQueryException(QueryException ex) { super(ex.getMessage(), ex); }