Пример #1
0
        public override bool Match(object valueToMatch)
        {
            // If it is a AttributeValuesMap, then gets the real value from the map
            // AttributeValuesMap is used to optimize Criteria Query
            // (reading only values of the object that the query needs to be
            // evaluated instead of reading the entire object)
            if (valueToMatch is NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap)
            {
                NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap attributeValues = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap
                                                                                           )valueToMatch;
                valueToMatch = attributeValues.GetAttributeValue(attributeName);
            }
            if (valueToMatch == null && criterionValue == null && oid == null)
            {
                return(true);
            }
            // if case sensitive (default value), just call the equals on the
            // objects
            if (isCaseSensitive)
            {
                if (objectIsNative)
                {
                    return(valueToMatch != null && NeoDatis.Odb.Impl.Core.Layers.Layer2.Meta.Compare.AttributeValueComparator
                           .Equals(valueToMatch, criterionValue));
                }
                NeoDatis.Odb.OID objectOid = (NeoDatis.Odb.OID)valueToMatch;
                if (oid == null)
                {
                    // TODO Should we return false or thrown exception?
                    // See junit TestCriteriaQuery6.test1
                    return(false);
                }
                // throw new
                // ODBRuntimeException(NeoDatisError.CRITERIA_QUERY_ON_UNKNOWN_OBJECT);
                return(oid.Equals(objectOid));
            }
            // && valueToMatch.equals(criterionValue);
            // Case insensitive (iequal) only works on String or Character!
            bool canUseCaseInsensitive = (criterionValue.GetType() == typeof(string) && valueToMatch
                                          .GetType() == typeof(string)) || (criterionValue.GetType() == typeof(char) && valueToMatch
                                                                            .GetType() == typeof(char));

            if (!canUseCaseInsensitive)
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.QueryAttributeTypeNotSupportedInIequalExpression
                                                           .AddParameter(valueToMatch.GetType().FullName));
            }
            // Cast to string to make the right comparison using the
            // equalsIgnoreCase
            string s1 = (string)valueToMatch;
            string s2 = (string)criterionValue;

            return(NeoDatis.Tool.Wrappers.OdbString.EqualsIgnoreCase(s1, s2));
        }