Ejemplo n.º 1
0
        /// <summary>
        /// Writes an DBObject into log
        /// </summary>
        /// <param name="myObjectUUID">The UUID of the Object</param>
        /// <param name="myTypeManager">The corresponding type manager</param>
        /// <param name="myTypeAttribute">The type attribute</param>
        public static void ShowDBObject(ObjectUUID myObjectUUID, DBTypeManager myTypeManager, TypeAttribute myTypeAttribute, DBObjectCache myObjectCache)
        {
            var currentDBObject = myObjectCache.LoadDBObjectStream(myTypeAttribute.GetRelatedType(myTypeManager), myObjectUUID);

            if (currentDBObject.Failed())
                throw new NotImplementedException();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes all paths included in the HashSet. Every object is represented via a given attribute.
        /// 
        /// example path between fry and morbo (attribute is "Name") 
        /// 
        /// output:
        /// Fry -> Leela -> Lrrr -> Morbo
        /// </summary>
        /// <param name="myPaths">An HashSet which contains Lists of UUIDs</param>
        /// <param name="myTypeManager">The type manager to load the DBObjects</param>
        /// <param name="myTypeAttribute">The Type Attribute</param>
        /// <param name="myAttribute">The Attribute which shall be used for output.</param>
        public static void ShowDBObjects(HashSet<List<ObjectUUID>> myPaths, DBTypeManager myTypeManager, TypeAttribute myTypeAttribute, String myAttribute, DBObjectCache myObjectCache)
        {
            var attributeUUID = myTypeAttribute.GetRelatedType(myTypeManager).GetTypeSpecificAttributeByName(myAttribute).UUID;

            foreach (var path in myPaths)
            {

                var pathString = new StringBuilder();
                Exceptional<DBObjectStream> currentDBObject;

                foreach (var _ObjectUUID in path)
                {
                    //load from DB
                    currentDBObject = myObjectCache.LoadDBObjectStream(myTypeAttribute.GetRelatedType(myTypeManager), _ObjectUUID);
                    if (currentDBObject.Failed())
                    {
                        throw new NotImplementedException();
                    }

                    pathString.Append(currentDBObject.Value.GetAttribute(attributeUUID) + " -> ");
                }

                ////_Logger.Info(pathString.ToString());
                pathString.Remove(0, pathString.Length);

            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="dbContext">The TypeManager of the database.</param>
 public CommonUsageGraph(DBContext dbContext)
     : this()
 {
     _DBContext = dbContext;
     _DBObjectCache = _DBContext.DBObjectCache;
     _Levels = new Dictionary<int, IExpressionLevel>();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// This will create a new dbContext, based on <paramref name="dbContext"/> reusing all shared data
        /// </summary>
        /// <param name="dbContext"></param>
        public DBContext(DBContext dbContext)
        {
            #region Immutable objects

            _DBPluginManager = dbContext.DBPluginManager;
            _DBSettingsManager = dbContext.DBSettingsManager;
            _IGraphFSSession = dbContext._IGraphFSSession;

            #endregion

            _SessionSettings = new DBSessionSettings(dbContext.SessionSettings);
            _DBObjectManager = new ObjectManagement.DBObjectManager(this, _IGraphFSSession);

            //
            _DBIndexManager = new Indices.DBIndexManager(_IGraphFSSession, this);

            _DBTypeManager = new DBTypeManager(dbContext.DBTypeManager);

            _DBObjectCache = _DBObjectManager.GetSimpleDBObjectCache(this);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method checks and integrates a DBObjectStream into the result graph.
        /// </summary>
        /// <param name="myData">The DataContainer.</param>
        /// <param name="myTypeManager">The TypeManager of the database.</param>
        /// <param name="myQueryCache">The current query cache.</param>
        /// <param name="myTypeOfBinExpr">The kind of the binary expression.</param>
        /// <param name="myResultGraph">The resulting IExpressionGraph.</param>
        /// <param name="myDBObjectStream">The DBObjectStream.</param>
        private Exceptional<object> CheckAndIntegrateDBObjectStream(DataContainer myData, DBContext myTypeManager, DBObjectCache myQueryCache, TypesOfBinaryExpression myTypeOfBinExpr, IExpressionGraph myResultGraph, DBObjectStream myDBObjectStream, LevelKey myLevelKey, SessionSettings mySessionToken)
        {
            //get the operand
            var operand = GetOperand(myData.IDChainDefinitions.Item1, myData.Extraordinaries.Item1, myTypeManager, myDBObjectStream, myQueryCache, mySessionToken);

            if(operand == null)
            {
                return new Exceptional<object>();
            }

            if (operand.Failed())
            {
                return new Exceptional<object>(operand);
            }

            Exceptional<AOperationDefinition> tempSimpleOperationResult;

            switch (myTypeOfBinExpr)
            {

                case TypesOfBinaryExpression.LeftComplex:

                    tempSimpleOperationResult = this.SimpleOperation(operand.Value, ((AOperationDefinition)myData.Operands.Item1), myTypeOfBinExpr);

                    break;
                case TypesOfBinaryExpression.RightComplex:

                    tempSimpleOperationResult = this.SimpleOperation(((AOperationDefinition)myData.Operands.Item1), operand.Value, myTypeOfBinExpr);

                    break;

                case TypesOfBinaryExpression.Complex:
                case TypesOfBinaryExpression.Atom:
                default:

                    throw new ArgumentException();
            }

            if (tempSimpleOperationResult.Failed())
            {
                return new Exceptional<object>(tempSimpleOperationResult);
            }

            var tempOperatorResult = ((ValueDefinition)tempSimpleOperationResult.Value);

            if ((Boolean)tempOperatorResult.Value.Value)
            {
                IntegrateInGraph(myDBObjectStream, myResultGraph, myLevelKey, myTypeManager, myQueryCache);
            }
            //else
            //{
            //    /// We need to add an empty level in case, the DBO should not be integerated. Otherwise the select does not know, either the level was never touched or
            //    /// not added due to an expression
            //    ExcludeFromGraph(myDBObjectStream, myResultGraph, myLevelKey, myTypeManager, myQueryCache);
            //}

            return new Exceptional<object>();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method returns the DBObjectStream that is referenced by this node.
        /// </summary>
        /// <param name="myDBObjectCache">The actual query cache.</param>
        /// <param name="myTypeUUID">The TypeUUID of the DBObject.</param>
        /// <returns>A DBObjectStream</returns>
        public DBObjectStream GetDBObjectStream(DBObjectCache myDBObjectCache, TypeUUID myTypeUUID)
        {
            lock (_ObjectUUID)
            {
                if (_Object != null)
                {
                    return _Object;
                }
                else
                {

                    var tempObject = myDBObjectCache.LoadDBObjectStream(myTypeUUID, GetObjectUUID());
                    if (tempObject.Failed())
                    {
                        return null;
                    }

                    _Object = tempObject.Value;

                    return _Object;
                }
            }
        }
Ejemplo n.º 7
0
        /// <param name="data">The DataContainer.</param>
        /// <param name="dbContext">The TypeManager of the database.</param>
        /// <param name="queryCache">The current query cache.</param>
        /// <param name="typeOfBinExpr">The type of the binary expression.</param>
        /// <param name="idx">The index for the complex part.</param>
        /// <param name="errors">A list of errors.</param>
        /// <param name="resultGraph">The IExpressionGraph that serves as result.</param>
        /// <returns>True if the method succeeded</returns>
        private Exceptional<Boolean> MatchData(DataContainer data, DBContext dbContext, DBObjectCache dbObjectCache, TypesOfBinaryExpression typeOfBinExpr, IEnumerable<Tuple<GraphDBType, AAttributeIndex>> idx, IExpressionGraph resultGraph, SessionSettings mySessionToken)
        {
            #region data

            LevelKey myLevelKey = CreateLevelKey(data.IDChainDefinitions.Item1, dbContext.DBTypeManager);

            #endregion

            foreach (var aIDX in idx)
            {

                //this is only for such type(DBVertex) that have no AAttributeIndex
                if (aIDX.Item2 == null)
                {
                    continue;
                }

                #region Execution

                if (aIDX.Item2.IsUUIDIndex && (data.IDChainDefinitions.Item1.LastAttribute != dbContext.DBTypeManager.GetUUIDTypeAttribute()))
                {
                    #region UUID idx - check ALL DBOs

                    var IndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(aIDX.Item2.IndexRelatedTypeUUID);

                    var idxKeyValues = (aIDX.Item2).GetAllValues(IndexRelatedType, dbContext);
                    if (idxKeyValues.CountIs(0))
                    {
                        continue;
                    }

                    var uuids = idxKeyValues.Aggregate((elem, aggrresult) => aggrresult.Union(elem));

                    var result = IntegrateUUID(data, dbContext, dbObjectCache, typeOfBinExpr, resultGraph, mySessionToken, myLevelKey, dbObjectCache.LoadListOfDBObjectStreams(aIDX.Item1, uuids));
                    if (result.Failed())
                    {
                        return new Exceptional<bool>(result);
                    }

                    if (resultGraph.ContainsLevelKey(myLevelKey))
                    {
                        #region clean lower levels

                        if (Type == TypesOfOperators.AffectsLowerLevels)
                        {
                            CleanLowerLevel(myLevelKey, dbContext, dbObjectCache, resultGraph);
                        }

                        #endregion

                    }
                    else
                    {
                        resultGraph.AddEmptyLevel(myLevelKey);
                    }

                    #endregion
                }
                else
                {

                    #region Get operationValue and type

                    var operationValue = (AOperationDefinition)data.Operands.Item1;

                    #endregion

                    #region Attribute index

                    if (aIDX.Item2.IndexKeyDefinition.IndexKeyAttributeUUIDs.Count > 1)
                    {
                        return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), "Currently it is not implemented to use compound indices."));
                    }

                    var interestingUUIDsByIdx = IndexSingleOperation(aIDX.Item2, operationValue, data.IDChainDefinitions.Item1.LastAttribute.UUID, typeOfBinExpr, dbContext);

                    #region integrate in graph

                    var runMT = DBConstants.RunMT;

                    if (runMT)
                    {
                        Parallel.ForEach(dbObjectCache.LoadListOfDBObjectStreams(data.IDChainDefinitions.Item1.LastType, interestingUUIDsByIdx), aDBO =>
                        {
                            IntegrateInGraph(aDBO.Value, resultGraph, myLevelKey, dbContext, dbObjectCache);
                        }
                        );
                    }
                    else
                    {
                        foreach (var aDBO in dbObjectCache.LoadListOfDBObjectStreams(data.IDChainDefinitions.Item1.LastType, interestingUUIDsByIdx))
                        {
                            IntegrateInGraph(aDBO.Value, resultGraph, myLevelKey, dbContext, dbObjectCache);
                        }
                    }

                    #endregion

                    if (resultGraph.ContainsLevelKey(myLevelKey))
                    {
                        #region clean lower levels

                        if (Type == TypesOfOperators.AffectsLowerLevels)
                        {
                            CleanLowerLevel(myLevelKey, dbContext, dbObjectCache, resultGraph);
                        }

                        #endregion

                    }
                    else
                    {
                        resultGraph.AddEmptyLevel(myLevelKey);
                    }

                    #endregion
                }

                #endregion
            }

            return new Exceptional<bool>(true);
        }
Ejemplo n.º 8
0
 public override IEnumerable<Exceptional<DBObjectStream>> GetAllEdgeDestinations(DBObjectCache dbObjectCache)
 {
     return _ObjectUUIDs.Select(kv => kv.Value.GetDBObjectStream(dbObjectCache));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="myIGraphDBSession">The filesystem where the information is stored.</param>
        /// <param name="DatabaseRootPath">The database root path.</param>
        public DBContext(IGraphFSSession graphFSSession, ObjectLocation myDatabaseRootPath, EntityUUID myUserID, Dictionary<String, ADBSettingsBase> myDBSettings, Boolean myRebuildIndices, DBPluginManager myDBPluginManager, DBSessionSettings sessionSettings = null)
        {
            _DBPluginManager    = myDBPluginManager;

            _DBTypeManager      = new TypeManagement.DBTypeManager(graphFSSession, myDatabaseRootPath, myUserID, myDBSettings, this);
            _DBSettingsManager  = new DBSettingsManager(_DBPluginManager.Settings, myDBSettings, graphFSSession, new ObjectLocation(myDatabaseRootPath.Name, DBConstants.DBSettingsLocation));
            _DBObjectManager    = new DBObjectManager(this, graphFSSession);
            _DBIndexManager     = new DBIndexManager(graphFSSession, this);
            _SessionSettings    = sessionSettings;
            _DBObjectCache      = _DBObjectManager.GetSimpleDBObjectCache(this);
            _IGraphFSSession    = graphFSSession;

            //init types
            var initExcept = _DBTypeManager.Init(graphFSSession, myDatabaseRootPath, myRebuildIndices);

            if (initExcept.Failed())
            {
                throw new GraphDBException(initExcept.IErrors);
            }
        }
Ejemplo n.º 10
0
        private Exceptional<IExpressionGraph> GetComplexAtom(DBContext dbContext, Dictionary<DBObjectStream, AOperationDefinition> operandsPrim, Dictionary<DBObjectStream, AOperationDefinition> operandsComparism, IDChainDefinition myIDChainDefinition, DBObjectCache dbObjectCache, ref IExpressionGraph result)
        {
            #region data

            LevelKey myLevelKey = CreateLevelKey(myIDChainDefinition, dbContext.DBTypeManager);

            #endregion

            foreach (var left in operandsPrim)
            {
                foreach (var right in operandsComparism)
                {
                    var tempResult = this.SimpleOperation(left.Value, right.Value, TypesOfBinaryExpression.Atom);
                    if (tempResult.Failed())
                        return new Exceptional<IExpressionGraph>(tempResult);

                    if ((Boolean)((ValueDefinition)tempResult.Value).Value.Value)
                    {
                        IntegrateInGraph(left.Key, result, myLevelKey, dbContext,dbObjectCache);
                        break;
                    }
                }
            }

            return new Exceptional<IExpressionGraph>(result);
        }
Ejemplo n.º 11
0
        private IObject GetDbos(IDChainDefinition myIDChainDefinition, DBObjectStream myDBObjectStream, DBContext dbContext, SessionSettings mySessionToken, DBObjectCache dbObjectCache)
        {
            if (myIDChainDefinition.LastAttribute.IsBackwardEdge)
            {
                var contBackwardExcept = myDBObjectStream.ContainsBackwardEdge(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition, dbContext, dbObjectCache, myIDChainDefinition.LastAttribute.GetRelatedType(dbContext.DBTypeManager));

                if (contBackwardExcept.Failed())
                    throw new GraphDBException(contBackwardExcept.IErrors);

                if (contBackwardExcept.Value)
                {
                    var beStream = dbObjectCache.LoadDBBackwardEdgeStream(myIDChainDefinition.LastType, myDBObjectStream.ObjectUUID).Value;
                    if (beStream.ContainsBackwardEdge(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition))
                        return beStream.GetBackwardEdges(myIDChainDefinition.LastAttribute.BackwardEdgeDefinition);
                    else
                        return null;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                if (myIDChainDefinition.LastAttribute.KindOfType == KindsOfType.SpecialAttribute)
                {
                    return myDBObjectStream.GetAttribute(myIDChainDefinition.LastAttribute.UUID, myIDChainDefinition.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext);
                }
                else
                {
                    return myDBObjectStream.GetAttribute(myIDChainDefinition.LastAttribute.UUID);
                }
            }
        }
Ejemplo n.º 12
0
        private void CleanLowerLevel(LevelKey myLevelKey, DBContext dbContext, DBObjectCache dbObjectCache, IExpressionGraph myGraph)
        {
            if (myLevelKey.Level > 0)
            {
                var previousLevelKey = myLevelKey.GetPredecessorLevel(dbContext.DBTypeManager);
                HashSet<ObjectUUID> toBeDeletedNodes = new HashSet<ObjectUUID>();

                foreach (var aLowerDBO in myGraph.Select(previousLevelKey, null, false))
                {
                    if(aLowerDBO.Failed())
                    {
                        throw new GraphDBException(new Error_ExpressionGraphInternal(new System.Diagnostics.StackTrace(true), "Could not load DBObjectStream from lower level."));
                    }

                    foreach (var aReferenceUUID in ((IReferenceEdge)aLowerDBO.Value.GetAttribute(myLevelKey.LastEdge.AttrUUID)).GetAllReferenceIDs())
                    {
                        if (!myGraph.GetLevel(myLevelKey.Level).ExpressionLevels[myLevelKey].Nodes.ContainsKey(aReferenceUUID))
                        {
                            //a reference occurred that is not in the higher level --> found a Zoidberg

                            toBeDeletedNodes.Add(aLowerDBO.Value.ObjectUUID);
                            break;
                        }
                    }
                }

                foreach (var aToBeDeletedNode in toBeDeletedNodes)
                {
                    myGraph.GetLevel(previousLevelKey.Level).RemoveNode(previousLevelKey, aToBeDeletedNode);
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Extracts data for a binary expression
        /// </summary>
        /// <param name="myComplexValue">The complex part of the binary expression.</param>
        /// <param name="mySimpleValue">The simple/atomic part of the expression.</param>
        /// <param name="errors">The list of errors.</param>
        /// <param name="typeOfBinExpr">The kind of the binary expression</param>
        /// <returns>A data tuple.</returns>
        private Exceptional<DataContainer> ExtractData(AExpressionDefinition myComplexValue, AExpressionDefinition mySimpleValue, ref TypesOfBinaryExpression typeOfBinExpr, DBObjectCache myDBObjectCache, SessionSettings mySessionToken, DBContext dbContext, Boolean aggregateAllowed)
        {
            #region data

            //the complex IDNode (sth. like U.Age or Count(U.Friends))
            IDChainDefinition complexIDNode = null;

            //the value that is on the opposite of the complex IDNode
            AExpressionDefinition simpleValue = null;

            //a complex IDNode may result in a complexValue (i.e. Count(U.Friends) --> 3)
            AExpressionDefinition complexValue = null;

            //reference to former myComplexValue
            AExpressionDefinition extraordinaryValue = null;

            #endregion

            #region extraction

            if (myComplexValue is IDChainDefinition)
            {
                #region IDNode

                #region Data

                complexIDNode = (IDChainDefinition)myComplexValue;
                var validateResult = complexIDNode.Validate(dbContext, false);
                if (validateResult.Failed())
                {
                    return new Exceptional<DataContainer>(validateResult);
                }

                if (complexIDNode.Any(id => id is ChainPartFuncDefinition))
                {
                    if (complexIDNode.Edges.IsNullOrEmpty())
                    {
                        #region parameterless function

                        var fcn = (complexIDNode.First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition);

                        // somes functions (aggregates) like SUM are not valid for where expressions, though they are not resolved
                        if (fcn.Function == null)
                            return new Exceptional<DataContainer>(new Error_FunctionDoesNotExist(fcn.FuncName));

                        Exceptional<FuncParameter> pResult = fcn.Function.ExecFunc(dbContext);
                        if (pResult.Failed())
                        {
                            return new Exceptional<DataContainer>(pResult);
                        }

                        //simpleValue = new AtomValue(fcn.Function.TypeOfResult, ((FuncParameter)pResult.Value).Value); //the new simple value extraced from the function
                        simpleValue = new ValueDefinition(((FuncParameter)pResult.Value).Value);
                        typeOfBinExpr = TypesOfBinaryExpression.Unknown; //we do not know if we are left or right associated
                        complexIDNode = null; //we resolved it... so it's null

                        #endregion
                    }
                    else
                    {
                        //extraordinaryValue = (complexIDNode.First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition);
                        extraordinaryValue = complexIDNode;

                        if (mySimpleValue is ValueDefinition)
                        {
                            simpleValue = mySimpleValue;
                        }
                    }
                }
                else
                {
                    if(mySimpleValue is ValueDefinition)
                    {
                        try
                        {
                            if (complexIDNode.IsUndefinedAttribute)
                            {
                                throw new GraphDBException(new Error_AttributeIsNotDefined(complexIDNode.UndefinedAttribute));
                            }

                            simpleValue = GetCorrectValueDefinition(complexIDNode.LastAttribute, complexIDNode.LastType, ((ValueDefinition)mySimpleValue), dbContext, mySessionToken);
                        }
                        catch (FormatException)
                        {
                            return new Exceptional<DataContainer>(new Error_DataTypeDoesNotMatch(complexIDNode.LastAttribute.GetDBType(dbContext.DBTypeManager).Name, ((ValueDefinition)mySimpleValue).Value.ObjectName));
                        }
                    }
                    else
                    {
                        if (mySimpleValue is TupleDefinition)
                        {
                            ((TupleDefinition)mySimpleValue).ConvertToAttributeType(complexIDNode.LastAttribute, dbContext);

                            simpleValue = mySimpleValue;
                        }
                        //else if (mySimpleValue is TupleNode)
                        //{
                        //    var simpleValE = (mySimpleValue as TupleNode).GetAsTupleValue(dbContext, complexIDNode.LastAttribute);
                        //    if (!simpleValE.Success())
                        //    {
                        //        return new Exceptional<DataContainer>(simpleValE);
                        //    }
                        //    simpleValue = simpleValE.Value;
                        //}
                        else
                        {
                            //return new Exceptional<DataContainer>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                        }
                    }
                }

                #endregion

                #endregion
            }
            else if (myComplexValue is TupleDefinition)
            {
                #region TupleSetNode

                complexValue = ((TupleDefinition)myComplexValue);
                simpleValue = mySimpleValue;
                typeOfBinExpr = TypesOfBinaryExpression.Atom;

                #endregion
            }
            else if (myComplexValue is AggregateDefinition)
            {
                #region AggregateNode

                if (aggregateAllowed)
                {
                    if (((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters.Count != 1)
                    {
                        return new Exceptional<DataContainer>(new Error_ArgumentException("An aggregate must have exactly one expression."));
                    }

                    if (!(((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters[0] is IDChainDefinition))
                    {
                       return new Exceptional<DataContainer>(new Error_ArgumentException("An aggregate must have exactly one IDNode."));
                    }

                    #region Data

                    complexIDNode = (((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition.Parameters[0] as IDChainDefinition);

                    if (complexIDNode == null)
                    {
                        return new Exceptional<DataContainer>(new Error_InvalidIDNode("Only single IDNodes are currently allowed in aggregates!"));
                    }

                    #endregion

                    #region values

                    simpleValue = mySimpleValue;
                    extraordinaryValue = myComplexValue;

                    #endregion
                }
                else
                {
                    return new Exceptional<DataContainer>(new Error_AggregateNotAllowed(((AggregateDefinition)myComplexValue).ChainPartAggregateDefinition));
                }
                #endregion
            }
            else
            {
                return new Exceptional<DataContainer>(new Error_NotImplementedExpressionNode(myComplexValue.GetType()));
            }

            #endregion

            return new Exceptional<DataContainer>(new DataContainer(new Tuple<IDChainDefinition, IDChainDefinition>(complexIDNode, null), new Tuple<AExpressionDefinition, AExpressionDefinition>(simpleValue, complexValue), new Tuple<AExpressionDefinition, AExpressionDefinition>(extraordinaryValue, null)));
        }
Ejemplo n.º 14
0
        public override void AddNodesWithComplexRelation(Exceptional<DBObjectStream> leftDBObject, LevelKey leftLevelKey, Exceptional<DBObjectStream> rightDBObject, LevelKey rightLevelKey, DBObjectCache dbObjectCache, int backwardResolutiondepth)
        {
            lock (_Levels)
            {
                if ((AddNodeIfValid(leftDBObject.Value, leftLevelKey, 0, leftDBObject.Value.ObjectUUID, backwardResolutiondepth)) && (AddNodeIfValid(rightDBObject.Value, rightLevelKey, 0, rightDBObject.Value.ObjectUUID, backwardResolutiondepth)))
                {
                    //both nodes have been inserted correctly
                    //--> create a connection between both
                    _Levels[leftLevelKey.Level].ExpressionLevels[leftLevelKey].Nodes[leftDBObject.Value.ObjectUUID].AddComplexConnection(rightLevelKey, rightDBObject.Value.ObjectUUID);
                    _Levels[rightLevelKey.Level].ExpressionLevels[rightLevelKey].Nodes[rightDBObject.Value.ObjectUUID].AddComplexConnection(leftLevelKey, leftDBObject.Value.ObjectUUID);
                }
                else
                {
                    #region remove both nodes

                    if (ContainsLevelKey(leftLevelKey))
                    {
                        _Levels[leftLevelKey.Level].RemoveNode(leftLevelKey, leftDBObject.Value.ObjectUUID);
                    }
                    if (ContainsLevelKey(leftLevelKey))
                    {
                        _Levels[rightLevelKey.Level].RemoveNode(rightLevelKey, rightDBObject.Value.ObjectUUID);
                    }

                    #endregion
                }
            }
        }
Ejemplo n.º 15
0
 public abstract void AddNodesWithComplexRelation(Exceptional<DBObjectStream> leftDBObject, LevelKey leftLevelKey, Exceptional<DBObjectStream> rightDBObject, LevelKey rightLevelKey, DBObjectCache dbObjectCache, int backwardResolution);
Ejemplo n.º 16
0
 public abstract Tuple<Exceptional<DBObjectStream>, ADBBaseObject> GetEdgeDestinationWeighted(DBObjectCache dbObjectCache);
Ejemplo n.º 17
0
        public override IEnumerable<Exceptional<DBObjectStream>> GetAllEdgeDestinations(DBObjectCache dbObjectCache)
        {
            yield return _ObjectUUID.Item2.GetDBObjectStream(dbObjectCache);

            yield break;
        }
 /// <summary>
 /// Get all weighted destinations of an edge
 /// </summary>
 /// <returns></returns>
 public abstract IEnumerable<Tuple<Exceptional<DBObjectStream>, ADBBaseObject>> GetAllEdgeDestinationsWeighted(DBObjectCache dbObjectCache);
Ejemplo n.º 19
0
 /// <summary>
 /// We need to add an empty level in case, the DBO should not be integerated. Otherwise the select does not know, either the level was never touched or 
 /// not added due to an expression
 /// </summary>
 /// <param name="myDBObjectStream"></param>
 /// <param name="myExpressionGraph"></param>
 /// <param name="myLevelKey"></param>
 /// <param name="myTypeManager"></param>
 /// <param name="myQueryCache"></param>
 private void ExcludeFromGraph(DBObjectStream myDBObjectStream, IExpressionGraph myExpressionGraph, LevelKey myLevelKey, DBContext myTypeManager, DBObjectCache myQueryCache)
 {
     myExpressionGraph.AddEmptyLevel(myLevelKey);
 }
Ejemplo n.º 20
0
        public override IEnumerable<Exceptional<DBObjectStream>> GetAllEdgeDestinations(DBObjectCache dbObjectCache)
        {
            foreach (var aReference in weightedSet.GetAll())
            {
                yield return aReference.Key.GetDBObjectStream(dbObjectCache);
            }

            yield break;
        }
Ejemplo n.º 21
0
 /// <summary>
 /// This method gets result of a simple atomic operation.
 /// </summary>
 /// <param name="myDBType">The DBTypeStream.</param>
 /// <param name="myTypeManager">The TypeManager of the database.</param>
 /// <param name="queryCache">The current query cache.</param>
 /// <param name="data">The DataContainer.</param>
 private void GetAtomResult(GraphDBType myDBType, DBContext myTypeManager, DBObjectCache dbObjectCache, DataContainer data, ref IExpressionGraph result)
 {
     //do nothing here
 }
Ejemplo n.º 22
0
        public override IEnumerable<Tuple<Exceptional<DBObjectStream>, ADBBaseObject>> GetAllEdgeDestinationsWeighted(DBObjectCache dbObjectCache)
        {
            foreach (var vals in weightedSet.GetAll())
            {
                yield return new Tuple<Exceptional<DBObjectStream>, ADBBaseObject>(vals.Key.GetDBObjectStream(dbObjectCache), vals.Value);
            }

            yield break;
        }
Ejemplo n.º 23
0
        private Exceptional<Boolean> GetComplexMatch(IEnumerable<Tuple<GraphDBType, AAttributeIndex>> myIDX, Dictionary<DBObjectStream, AOperationDefinition> operands, DBObjectCache dbObjectCache, IDChainDefinition primIDNode, IDChainDefinition operandIDNode, DBContext dbContext, TypesOfAssociativity associativity, ref IExpressionGraph resultGraph, SessionSettings mySessionToken)
        {
            LevelKey primLevelKey = CreateLevelKey(primIDNode, dbContext.DBTypeManager);
            LevelKey operandLevelKey = CreateLevelKey(operandIDNode, dbContext.DBTypeManager);

            foreach (var aIDX in myIDX)
            {
                if (aIDX.Item2.IsUUIDIndex)
                {
                    #region UUID idx

                    var currentIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(aIDX.Item2.IndexRelatedTypeUUID);

                    foreach (var aOperand in operands)
                    {

                        foreach (var _ObjectUUIDs in ((UUIDIndex)aIDX.Item2).GetAllUUIDs(currentIndexRelatedType, dbContext))
                        {
                            var DBObjectStream = dbObjectCache.LoadDBObjectStream(aIDX.Item1, _ObjectUUIDs);
                            if (DBObjectStream.Failed())
                            {
                                return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                            }

                            if (IsValidDBObjectStreamForBinExpr(DBObjectStream.Value, primIDNode.LastAttribute, dbContext.DBTypeManager))
                            {
                                var aCtype = GraphDBTypeMapper.ConvertGraph2CSharp(primIDNode.LastAttribute.GetDBType(dbContext.DBTypeManager).Name);
                                IObject dbos = GetDbos(primIDNode, DBObjectStream.Value, dbContext, mySessionToken, dbObjectCache);

                                Exceptional<AOperationDefinition> tempResult;
                                if (aCtype == BasicType.SetOfDBObjects)
                                {
                                    tempResult = this.SimpleOperation(new TupleDefinition(aCtype, dbos, primIDNode.LastAttribute.GetDBType(dbContext.DBTypeManager)), aOperand.Value, TypesOfBinaryExpression.Complex);
                                }
                                else
                                {
                                    tempResult = this.SimpleOperation(new ValueDefinition(aCtype, dbos), aOperand.Value, TypesOfBinaryExpression.Complex);

                                }

                                if (tempResult.Failed())
                                    return new Exceptional<bool>(tempResult);

                                var tempOperatorResult = ((ValueDefinition)tempResult.Value);

                                if ((Boolean)tempOperatorResult.Value.Value)
                                {
                                    switch (associativity)
                                    {
                                        case TypesOfAssociativity.Neutral:
                                        case TypesOfAssociativity.Left:

                                            IntegrateInGraph(aOperand.Key, resultGraph, operandLevelKey, dbContext, dbObjectCache);

                                            break;
                                        case TypesOfAssociativity.Right:

                                            IntegrateInGraph(DBObjectStream.Value, resultGraph, primLevelKey, dbContext, dbObjectCache);

                                            break;
                                        default:

                                            return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                }
                else
                {
                    return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                }
            }

            return new Exceptional<bool>(true);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// This method extracts an IOperationValue out of a DBObjectStream.
        /// </summary>
        /// <param name="myIDChainDefinition">The corresponding IDNode.</param>
        /// <param name="myExtraordinary">Sth extraordinary like an aggregate or function call.</param>
        /// <param name="dbContext">The TypeManager of the database.</param>
        /// <param name="myDBObjectStream">The DBObjectStream.</param>
        /// <returns>An IOperationValue.</returns>
        private Exceptional<AOperationDefinition> GetOperand(IDChainDefinition myIDChainDefinition, AExpressionDefinition myExtraordinary, DBContext dbContext, DBObjectStream myDBObjectStream, DBObjectCache dbObjectCache, SessionSettings mySessionToken)
        {
            var aCtype = GraphDBTypeMapper.ConvertGraph2CSharp(myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager).Name);
            IObject dbos = GetDbos(myIDChainDefinition, myDBObjectStream, dbContext, mySessionToken, dbObjectCache);

            if (dbos == null)
            {
                return null;
            }

            AOperationDefinition operand = null;

            if (myExtraordinary != null)
            {
                #region extraordinary

                if (myExtraordinary is AggregateDefinition)
                {
                    System.Diagnostics.Debug.Assert(false);

                    //var aggrNode = ((AggregateDefinition)myExtraordinary).ChainPartAggregateDefinition;

                    //aggrNode.Validate(dbContext);

                    ////result of aggregate
                    //var pResult = aggrNode.Aggregate.Aggregate(dbos, myIDChainDefinition.LastAttribute, dbContext);
                    //if (pResult.Failed())
                    //    return new Exceptional<AOperationDefinition>(pResult);

                    //aCtype = aggrNode.Aggregate.TypeOfResult;
                    //operand = new ValueDefinition(aggrNode.Aggregate.TypeOfResult, pResult.Value);
                }
                else
                {
                    if (myExtraordinary is IDChainDefinition)
                    {
                        var chainFunc = (myExtraordinary as IDChainDefinition).First(id => id is ChainPartFuncDefinition) as ChainPartFuncDefinition;

                        chainFunc.Validate(dbContext);

                        var func = chainFunc.Function;
                        func.CallingAttribute = myIDChainDefinition.LastAttribute;
                        func.CallingObject = dbos;
                        //result of function

                        var pResult = chainFunc.Execute(myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager), myDBObjectStream, myIDChainDefinition.Reference.Item1, dbContext);
                        if (pResult.Failed())
                            return new Exceptional<AOperationDefinition>(pResult);

                        //aCtype = funcCallNode.Function.TypeOfResult;
                        //aCtype = ((FuncParameter)pResult.Value).TypeOfOperatorResult;
                        operand = new ValueDefinition(((FuncParameter)pResult.Value).Value);
                        aCtype = (operand as ValueDefinition).Value.Type;
                    }
                    else
                    {
                    return new Exceptional<AOperationDefinition>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                    }
                }

                #endregion
            }
            else
            {
                #region simple

                if (aCtype == BasicType.SetOfDBObjects)
                {
                    operand = new TupleDefinition(aCtype, dbos, myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager));
                }
                else
                {
                    if (dbos is AListOfBaseEdgeType)
                    {
                        operand = new TupleDefinition(aCtype, dbos, myIDChainDefinition.LastAttribute.GetDBType(dbContext.DBTypeManager));
                    }
                    else if (dbos is ADBBaseObject)
                    {
                        operand = new ValueDefinition(dbos as ADBBaseObject);
                    }
                    else
                    {
                        operand = new ValueDefinition(aCtype, dbos);
                    }
                }

                #endregion
            }
            return new Exceptional<AOperationDefinition>(operand);
        }
Ejemplo n.º 25
0
 public abstract IEnumerable<Exceptional<DBObjectStream>> GetAllEdgeDestinations(DBObjectCache dbObjectCache);
Ejemplo n.º 26
0
 private void IntegrateInGraph(DBObjectStream myDBObjectStream, IExpressionGraph myExpressionGraph, LevelKey myLevelKey, DBContext myTypeManager, DBObjectCache myQueryCache)
 {
     if (this.Type == TypesOfOperators.AffectsLowerLevels)
     {
         myExpressionGraph.AddNode(myDBObjectStream, myLevelKey, 1);
     }
     else
     {
         myExpressionGraph.AddNode(myDBObjectStream, myLevelKey, 0);
     }
 }
Ejemplo n.º 27
0
        private Exceptional<object> IntegrateUUID(DataContainer data, DBContext dbContext, DBObjectCache dbObjectCache, TypesOfBinaryExpression typeOfBinExpr, IExpressionGraph resultGraph, SessionSettings mySessionToken, LevelKey myLevelKey, IEnumerable<Exceptional<DBObjectStream>> myDBObjects)
        {
            foreach (var aDBO in myDBObjects)
            {
                if (aDBO.Failed())
                {
                    return new Exceptional<object>(aDBO);
                }

                if (IsValidDBObjectStreamForBinExpr(aDBO.Value, data.IDChainDefinitions.Item1.LastAttribute, dbContext.DBTypeManager))
                {
                    //check and integrate
                    var result = CheckAndIntegrateDBObjectStream(data, dbContext, dbObjectCache, typeOfBinExpr, resultGraph, aDBO.Value, myLevelKey, mySessionToken);
                    if(!result.Success())
                    {
                        return new Exceptional<object>(result);
                    }
                }
            }

            return new Exceptional<object>();
        }
Ejemplo n.º 28
0
        private Exceptional<Boolean> MatchComplexData(TypesOfAssociativity associativity, DataContainer data, DBContext dbContext, DBObjectCache dbObjectCache, TypesOfBinaryExpression typeOfBinExpr, IEnumerable<Tuple<GraphDBType, AAttributeIndex>> leftIndices, IEnumerable<Tuple<GraphDBType, AAttributeIndex>> rightIndices, ref List<GraphDBError> errors, ref IExpressionGraph result, SessionSettings mySessionToken)
        {
            #region data

            Dictionary<DBObjectStream, AOperationDefinition> operandsLeft = null;
            Dictionary<DBObjectStream, AOperationDefinition> operandsRight = null;

            #endregion

            #region handle extraordinaries

            if (data.Extraordinaries.Item1 != null)
            {
                #region left extraordinary
                //there is something like a function or so

                operandsLeft = new Dictionary<DBObjectStream, AOperationDefinition>();

                //we have to calculate the real operand.
                //TODO: try to use attribute idx instead of uuid idx

                foreach (var aLeftIDX in leftIndices)
                {
                    AAttributeIndex currentLeftIdx = null;

                    #region get UUID idx
                    if (!(aLeftIDX.Item2.IsUUIDIndex))
                    {
                        currentLeftIdx = aLeftIDX.Item1.GetUUIDIndex(dbContext);
                    }
                    else
                    {
                        currentLeftIdx = aLeftIDX.Item2;
                    }

                    #endregion

                    var currentIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(currentLeftIdx.IndexRelatedTypeUUID);

                    foreach (var aObjectUUIDs_Left in currentLeftIdx.GetAllValues(currentIndexRelatedType, dbContext))
                    {
                        foreach (var aObjectUUID_Left in aObjectUUIDs_Left)
                        {
                            var leftDBObject = dbObjectCache.LoadDBObjectStream(aLeftIDX.Item1, aObjectUUID_Left);
                            if (leftDBObject.Failed())
                            {
                                throw new NotImplementedException();
                            }

                            if (IsValidDBObjectStreamForBinExpr(leftDBObject.Value, data.IDChainDefinitions.Item1.LastAttribute, dbContext.DBTypeManager))
                            {
                                var oper = GetOperand(data.IDChainDefinitions.Item1, data.Extraordinaries.Item1, dbContext, leftDBObject.Value, dbObjectCache, mySessionToken);
                                if (oper.Failed())
                                    return new Exceptional<bool>(oper);

                                if (oper != null)
                                {
                                    operandsLeft.Add(leftDBObject.Value, oper.Value);
                                }
                            }
                        }
                    }
                }

                //from now on the binary expression is right complex, because there are atom values on the left
                typeOfBinExpr = TypesOfBinaryExpression.RightComplex;

                #endregion
            }

            if (data.Extraordinaries.Item2 != null)
            {
                #region right extraordinary
                //there is something like a function or so
                operandsRight = new Dictionary<DBObjectStream, AOperationDefinition>();

                foreach (var aRightIDX in rightIndices)
                {
                    AAttributeIndex currentRightIdx = null;

                    #region get UUID idx
                    //we have to calculate the real operand.
                    //TODO: try to use attribute idx instead of uuid idx

                    if (!(aRightIDX.Item2.IsUUIDIndex))
                    {
                        currentRightIdx = aRightIDX.Item1.GetUUIDIndex(dbContext);
                    }
                    else
                    {
                        currentRightIdx = aRightIDX.Item2;
                    }

                    #endregion

                    var currentIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(currentRightIdx.IndexRelatedTypeUUID);

                    foreach (var aObjectUUIDs_Right in currentRightIdx.GetAllValues(currentIndexRelatedType, dbContext))
                    {
                        foreach (var aObjectUUID_Right in aObjectUUIDs_Right)
                        {
                            var rightDBObject = dbObjectCache.LoadDBObjectStream(aRightIDX.Item1, aObjectUUID_Right);
                            if (rightDBObject.Failed())
                            {
                                throw new NotImplementedException();
                            }

                            if (IsValidDBObjectStreamForBinExpr(rightDBObject.Value, data.IDChainDefinitions.Item2.LastAttribute, dbContext.DBTypeManager))
                            {
                                var oper = GetOperand(data.IDChainDefinitions.Item2, data.Extraordinaries.Item2, dbContext, rightDBObject.Value, dbObjectCache, mySessionToken);
                                if (oper.Failed())
                                    return new Exceptional<bool>(oper);

                                if (oper != null)
                                {
                                    operandsRight.Add(rightDBObject.Value, oper.Value);
                                }
                            }
                        }
                    }
                }

                if (typeOfBinExpr == TypesOfBinaryExpression.RightComplex)
                {
                    typeOfBinExpr = TypesOfBinaryExpression.Atom;
                }

                #endregion
            }

            #endregion

            switch (typeOfBinExpr)
            {
                case TypesOfBinaryExpression.Atom:

                    #region atom

                    switch (associativity)
                    {
                        case TypesOfAssociativity.Unknown:
                        case TypesOfAssociativity.Neutral:
                            GetComplexAtom(dbContext, operandsLeft, operandsRight, data.IDChainDefinitions.Item1, dbObjectCache, ref result);
                            GetComplexAtom(dbContext, operandsRight, operandsLeft, data.IDChainDefinitions.Item2, dbObjectCache, ref result);
                            break;

                        case TypesOfAssociativity.Left:

                            GetComplexAtom(dbContext, operandsLeft, operandsRight, data.IDChainDefinitions.Item1, dbObjectCache, ref result);

                            break;
                        case TypesOfAssociativity.Right:

                            GetComplexAtom(dbContext, operandsRight, operandsLeft, data.IDChainDefinitions.Item2, dbObjectCache, ref result);

                            break;

                        default:
                            return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                    }

                    #endregion

                    break;
                case TypesOfBinaryExpression.LeftComplex:

                    #region Left complex

                    GetComplexMatch(leftIndices, operandsRight, dbObjectCache, data.IDChainDefinitions.Item1, data.IDChainDefinitions.Item2, dbContext, associativity, ref result, mySessionToken);

                    #endregion

                    break;
                case TypesOfBinaryExpression.RightComplex:

                    #region Right complex

                    GetComplexMatch(rightIndices, operandsLeft, dbObjectCache, data.IDChainDefinitions.Item2, data.IDChainDefinitions.Item1, dbContext, associativity, ref result, mySessionToken);

                    #endregion

                    break;
                case TypesOfBinaryExpression.Complex:

                    #region Complex

                    LevelKey leftLevelKey = CreateLevelKey(data.IDChainDefinitions.Item1, dbContext.DBTypeManager);
                    LevelKey rightLevelKey = CreateLevelKey(data.IDChainDefinitions.Item2, dbContext.DBTypeManager);
                    GraphDBType leftGraphDBType = data.IDChainDefinitions.Item1.LastType;
                    GraphDBType rightGraphDBType = data.IDChainDefinitions.Item2.LastType;

                    #region exception

                    if (leftIndices.CountIsGreater(1) || rightIndices.CountIsGreater(1))
                    {
                        return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                    }

                    #endregion

                    var leftIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(leftIndices.First().Item2.IndexRelatedTypeUUID);
                    var rightIndexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(rightIndices.First().Item2.IndexRelatedTypeUUID);

                    foreach (var ObjectUUIDs_left in leftIndices.First().Item2.GetAllValues(leftIndexRelatedType, dbContext))
                    {
                        foreach (var aLeftUUID in ObjectUUIDs_left)
                        {
                            var leftDBObject = dbObjectCache.LoadDBObjectStream(leftIndices.First().Item1, aLeftUUID);
                            if (leftDBObject.Failed())
                            {
                                return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                            }

                            if (IsValidDBObjectStreamForBinExpr(leftDBObject.Value, data.IDChainDefinitions.Item1.LastAttribute, dbContext.DBTypeManager))
                            {

                                foreach (var ObjectUUIDs_right in rightIndices.First().Item2.GetAllValues(rightIndexRelatedType, dbContext))
                                {
                                    foreach (var aRightUUID in ObjectUUIDs_right)
                                    {

                                        var rightDBObject = dbObjectCache.LoadDBObjectStream(rightIndices.First().Item1, aRightUUID);
                                        if (rightDBObject.Failed())
                                        {
                                            return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                                        }

                                        if (IsValidDBObjectStreamForBinExpr(rightDBObject.Value, data.IDChainDefinitions.Item2.LastAttribute, dbContext.DBTypeManager))
                                        {
                                            //everything is valid

                                            var leftType = GraphDBTypeMapper.ConvertGraph2CSharp(data.IDChainDefinitions.Item1.LastAttribute.GetDBType(dbContext.DBTypeManager).Name);
                                            var rightType = GraphDBTypeMapper.ConvertGraph2CSharp(data.IDChainDefinitions.Item2.LastAttribute.GetDBType(dbContext.DBTypeManager).Name);

                                            AOperationDefinition leftValue;
                                            AOperationDefinition rightValue;

                                            if (data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.SetOfReferences
                                                || data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.ListOfNoneReferences || data.IDChainDefinitions.Item1.LastAttribute.KindOfType == KindsOfType.SetOfNoneReferences)
                                                leftValue = new TupleDefinition(leftType, leftDBObject.Value.GetAttribute(data.IDChainDefinitions.Item1.LastAttribute.UUID), data.IDChainDefinitions.Item1.LastAttribute.GetDBType(dbContext.DBTypeManager));
                                            else
                                                leftValue = new ValueDefinition(leftType, leftDBObject.Value.GetAttribute(data.IDChainDefinitions.Item1.LastAttribute.UUID, data.IDChainDefinitions.Item1.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext));

                                            if (data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.SetOfReferences
                                                || data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.ListOfNoneReferences || data.IDChainDefinitions.Item2.LastAttribute.KindOfType == KindsOfType.SetOfNoneReferences)
                                                rightValue = new TupleDefinition(rightType, rightDBObject.Value.GetAttribute(data.IDChainDefinitions.Item2.LastAttribute.UUID), data.IDChainDefinitions.Item2.LastAttribute.GetDBType(dbContext.DBTypeManager));
                                            else
                                                rightValue = new ValueDefinition(rightType, rightDBObject.Value.GetAttribute(data.IDChainDefinitions.Item2.LastAttribute.UUID, data.IDChainDefinitions.Item2.LastAttribute.GetRelatedType(dbContext.DBTypeManager), dbContext));

                                            var tempSimpleOperationResult = this.SimpleOperation(leftValue, rightValue, typeOfBinExpr);
                                            if (tempSimpleOperationResult.Failed())
                                                return new Exceptional<bool>(tempSimpleOperationResult);

                                            var tempOperatorResult = tempSimpleOperationResult.Value;

                                            if ((Boolean)(tempOperatorResult as ValueDefinition).Value.Value)
                                            {
                                                //found sth that is really true

                                                #region insert into graph

                                                switch (associativity)
                                                {
                                                    case TypesOfAssociativity.Neutral:
                                                    case TypesOfAssociativity.Left:

                                                        IntegrateInGraph(leftDBObject.Value, result, leftLevelKey, dbContext, dbObjectCache);

                                                        break;
                                                    case TypesOfAssociativity.Right:

                                                        IntegrateInGraph(rightDBObject.Value, result, rightLevelKey, dbContext, dbObjectCache);

                                                        break;
                                                    case TypesOfAssociativity.Unknown:

                                                        if (Type == TypesOfOperators.AffectsLowerLevels)
                                                        {
                                                            result.AddNodesWithComplexRelation(leftDBObject, leftLevelKey, rightDBObject, rightLevelKey, dbObjectCache, 1);
                                                        }
                                                        else
                                                        {
                                                            result.AddNodesWithComplexRelation(leftDBObject, leftLevelKey, rightDBObject, rightLevelKey, dbObjectCache, 0);
                                                        }

                                                        break;
                                                    default:

                                                        return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                                                }

                                                #endregion
                                            }
                                        }
                                    }
                                }

                                #region clean lower levels

                                if (Type == TypesOfOperators.AffectsLowerLevels)
                                {
                                    switch (associativity)
                                    {
                                        case TypesOfAssociativity.Neutral:
                                        case TypesOfAssociativity.Left:

                                            CleanLowerLevel(leftLevelKey, dbContext, dbObjectCache, result);

                                            break;
                                        case TypesOfAssociativity.Right:

                                            CleanLowerLevel(rightLevelKey, dbContext, dbObjectCache, result);

                                            break;
                                        case TypesOfAssociativity.Unknown:

                                            CleanLowerLevel(leftLevelKey, dbContext, dbObjectCache, result);
                                            CleanLowerLevel(rightLevelKey, dbContext, dbObjectCache, result);

                                            break;
                                        default:

                                            return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                                    }
                                }

                                #endregion
                            }
                        }
                    }

                    #endregion

                    break;
                default:

                    return new Exceptional<bool>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
            }

            return new Exceptional<bool>(true);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Removes a DBObject.
        /// </summary>
        /// <param name="myGraphType">The Type of the DBObject that is to be removed.</param>
        /// <param name="myDBObject">The UUID of the DBObject.</param>
        public Exceptional RemoveDBObject(GraphDBType myTypeOfDBObject, DBObjectStream myDBObject, DBObjectCache myDBObjectCache, SessionSettings myToken)
        {
            #region Input exceptions

            if (myTypeOfDBObject == null)
            {
                return new Exceptional(new Error_ArgumentNullOrEmpty("myTypeOfDBObject"));
            }
            if (myDBObject == null)
            {
                return new Exceptional(new Error_ArgumentNullOrEmpty("myUUID"));
            }

            #endregion

            #region Data

            ObjectLocation myDBObjectLocation;

            #endregion

            // Get DBObject path
            myDBObjectLocation = myDBObject.ObjectLocation;

            #region remove from attributeIDX

            foreach (var anIndex in myTypeOfDBObject.GetAllAttributeIndices(false))
            {
                anIndex.Remove(myDBObject, myTypeOfDBObject, _DBContext);
            }

            #endregion

            #region remove from fs

            #region Remove DBOBJECTSTREAM

            var _RemoveObjectExceptional = _IGraphFSSession.RemoveObjectIfExists(myDBObjectLocation, DBConstants.DBOBJECTSTREAM);
            if (_RemoveObjectExceptional.Failed())
            {
                return _RemoveObjectExceptional;
            }

            #endregion

            #region Remove DBBACKWARDEDGESTREAM

            _RemoveObjectExceptional = _IGraphFSSession.RemoveObjectIfExists(myDBObjectLocation, DBConstants.DBBACKWARDEDGESTREAM);
            if (_RemoveObjectExceptional.Failed())
            {
                return _RemoveObjectExceptional;
            }

            #endregion

            #region Remove UNDEFATTRIBUTESSTREAM

            _RemoveObjectExceptional = _IGraphFSSession.RemoveObjectIfExists(myDBObjectLocation, DBConstants.UNDEFATTRIBUTESSTREAM);
            if (_RemoveObjectExceptional.Failed())
            {
                return _RemoveObjectExceptional;
            }

            #endregion

            #endregion

            return Exceptional.OK;
        }
Ejemplo n.º 30
0
 public override Tuple<Exceptional<DBObjectStream>, ADBBaseObject> GetEdgeDestinationWeighted(DBObjectCache dbObjectCache)
 {
     return new Tuple<Exceptional<DBObjectStream>, ADBBaseObject>(_Reference.GetDBObjectStream(dbObjectCache), _Count);
 }