HHH-4613 - KEY, VALUE and ENTRY should not be strict keywords
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18822 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
9f6e1ada66
commit
d7de0dad4e
|
@ -99,9 +99,9 @@ tokens
|
|||
OBJECT="object";
|
||||
OF="of";
|
||||
TRAILING="trailing";
|
||||
KEY="key";
|
||||
VALUE="value";
|
||||
ENTRY="entry";
|
||||
KEY;
|
||||
VALUE;
|
||||
ENTRY;
|
||||
|
||||
// -- Synthetic token types --
|
||||
AGGREGATE; // One of the aggregate functions (e.g. min, max, avg)
|
||||
|
@ -638,20 +638,26 @@ vectorExpr
|
|||
// NOTE: handleDotIdent() is called immediately after the first IDENT is recognized because
|
||||
// the method looks a head to find keywords after DOT and turns them into identifiers.
|
||||
identPrimary
|
||||
: mapComponentReference
|
||||
| identifier { handleDotIdent(); }
|
||||
: i:identifier { handleDotIdent(); }
|
||||
( options { greedy=true; } : DOT^ ( identifier | ELEMENTS | o:OBJECT { #o.setType(IDENT); } ) )*
|
||||
( options { greedy=true; } :
|
||||
( op:OPEN^ { #op.setType(METHOD_CALL);} exprList CLOSE! )
|
||||
( op:OPEN^ { #op.setType(METHOD_CALL);} e:exprList CLOSE! ) {
|
||||
AST path = #e.getFirstChild();
|
||||
if ( #i.getText().equals( "key" ) ) {
|
||||
#identPrimary = #( [KEY], path );
|
||||
}
|
||||
else if ( #i.getText().equals( "value" ) ) {
|
||||
#identPrimary = #( [VALUE], path );
|
||||
}
|
||||
else if ( #i.getText().equals( "entry" ) ) {
|
||||
#identPrimary = #( [ENTRY], path );
|
||||
}
|
||||
}
|
||||
)?
|
||||
// Also allow special 'aggregate functions' such as count(), avg(), etc.
|
||||
| aggregate
|
||||
;
|
||||
|
||||
mapComponentReference
|
||||
: ( KEY^ | VALUE^ | ENTRY^ ) OPEN! path CLOSE!
|
||||
;
|
||||
|
||||
aggregate
|
||||
: ( SUM^ | AVG^ | MAX^ | MIN^ ) OPEN! additiveExpression CLOSE! { #aggregate.setType(AGGREGATE); }
|
||||
// Special case for count - It's 'parameters' can be keywords.
|
||||
|
|
|
@ -85,6 +85,7 @@ public class ASTParserLoadingTest extends FunctionalTestCase {
|
|||
"hql/CrazyIdFieldNames.hbm.xml",
|
||||
"hql/Image.hbm.xml",
|
||||
"hql/ComponentContainer.hbm.xml",
|
||||
"hql/VariousKeywordPropertyEntity.hbm.xml",
|
||||
"batchfetch/ProductLine.hbm.xml",
|
||||
"cid/Customer.hbm.xml",
|
||||
"cid/Order.hbm.xml",
|
||||
|
@ -174,6 +175,23 @@ public class ASTParserLoadingTest extends FunctionalTestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
public void testJPAQLQualifiedIdentificationVariablesControl() {
|
||||
// just checking syntax here...
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
s.createQuery( "from VariousKeywordPropertyEntity where type = 'something'" ).list();
|
||||
s.createQuery( "from VariousKeywordPropertyEntity where value = 'something'" ).list();
|
||||
s.createQuery( "from VariousKeywordPropertyEntity where key = 'something'" ).list();
|
||||
s.createQuery( "from VariousKeywordPropertyEntity where entry = 'something'" ).list();
|
||||
|
||||
s.createQuery( "from VariousKeywordPropertyEntity e where e.type = 'something'" ).list();
|
||||
s.createQuery( "from VariousKeywordPropertyEntity e where e.value = 'something'" ).list();
|
||||
s.createQuery( "from VariousKeywordPropertyEntity e where e.key = 'something'" ).list();
|
||||
s.createQuery( "from VariousKeywordPropertyEntity e where e.entry = 'something'" ).list();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
public void testJPAQLQualifiedIdentificationVariables() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
~ indicated by the @author tags or express copyright attribution
|
||||
~ statements applied by the authors. All third-party contributions are
|
||||
~ distributed under license by Red Hat Inc.
|
||||
~
|
||||
~ This copyrighted material is made available to anyone wishing to use, modify,
|
||||
~ copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
~ Lesser General Public License, as published by the Free Software Foundation.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
~ for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU Lesser General Public License
|
||||
~ along with this distribution; if not, write to:
|
||||
~ Free Software Foundation, Inc.
|
||||
~ 51 Franklin Street, Fifth Floor
|
||||
~ Boston, MA 02110-1301 USA
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.hql">
|
||||
|
||||
<class name="VariousKeywordPropertyEntity">
|
||||
<id name="id" type="long">
|
||||
<generator class="increment"/>
|
||||
</id>
|
||||
<property name="type" type="string" />
|
||||
<property name="value" type="string" />
|
||||
<property name="key" type="string" />
|
||||
<property name="entry" type="string" />
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.hql;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class VariousKeywordPropertyEntity {
|
||||
private Long id;
|
||||
private String value;
|
||||
private String key;
|
||||
private String entry;
|
||||
private String type;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getEntry() {
|
||||
return entry;
|
||||
}
|
||||
|
||||
public void setEntry(String entry) {
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue