Source Code Cross Referenced for QueryTest.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » cmp2 » commerce » 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 » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.cmp2.commerce 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.cmp2.commerce;
023:
024:        import java.util.Collection;
025:        import java.util.Set;
026:        import java.lang.reflect.Method;
027:        import javax.management.MBeanServer;
028:        import javax.management.MBeanServerFactory;
029:        import javax.management.ObjectName;
030:
031:        import junit.framework.Test;
032:        import org.jboss.ejb.EntityContainer;
033:        import org.jboss.ejb.plugins.cmp.ejbql.Catalog;
034:        import org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler;
035:        import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData;
036:        import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData;
037:        import org.jboss.mx.server.ServerConstants;
038:        import org.jboss.mx.server.registry.MBeanEntry;
039:        import org.jboss.mx.server.registry.MBeanRegistry;
040:        import org.jboss.test.JBossTestCase;
041:        import org.jboss.mx.util.MBeanProxyExt;
042:        import org.jboss.util.UnreachableStatementException;
043:
044:        public class QueryTest extends org.jboss.test.util.ejb.EJBTestCase {
045:            private JDBCEJBQLCompiler compiler;
046:            private static final String javaVersion = System
047:                    .getProperty("java.specification.version");
048:            private static final Class[] NO_PARAMS = new Class[] {};
049:
050:            public static Test suite() throws Exception {
051:                return JBossTestCase.getDeploySetup(QueryTest.class,
052:                        "cmp2-commerce.jar");
053:            }
054:
055:            public QueryTest(String name) {
056:                super (name);
057:            }
058:
059:            public void setUpEJB() throws Exception {
060:                MBeanServer server = (MBeanServer) MBeanServerFactory
061:                        .findMBeanServer(null).get(0);
062:                ObjectName name = new ObjectName(
063:                        "jboss.j2ee:jndiName=commerce/Order,service=EJB");
064:                MBeanRegistry registry = (MBeanRegistry) MBeanProxyExt.create(
065:                        MBeanRegistry.class, ServerConstants.MBEAN_REGISTRY,
066:                        server);
067:                MBeanEntry entry = registry.get(name);
068:                EntityContainer container = (EntityContainer) entry
069:                        .getResourceInstance();
070:                Catalog catalog = (Catalog) container.getEjbModule()
071:                        .getModuleData("CATALOG");
072:                compiler = new JDBCEJBQLCompiler(catalog);
073:            }
074:
075:            private String compileEJBQL(String ejbql) {
076:                return compileEJBQL(ejbql, java.util.Collection.class,
077:                        NO_PARAMS);
078:            }
079:
080:            private String compileEJBQL(String ejbql, Class returnType,
081:                    Class[] paramClasses) {
082:                try {
083:                    compiler.compileEJBQL(ejbql, returnType, paramClasses,
084:                            new JDBCQueryMetaData() {
085:                                public Method getMethod() {
086:                                    throw new UnsupportedOperationException();
087:                                }
088:
089:                                public boolean isResultTypeMappingLocal() {
090:                                    return true;
091:                                }
092:
093:                                public JDBCReadAheadMetaData getReadAhead() {
094:                                    return new JDBCReadAheadMetaData("on-load",
095:                                            100, "*");
096:                                }
097:
098:                                public Class getQLCompilerClass() {
099:                                    throw new UnsupportedOperationException();
100:                                }
101:
102:                                public boolean isLazyResultSetLoading() {
103:                                    return false;
104:                                }
105:                            });
106:                    return compiler.getSQL().trim();
107:                } catch (Throwable t) {
108:                    fail(t.getMessage());
109:                    throw new UnreachableStatementException();
110:                }
111:            }
112:
113:            private String compileJBossQL(String ejbql, Class returnType,
114:                    Class[] paramClasses) {
115:                return compileJBossQL(ejbql, returnType, paramClasses,
116:                        new JDBCQueryMetaData() {
117:                            public Method getMethod() {
118:                                throw new UnsupportedOperationException();
119:                            }
120:
121:                            public boolean isResultTypeMappingLocal() {
122:                                return true;
123:                            }
124:
125:                            public JDBCReadAheadMetaData getReadAhead() {
126:                                return new JDBCReadAheadMetaData("on-load",
127:                                        100, "*");
128:                            }
129:
130:                            public Class getQLCompilerClass() {
131:                                throw new UnsupportedOperationException();
132:                            }
133:
134:                            public boolean isLazyResultSetLoading() {
135:                                return false;
136:                            }
137:                        });
138:            }
139:
140:            private String compileJBossQL(String ejbql, Class returnType,
141:                    Class[] paramClasses, JDBCQueryMetaData metadata) {
142:                try {
143:                    compiler.compileJBossQL(ejbql, returnType, paramClasses,
144:                            metadata);
145:                    return compiler.getSQL();
146:                } catch (Throwable t) {
147:                    fail(t.getMessage());
148:                    throw new UnreachableStatementException();
149:                }
150:            }
151:
152:            public void testJBossQL() throws Exception {
153:                assertEquals(
154:                        "SELECT t0_u.USER_ID FROM USER_DATA t0_u WHERE (ucase(t0_u.USER_NAME) = ?)",
155:                        compileJBossQL(
156:                                "SELECT OBJECT(u) FROM user u WHERE UCASE(u.userName) = ?1",
157:                                Collection.class, new Class[] { String.class }));
158:
159:                assertEquals(
160:                        "SELECT t0_u.USER_ID FROM USER_DATA t0_u WHERE (lcase(t0_u.USER_NAME) = ?)",
161:                        compileJBossQL(
162:                                "SELECT OBJECT(u) FROM user u WHERE LCASE(u.userName) = ?1",
163:                                Collection.class, new Class[] { String.class }));
164:
165:                String expected = "1.4".equals(javaVersion) ? "SELECT t0_o1.ORDER_NUMBER FROM ORDER_DATA t0_o1, ORDER_DATA t3_o2, CUSTOMEREJB t2_o2_customer, CUSTOMEREJB t1_o1_customer WHERE (( NOT (t1_o1_customer.id=t2_o2_customer.id)) AND (t0_o1.CC_TYPE=t3_o2.CC_TYPE AND t0_o1.CC_FIRST_NAME=t3_o2.CC_FIRST_NAME AND t0_o1.CC_MI=t3_o2.CC_MI AND t0_o1.CC_LAST_NAME=t3_o2.CC_LAST_NAME AND t0_o1.CC_BILLING_ZIP=t3_o2.CC_BILLING_ZIP AND t0_o1.CC_CARD_NUMBER=t3_o2.CC_CARD_NUMBER) AND t3_o2.customer=t2_o2_customer.id AND t0_o1.customer=t1_o1_customer.id)"
166:                        : "SELECT t0_o1.ORDER_NUMBER FROM ORDER_DATA t0_o1, ORDER_DATA t3_o2, CUSTOMEREJB t1_o1_customer, CUSTOMEREJB t2_o2_customer WHERE (( NOT (t1_o1_customer.id=t2_o2_customer.id)) AND (t0_o1.CC_TYPE=t3_o2.CC_TYPE AND t0_o1.CC_FIRST_NAME=t3_o2.CC_FIRST_NAME AND t0_o1.CC_MI=t3_o2.CC_MI AND t0_o1.CC_LAST_NAME=t3_o2.CC_LAST_NAME AND t0_o1.CC_BILLING_ZIP=t3_o2.CC_BILLING_ZIP AND t0_o1.CC_CARD_NUMBER=t3_o2.CC_CARD_NUMBER) AND t0_o1.customer=t1_o1_customer.id AND t3_o2.customer=t2_o2_customer.id)";
167:                String compiled = compileJBossQL(
168:                        "SELECT OBJECT(o1) FROM OrderX o1, OrderX o2 WHERE o1.customer <> o2.customer AND o1.creditCard = o2.creditCard",
169:                        Collection.class, NO_PARAMS);
170:                /*
171:                assertTrue("Expected: " + expected + " but got: " + compiled, expected.equals(compiled));
172:                 */
173:                if (expected.equals(compiled) == false)
174:                    System.err.println("Expected: " + expected + " but got: "
175:                            + compiled);
176:
177:                assertEquals(
178:                        "SELECT t0_o.ORDER_NUMBER " + "FROM ORDER_DATA t0_o "
179:                                + "WHERE ((t0_o.CC_TYPE=? "
180:                                + "AND t0_o.CC_FIRST_NAME=? "
181:                                + "AND t0_o.CC_MI=? "
182:                                + "AND t0_o.CC_LAST_NAME=? "
183:                                + "AND t0_o.CC_BILLING_ZIP=? "
184:                                + "AND t0_o.CC_CARD_NUMBER=?))",
185:                        compileJBossQL(
186:                                "SELECT OBJECT(o) FROM OrderX o WHERE o.creditCard = ?1",
187:                                Collection.class, new Class[] { Card.class }));
188:
189:                assertEquals(
190:                        "SELECT t0_o.ORDER_NUMBER " + "FROM ORDER_DATA t0_o "
191:                                + "WHERE (( NOT (t0_o.CC_TYPE=? "
192:                                + "AND t0_o.CC_FIRST_NAME=? "
193:                                + "AND t0_o.CC_MI=? "
194:                                + "AND t0_o.CC_LAST_NAME=? "
195:                                + "AND t0_o.CC_BILLING_ZIP=? "
196:                                + "AND t0_o.CC_CARD_NUMBER=?)))",
197:                        compileJBossQL(
198:                                "SELECT OBJECT(o) FROM OrderX o WHERE o.creditCard <> ?1",
199:                                Collection.class, new Class[] { Card.class }));
200:
201:                assertEquals(
202:                        "SELECT DISTINCT t0_u.USER_ID, t0_u.USER_NAME FROM USER_DATA t0_u ORDER BY t0_u.USER_NAME ASC",
203:                        compileJBossQL(
204:                                "SELECT DISTINCT OBJECT(u) FROM user u ORDER BY u.userName",
205:                                Collection.class, NO_PARAMS));
206:                assertEquals(
207:                        "SELECT DISTINCT t0_u.USER_ID FROM USER_DATA t0_u ORDER BY t0_u.USER_ID ASC",
208:                        compileJBossQL(
209:                                "SELECT DISTINCT OBJECT(u) FROM user u ORDER BY u.userId",
210:                                Collection.class, NO_PARAMS));
211:                assertEquals(
212:                        "SELECT DISTINCT t0_u.USER_NAME FROM USER_DATA t0_u ORDER BY t0_u.USER_NAME ASC",
213:                        compileJBossQL(
214:                                "SELECT DISTINCT u.userName FROM user u ORDER BY u.userName",
215:                                Collection.class, NO_PARAMS));
216:                assertEquals(
217:                        "SELECT DISTINCT ucase(t0_u.USER_NAME) FROM USER_DATA t0_u ORDER BY t0_u.USER_NAME ASC",
218:                        compileJBossQL(
219:                                "SELECT DISTINCT UCASE(u.userName) FROM user u ORDER BY u.userName",
220:                                Collection.class, new Class[] { String.class }));
221:                assertEquals(
222:                        "SELECT DISTINCT t0_u.USER_NAME, t0_u.USER_ID FROM USER_DATA t0_u ORDER BY t0_u.USER_ID ASC",
223:                        compileJBossQL(
224:                                "SELECT DISTINCT u.userName FROM user u ORDER BY u.userId",
225:                                Collection.class, new Class[] { String.class }));
226:
227:                assertEquals(
228:                        "SELECT t0_o.ORDER_NUMBER FROM ORDER_DATA t0_o, ADDRESSEJB t1_o_shippingAddress WHERE (t1_o_shippingAddress.city = ? AND t0_o.SHIPPING_ADDRESS=t1_o_shippingAddress.id) OR (t1_o_shippingAddress.state = ? AND t0_o.SHIPPING_ADDRESS=t1_o_shippingAddress.id)",
229:                        compileJBossQL(
230:                                "SELECT OBJECT(o) FROM OrderX o WHERE o.shippingAddress.city=?1 OR o.shippingAddress.state=?2",
231:                                Collection.class, new Class[] { String.class,
232:                                        String.class }));
233:
234:                assertEquals(
235:                        "SELECT t0_o.ORDER_NUMBER, t1_o_shippingAddress.state FROM ORDER_DATA t0_o, ADDRESSEJB t1_o_shippingAddress WHERE t0_o.SHIPPING_ADDRESS=t1_o_shippingAddress.id ORDER BY t1_o_shippingAddress.state ASC",
236:                        compileJBossQL(
237:                                "SELECT OBJECT(o) FROM OrderX o ORDER BY o.shippingAddress.state",
238:                                Collection.class, new Class[] { String.class,
239:                                        String.class }));
240:
241:                JDBCQueryMetaData lazyMD = new JDBCQueryMetaData() {
242:                    public Method getMethod() {
243:                        throw new UnsupportedOperationException();
244:                    }
245:
246:                    public boolean isResultTypeMappingLocal() {
247:                        return true;
248:                    }
249:
250:                    public JDBCReadAheadMetaData getReadAhead() {
251:                        return new JDBCReadAheadMetaData("on-load", 4, "*");
252:                    }
253:
254:                    public Class getQLCompilerClass() {
255:                        throw new UnsupportedOperationException();
256:                    }
257:
258:                    public boolean isLazyResultSetLoading() {
259:                        return true;
260:                    }
261:
262:                };
263:
264:                assertEquals(
265:                        "SELECT (SELECT count(t0_o.id) FROM ADDRESSEJB t0_o WHERE (t0_o.state = 'CA')), t0_o.id "
266:                                + "FROM ADDRESSEJB t0_o WHERE (t0_o.state = 'CA')",
267:                        compileJBossQL(
268:                                "select object(o) from Address o where o.state='CA'",
269:                                Collection.class, NO_PARAMS, lazyMD));
270:
271:                assertEquals(
272:                        "SELECT DISTINCT (SELECT count(DISTINCT t0_o.id) FROM LINEITEMEJB t0_o WHERE (t0_o.quantity > 1000)), t0_o.id "
273:                                + "FROM LINEITEMEJB t0_o WHERE (t0_o.quantity > 1000)",
274:                        compileJBossQL(
275:                                "select object(o) from LineItem o where o.quantity > 1000 offset 1 limit 2",
276:                                Set.class, NO_PARAMS, lazyMD));
277:
278:                assertEquals(
279:                        "SELECT (SELECT count(t0_o.city) FROM ADDRESSEJB t0_o WHERE (t0_o.state = 'CA')), t0_o.city "
280:                                + "FROM ADDRESSEJB t0_o WHERE (t0_o.state = 'CA')",
281:                        compileJBossQL(
282:                                "select o.city from Address o where o.state='CA'",
283:                                Collection.class, NO_PARAMS, lazyMD));
284:
285:                assertEquals(
286:                        "SELECT DISTINCT (SELECT count(DISTINCT t0_o.city) FROM ADDRESSEJB t0_o WHERE (t0_o.state = 'CA')), t0_o.city "
287:                                + "FROM ADDRESSEJB t0_o WHERE (t0_o.state = 'CA')",
288:                        compileJBossQL(
289:                                "select distinct o.city from Address o where o.state='CA'",
290:                                Collection.class, NO_PARAMS, lazyMD));
291:            }
292:
293:            public void testEJBQL() throws Exception {
294:                assertEquals("SELECT t0_o.ORDER_NUMBER FROM ORDER_DATA t0_o",
295:                        compileEJBQL("SELECT OBJECT(o) FROM OrderX o"));
296:
297:                assertEquals(
298:                        "SELECT t0_o.ORDER_NUMBER FROM ORDER_DATA t0_o, ADDRESSEJB t1_o_shippingAddress WHERE (t1_o_shippingAddress.city = ? AND t0_o.SHIPPING_ADDRESS=t1_o_shippingAddress.id) OR (t1_o_shippingAddress.state = ? AND t0_o.SHIPPING_ADDRESS=t1_o_shippingAddress.id)",
299:                        compileEJBQL(
300:                                "SELECT OBJECT(o) FROM OrderX o WHERE o.shippingAddress.city=?1 OR o.shippingAddress.state=?2",
301:                                Collection.class, new Class[] { String.class,
302:                                        String.class }));
303:
304:                String expected = "1.4".equals(javaVersion) ? "SELECT t0_o.ORDER_NUMBER "
305:                        + "FROM ORDER_DATA t0_o, LINEITEMEJB t4_l, PRODUCTCATEGORYEJB t1_pc, PRODUCT_PRODUCT_CATEGORY t5_l_product_productCategories_R, PRODUCT t6_l_product "
306:                        + "WHERE (((t0_o.ORDER_NUMBER = ? AND t1_pc.name = ?))) "
307:                        + "AND t6_l_product.id=t5_l_product_productCategories_R.PRODUCT_ID "
308:                        + "AND t1_pc.id=t5_l_product_productCategories_R.PRODUCT_CATEGORY_ID "
309:                        + "AND t1_pc.subId=t5_l_product_productCategories_R.PRODUCT_CATEGORY_SUBID "
310:                        + "AND t4_l.product=t6_l_product.id AND t0_o.ORDER_NUMBER=t4_l.ORDER_NUMBER"
311:                        : "SELECT t0_o.ORDER_NUMBER "
312:                                + "FROM ORDER_DATA t0_o, LINEITEMEJB t4_l, PRODUCTCATEGORYEJB t1_pc, PRODUCT_PRODUCT_CATEGORY t5_l_product_productCategories_R, PRODUCT t6_l_product "
313:                                + "WHERE (((t0_o.ORDER_NUMBER = ? AND t1_pc.name = ?))) "
314:                                + "AND t0_o.ORDER_NUMBER=t4_l.ORDER_NUMBER "
315:                                + "AND t6_l_product.id=t5_l_product_productCategories_R.PRODUCT_ID "
316:                                + "AND t1_pc.id=t5_l_product_productCategories_R.PRODUCT_CATEGORY_ID "
317:                                + "AND t1_pc.subId=t5_l_product_productCategories_R.PRODUCT_CATEGORY_SUBID "
318:                                + "AND t4_l.product=t6_l_product.id";
319:
320:                String compiled = compileEJBQL(
321:                        "SELECT OBJECT(o) FROM OrderX o, "
322:                                + "IN(o.lineItems) l, "
323:                                + "IN(l.product.productCategories) pc "
324:                                + "WHERE (o.ordernumber = ?1 and pc.name=?2)",
325:                        Collection.class, new Class[] { Long.class,
326:                                String.class });
327:                /*
328:                assertEquals(expected, compiled);
329:                 */
330:                if (expected.equals(compiled) == false)
331:                    System.err.println("Expected: " + expected + " but got: "
332:                            + compiled);
333:
334:                expected = "SELECT DISTINCT t0_o.ORDER_NUMBER "
335:                        + "FROM ORDER_DATA t0_o, LINEITEMEJB t3_l "
336:                        + "WHERE (t0_o.ORDER_NUMBER = ?) OR (EXISTS (SELECT t2_o_lineItems.id FROM LINEITEMEJB t2_o_lineItems "
337:                        + "WHERE t0_o.ORDER_NUMBER=t2_o_lineItems.ORDER_NUMBER AND t2_o_lineItems.id=t3_l.id))";
338:                compiled = compileEJBQL(
339:                        "SELECT OBJECT(o) FROM OrderX o, LineItem l WHERE o.ordernumber = ?1 OR l MEMBER o.lineItems",
340:                        Set.class, new Class[] { Long.class });
341:                assertTrue("Expected: " + expected + " but got: " + compiled,
342:                        expected.equals(compiled));
343:
344:                assertEquals(
345:                        "SELECT DISTINCT t0_o.ORDER_NUMBER "
346:                                + "FROM ORDER_DATA t0_o, LINEITEMEJB t3_l "
347:                                + "WHERE (t0_o.ORDER_NUMBER = ?) OR ( NOT EXISTS (SELECT t2_o_lineItems.id FROM LINEITEMEJB t2_o_lineItems "
348:                                + "WHERE t0_o.ORDER_NUMBER=t2_o_lineItems.ORDER_NUMBER AND t2_o_lineItems.id=t3_l.id))",
349:                        compileEJBQL(
350:                                "SELECT OBJECT(o) FROM OrderX o, LineItem l WHERE o.ordernumber = ?1 OR l NOT MEMBER o.lineItems",
351:                                Set.class, new Class[] { Long.class }));
352:
353:                assertEquals(
354:                        "SELECT DISTINCT t0_p.id "
355:                                + "FROM PRODUCT t0_p, PRODUCTCATEGORYEJB t4_pc "
356:                                + "WHERE (t0_p.id = ?) OR (EXISTS ("
357:                                + "SELECT t3_p_productCategories_RELATION_.PRODUCT_CATEGORY_ID, t3_p_productCategories_RELATION_.PRODUCT_CATEGORY_SUBID "
358:                                + "FROM PRODUCT_PRODUCT_CATEGORY t3_p_productCategories_RELATION_ "
359:                                + "WHERE t0_p.id=t3_p_productCategories_RELATION_.PRODUCT_ID "
360:                                + "AND t4_pc.id=t3_p_productCategories_RELATION_.PRODUCT_CATEGORY_ID "
361:                                + "AND t4_pc.subId=t3_p_productCategories_RELATION_.PRODUCT_CATEGORY_SUBID))",
362:                        compileEJBQL(
363:                                "SELECT OBJECT(p) FROM Product p, ProductCategory pc WHERE p.id = ?1 OR pc MEMBER p.productCategories",
364:                                Set.class, new Class[] { Long.class }));
365:
366:                assertEquals(
367:                        "SELECT DISTINCT t0_p.id "
368:                                + "FROM PRODUCT t0_p, PRODUCTCATEGORYEJB t4_pc "
369:                                + "WHERE (t0_p.id = ?) OR ( NOT EXISTS ("
370:                                + "SELECT t3_p_productCategories_RELATION_.PRODUCT_CATEGORY_ID, t3_p_productCategories_RELATION_.PRODUCT_CATEGORY_SUBID "
371:                                + "FROM PRODUCT_PRODUCT_CATEGORY t3_p_productCategories_RELATION_ "
372:                                + "WHERE t0_p.id=t3_p_productCategories_RELATION_.PRODUCT_ID "
373:                                + "AND t4_pc.id=t3_p_productCategories_RELATION_.PRODUCT_CATEGORY_ID "
374:                                + "AND t4_pc.subId=t3_p_productCategories_RELATION_.PRODUCT_CATEGORY_SUBID))",
375:                        compileEJBQL(
376:                                "SELECT OBJECT(p) FROM Product p, ProductCategory pc WHERE p.id = ?1 OR pc NOT MEMBER p.productCategories",
377:                                Set.class, new Class[] { Long.class }));
378:
379:                assertEquals(
380:                        "SELECT DISTINCT t0_o.ORDER_NUMBER "
381:                                + "FROM ORDER_DATA t0_o "
382:                                + "WHERE (t0_o.ORDER_NUMBER = ?) OR (EXISTS (SELECT t2_o_lineItems.id "
383:                                + "FROM LINEITEMEJB t2_o_lineItems "
384:                                + "WHERE t0_o.ORDER_NUMBER=t2_o_lineItems.ORDER_NUMBER))",
385:                        compileEJBQL(
386:                                "SELECT OBJECT(o) FROM OrderX o WHERE o.ordernumber = ?1 OR o.lineItems IS NOT EMPTY",
387:                                Set.class, new Class[] { Long.class }));
388:
389:                assertEquals(
390:                        "SELECT t0_l.id FROM CUSTOMEREJB t1_c, ORDER_DATA t3_o, LINEITEMEJB t0_l WHERE ((t1_c.id = 1)) AND t1_c.id=t3_o.customer AND t3_o.ORDER_NUMBER=t0_l.ORDER_NUMBER",
391:                        compileEJBQL("SELECT OBJECT(l) FROM Customer c, IN(c.orders) o, IN(o.lineItems) l WHERE c.id=1"));
392:
393:                // customer query was SELECT OBJECT(s) FROM Service AS s, Platform AS p WHERE p.id = ?1 AND s.server MEMBER OF p.servers
394:                assertEquals(
395:                        "SELECT t0_l.id FROM LINEITEMEJB t0_l, CUSTOMEREJB t1_c, ORDER_DATA t3_l_order WHERE (t1_c.id = 1 AND EXISTS (SELECT t2_c_orders.ORDER_NUMBER FROM ORDER_DATA t2_c_orders WHERE t1_c.id=t2_c_orders.customer AND t2_c_orders.ORDER_NUMBER=t3_l_order.ORDER_NUMBER) AND t0_l.ORDER_NUMBER=t3_l_order.ORDER_NUMBER)",
396:                        compileEJBQL("SELECT OBJECT(l) FROM LineItem l, Customer c WHERE c.id=1 AND l.order MEMBER OF c.orders"));
397:
398:                StringBuffer sql = new StringBuffer(200);
399:                sql
400:                        .append("SELECT DISTINCT t0_li.id ")
401:                        .append(
402:                                "FROM LINEITEMEJB t0_li, ORDER_DATA t1_li_order, ADDRESSEJB t2_li_order_billingAddress ")
403:                        .append(
404:                                "WHERE (t1_li_order.BILLING_ADDRESS IS  NOT NULL AND t0_li.ORDER_NUMBER=t1_li_order.ORDER_NUMBER AND t1_li_order.BILLING_ADDRESS=t2_li_order_billingAddress.id)");
405:                assertEquals(
406:                        sql.toString(),
407:                        compileEJBQL("SELECT DISTINCT OBJECT(li) FROM LineItem AS li WHERE li.order.billingAddress IS NOT NULL"));
408:            }
409:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.