@Override public void betweenFunctionArguments() { if ( startedType ) { throw new QueryException( "CAST function should only have 2 arguments" ); } startedType = true; }
/** * Return the HQL query string that was invalid. */ public String getQueryString() { return ((QueryException) getCause()).getQueryString(); }
public HibernateQueryException(QueryException ex) { super(ex.getMessage(), ex); }
/** * Called from {@link #wrapWithQueryString(String)} when we really need to generate a new QueryException * (or subclass). * <p/> * NOTE : implementors should take care to use {@link #getOriginalMessage()} for the message, not * {@link #getMessage()} * * @param queryString The query string * * @return The generated QueryException (or subclass) * * @see #getOriginalMessage() */ protected QueryException generateQueryException(String queryString) { return new QueryException( getOriginalMessage(), queryString, this ); } }
/** * Wraps this exception with another, of same kind, with the specified queryString. If this exception already * has a queryString defined, the same exception ({@code this}) is returned. Otherwise the protected * {@link #generateQueryException(String)} is called, to allow subclasses to properly create the correct * subclass for return. * * @param queryString The query string that led to the QueryException * * @return {@code this}, if {@code this} has {@code null} for {@link #getQueryString()}; otherwise a new * QueryException (or subclass) is returned. */ public final QueryException wrapWithQueryString(String queryString) { if ( this.getQueryString() != null ) { return this; } return generateQueryException( queryString ); }
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 ); } }
if ( qe.getQueryString() == null ) { throw qe.wrapWithQueryString( queryString ); throw new QueryException( "Incorrect query syntax", queryString, e );
private static net.sf.hibernate.QueryException adaptQueryException( final org.hibernate.QueryException ex) { final String message = ex.getMessage(); final net.sf.hibernate.QueryException result = new net.sf.hibernate.QueryException(ex) { @Override public String getMessage() { return message; } @Override public String toString() { return toStringWithClassName(this, net.sf.hibernate.QueryException.class); } }; result.setQueryString(ex.getQueryString()); return result; }
/** * Returns the locations of all occurrences of the named parameter. */ public int[] getNamedParameterLocations(String name) throws QueryException { Object o = namedParameters.get( name ); if ( o == null ) { QueryException qe = new QueryException( QueryTranslator.ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name ); qe.setQueryString( queryTranslatorImpl.getQueryString() ); throw qe; } if ( o instanceof Integer ) { return new int[]{( ( Integer ) o ).intValue()}; } else { return ArrayHelper.toIntArray( ( ArrayList ) o ); } }
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 ); } }
if ( qe.getQueryString() == null ) { throw qe.wrapWithQueryString( hql ); throw new QueryException( e.getMessage(), hql ); throw new QueryException( e.getMessage(), hql );
/** * Wraps this exception with another, of same kind, with the specified queryString. If this exception already * has a queryString defined, the same exception ({@code this}) is returned. Otherwise the protected * {@link #generateQueryException(String)} is called, to allow subclasses to properly create the correct * subclass for return. * * @param queryString The query string that led to the QueryException * * @return {@code this}, if {@code this} has {@code null} for {@link #getQueryString()}; otherwise a new * QueryException (or subclass) is returned. */ public final QueryException wrapWithQueryString(String queryString) { if ( this.getQueryString() != null ) { return this; } return generateQueryException( queryString ); }
public static void panic() { //overriden to avoid System.exit throw new QueryException( "Parser: panic" ); } }
@Override 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 ); } }
public HibernateQueryException(QueryException ex) { super(ex.getMessage(), ex); }
/** * Return the HQL query string that was invalid. */ public String getQueryString() { return ((QueryException) getCause()).getQueryString(); }
public void end(QueryTranslatorImpl q) { if ( afterMemberDeclarations ) { //The exception throwned by the AST query translator contains the error token location, respensent by line and colum, //but it hard to get that info here. throw new QueryException( "alias not specified for IN" ); } }
@Override 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 ); } }
@Test public void testInsertWithSubqueriesAndNamedParams() { TestData data = new TestData(); data.prepare(); Session s = openSession(); Transaction t = s.beginTransaction(); org.hibernate.Query q = s.createQuery( "insert into Pickup (id, owner, vin) select :id, (select a.description from Animal a where a.description = :description), :vin from Car" ); q.setParameter("id", 5l); q.setParameter("description", "Frog"); q.setParameter("vin", "some"); q.executeUpdate(); t.commit(); t = s.beginTransaction(); try { org.hibernate.Query q1 = s.createQuery( "insert into Pickup (id, owner, vin) select :id, (select :description from Animal a where a.description = :description), :vin from Car" ); fail("Unsupported exception should have been thrown"); } catch (IllegalArgumentException e) { assertTyping( QueryException.class, e.getCause() ); } catch(QueryException e) { assertTrue(e.getMessage().indexOf("Use of parameters in subqueries of INSERT INTO DML statements is not supported.") > -1); } t.commit(); t = s.beginTransaction(); s.createQuery( "delete Vehicle" ).executeUpdate(); t.commit(); s.close(); data.cleanup(); }
/** * Return the HQL query string that was invalid. */ public String getQueryString() { return ((QueryException) getCause()).getQueryString(); }