Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 189758 Details for
Bug 338164
[Query2] No support for BigInteger or java.util.Date
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Hacked up support for Date and BigInteger
query2_date_support.diff (text/plain), 12.35 KB, created by
jgielstra Mising name
on 2011-02-24 18:03:34 EST
(
hide
)
Description:
Hacked up support for Date and BigInteger
Filename:
MIME Type:
Creator:
jgielstra Mising name
Created:
2011-02-24 18:03:34 EST
Size:
12.35 KB
patch
obsolete
>Index: src/org/eclipse/emf/query2/internal/fql/SpiFqlPrimitiveType.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.query/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/internal/fql/SpiFqlPrimitiveType.java,v >retrieving revision 1.1 >diff -u -r1.1 SpiFqlPrimitiveType.java >--- src/org/eclipse/emf/query2/internal/fql/SpiFqlPrimitiveType.java 7 Dec 2010 11:44:55 -0000 1.1 >+++ src/org/eclipse/emf/query2/internal/fql/SpiFqlPrimitiveType.java 24 Feb 2011 23:02:05 -0000 >@@ -14,5 +14,5 @@ > * Simple attribute value types that are supported by queries. > */ > public enum SpiFqlPrimitiveType { >- STRING, BOOLEAN, INTEGER, LONG, DOUBLE, FLOAT >+ STRING, BOOLEAN, INTEGER, LONG, DOUBLE, FLOAT, DATE > } >Index: src/org/eclipse/emf/query2/internal/messages/BugMessages.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.query/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/internal/messages/BugMessages.java,v >retrieving revision 1.1 >diff -u -r1.1 BugMessages.java >--- src/org/eclipse/emf/query2/internal/messages/BugMessages.java 7 Dec 2010 11:44:57 -0000 1.1 >+++ src/org/eclipse/emf/query2/internal/messages/BugMessages.java 24 Feb 2011 23:02:05 -0000 >@@ -702,7 +702,11 @@ > /** > * Message: "VirtualAtomicAttrReference has to refer to a TypeAttrReference" > */ >- VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF("VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF_XMSG"); //$NON-NLS-1$ >+ VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF("VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF_XMSG"), //$NON-NLS-1$ >+ /** >+ * Message: "VirtualAtomicAttrReference has to refer to a TypeAttrReference" >+ */ >+ INVALID_DATE_FORMAT("INVALID_DATE_FORMAT"); //$NON-NLS-1$ > > private final static LocalizedResourceBundleAccessor ACCESSOR = new LocalizedResourceBundleAccessor(BugMessages.class); > >Index: src/org/eclipse/emf/query2/internal/messages/BugMessages.properties >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.query/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/internal/messages/BugMessages.properties,v >retrieving revision 1.1 >diff -u -r1.1 BugMessages.properties >--- src/org/eclipse/emf/query2/internal/messages/BugMessages.properties 7 Dec 2010 11:44:57 -0000 1.1 >+++ src/org/eclipse/emf/query2/internal/messages/BugMessages.properties 24 Feb 2011 23:02:05 -0000 >@@ -106,3 +106,4 @@ > UNKNOWN_PRIMITIVE_TYPE_XMSG=The primitive type {0} is not recognized > VIRTUAL_ATOMIC_ENTRY_REF_HAS_TO_REFER_TO_TYPE_REF_XMSG=VirtualAtomicEntryReference has to refer to a TypeReference > VIRTUAL_ATTOMIC_ATTR_REF_SHOULD_REFER_TO_TYPE_ATTR_REF_XMSG=VirtualAtomicAttrReference has to refer to a TypeAttrReference >+INVALID_DATE_FORMAT=Unable to parse date MM/dd/yyyy for {0} reason: {1} >Index: src/org/eclipse/emf/query2/internal/moinql/preprocessor/TypeCheckerImpl.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.query/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/internal/moinql/preprocessor/TypeCheckerImpl.java,v >retrieving revision 1.4 >diff -u -r1.4 TypeCheckerImpl.java >--- src/org/eclipse/emf/query2/internal/moinql/preprocessor/TypeCheckerImpl.java 3 Feb 2011 05:32:55 -0000 1.4 >+++ src/org/eclipse/emf/query2/internal/moinql/preprocessor/TypeCheckerImpl.java 24 Feb 2011 23:02:07 -0000 >@@ -13,10 +13,15 @@ > */ > package org.eclipse.emf.query2.internal.moinql.preprocessor; > >+import java.math.BigInteger; >+import java.text.ParseException; >+import java.text.SimpleDateFormat; > import java.util.ArrayList; > import java.util.Arrays; >+import java.util.Calendar; > import java.util.Collection; > import java.util.Collections; >+import java.util.Date; > import java.util.HashMap; > import java.util.HashSet; > import java.util.Iterator; >@@ -24,6 +29,8 @@ > import java.util.Map; > import java.util.Set; > >+import javax.xml.datatype.XMLGregorianCalendar; >+ > import org.eclipse.emf.common.util.URI; > import org.eclipse.emf.ecore.EAttribute; > import org.eclipse.emf.ecore.EClass; >@@ -34,6 +41,7 @@ > import org.eclipse.emf.ecore.EStructuralFeature; > import org.eclipse.emf.ecore.EcorePackage; > import org.eclipse.emf.ecore.util.EcoreUtil; >+import org.eclipse.emf.ecore.xml.type.internal.XMLCalendar; > import org.eclipse.emf.query2.EmfHelper; > import org.eclipse.emf.query2.FromEntry; > import org.eclipse.emf.query2.FromFixedSet; >@@ -1064,16 +1072,26 @@ > } > } > } else if (mqlWhereClause instanceof WhereString) { >- if (!(attrRes.attrType.equals(SpiFqlPrimitiveType.STRING))) { >+ if (attrRes.attrType.equals(SpiFqlPrimitiveType.DATE)){ >+ try{ >+ String sDt = ((WhereString) mqlWhereClause).getStringValue(); >+ value = new SimpleDateFormat("MM/dd/yyyy").parse(sDt); >+ }catch(ParseException p){ >+ throw new BugException(BugMessages.INVALID_DATE_FORMAT, mqlWhereClause.getClass().getCanonicalName(), >+ p.getMessage()); //$NON-NLS-1$ >+ >+ } >+ }else if (!(attrRes.attrType.equals(SpiFqlPrimitiveType.STRING))) { > this.reportError(mqlWhereClause, ApiMessages.COMPARISON_INCOMPATIBLE_TYPE_CHECK, new Object[] { attrName, > attrRes.attrType, SpiFqlPrimitiveType.STRING }); >+ value=null; >+ }else{ >+ value = ((WhereString) mqlWhereClause).getStringValue(); > } >- value = ((WhereString) mqlWhereClause).getStringValue(); > } else { > throw new BugException(BugMessages.UNEXPECTED_SUBTYPE, mqlWhereClause.getClass().getCanonicalName(), > "WhereComparator"); //$NON-NLS-1$ > } >- > // if we are dealing with strings, check if we have trailing > // blanks > // in the constant or pattern. Also, a string cannot exceed a >@@ -1695,6 +1713,9 @@ > // the caller permits like-operations) > ok = (operation.equals(Operation.EQUAL) || operation.equals(Operation.NOTEQUAL) || (operation.equals(Operation.LIKE) && likeOperationAllowed)); > break; >+ case DATE: >+ 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); >+ break; > default: > // all other types do not allow liking under any circumstances > ok = !operation.equals(Operation.LIKE); >@@ -1992,15 +2013,17 @@ > Class<?> instanceClass = attrMofType.getInstanceClass(); > if (primName.equals("EBoolean") || instanceClass == boolean.class || instanceClass == Boolean.class) { //$NON-NLS-1$ > attrType = SpiFqlPrimitiveType.BOOLEAN; >- } else if (primName.equals("EInt") || instanceClass == int.class || instanceClass == Integer.class) { //$NON-NLS-1$ >+ } else if (primName.equals("EInt") || instanceClass == int.class || instanceClass == Integer.class ) { //$NON-NLS-1$ > attrType = SpiFqlPrimitiveType.INTEGER; >- } else if (primName.equals("ELong") || instanceClass == long.class || instanceClass == Integer.class) { //$NON-NLS-1$ >+ } else if (primName.equals("ELong") || instanceClass == long.class || instanceClass == Integer.class || instanceClass == BigInteger.class) { //$NON-NLS-1$ > attrType = SpiFqlPrimitiveType.LONG; > } else if (primName.equals("EFloat") || instanceClass == float.class || instanceClass == Float.class) { //$NON-NLS-1$ > attrType = SpiFqlPrimitiveType.FLOAT; > } else if (primName.equals("EDouble") || instanceClass == double.class || instanceClass == Double.class) { //$NON-NLS-1$ > attrType = SpiFqlPrimitiveType.DOUBLE; >- } else if (primName.equals("EString") || instanceClass == String.class) { //$NON-NLS-1$ >+ } else if (primName.equals("Date") || instanceClass == Date.class||instanceClass==XMLCalendar.class || instanceClass==XMLGregorianCalendar.class) { //$NON-NLS-1$ >+ attrType = SpiFqlPrimitiveType.DATE; >+ }else if (primName.equals("EString") || instanceClass == String.class) { //$NON-NLS-1$ > attrType = SpiFqlPrimitiveType.STRING; > } else { > throw new BugException(BugMessages.UNKNOWN_PRIMITIVE_TYPE, primName); >Index: src/org/eclipse/emf/query2/internal/shared/AuxServices.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf.query/org.eclipse.emf.query2/plugins/org.eclipse.emf.query2.core/src/org/eclipse/emf/query2/internal/shared/AuxServices.java,v >retrieving revision 1.2 >diff -u -r1.2 AuxServices.java >--- src/org/eclipse/emf/query2/internal/shared/AuxServices.java 16 Dec 2010 13:19:03 -0000 1.2 >+++ src/org/eclipse/emf/query2/internal/shared/AuxServices.java 24 Feb 2011 23:02:10 -0000 >@@ -13,9 +13,11 @@ > */ > package org.eclipse.emf.query2.internal.shared; > >+import java.math.BigInteger; > import java.util.ArrayList; > import java.util.Arrays; > import java.util.Collections; >+import java.util.Date; > import java.util.HashMap; > import java.util.HashSet; > import java.util.Iterator; >@@ -24,8 +26,11 @@ > import java.util.Map; > import java.util.Set; > >+import javax.xml.datatype.XMLGregorianCalendar; >+ > import org.eclipse.emf.common.util.Enumerator; > import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.xml.type.internal.XMLCalendar; > import org.eclipse.emf.query2.internal.fql.SpiFacilityQueryLanguage; > import org.eclipse.emf.query2.internal.fql.SpiFqlComparisonOperation; > import org.eclipse.emf.query2.internal.fql.SpiFqlFromTypeCategory; >@@ -185,7 +190,7 @@ > } > > // sanity check >- if (!obj1.getClass().equals(obj2.getClass())) { >+ if (!comparible(obj1, obj2)){ > throw new BugException(BugMessages.UNEXPECTED_DIFFERENT_VALUE_TYPES, obj1.getClass().getName(), obj2.getClass().getName()); > } > >@@ -194,6 +199,7 @@ > */ > > // strings or booleans >+ > if (obj1 instanceof String || obj1 instanceof Boolean) { > if (operation == SpiFqlComparisonOperation.EQUAL) { > return obj1.equals(obj2); >@@ -203,6 +209,21 @@ > throw new BugException(BugMessages.UNEXPECTED_COMPARATOR_STRING_BOOL, operation); > } > } >+ /* >+ * Need to take verify TZ into taken into account >+ */ >+ if ( obj1 instanceof Date ){ >+ obj1 = (Long)((Date)obj1).getTime(); >+ }else if ( obj1 instanceof XMLGregorianCalendar){ >+ obj1 =(Long)((XMLGregorianCalendar)obj1).toGregorianCalendar().getTimeInMillis(); >+ >+ } >+ if ( obj2 instanceof Date ){ >+ obj2 = (Long)((Date)obj2).getTime(); >+ }else if ( obj2 instanceof XMLGregorianCalendar){ >+ obj2 =(Long)((XMLGregorianCalendar)obj2).toGregorianCalendar().getTimeInMillis(); >+ >+ } > > // numerals > Number valueNumber = (Number) obj1; >@@ -250,7 +271,37 @@ > throw new BugException(BugMessages.UNKNOWN_OPERATOR, operation); > } > } >- >+ /* >+ * Determine is the two values can be compared >+ */ >+ private static boolean comparible(Object obj1, Object obj2) { >+ if ( obj1.getClass().equals(obj2.getClass())) return true; >+ SpiFqlPrimitiveType a = getPrimitiveType(obj1),b=(getPrimitiveType(obj2)); >+ return a!=null && b!=null && a.equals(b); >+ } >+ /* >+ * Logic Copied from org.eclipse.emf.query2.internal.moinql.preprocessor.TypeCheckerImpl.AttributeResolution ( Duplicated Yuck .. ) >+ */ >+ private static SpiFqlPrimitiveType getPrimitiveType(Object obj){ >+ Class instanceClass = obj.getClass(); >+ SpiFqlPrimitiveType attrType=null; >+ if (instanceClass == boolean.class || instanceClass == Boolean.class) { //$NON-NLS-1$ >+ attrType = SpiFqlPrimitiveType.BOOLEAN; >+ } else if ( instanceClass == int.class || instanceClass == Integer.class ) { //$NON-NLS-1$ >+ attrType = SpiFqlPrimitiveType.INTEGER; >+ } else if ( instanceClass == long.class || instanceClass == Integer.class || instanceClass == BigInteger.class) { //$NON-NLS-1$ >+ attrType = SpiFqlPrimitiveType.LONG; >+ } else if ( instanceClass == float.class || instanceClass == Float.class) { //$NON-NLS-1$ >+ attrType = SpiFqlPrimitiveType.FLOAT; >+ } else if ( instanceClass == double.class || instanceClass == Double.class) { //$NON-NLS-1$ >+ attrType = SpiFqlPrimitiveType.DOUBLE; >+ } else if ( instanceClass == Date.class || instanceClass==XMLCalendar.class ||instanceClass==XMLGregorianCalendar.class) { //$NON-NLS-1$ >+ attrType = SpiFqlPrimitiveType.DATE; >+ }else if ( instanceClass == String.class) { //$NON-NLS-1$ >+ attrType = SpiFqlPrimitiveType.STRING; >+ } >+ return attrType; >+ } > /* > * -------- PUBLIC TRANSFORMATION SERVICES -------- > */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 338164
: 189758