[hibernate-commits] Hibernate SVN: r18822 - in core/trunk: testsuite/src/test/java/org/hibernate/test/hql and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Wed Feb 17 14:56:42 EST 2010
Author: steve.ebersole at jboss.com
Date: 2010-02-17 14:56:41 -0500 (Wed, 17 Feb 2010)
New Revision: 18822
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/VariousKeywordPropertyEntity.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/VariousKeywordPropertyEntity.java
Modified:
core/trunk/core/src/main/antlr/hql.g
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-4613 - KEY, VALUE and ENTRY should not be strict keywords
Modified: core/trunk/core/src/main/antlr/hql.g
===================================================================
--- core/trunk/core/src/main/antlr/hql.g 2010-02-17 18:49:38 UTC (rev 18821)
+++ core/trunk/core/src/main/antlr/hql.g 2010-02-17 19:56:41 UTC (rev 18822)
@@ -99,9 +99,9 @@
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 @@
// 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.
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-02-17 18:49:38 UTC (rev 18821)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-02-17 19:56:41 UTC (rev 18822)
@@ -85,6 +85,7 @@
"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 @@
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();
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/VariousKeywordPropertyEntity.hbm.xml (from rev 18810, core/trunk/testsuite/src/test/java/org/hibernate/test/hql/SimpleEntityWithAssociation.hbm.xml)
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/VariousKeywordPropertyEntity.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/VariousKeywordPropertyEntity.hbm.xml 2010-02-17 19:56:41 UTC (rev 18822)
@@ -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>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/VariousKeywordPropertyEntity.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/VariousKeywordPropertyEntity.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/VariousKeywordPropertyEntity.java 2010-02-17 19:56:41 UTC (rev 18822)
@@ -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;
+ }
+}
More information about the hibernate-commits
mailing list