Skip to content

Commit 3370dc8

Browse files
committed
fix bug in handling of 'this', fix error locations for HQL validation
Signed-off-by: Gavin King <[email protected]>
1 parent eb1b78f commit 3370dc8

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.hibernate.processor.test.data.basic;
2+
3+
import jakarta.data.repository.Repository;
4+
5+
@Repository
6+
public interface Concrete extends IdOperations<Book> {
7+
}

tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/basic/DataTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
import org.junit.Test;
1212

1313
import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
14+
import static org.hibernate.processor.test.util.TestUtil.assertNoMetamodelClassGeneratedFor;
1415
import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString;
1516

1617
/**
1718
* @author Gavin King
1819
*/
1920
public class DataTest extends CompilationTest {
2021
@Test
21-
@WithClasses({ Author.class, Book.class, BookAuthorRepository.class })
22+
@WithClasses({ Author.class, Book.class, BookAuthorRepository.class, IdOperations.class, Concrete.class })
2223
public void test() {
2324
System.out.println( getMetaModelSourceAsString( Author.class ) );
2425
System.out.println( getMetaModelSourceAsString( Book.class ) );
@@ -30,5 +31,7 @@ public void test() {
3031
assertMetamodelClassGeneratedFor( Author.class );
3132
assertMetamodelClassGeneratedFor( Book.class );
3233
assertMetamodelClassGeneratedFor( BookAuthorRepository.class );
34+
assertMetamodelClassGeneratedFor( Concrete.class );
35+
assertNoMetamodelClassGeneratedFor( IdOperations.class );
3336
}
3437
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright (c) 2023,2024 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
package org.hibernate.processor.test.data.basic;
17+
18+
import java.util.List;
19+
import java.util.stream.Stream;
20+
21+
import jakarta.data.Limit;
22+
import jakarta.data.Order;
23+
import jakarta.data.Sort;
24+
import jakarta.data.repository.Query;
25+
26+
/**
27+
* This interface contains common operations for the NaturalNumbers and AsciiCharacters repositories.
28+
*
29+
* @param <T> type of entity.
30+
*/
31+
public interface IdOperations<T> {
32+
@Query("where id(this) between ?1 and ?2")
33+
Stream<T> findByIdBetween(long minimum, long maximum, Sort<T> sort);
34+
35+
@Query("where id(this) >= ?1")
36+
List<T> findByIdGreaterThanEqual(long minimum,
37+
Limit limit,
38+
Order<T> sorts);
39+
40+
@Query("where id(this) > ?1")
41+
T[] findByIdLessThan(long exclusiveMax, Sort<T> primarySort, Sort<T> secondarySort);
42+
43+
@Query("where id(this) <= ?1")
44+
List<T> findByIdLessThanEqual(long maximum, Order<T> sorts);
45+
}

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -2177,14 +2177,17 @@ else if ( isInsertUpdateDelete(hql) ) {
21772177
String thisText = "";
21782178
final List<? extends Token> allTokens = hqlLexer.getAllTokens();
21792179
for (Token token : allTokens) {
2180-
switch ( token.getType() ) {
2180+
if ( token.getType() == IDENTIFIER ) {
21812181
//TEMPORARY until HQL gets support for 'this'
2182-
case IDENTIFIER:
2183-
final String text = token.getText();
2184-
if ( text.equalsIgnoreCase("this") ) {
2185-
thisText = " as " + text;
2186-
}
2187-
break;
2182+
final String text = token.getText();
2183+
if ( text.equalsIgnoreCase("this") ) {
2184+
thisText = " as " + text;
2185+
}
2186+
break;
2187+
}
2188+
}
2189+
for (Token token : allTokens) {
2190+
switch ( token.getType() ) {
21882191
case FROM:
21892192
return hql;
21902193
case WHERE:
@@ -2238,7 +2241,7 @@ private void validateHql(
22382241
hql,
22392242
returnType,
22402243
true,
2241-
new ErrorHandler( context, method, mirror, value, hql),
2244+
new ErrorHandler( context, isLocal(method) ? method : element, mirror, value, hql ),
22422245
ProcessorSessionFactory.create( context.getProcessingEnvironment() )
22432246
);
22442247
if ( statement != null ) {

0 commit comments

Comments
 (0)