Пример #1
0
        /// <summary>
        /// This will check the exceptional for errors. Depending on the SettingInvalidReferenceHandling an expcetion will be thrown or false will be return on any load error.
        /// </summary>
        /// <param name="dbStream"></param>
        /// <param name="myLevelKey"></param>
        /// <returns></returns>
        private Boolean CheckLoadedDBObjectStream(Exceptional<DBObjectStream> dbStream, GraphDBType myDBType, TypeAttribute myTypeAttribute = null)
        {

            SettingInvalidReferenceHandling invalidReferenceSetting = null;
            GraphDBType currentType = myDBType;

            if (dbStream.Failed())
            {
                #region error

                #region get setting

                if (invalidReferenceSetting == null)
                {
                    //currentType = _DBContext.DBTypeManager.GetTypeByUUID(myLevelKey.LastEdge.TypeUUID);

                    //if (myLevelKey.LastEdge.AttrUUID != null)
                    if (myTypeAttribute != null)
                    {
                        invalidReferenceSetting = (SettingInvalidReferenceHandling)_DBContext.DBSettingsManager.GetSetting(SettingInvalidReferenceHandling.UUID, _DBContext, TypesSettingScope.ATTRIBUTE, currentType, myTypeAttribute).Value; // currentType.GetTypeAttributeByUUID(myLevelKey.LastEdge.AttrUUID)).Value;
                    }
                    else
                    {
                        invalidReferenceSetting = (SettingInvalidReferenceHandling)_DBContext.DBSettingsManager.GetSetting(SettingInvalidReferenceHandling.UUID, _DBContext, TypesSettingScope.TYPE, currentType).Value;
                    }
                }

                #endregion

                switch (invalidReferenceSetting.Behaviour)
                {
                    case BehaviourOnInvalidReference.ignore:
                        #region ignore

                        return false;

                        #endregion
                    case BehaviourOnInvalidReference.log:

                    default:

                        throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace()));
                }

                #endregion
            }

            return true;

        }
Пример #2
0
        private Exceptional<ResultType> AddAttributeToDBObject(GraphDBType myTypeOfDBObject, ObjectUUID myUUID, AttributeUUID myAttributeUUID, IObject myAttributeValue)
        {
            //myGraphType is needed due to correctness concerning the attribute name

            #region Input exceptions

            if ((myTypeOfDBObject == null) || (myUUID == null) || (myAttributeUUID == null) || (myAttributeValue == null))
            {
                throw new ArgumentNullException();
            }

            #endregion

            #region Check GraphType for new Attribute

            TypeAttribute typeAttribute = myTypeOfDBObject.GetTypeAttributeByUUID(myAttributeUUID);

            if (typeAttribute == null)
            {
                //Todo: add notification here (the user has to be informed about the detailed circumstances)

                GraphDBError aError = new Error_AttributeIsNotDefined(myTypeOfDBObject.Name, myAttributeUUID.ToString());

                return new Exceptional<ResultType>(aError);
            }

            #endregion

            #region Data

            var objectLocation = new ObjectLocation(myTypeOfDBObject.ObjectLocation, DBConstants.DBObjectsLocation, myUUID.ToString());
            Exceptional<DBObjectStream> aNewDBObject;
            Exceptional<ResultType> result = new Exceptional<ResultType>();

            #endregion

            #region add attribute

            aNewDBObject = _DBContext.DBObjectManager.LoadDBObject(myTypeOfDBObject, myUUID);

            if (aNewDBObject.Failed())
            {
                result.PushIError(new Error_LoadObject(aNewDBObject.Value.ObjectLocation));
                return result;
            }

            result = aNewDBObject.Value.AddAttribute(typeAttribute.UUID, myAttributeValue);

            if (result.Failed())
                return result;

            try
            {
                _DBContext.DBObjectManager.FlushDBObject(aNewDBObject.Value);
            }
            catch (Exception ex)
            {
                result.PushIError(new Error_FlushObject(aNewDBObject.Value.ObjectLocation, ex));
                aNewDBObject.Value.RemoveAttribute(typeAttribute.UUID);
            }

            #endregion

            return result;
        }
Пример #3
0
        /// <summary>
        /// Validates the expression (Set the TypeOfBinaryExpression, do some simplifications and validates all IDChains
        /// </summary>
        /// <param name="myDBContext"></param>
        /// <param name="types">This is optional, usually you wont pass any types</param>
        /// <returns></returns>
        public Exceptional Validate(DBContext myDBContext, params GraphDBType[] types)
        {
            if (IsValidated)
            {
                return ValidateResult;
            }
            ValidateResult = new Exceptional();

            Operator = myDBContext.DBPluginManager.GetBinaryOperator(_OperatorSymbol);

            #region Left - Valid TypesOfBinaryExpression are RightComplex (left is atom) or LeftComplex (left is complex)

            if (_Left is ValueDefinition)
            {
                TypeOfBinaryExpression = TypesOfBinaryExpression.RightComplex;
            }
            else if (_Left is IDChainDefinition)
            {
                ValidateResult.PushIExceptional((_Left as IDChainDefinition).Validate(myDBContext, true, types));
                TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex;
            }
            else if (_Left is TupleDefinition)
            {

                #region TupleDefinition

                if (IsEncapsulatedBinaryExpression(_Left as TupleDefinition))
                {
                    var exceptionalResult = TryGetBinexpression((_Left as TupleDefinition).First().Value, myDBContext);
                    if (exceptionalResult.Failed())
                    {
                        return ValidateResult.PushIExceptional(exceptionalResult);
                    }
                    _Left = exceptionalResult.Value;
                    TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex;
                }
                else
                {
                    var correctTuple = AssignCorrectTuple((_Left as TupleDefinition), Operator, myDBContext);
                    if (correctTuple.Failed())
                    {
                        return new Exceptional(correctTuple);
                    }
                    _Left = correctTuple.Value;
                    TypeOfBinaryExpression = TypesOfBinaryExpression.RightComplex;
                }

                #endregion

            }
            else if (_Left is AggregateDefinition)
            {
                TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex;
            }
            else if (_Left is UnaryExpressionDefinition)
            {
                TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex;
                var binExprResult = (_Left as UnaryExpressionDefinition).GetBinaryExpression(myDBContext);

                ValidateResult.PushIExceptional(binExprResult);

                _Left = binExprResult.Value;
            }
            else
            {
                #region try binexpr

                var exceptionalResult = TryGetBinexpression(_Left, myDBContext);
                if (exceptionalResult.Failed())
                {
                    return ValidateResult.PushIExceptional(exceptionalResult);
                }
                _Left = exceptionalResult.Value;
                TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex;

                #endregion
            }

            #endregion

            if (ValidateResult.Failed())
            {
                return ValidateResult;
            }

            #region Right

            if (_Right is ValueDefinition)
            {
                if (TypeOfBinaryExpression == TypesOfBinaryExpression.RightComplex)
                {
                    TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                }
            }
            else if (_Right is IDChainDefinition)
            {
                ValidateResult.PushIExceptional((_Right as IDChainDefinition).Validate(myDBContext, false, types));
                if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex)
                {
                    TypeOfBinaryExpression = TypesOfBinaryExpression.Complex;
                }
            }
            else if (_Right is UnaryExpressionDefinition)
            {
                if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex)
                {
                    TypeOfBinaryExpression = TypesOfBinaryExpression.Complex;
                }
                var binExprResult = (_Right as UnaryExpressionDefinition).GetBinaryExpression(myDBContext);

                ValidateResult.PushIExceptional(binExprResult);

                _Right = binExprResult.Value;
            }
            else if (_Right is TupleDefinition)
            {

                #region TupleDefinition

                if (IsEncapsulatedBinaryExpression(_Right as TupleDefinition))
                {
                    var exceptionalResult = TryGetBinexpression((_Right as TupleDefinition).First().Value, myDBContext);
                    if (exceptionalResult.Failed())
                    {
                        return ValidateResult.PushIExceptional(exceptionalResult);
                    }
                    _Right = exceptionalResult.Value;
                    if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex)
                    {
                        TypeOfBinaryExpression = TypesOfBinaryExpression.Complex;
                    }
                }
                else
                {
                    var correctTuple = AssignCorrectTuple((_Right as TupleDefinition), Operator, myDBContext);
                    if (correctTuple.Failed())
                    {
                        return new Exceptional(correctTuple);
                    }
                    _Right = correctTuple.Value;
                    if (TypeOfBinaryExpression == TypesOfBinaryExpression.RightComplex)
                    {
                        TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                    }
                }

                #endregion

            }
            else if (_Right is AggregateDefinition)
            {
                if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex)
                {
                    TypeOfBinaryExpression = TypesOfBinaryExpression.Complex;
                }
            }
            else
            {
                #region try binexpr

                var exceptionalResult = TryGetBinexpression(_Right, myDBContext);
                if (exceptionalResult.Failed())
                {
                    return ValidateResult.PushIExceptional(exceptionalResult);
                }
                _Right = exceptionalResult.Value;
                if (TypeOfBinaryExpression == TypesOfBinaryExpression.LeftComplex)
                {
                    TypeOfBinaryExpression = TypesOfBinaryExpression.Complex;
                }

                #endregion
            }

            #endregion

            if (ValidateResult.Failed())
            {
                return ValidateResult;
            }

            #region try to get values from complex expr

            Exceptional<AOperationDefinition> leftTemp;
            Exceptional<AOperationDefinition> rightTemp;

            switch (TypeOfBinaryExpression)
            {
                case TypesOfBinaryExpression.Atom:

                    break;

                case TypesOfBinaryExpression.LeftComplex:

                    #region leftComplex

                    leftTemp = TryGetOperationValue(_Left);

                    if (leftTemp != null)
                    {
                        if (leftTemp.Failed())
                        {
                            return ValidateResult.PushIExceptional(leftTemp);
                        }
                        TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                        _Left = leftTemp.Value;
                    }

                    #endregion

                    break;

                case TypesOfBinaryExpression.RightComplex:

                    #region rightComplex

                    rightTemp = TryGetOperationValue(_Right);

                    if (rightTemp != null)
                    {
                        if (rightTemp.Failed())
                        {
                            return ValidateResult.PushIExceptional(rightTemp);
                        }
                        TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                        _Right = rightTemp.Value;
                    }

                    #endregion

                    break;

                case TypesOfBinaryExpression.Complex:

                    #region complex

                    leftTemp = TryGetOperationValue(_Left);
                    rightTemp = TryGetOperationValue(_Right);

                    #region Check for errors

                    if (leftTemp != null && leftTemp.Failed())
                    {
                        return ValidateResult.PushIExceptional(leftTemp);
                    }
                    if (rightTemp != null && rightTemp.Failed())
                    {
                        return ValidateResult.PushIExceptional(rightTemp);
                    }

                    #endregion

                    if ((leftTemp != null) && (rightTemp != null))
                    {
                        TypeOfBinaryExpression = TypesOfBinaryExpression.Atom;
                        _Left = leftTemp.Value;
                        _Right = rightTemp.Value;
                    }
                    else
                    {
                        if (leftTemp != null)
                        {
                            TypeOfBinaryExpression = TypesOfBinaryExpression.RightComplex;
                            _Left = leftTemp.Value;
                        }
                        else if (rightTemp != null)
                        {
                            TypeOfBinaryExpression = TypesOfBinaryExpression.LeftComplex;
                            _Right = rightTemp.Value;
                        }
                    }

                    #endregion

                    break;
            }

            #endregion

            #region process values

            if (TypeOfBinaryExpression == TypesOfBinaryExpression.Atom)
            {
                #region atomic values

                if ((_Left is AOperationDefinition) && (_Right is AOperationDefinition))
                {
                    var opResult = Operator.SimpleOperation(((AOperationDefinition)_Left), ((AOperationDefinition)_Right), TypeOfBinaryExpression);
                    if (opResult.Failed())
                    {
                        return ValidateResult.PushIExceptional(opResult);
                    }
                    ResultValue = new Exceptional<AOperationDefinition>(opResult.Value);
                }

                #endregion
            }
            else
            {
                #region some kind of complex values

                if (IsCombinableAble(_Left, _Right))
                {
                    #region summarize expressions
                    //sth like (U.Age + 1) + 1 --> U.Age + 2

                    SimpleCombination(ref _Left, ref _Right);

                    #endregion
                }
                else
                {
                    #region tweak expressions

                    while (IsTweakAble(_Left, _Right))
                    {
                        SimpleExpressionTweak(ref _Left, ref _Right, myDBContext);
                    }

                    #endregion
                }

                #endregion
            }

            #endregion

            return ValidateResult;
        }