Source Code Cross Referenced for PropertyValueComparator.java in  » J2EE » fleXive » com » flexive » shared » search » query » 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 » J2EE » fleXive » com.flexive.shared.search.query 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***************************************************************
002:         *  This file is part of the [fleXive](R) project.
003:         *
004:         *  Copyright (c) 1999-2008
005:         *  UCS - unique computing solutions gmbh (http://www.ucs.at)
006:         *  All rights reserved
007:         *
008:         *  The [fleXive](R) project is free software; you can redistribute
009:         *  it and/or modify it under the terms of the GNU General Public
010:         *  License as published by the Free Software Foundation;
011:         *  either version 2 of the License, or (at your option) any
012:         *  later version.
013:         *
014:         *  The GNU General Public License can be found at
015:         *  http://www.gnu.org/copyleft/gpl.html.
016:         *  A copy is found in the textfile GPL.txt and important notices to the
017:         *  license from the author are found in LICENSE.txt distributed with
018:         *  these libraries.
019:         *
020:         *  This library is distributed in the hope that it will be useful,
021:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         *  GNU General Public License for more details.
024:         *
025:         *  For further information about UCS - unique computing solutions gmbh,
026:         *  please see the company website: http://www.ucs.at
027:         *
028:         *  For further information about [fleXive](R), please see the
029:         *  project website: http://www.flexive.org
030:         *
031:         *
032:         *  This copyright notice MUST APPEAR in all copies of the file!
033:         ***************************************************************/package com.flexive.shared.search.query;
034:
035:        import com.flexive.shared.FxFormatUtils;
036:        import com.flexive.shared.FxSharedUtils;
037:        import com.flexive.shared.exceptions.FxInvalidStateException;
038:        import com.flexive.shared.search.Table;
039:        import com.flexive.shared.structure.FxAssignment;
040:        import com.flexive.shared.structure.FxDataType;
041:        import com.flexive.shared.structure.FxProperty;
042:        import com.flexive.shared.value.FxString;
043:        import com.flexive.shared.value.FxValue;
044:
045:        import java.util.Arrays;
046:        import java.util.Collections;
047:        import java.util.List;
048:
049:        /**
050:         * Supported value comparators for FxValues.
051:         *
052:         * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
053:         */
054:        public enum PropertyValueComparator implements  ValueComparator {
055:            EQ("="), NE("!="), LT("<"), LE("<="), GT(">"), GE(">="), EMPTY(
056:                    "NULL", false) {
057:                @Override
058:                public String getSql(String leftHandSide, String rightHandSide) {
059:                    return leftHandSide + " IS NULL";
060:                }
061:            },
062:            NOT_EMPTY("NOTNULL", false) {
063:                @Override
064:                public String getSql(String leftHandSide, String rightHandSide) {
065:                    return leftHandSide + " IS NOT NULL";
066:                }
067:
068:            },
069:            LIKE("LIKE");
070:
071:            private static final List<PropertyValueComparator> NUMERIC_OPERATORS = Collections
072:                    .unmodifiableList(Arrays.asList(EQ, NE, LT, LE, GT, GE));
073:            private static final List<PropertyValueComparator> STRING_OPERATORS = Collections
074:                    .unmodifiableList(Arrays.asList(EQ, NE, EMPTY, NOT_EMPTY,
075:                            LIKE));
076:            private static final List<PropertyValueComparator> ORDINAL_OPERATORS = Collections
077:                    .unmodifiableList(Arrays.asList(EQ, NE));
078:            private static final List<PropertyValueComparator> DATE_OPERATORS = Collections
079:                    .unmodifiableList(Arrays.asList(EQ, NE, LT, LE, GT, GE,
080:                            EMPTY, NOT_EMPTY));
081:            private static final List<PropertyValueComparator> DATERANGE_OPERATORS = Collections
082:                    .unmodifiableList(Arrays.asList(LT, LE, GT, GE, EMPTY,
083:                            NOT_EMPTY));
084:            private static final List<PropertyValueComparator> EMPTY_OPERATORS = Collections
085:                    .unmodifiableList(Arrays.asList(EMPTY, NOT_EMPTY));
086:
087:            private String id;
088:            private boolean needsInput;
089:
090:            private PropertyValueComparator(String id) {
091:                this (id, true);
092:            }
093:
094:            private PropertyValueComparator(String id, boolean needsInput) {
095:                this .id = id;
096:                this .needsInput = needsInput;
097:            }
098:
099:            public final String getSql(FxAssignment assignment, FxValue value) {
100:                final String sqlValue;
101:                if (needsInput) {
102:                    if (value.isEmpty()) {
103:                        throw new FxInvalidStateException(
104:                                "ex.sqlQueryBuilder.value.empty", assignment
105:                                        .getLabel(), id).asRuntimeException();
106:                    }
107:                    try {
108:                        sqlValue = value.getSqlValue();
109:                    } catch (RuntimeException e) {
110:                        throw new FxInvalidStateException(
111:                                "ex.sqlQueryBuilder.value.invalid", assignment
112:                                        .getLabel(), id, value)
113:                                .asRuntimeException();
114:                    }
115:                } else {
116:                    sqlValue = null;
117:                }
118:                return "/*" + assignment.getAlias()
119:                        + "*/ " // include assignment alias in comment for better readability
120:                        + getSql(Table.CONTENT.getColumnName("#"
121:                                + assignment.getId()), sqlValue);
122:            }
123:
124:            public final String getSql(FxProperty property, FxValue value) {
125:                final String sqlValue;
126:                if (needsInput) {
127:                    try {
128:                        sqlValue = value.getSqlValue();
129:                    } catch (RuntimeException e) {
130:                        throw new FxInvalidStateException(
131:                                "ex.sqlQueryBuilder.value.invalid", property
132:                                        .getName(), id, value)
133:                                .asRuntimeException();
134:                    }
135:                } else {
136:                    sqlValue = null;
137:                }
138:                return getSql(Table.CONTENT.getColumnName(property.getName()),
139:                        sqlValue);
140:            }
141:
142:            public final String getSql(String columnName, FxValue value) {
143:                return getSql(columnName, value != null ? value.getSqlValue()
144:                        : null);
145:            }
146:
147:            public final String getSql(String columnName, Object value) {
148:                return getSql(columnName, FxFormatUtils.escapeForSql(value));
149:            }
150:
151:            /**
152:             * Returns the SQL expression generated by combining both parameters with
153:             * this comparator.
154:             *
155:             * @param leftHandSide  the left-hand-side of the comparison
156:             * @param rightHandSide the right-hand-side of the comparison
157:             * @return  the SQL query
158:             */
159:            protected String getSql(String leftHandSide, String rightHandSide) {
160:                return leftHandSide + " " + id + " " + rightHandSide;
161:            }
162:
163:            /** {@inheritDoc} */
164:            public boolean isNeedsInput() {
165:                return needsInput;
166:            }
167:
168:            /** {@inheritDoc} */
169:            public FxString getLabel() {
170:                return FxSharedUtils.getEnumLabel(this );
171:            }
172:
173:            /**
174:             * Returns a list of value comparators applicable to the given data type.
175:             *
176:             * @param dataType  the data type
177:             * @return      a list of value comparators applicable to the given data type.
178:             */
179:            public static List<PropertyValueComparator> getAvailable(
180:                    FxDataType dataType) {
181:                switch (dataType) {
182:                case Double:
183:                case Float:
184:                case LargeNumber:
185:                case Number:
186:                    return NUMERIC_OPERATORS;
187:                case String1024:
188:                case Text:
189:                case HTML:
190:                    return STRING_OPERATORS;
191:                case Binary:
192:                    return EMPTY_OPERATORS;
193:                case Date:
194:                case DateTime:
195:                    return DATE_OPERATORS;
196:                case DateRange:
197:                case DateTimeRange:
198:                    return DATERANGE_OPERATORS;
199:                default:
200:                    return ORDINAL_OPERATORS;
201:                }
202:            }
203:
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.