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:
parent
eb1b78ff0b
commit
3370dc81bc
|
@ -0,0 +1,7 @@
|
||||||
|
package org.hibernate.processor.test.data.basic;
|
||||||
|
|
||||||
|
import jakarta.data.repository.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface Concrete extends IdOperations<Book> {
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import org.hibernate.processor.test.util.WithClasses;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
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;
|
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 {
|
public class DataTest extends CompilationTest {
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({ Author.class, Book.class, BookAuthorRepository.class })
|
@WithClasses({ Author.class, Book.class, BookAuthorRepository.class, IdOperations.class, Concrete.class })
|
||||||
public void test() {
|
public void test() {
|
||||||
System.out.println( getMetaModelSourceAsString( Author.class ) );
|
System.out.println( getMetaModelSourceAsString( Author.class ) );
|
||||||
System.out.println( getMetaModelSourceAsString( Book.class ) );
|
System.out.println( getMetaModelSourceAsString( Book.class ) );
|
||||||
|
@ -30,5 +31,7 @@ public class DataTest extends CompilationTest {
|
||||||
assertMetamodelClassGeneratedFor( Author.class );
|
assertMetamodelClassGeneratedFor( Author.class );
|
||||||
assertMetamodelClassGeneratedFor( Book.class );
|
assertMetamodelClassGeneratedFor( Book.class );
|
||||||
assertMetamodelClassGeneratedFor( BookAuthorRepository.class );
|
assertMetamodelClassGeneratedFor( BookAuthorRepository.class );
|
||||||
|
assertMetamodelClassGeneratedFor( Concrete.class );
|
||||||
|
assertNoMetamodelClassGeneratedFor( IdOperations.class );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -2177,14 +2177,17 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
String thisText = "";
|
String thisText = "";
|
||||||
final List<? extends Token> allTokens = hqlLexer.getAllTokens();
|
final List<? extends Token> allTokens = hqlLexer.getAllTokens();
|
||||||
for (Token token : allTokens) {
|
for (Token token : allTokens) {
|
||||||
switch ( token.getType() ) {
|
if ( token.getType() == IDENTIFIER ) {
|
||||||
//TEMPORARY until HQL gets support for 'this'
|
//TEMPORARY until HQL gets support for 'this'
|
||||||
case IDENTIFIER:
|
|
||||||
final String text = token.getText();
|
final String text = token.getText();
|
||||||
if ( text.equalsIgnoreCase("this") ) {
|
if ( text.equalsIgnoreCase("this") ) {
|
||||||
thisText = " as " + text;
|
thisText = " as " + text;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Token token : allTokens) {
|
||||||
|
switch ( token.getType() ) {
|
||||||
case FROM:
|
case FROM:
|
||||||
return hql;
|
return hql;
|
||||||
case WHERE:
|
case WHERE:
|
||||||
|
@ -2238,7 +2241,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
hql,
|
hql,
|
||||||
returnType,
|
returnType,
|
||||||
true,
|
true,
|
||||||
new ErrorHandler( context, method, mirror, value, hql),
|
new ErrorHandler( context, isLocal(method) ? method : element, mirror, value, hql ),
|
||||||
ProcessorSessionFactory.create( context.getProcessingEnvironment() )
|
ProcessorSessionFactory.create( context.getProcessingEnvironment() )
|
||||||
);
|
);
|
||||||
if ( statement != null ) {
|
if ( statement != null ) {
|
||||||
|
|
Loading…
Reference in New Issue