mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 16:44:57 +00:00
support 'this' with @Query repository methods
in a very temporary way Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
e1bcd01321
commit
8aaf0c7c9d
@ -16,4 +16,10 @@ public interface Bookshop extends CrudRepository<Book,String> {
|
|||||||
|
|
||||||
@Query("select isbn where title like ?1 order by isbn")
|
@Query("select isbn where title like ?1 order by isbn")
|
||||||
String[] ssns(String title);
|
String[] ssns(String title);
|
||||||
|
|
||||||
|
@Query("select count(this) where title like ?1 order by isbn")
|
||||||
|
long count1(String title);
|
||||||
|
|
||||||
|
@Query("select count(this) where this.title like ?1 order by this.isbn")
|
||||||
|
long count2(String title);
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@
|
|||||||
import static org.hibernate.grammars.hql.HqlLexer.FROM;
|
import static org.hibernate.grammars.hql.HqlLexer.FROM;
|
||||||
import static org.hibernate.grammars.hql.HqlLexer.GROUP;
|
import static org.hibernate.grammars.hql.HqlLexer.GROUP;
|
||||||
import static org.hibernate.grammars.hql.HqlLexer.HAVING;
|
import static org.hibernate.grammars.hql.HqlLexer.HAVING;
|
||||||
|
import static org.hibernate.grammars.hql.HqlLexer.IDENTIFIER;
|
||||||
import static org.hibernate.grammars.hql.HqlLexer.ORDER;
|
import static org.hibernate.grammars.hql.HqlLexer.ORDER;
|
||||||
import static org.hibernate.grammars.hql.HqlLexer.WHERE;
|
import static org.hibernate.grammars.hql.HqlLexer.WHERE;
|
||||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||||
@ -2155,9 +2156,17 @@ else if ( isInsertUpdateDelete(hql) ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final HqlLexer hqlLexer = HqlParseTreeBuilder.INSTANCE.buildHqlLexer( hql );
|
final HqlLexer hqlLexer = HqlParseTreeBuilder.INSTANCE.buildHqlLexer( hql );
|
||||||
|
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() ) {
|
switch ( token.getType() ) {
|
||||||
|
//TEMPORARY until HQL gets support for 'this'
|
||||||
|
case IDENTIFIER:
|
||||||
|
final String text = token.getText();
|
||||||
|
if ( text.equalsIgnoreCase("this") ) {
|
||||||
|
thisText = " as " + text;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case FROM:
|
case FROM:
|
||||||
return hql;
|
return hql;
|
||||||
case WHERE:
|
case WHERE:
|
||||||
@ -2165,11 +2174,11 @@ else if ( isInsertUpdateDelete(hql) ) {
|
|||||||
case GROUP:
|
case GROUP:
|
||||||
case ORDER:
|
case ORDER:
|
||||||
return new StringBuilder(hql)
|
return new StringBuilder(hql)
|
||||||
.insert(token.getStartIndex(), "from " + entityType + " ")
|
.insert(token.getStartIndex(), "from " + entityType + thisText + " ")
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hql + " from " + entityType;
|
return hql + " from " + entityType + thisText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user