Source Code Cross Referenced for SetLiteral.java in  » Database-ORM » TJDO » com » triactive » jdo » store » 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 » TJDO » com.triactive.jdo.store 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003 (C) TJDO.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the TJDO License version 1.0.
006:         * See the terms of the TJDO License in the documentation provided with this software.
007:         *
008:         * $Id: SetLiteral.java,v 1.2 2004/01/25 22:31:27 jackknifebarber Exp $
009:         */
010:
011:        package com.triactive.jdo.store;
012:
013:        import javax.jdo.JDOUserException;
014:        import java.util.Iterator;
015:        import java.util.Set;
016:
017:        /**
018:         * A SetLiteral is a SQL expression that will test if a column of table
019:         * falls within the given Set of values.  This is used for <code>Query</code>s
020:         * where a transient Set is passed in as a parameter. 
021:         *
022:         * @author <a href="mailto:pierreg0@users.sourceforge.net">Kelly Grizzle</a>
023:         * @version $Revision: 1.2 $
024:         */
025:
026:        class SetLiteral extends SetExpression {
027:            private final Set value;
028:            private final boolean isEmpty;
029:            private final boolean containsNull;
030:            private final DatabaseAdapter dba;
031:
032:            /**
033:             * Construct a SetLiteral.
034:             * 
035:             * @param qs     The QueryStatement the SetLiteral will be used in.
036:             * @param value  The transient Set that is the value of the SetLiteral.
037:             */
038:
039:            public SetLiteral(QueryStatement qs, Set value) {
040:                super (qs);
041:
042:                this .value = value;
043:
044:                containsNull = (null != value) && value.contains(null);
045:                dba = qs.getStoreManager().getDatabaseAdapter();
046:
047:                /*
048:                 * We'll consider the Set to be empty if it is null, is truly empty,
049:                 * or only contains null.  If it contains null we need a special case
050:                 * when creating the SQL.
051:                 */
052:                isEmpty = (null == value) || (value.isEmpty())
053:                        || (1 == value.size() && containsNull);
054:
055:                /*
056:                 * If the Set is empty, don't build the list of SQLExpressions.
057:                 */
058:                if (!isEmpty) {
059:                    st.append("(");
060:
061:                    boolean hadPrev = false;
062:
063:                    for (Iterator it = value.iterator(); it.hasNext();) {
064:                        Object current = it.next();
065:
066:                        if (null != current) {
067:                            Mapping m = dba.getMapping(current.getClass());
068:                            SQLExpression expr = m.newSQLLiteral(qs, current);
069:
070:                            /*
071:                             * Append the SQLExpression (should be a literal) for the current element.
072:                             */
073:                            st.append(hadPrev ? "," : "");
074:                            st.append(expr);
075:
076:                            hadPrev = true;
077:                        }
078:                    }
079:
080:                    st.append(")");
081:                }
082:            }
083:
084:            /**
085:             * Return the BooleanExpression that results from SetLiteral.contains(SQLExpression).
086:             * 
087:             * @param expr   The SQLExpression that is checked for membership in the Set.
088:             * 
089:             * @return  The BooleanExpression that results from SetLiteral.contains(SQLExpression).
090:             */
091:            public BooleanExpression containsMethod(SQLExpression expr) {
092:                BooleanExpression returnVal = isEmpty ? new BooleanLiteral(qs,
093:                        false) : expr.in(this );
094:
095:                /*
096:                 * The expression FIELD IN ('Foo','Bar',NULL) does not work as we need it to.
097:                 * To get around this, if there is a null in the Set parameter, we will explicitly
098:                 * check if expr is NULL.
099:                 */
100:                if (containsNull)
101:                    returnVal = returnVal.ior(expr.eq(new NullLiteral(qs)));
102:
103:                return returnVal;
104:            }
105:
106:            public BooleanExpression isEmptyMethod() {
107:                return new BooleanLiteral(qs, isEmpty);
108:            }
109:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.