fix bug in handling of 'this', fix error locations for HQL validation

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-03-29 15:23:32 +01:00 committed by Christian Beikov
parent 0f5827a7d1
commit af153b00fb
4 changed files with 67 additions and 9 deletions

View File

@ -0,0 +1,7 @@
package org.hibernate.processor.test.data.basic;
import jakarta.data.repository.Repository;
@Repository
public interface Concrete extends IdOperations<Book> {
}

View File

@ -11,6 +11,7 @@ import org.hibernate.processor.test.util.WithClasses;
import org.junit.Test;
import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
import static org.hibernate.processor.test.util.TestUtil.assertNoMetamodelClassGeneratedFor;
import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString;
/**
@ -18,7 +19,7 @@ import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsStr
*/
public class DataTest extends CompilationTest {
@Test
@WithClasses({ Author.class, Book.class, BookAuthorRepository.class })
@WithClasses({ Author.class, Book.class, BookAuthorRepository.class, IdOperations.class, Concrete.class })
public void test() {
System.out.println( getMetaModelSourceAsString( Author.class ) );
System.out.println( getMetaModelSourceAsString( Book.class ) );
@ -30,5 +31,7 @@ public class DataTest extends CompilationTest {
assertMetamodelClassGeneratedFor( Author.class );
assertMetamodelClassGeneratedFor( Book.class );
assertMetamodelClassGeneratedFor( BookAuthorRepository.class );
assertMetamodelClassGeneratedFor( Concrete.class );
assertNoMetamodelClassGeneratedFor( IdOperations.class );
}
}

View File

@ -0,0 +1,45 @@
/**
* Copyright (c) 2023,2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.hibernate.processor.test.data.basic;
import java.util.List;
import java.util.stream.Stream;
import jakarta.data.Limit;
import jakarta.data.Order;
import jakarta.data.Sort;
import jakarta.data.repository.Query;
/**
* This interface contains common operations for the NaturalNumbers and AsciiCharacters repositories.
*
* @param <T> type of entity.
*/
public interface IdOperations<T> {
@Query("where id(this) between ?1 and ?2")
Stream<T> findByIdBetween(long minimum, long maximum, Sort<T> sort);
@Query("where id(this) >= ?1")
List<T> findByIdGreaterThanEqual(long minimum,
Limit limit,
Order<T> sorts);
@Query("where id(this) > ?1")
T[] findByIdLessThan(long exclusiveMax, Sort<T> primarySort, Sort<T> secondarySort);
@Query("where id(this) <= ?1")
List<T> findByIdLessThanEqual(long maximum, Order<T> sorts);
}

View File

@ -2177,14 +2177,17 @@ public class AnnotationMetaEntity extends AnnotationMeta {
String thisText = "";
final List<? extends Token> allTokens = hqlLexer.getAllTokens();
for (Token token : allTokens) {
switch ( token.getType() ) {
if ( token.getType() == IDENTIFIER ) {
//TEMPORARY until HQL gets support for 'this'
case IDENTIFIER:
final String text = token.getText();
if ( text.equalsIgnoreCase("this") ) {
thisText = " as " + text;
}
break;
final String text = token.getText();
if ( text.equalsIgnoreCase("this") ) {
thisText = " as " + text;
}
break;
}
}
for (Token token : allTokens) {
switch ( token.getType() ) {
case FROM:
return hql;
case WHERE:
@ -2238,7 +2241,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
hql,
returnType,
true,
new ErrorHandler( context, method, mirror, value, hql),
new ErrorHandler( context, isLocal(method) ? method : element, mirror, value, hql ),
ProcessorSessionFactory.create( context.getProcessingEnvironment() )
);
if ( statement != null ) {