From 69c34cd385cfd06409b8009af5c9a681233d26b1 Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Thu, 8 Mar 2007 09:34:25 +0000 Subject: [PATCH] OPENJPA-46: TRUE and FALSE should be case-insensitive in JPQL git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@515986 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/openjpa/kernel/jpql/JPQL.jjt | 6 ++- .../TestCaseInsensitiveKeywordsInJPQL.java | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java diff --git a/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt b/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt index 1cf7d964e..6bb2cc3c1 100644 --- a/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt +++ b/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt @@ -248,7 +248,6 @@ TOKEN : /* literals */ | ((["0"-"9"])+ ".") ()? (["f","F","d","D"])? | ((["0"-"9"])+) () (["f","F","d","D"])? | ((["0"-"9"])+) ()? (["f","F","d","D"])?) > - | < BOOLEAN_LITERAL: "TRUE" | "FALSE" | "true" | "false" > | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | < STRING_LITERAL: "'" (("''" | ~["'"]) @@ -277,6 +276,11 @@ TOKEN : /* literals */ > } +TOKEN [ IGNORE_CASE ]: /* boolean literals can be case-insensitive */ +{ + < BOOLEAN_LITERAL: "TRUE" | "FALSE" > +} + /* From the Java 1.0.2 specification */ TOKEN : /* IDENTIFIERS */ { diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java new file mode 100644 index 000000000..0a225e82f --- /dev/null +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestCaseInsensitiveKeywordsInJPQL.java @@ -0,0 +1,41 @@ +package org.apache.openjpa.persistence.simple; + +import javax.persistence.Query; +import javax.persistence.EntityManager; + +import org.apache.openjpa.persistence.test.PersistenceTestCase; + +public class TestCaseInsensitiveKeywordsInJPQL + extends PersistenceTestCase { + + public Class[] getEntityTypes() { + return new Class[] { AllFieldTypes.class }; + } + + public void testCaseInsensitiveBooleans() { + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + + AllFieldTypes aft = new AllFieldTypes(); + em.persist(aft); + aft.setBooleanField(true); + + aft = new AllFieldTypes(); + em.persist(aft); + aft.setBooleanField(false); + + em.flush(); + + Query q = em.createQuery( + "select count(o) from AllFieldTypes o where o.booleanField = TrUe"); + Number n = (Number) q.getSingleResult(); + assertEquals(1, n.intValue()); + + q = em.createQuery("select count(o) from AllFieldTypes o " + + "where o.booleanField = falSe"); + n = (Number) q.getSingleResult(); + assertEquals(1, n.intValue()); + + em.getTransaction().rollback(); + } +} \ No newline at end of file