Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 338164
Collapse All | Expand All

(-)src/org/eclipse/emf/query2/internal/fql/SpiFqlPrimitiveType.java (-1 / +1 lines)
Lines 14-18 Link Here
14
 * Simple attribute value types that are supported by queries.
14
 * Simple attribute value types that are supported by queries.
15
 */
15
 */
16
public enum SpiFqlPrimitiveType {
16
public enum SpiFqlPrimitiveType {
17
	STRING, BOOLEAN, INTEGER, LONG, DOUBLE, FLOAT
17
	STRING, BOOLEAN, INTEGER, LONG, DOUBLE, FLOAT, DATE
18
}
18
}
(-)src/org/eclipse/emf/query2/internal/messages/BugMessages.java (-1 / +5 lines)
Lines 702-708 Link Here
702
	/**
702
	/**
703
	 * Message: "VirtualAtomicAttrReference has to refer to a TypeAttrReference"
703
	 * Message: "VirtualAtomicAttrReference has to refer to a TypeAttrReference"
704
	 */
704
	 */
705
	VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF("VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF_XMSG"); //$NON-NLS-1$
705
	VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF("VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF_XMSG"),  //$NON-NLS-1$
706
	/**
707
	 * Message: "VirtualAtomicAttrReference has to refer to a TypeAttrReference"
708
	 */
709
	INVALID_DATE_FORMAT("INVALID_DATE_FORMAT"); //$NON-NLS-1$
706
710
707
	private final static LocalizedResourceBundleAccessor ACCESSOR = new LocalizedResourceBundleAccessor(BugMessages.class);
711
	private final static LocalizedResourceBundleAccessor ACCESSOR = new LocalizedResourceBundleAccessor(BugMessages.class);
708
712
(-)src/org/eclipse/emf/query2/internal/messages/BugMessages.properties (+1 lines)
Lines 106-108 Link Here
106
UNKNOWN_PRIMITIVE_TYPE_XMSG=The primitive type {0} is not recognized
106
UNKNOWN_PRIMITIVE_TYPE_XMSG=The primitive type {0} is not recognized
107
VIRTUAL_ATOMIC_ENTRY_REF_HAS_TO_REFER_TO_TYPE_REF_XMSG=VirtualAtomicEntryReference has to refer to a TypeReference
107
VIRTUAL_ATOMIC_ENTRY_REF_HAS_TO_REFER_TO_TYPE_REF_XMSG=VirtualAtomicEntryReference has to refer to a TypeReference
108
VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF_XMSG=VirtualAtomicAttrReference has to refer to a TypeAttrReference
108
VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF_XMSG=VirtualAtomicAttrReference has to refer to a TypeAttrReference
109
INVALID_DATE_FORMAT=Unable to parse date MM/dd/yyyy for {0} reason: {1}
(-)src/org/eclipse/emf/query2/internal/moinql/preprocessor/TypeCheckerImpl.java (-6 / +29 lines)
Lines 13-22 Link Here
13
 */
13
 */
14
package org.eclipse.emf.query2.internal.moinql.preprocessor;
14
package org.eclipse.emf.query2.internal.moinql.preprocessor;
15
15
16
import java.math.BigInteger;
17
import java.text.ParseException;
18
import java.text.SimpleDateFormat;
16
import java.util.ArrayList;
19
import java.util.ArrayList;
17
import java.util.Arrays;
20
import java.util.Arrays;
21
import java.util.Calendar;
18
import java.util.Collection;
22
import java.util.Collection;
19
import java.util.Collections;
23
import java.util.Collections;
24
import java.util.Date;
20
import java.util.HashMap;
25
import java.util.HashMap;
21
import java.util.HashSet;
26
import java.util.HashSet;
22
import java.util.Iterator;
27
import java.util.Iterator;
Lines 24-29 Link Here
24
import java.util.Map;
29
import java.util.Map;
25
import java.util.Set;
30
import java.util.Set;
26
31
32
import javax.xml.datatype.XMLGregorianCalendar;
33
27
import org.eclipse.emf.common.util.URI;
34
import org.eclipse.emf.common.util.URI;
28
import org.eclipse.emf.ecore.EAttribute;
35
import org.eclipse.emf.ecore.EAttribute;
29
import org.eclipse.emf.ecore.EClass;
36
import org.eclipse.emf.ecore.EClass;
Lines 34-39 Link Here
34
import org.eclipse.emf.ecore.EStructuralFeature;
41
import org.eclipse.emf.ecore.EStructuralFeature;
35
import org.eclipse.emf.ecore.EcorePackage;
42
import org.eclipse.emf.ecore.EcorePackage;
36
import org.eclipse.emf.ecore.util.EcoreUtil;
43
import org.eclipse.emf.ecore.util.EcoreUtil;
44
import org.eclipse.emf.ecore.xml.type.internal.XMLCalendar;
37
import org.eclipse.emf.query2.EmfHelper;
45
import org.eclipse.emf.query2.EmfHelper;
38
import org.eclipse.emf.query2.FromEntry;
46
import org.eclipse.emf.query2.FromEntry;
39
import org.eclipse.emf.query2.FromFixedSet;
47
import org.eclipse.emf.query2.FromFixedSet;
Lines 1064-1079 Link Here
1064
						}
1072
						}
1065
					}
1073
					}
1066
				} else if (mqlWhereClause instanceof WhereString) {
1074
				} else if (mqlWhereClause instanceof WhereString) {
1067
					if (!(attrRes.attrType.equals(SpiFqlPrimitiveType.STRING))) {
1075
					if (attrRes.attrType.equals(SpiFqlPrimitiveType.DATE)){
1076
						try{
1077
						String sDt = ((WhereString) mqlWhereClause).getStringValue();
1078
						value = new SimpleDateFormat("MM/dd/yyyy").parse(sDt);
1079
						}catch(ParseException p){
1080
							throw new BugException(BugMessages.INVALID_DATE_FORMAT, mqlWhereClause.getClass().getCanonicalName(),
1081
							p.getMessage()); //$NON-NLS-1$
1082
							
1083
						}
1084
					}else if (!(attrRes.attrType.equals(SpiFqlPrimitiveType.STRING))) {
1068
						this.reportError(mqlWhereClause, ApiMessages.COMPARISON_INCOMPATIBLE_TYPE_CHECK, new Object[] { attrName,
1085
						this.reportError(mqlWhereClause, ApiMessages.COMPARISON_INCOMPATIBLE_TYPE_CHECK, new Object[] { attrName,
1069
								attrRes.attrType, SpiFqlPrimitiveType.STRING });
1086
								attrRes.attrType, SpiFqlPrimitiveType.STRING });
1087
						value=null;
1088
					}else{
1089
						value = ((WhereString) mqlWhereClause).getStringValue();
1070
					}
1090
					}
1071
					value = ((WhereString) mqlWhereClause).getStringValue();
1072
				} else {
1091
				} else {
1073
					throw new BugException(BugMessages.UNEXPECTED_SUBTYPE, mqlWhereClause.getClass().getCanonicalName(),
1092
					throw new BugException(BugMessages.UNEXPECTED_SUBTYPE, mqlWhereClause.getClass().getCanonicalName(),
1074
							"WhereComparator"); //$NON-NLS-1$
1093
							"WhereComparator"); //$NON-NLS-1$
1075
				}
1094
				}
1076
1077
				// if we are dealing with strings, check if we have trailing
1095
				// if we are dealing with strings, check if we have trailing
1078
				// blanks
1096
				// blanks
1079
				// in the constant or pattern. Also, a string cannot exceed a
1097
				// in the constant or pattern. Also, a string cannot exceed a
Lines 1695-1700 Link Here
1695
			// the caller permits like-operations)
1713
			// the caller permits like-operations)
1696
			ok = (operation.equals(Operation.EQUAL) || operation.equals(Operation.NOTEQUAL) || (operation.equals(Operation.LIKE) && likeOperationAllowed));
1714
			ok = (operation.equals(Operation.EQUAL) || operation.equals(Operation.NOTEQUAL) || (operation.equals(Operation.LIKE) && likeOperationAllowed));
1697
			break;
1715
			break;
1716
		case DATE:
1717
			ok = operation.equals(Operation.EQUAL) || operation.equals(Operation.NOTEQUAL) || operation.equals(Operation.SMALLER) || operation.equals(Operation.SMALLEREQUAL) || operation.equals(Operation.GREATER) || operation.equals(Operation.GREATEREQUAL);
1718
			break;	
1698
		default:
1719
		default:
1699
			// all other types do not allow liking under any circumstances
1720
			// all other types do not allow liking under any circumstances
1700
			ok = !operation.equals(Operation.LIKE);
1721
			ok = !operation.equals(Operation.LIKE);
Lines 1992-2006 Link Here
1992
			Class<?> instanceClass = attrMofType.getInstanceClass();
2013
			Class<?> instanceClass = attrMofType.getInstanceClass();
1993
			if (primName.equals("EBoolean") || instanceClass == boolean.class || instanceClass == Boolean.class) { //$NON-NLS-1$
2014
			if (primName.equals("EBoolean") || instanceClass == boolean.class || instanceClass == Boolean.class) { //$NON-NLS-1$
1994
				attrType = SpiFqlPrimitiveType.BOOLEAN;
2015
				attrType = SpiFqlPrimitiveType.BOOLEAN;
1995
			} else if (primName.equals("EInt") || instanceClass == int.class || instanceClass == Integer.class) { //$NON-NLS-1$
2016
			} else if (primName.equals("EInt") || instanceClass == int.class || instanceClass == Integer.class ) { //$NON-NLS-1$
1996
				attrType = SpiFqlPrimitiveType.INTEGER;
2017
				attrType = SpiFqlPrimitiveType.INTEGER;
1997
			} else if (primName.equals("ELong") || instanceClass == long.class || instanceClass == Integer.class) { //$NON-NLS-1$
2018
			} else if (primName.equals("ELong") || instanceClass == long.class || instanceClass == Integer.class || instanceClass == BigInteger.class) { //$NON-NLS-1$
1998
				attrType = SpiFqlPrimitiveType.LONG;
2019
				attrType = SpiFqlPrimitiveType.LONG;
1999
			} else if (primName.equals("EFloat") || instanceClass == float.class || instanceClass == Float.class) { //$NON-NLS-1$
2020
			} else if (primName.equals("EFloat") || instanceClass == float.class || instanceClass == Float.class) { //$NON-NLS-1$
2000
				attrType = SpiFqlPrimitiveType.FLOAT;
2021
				attrType = SpiFqlPrimitiveType.FLOAT;
2001
			} else if (primName.equals("EDouble") || instanceClass == double.class || instanceClass == Double.class) { //$NON-NLS-1$
2022
			} else if (primName.equals("EDouble") || instanceClass == double.class || instanceClass == Double.class) { //$NON-NLS-1$
2002
				attrType = SpiFqlPrimitiveType.DOUBLE;
2023
				attrType = SpiFqlPrimitiveType.DOUBLE;
2003
			} else if (primName.equals("EString") || instanceClass == String.class) { //$NON-NLS-1$
2024
			} else if (primName.equals("Date") || instanceClass == Date.class||instanceClass==XMLCalendar.class || instanceClass==XMLGregorianCalendar.class) { //$NON-NLS-1$
2025
				attrType = SpiFqlPrimitiveType.DATE;	
2026
			}else if (primName.equals("EString") || instanceClass == String.class) { //$NON-NLS-1$
2004
				attrType = SpiFqlPrimitiveType.STRING;
2027
				attrType = SpiFqlPrimitiveType.STRING;
2005
			} else {
2028
			} else {
2006
				throw new BugException(BugMessages.UNKNOWN_PRIMITIVE_TYPE, primName);
2029
				throw new BugException(BugMessages.UNKNOWN_PRIMITIVE_TYPE, primName);
(-)src/org/eclipse/emf/query2/internal/shared/AuxServices.java (-2 / +53 lines)
Lines 13-21 Link Here
13
 */
13
 */
14
package org.eclipse.emf.query2.internal.shared;
14
package org.eclipse.emf.query2.internal.shared;
15
15
16
import java.math.BigInteger;
16
import java.util.ArrayList;
17
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.Arrays;
18
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.Date;
19
import java.util.HashMap;
21
import java.util.HashMap;
20
import java.util.HashSet;
22
import java.util.HashSet;
21
import java.util.Iterator;
23
import java.util.Iterator;
Lines 24-31 Link Here
24
import java.util.Map;
26
import java.util.Map;
25
import java.util.Set;
27
import java.util.Set;
26
28
29
import javax.xml.datatype.XMLGregorianCalendar;
30
27
import org.eclipse.emf.common.util.Enumerator;
31
import org.eclipse.emf.common.util.Enumerator;
28
import org.eclipse.emf.common.util.URI;
32
import org.eclipse.emf.common.util.URI;
33
import org.eclipse.emf.ecore.xml.type.internal.XMLCalendar;
29
import org.eclipse.emf.query2.internal.fql.SpiFacilityQueryLanguage;
34
import org.eclipse.emf.query2.internal.fql.SpiFacilityQueryLanguage;
30
import org.eclipse.emf.query2.internal.fql.SpiFqlComparisonOperation;
35
import org.eclipse.emf.query2.internal.fql.SpiFqlComparisonOperation;
31
import org.eclipse.emf.query2.internal.fql.SpiFqlFromTypeCategory;
36
import org.eclipse.emf.query2.internal.fql.SpiFqlFromTypeCategory;
Lines 185-191 Link Here
185
		}
190
		}
186
191
187
		// sanity check
192
		// sanity check
188
		if (!obj1.getClass().equals(obj2.getClass())) {
193
		if (!comparible(obj1, obj2)){
189
			throw new BugException(BugMessages.UNEXPECTED_DIFFERENT_VALUE_TYPES, obj1.getClass().getName(), obj2.getClass().getName());
194
			throw new BugException(BugMessages.UNEXPECTED_DIFFERENT_VALUE_TYPES, obj1.getClass().getName(), obj2.getClass().getName());
190
		}
195
		}
191
196
Lines 194-199 Link Here
194
		 */
199
		 */
195
200
196
		// strings or booleans
201
		// strings or booleans
202
		
197
		if (obj1 instanceof String || obj1 instanceof Boolean) {
203
		if (obj1 instanceof String || obj1 instanceof Boolean) {
198
			if (operation == SpiFqlComparisonOperation.EQUAL) {
204
			if (operation == SpiFqlComparisonOperation.EQUAL) {
199
				return obj1.equals(obj2);
205
				return obj1.equals(obj2);
Lines 203-208 Link Here
203
				throw new BugException(BugMessages.UNEXPECTED_COMPARATOR_STRING_BOOL, operation);
209
				throw new BugException(BugMessages.UNEXPECTED_COMPARATOR_STRING_BOOL, operation);
204
			}
210
			}
205
		}
211
		}
212
		/*
213
		 *  Need to take verify TZ into taken into account
214
		 */
215
		if ( obj1 instanceof Date ){
216
			obj1 = (Long)((Date)obj1).getTime();
217
		}else if ( obj1 instanceof XMLGregorianCalendar){
218
			obj1 =(Long)((XMLGregorianCalendar)obj1).toGregorianCalendar().getTimeInMillis();
219
			
220
		}
221
		if ( obj2 instanceof Date ){
222
			obj2 = (Long)((Date)obj2).getTime();
223
		}else if ( obj2 instanceof XMLGregorianCalendar){
224
			obj2 =(Long)((XMLGregorianCalendar)obj2).toGregorianCalendar().getTimeInMillis();
225
			
226
		}
206
227
207
		// numerals
228
		// numerals
208
		Number valueNumber = (Number) obj1;
229
		Number valueNumber = (Number) obj1;
Lines 250-256 Link Here
250
			throw new BugException(BugMessages.UNKNOWN_OPERATOR, operation);
271
			throw new BugException(BugMessages.UNKNOWN_OPERATOR, operation);
251
		}
272
		}
252
	}
273
	}
253
274
	/*
275
	 * Determine is the two values can be compared 
276
	 */
277
	private static boolean comparible(Object obj1, Object obj2) {
278
		if ( obj1.getClass().equals(obj2.getClass())) return true;
279
		SpiFqlPrimitiveType a = getPrimitiveType(obj1),b=(getPrimitiveType(obj2));
280
		return a!=null && b!=null && a.equals(b);
281
	}
282
	/*
283
	 * Logic Copied from org.eclipse.emf.query2.internal.moinql.preprocessor.TypeCheckerImpl.AttributeResolution ( Duplicated Yuck .. )
284
	 */
285
	private static SpiFqlPrimitiveType getPrimitiveType(Object obj){
286
		Class instanceClass = obj.getClass();
287
		SpiFqlPrimitiveType attrType=null;
288
		if (instanceClass == boolean.class || instanceClass == Boolean.class) { //$NON-NLS-1$
289
			attrType = SpiFqlPrimitiveType.BOOLEAN;
290
		} else if ( instanceClass == int.class || instanceClass == Integer.class ) { //$NON-NLS-1$
291
			attrType = SpiFqlPrimitiveType.INTEGER;
292
		} else if ( instanceClass == long.class || instanceClass == Integer.class || instanceClass == BigInteger.class) { //$NON-NLS-1$
293
			attrType = SpiFqlPrimitiveType.LONG;
294
		} else if ( instanceClass == float.class || instanceClass == Float.class) { //$NON-NLS-1$
295
			attrType = SpiFqlPrimitiveType.FLOAT;
296
		} else if ( instanceClass == double.class || instanceClass == Double.class) { //$NON-NLS-1$
297
			attrType = SpiFqlPrimitiveType.DOUBLE;
298
		} else if ( instanceClass == Date.class || instanceClass==XMLCalendar.class ||instanceClass==XMLGregorianCalendar.class) { //$NON-NLS-1$
299
			attrType = SpiFqlPrimitiveType.DATE;	
300
		}else if ( instanceClass == String.class) { //$NON-NLS-1$
301
			attrType = SpiFqlPrimitiveType.STRING;
302
		}
303
		return attrType;
304
	}
254
	/*
305
	/*
255
	 * -------- PUBLIC TRANSFORMATION SERVICES --------
306
	 * -------- PUBLIC TRANSFORMATION SERVICES --------
256
	 */
307
	 */

Return to bug 338164