Source Code Cross Referenced for EJBQLTest.java in  » Database-ORM » Speedo_1.4.5 » org » objectweb » speedo » ejb » runtime » query » parser » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Speedo_1.4.5 » org.objectweb.speedo.ejb.runtime.query.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Speedo: an implementation of JDO compliant personality on top of JORM generic
003:         * I/O sub-system.
004:         * Copyright (C) 2001-2006 France Telecom
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * Contact: speedo@objectweb.org
021:         *
022:         * Authors: S. Chassande-Barrioz. A. Lefebvre
023:         *
024:         */package org.objectweb.speedo.ejb.runtime.query.parser;
025:
026:        import junit.framework.TestCase;
027:
028:        import java.io.CharArrayReader;
029:
030:        import org.objectweb.util.monolog.api.Logger;
031:        import org.objectweb.util.monolog.api.BasicLevel;
032:        import org.objectweb.util.monolog.Monolog;
033:        import org.objectweb.speedo.query.ejb.parser.EJBQL;
034:
035:        /**
036:         * Speedo QL Test
037:         * Test a list of valid filters.
038:         */
039:        public class EJBQLTest extends TestCase {
040:            final static String filters[] = {
041:                    //tests from specification
042:                    "SELECT DISTINCT o FROM Order AS o JOIN o.lineItems AS l WHERE l.shipped = FALSE",
043:                    "SELECT DISTINCT o FROM Order o JOIN o.lineItems l JOIN l.product p "
044:                            + "WHERE p.productType = 'office_supplies'",
045:                    "SELECT DISTINCT o1 FROM Order o1, Order o2 "
046:                            + "WHERE o1.quantity > o2.quantity AND "
047:                            + "o2.customer.lastname = 'Smith' AND "
048:                            + "o2.customer.firstname= 'John'",
049:                    "SELECT DISTINCT l.product FROM Order AS o, IN(o.lineItems) l",
050:                    "select c from Customer c, Employee e where c.hatsize = e.shoesize",
051:                    "SELECT c FROM Customer c JOIN c.orders o WHERE c.status = 1",
052:                    "SELECT c FROM Customer c INNER JOIN c.orders o WHERE c.status = 1",
053:                    "SELECT OBJECT(c) FROM Customer c, IN(c.orders) o WHERE c.status = 1",
054:                    "SELECT c FROM Customer c LEFT JOIN c.orders o WHERE c.status = 1",
055:                    "SELECT c FROM Customer c LEFT OUTER JOIN c.orders o WHERE c.status = 1",
056:                    "SELECT d FROM Department d LEFT JOIN FETCH d.employees WHERE d.deptno = 1",
057:                    "SELECT DISTINCT o FROM Order o JOIN o.lineItems l JOIN l.product p "
058:                            + "WHERE p.productType = 'office_supplies'",
059:                    "SELECT DISTINCT o FROM Order o, IN(o.lineItems) l "
060:                            + "WHERE l.product.productType = 'office_supplies'",
061:                    "SELECT o FROM Order AS o, IN(o.lineItems) l, Product p",
062:                    //TODO handled names parameters
063:                    "SELECT c FROM Customer c WHERE c.status = :stat",
064:                    "SELECT o FROM Order o WHERE o.x BETWEEN o.y AND o.z",
065:                    "SELECT o FROM Order o WHERE o.y <= o.x AND o.x <= o.z",
066:                    "SELECT p FROM Order p WHERE p.age BETWEEN 15 and 19",
067:                    "SELECT p FROM Order p WHERE p.age >= 15 AND p.age <= 19",
068:                    "SELECT p FROM Order p WHERE p.age NOT BETWEEN 15 and 19",
069:                    "SELECT p FROM Order p WHERE p.age < 15 OR p.age > 19",
070:                    "SELECT o FROM Order o WHERE o.country IN ('UK','US','France')",
071:                    "SELECT o FROM Order o WHERE (o.country='UK') OR (o.country='US') OR (o.country='France')",
072:                    "SELECT DISTINCT emp FROM Employee emp WHERE EXISTS ("
073:                            + "SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp = emp.spouse)",
074:                    "SELECT c FROM Customer c WHERE (SELECT COUNT(o) FROM c.orders o) > 10",
075:                    "SELECT goodCustomer FROM Customer goodCustomer "
076:                            + "WHERE goodCustomer.balanceOwed < "
077:                            + "(SELECT avg(c.balanceOwed) FROM Customer c)",
078:                    "SELECT c.status, avg(c.filledOrderCount), count(c) FROM Customer c "
079:                            + "GROUP BY c.status HAVING c.status IN (1, 2)",
080:                    "SELECT c.country, COUNT(c) FROM Customer c GROUP BY c.country "
081:                            + "HAVING COUNT(c.country) > 3",
082:                    //TODO: handle any keyword as part of a path - replacing with ccount for now
083:                    //	"SELECT c.id, c.status FROM Customer c JOIN c.orders o WHERE o.count > 100",
084:                    "SELECT c.id, c.status FROM Customer c JOIN c.orders o WHERE o.ccount > 100",
085:                    //TODO: handle any keyword as part of a path - replacing with ccount for now
086:                    //"SELECT NEW com.acme.example.CustomerDetails(c.id, c.status, o.count) "
087:                    //	+ "FROM Customer c JOIN c.orders o WHERE o.count > 100",
088:                    "SELECT NEW com.acme.example.CustomerDetails(c.id, c.status, o.ccount) "
089:                            + "FROM Customer c JOIN c.orders o WHERE o.ccount > 100",
090:                    "SELECT AVG(o.quantity) FROM Order o",
091:                    "SELECT SUM(l.price) FROM Order o JOIN o.lineItems l JOIN o.customer c "
092:                            + "WHERE c.lastname = 'Smith' AND c.firstname = 'John'",
093:                    "SELECT COUNT(o) FROM Order o",
094:                    "SELECT COUNT(l.price) FROM Order o JOIN o.lineItems l JOIN o.customer c "
095:                            + "WHERE c.lastname = 'Smith' AND c.firstname = 'John'",
096:                    "SELECT COUNT(l) FROM Order o JOIN o.lineItems l JOIN o.customer c "
097:                            + "WHERE c.lastname = 'Smith' AND c.firstname = 'John' "
098:                            + "AND l.price IS NOT NULL",
099:                    "SELECT o FROM Customer c JOIN c.orders o JOIN c.address a "
100:                            + "WHERE a.state = 'CA' ORDER BY o.quantity, o.totalcost",
101:                    "SELECT o.quantity, a.zipcode FROM Customer c JOIN c.orders o JOIN c.address a "
102:                            + "WHERE a.state = 'CA' ORDER BY o.quantity, a.zipcode",
103:                    //the following one is identified as not legal in the spec because orderby
104:                    // is not reflected in the select clause
105:                    /*
106:                    "SELECT p.product_name FROM Order o JOIN o.lineItems l JOIN l.product p JOIN o.customer c "
107:                    + "WHERE c.lastname = 'Smith' AND c.firstname = 'John' "
108:                    + "ORDER BY p.price", 
109:                     */
110:                    "DELETE FROM Customer c WHERE c.status = 'inactive'",
111:                    "DELETE FROM Customer c WHERE c.status = 'inactive' AND c.orders IS EMPTY",
112:                    "UPDATE customer c SET c.status = 'outstanding' "
113:                            + "WHERE c.balance < 10000  AND 1000 > "
114:                            + "(SELECT COUNT(o) FROM customer cust JOIN cust.order o)",
115:                    //tests from specification: Examples
116:                    "SELECT o FROM Order o",
117:                    "SELECT o FROM Order o WHERE o.shippingAddress.state = 'CA'",
118:                    "SELECT DISTINCT o.shippingAddress.state FROM Order o",
119:                    "SELECT o FROM Order o WHERE o.lineItems IS NOT EMPTY",
120:                    "SELECT o FROM Order o WHERE o.lineItems IS EMPTY",
121:                    "SELECT DISTINCT o FROM Order o JOIN o.lineItems l WHERE l.shipped = FALSE",
122:                    "SELECT o FROM Order o WHERE "
123:                            + "NOT (o.shippingAddress.state = o.billingAddress.state "
124:                            + "AND o.shippingAddress.city = o.billingAddress.city "
125:                            + "AND o.shippingAddress.street = o.billingAddress.street)",
126:                    "SELECT o FROM Order o WHERE o.shippingAddress <> o.billingAddress",
127:                    "SELECT DISTINCT o FROM Order o JOIN o.lineItems l "
128:                            + "WHERE l.product.type = 'book' AND "
129:                            + "l.product.name = 'Applying Enterprise JavaBeans: Component-Based Development for the J2EE Platform'",
130:                    "SELECT DISTINCT o FROM Order o, IN(o.lineItems) l WHERE l.product.name = ?1",
131:                    //additional tests
132:                    "SELECT o.shippingAddress.state FROM Order o",
133:                    "SELECT o FROM Order o WHERE o.shippingAddress.state IS NOT EMPTY",
134:                    "SELECT o FROM Order o WHERE o.shippingAddress.state = ?1",
135:                    "SELECT o FROM Order o WHERE o.shippingAddress.state = o.state",
136:                    "SELECT o FROM Order o WHERE 'CA' = o.shippingAddress.state",
137:                    "SELECT o FROM Order o WHERE 12 = o.shippingAddress.state",
138:                    "SELECT o FROM Order o WHERE o.shippingAddress.state = 12"
139:
140:            };
141:
142:            private final static String LOGGER_NAME = "org.objectweb.speedo.rt.query.parser.ejbql";
143:
144:            private static Logger logger = null;
145:
146:            static {
147:                logger = Monolog.initialize().getLogger(LOGGER_NAME);
148:            }
149:
150:            public EJBQLTest(String name) {
151:                super (name);
152:            }
153:
154:            public void testAll() {
155:                logger.log(BasicLevel.DEBUG, "EJBQL Test - javacc grammar");
156:                for (int i = 0; i < filters.length; i++) {
157:                    String filter = filters[i];
158:                    logger.log(BasicLevel.DEBUG, "Testing: " + filter);
159:                    try {
160:                        new EJBQL(new CharArrayReader(filter.toCharArray()))
161:                                .EJBQL();
162:                    } catch (Throwable e) {
163:                        logger
164:                                .log(BasicLevel.ERROR, "Parsing of: " + filter,
165:                                        e);
166:                        fail("Parsing of: " + filter);
167:                    }
168:
169:                }
170:            }
171:        }
ww__w__.j__a___v___a_2___s.c_o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.