コード例 #1
0
ファイル: AlterType_DropIndices.cs プロジェクト: Vadi/sones
        /// <summary>
        /// Execute the removal of attribute indices
        /// <seealso cref=" AAlterTypeCommand"/>
        /// </summary>        
        public override Exceptional Execute(DBContext myDBContext, GraphDBType myGraphDBType)
        {
            var retExceptional = new Exceptional();

            foreach (var index in _IdxDropList)
            {
                var dropIdxExcept = myGraphDBType.RemoveIndex(index.Key, index.Value, myDBContext);

                if (!dropIdxExcept.Success())
                {
                    retExceptional.PushIExceptional(dropIdxExcept);
                }
            }

            return retExceptional;
        }
コード例 #2
0
        /// <summary>
        /// Executes the removal of certain myAttributes.
        /// <seealso cref=" AAlterTypeCommand"/>
        /// </summary>
        public override Exceptional Execute(DBContext myDBContext, GraphDBType myGraphDBType)
        {
            Exceptional result = new Exceptional();

            foreach (String aAttributeName in _ListOfAttributes)
            {
                var attr = myGraphDBType.GetTypeAttributeByName(aAttributeName);

                if (attr != null)
                {
                    var idxs = new List<Indices.AAttributeIndex>(myGraphDBType.GetAttributeIndices(myDBContext, attr.UUID));

                    foreach (var item in idxs)
                    {
                        var remIdxResult = myGraphDBType.RemoveIndex(item.IndexName, item.IndexEdition, myDBContext);

                        if (remIdxResult.Failed())
                        {
                            result.PushIExceptional(remIdxResult);
                        }
                    }
                }
                else
                {
                    result.PushIError(new Error_AttributeIsNotDefined(aAttributeName));
                    return result;
                }

                //Hack: remove myAttributes in DBObjects
                var aTempResult = myDBContext.DBTypeManager.RemoveAttributeFromType(myGraphDBType.Name, aAttributeName, myDBContext.DBTypeManager);

                if (aTempResult.Failed())
                {
                    result.PushIExceptional(aTempResult);
                    return result;
                }
            }

            return result;
        }
コード例 #3
0
        public override Exceptional Execute(DBContext dbContext, GraphDBType graphDBType)
        {
            var listOfTypeAttributes = new Dictionary<TypeAttribute, GraphDBType>();
            var retExcept = new Exceptional();
            var existingTypeAttributes = graphDBType.GetAllAttributes(dbContext);

            foreach (var attr in _ListOfAttributes)
            {
                var createExcept = attr.CreateTypeAttribute(dbContext);

                if (!createExcept.Success())
                {
                    retExcept.PushIExceptional(createExcept);
                }

                if (existingTypeAttributes.Exists(item => item.Name == createExcept.Value.Name))
                {
                    retExcept.PushIExceptional(new Exceptional(new Error_AttributeAlreadyExists(createExcept.Value.Name)));
                }

                var attrType = dbContext.DBTypeManager.GetTypeByName(attr.AttributeType.Name);

                if (attrType == null)
                {
                    retExcept.PushIExceptional(new Exceptional(new Error_TypeDoesNotExist(attr.AttributeType.Name)));
                    return retExcept;
                }

                if (attrType.IsUserDefined)
                {
                    retExcept.PushIExceptional(new Exceptional(new Error_InvalidReferenceAssignmentOfUndefAttr()));
                    return retExcept;
                }

                createExcept.Value.DBTypeUUID = attrType.UUID;
                createExcept.Value.RelatedGraphDBTypeUUID = graphDBType.UUID;

                graphDBType.AddAttribute(createExcept.Value, dbContext.DBTypeManager, true);

                var flushExcept = dbContext.DBTypeManager.FlushType(graphDBType);

                if (!flushExcept.Success())
                {
                    retExcept.PushIExceptional(flushExcept);
                }

                listOfTypeAttributes.Add(createExcept.Value, attrType);
            }

            var dbobjects = dbContext.DBObjectCache.SelectDBObjectsForLevelKey(new LevelKey(graphDBType, dbContext.DBTypeManager), dbContext);

            foreach (var item in dbobjects)
            {
                if (!item.Success())
                {
                    retExcept.PushIExceptional(item);
                }
                else
                {
                    var undefAttrExcept = item.Value.GetUndefinedAttributePayload(dbContext.DBObjectManager);

                    if (!undefAttrExcept.Success())
                    {
                        retExcept.PushIExceptional(undefAttrExcept);
                    }

                    foreach (var attr in listOfTypeAttributes)
                    {
                        IObject value;

                        if (undefAttrExcept.Value.TryGetValue(attr.Key.Name, out value))
                        {
                            var typeOfOperator = GraphDBTypeMapper.ConvertGraph2CSharp(attr.Value.Name);

                            if (GraphDBTypeMapper.IsAValidAttributeType(attr.Value, typeOfOperator, dbContext, value))
                            {
                                item.Value.AddAttribute(attr.Key.UUID, value);

                                var removeExcept = item.Value.RemoveUndefinedAttribute(attr.Key.Name, dbContext.DBObjectManager);

                                if (!removeExcept.Success())
                                {
                                    retExcept.PushIExceptional(removeExcept);
                                }

                                var flushExcept = dbContext.DBObjectManager.FlushDBObject(item.Value);

                                if (!flushExcept.Success())
                                {
                                    retExcept.PushIExceptional(flushExcept);
                                }
                            }
                            else
                            {
                                retExcept.PushIExceptional(new Exceptional(new Error_InvalidUndefAttrType(attr.Key.Name, attr.Value.Name)));
                            }
                        }
                    }
                }
            }

            return Exceptional.OK;
        }
コード例 #4
0
ファイル: DBTypeManager.cs プロジェクト: TheByte/sones
        public Exceptional<QueryResult> AlterType(DBContext dbInnerContext, GraphDBType atype, AAlterTypeCommand alterTypeCommand)
        {
            var result = alterTypeCommand.Execute(dbInnerContext, atype);

            if (!result.Success())
            {
                var retVal = new Exceptional<QueryResult>(result);
                return retVal;
            }
            else
            {
                var resultReadout = alterTypeCommand.CreateVertex(dbInnerContext, atype);

                if (resultReadout != null)
                {
                    var retVal = new Exceptional<QueryResult>(new QueryResult(resultReadout));
                    retVal.PushIExceptional(result);

                    return retVal;
                }

                return new Exceptional<QueryResult>(result);
            }
        }
コード例 #5
0
        internal Exceptional SetBackwardEdges(Dictionary<AttributeUUID, IObject> userdefinedAttributes, ObjectUUID reference)
        {
            var returnVal = new Exceptional();

            #region process attributes

            foreach (var aUserDefinedAttribute in userdefinedAttributes)
            {
                #region Data

                GraphDBType     typeOFAttribute     = null;
                TypeAttribute   attributesOfType    = null;

                #endregion

                #region get GraphType of Attribute

                //attributesOfType = _graphDBType.Attributes[aUserDefinedAttribute.Key];
                attributesOfType = _graphDBType.GetTypeAttributeByUUID(aUserDefinedAttribute.Key);

                typeOFAttribute = _dbContext.DBTypeManager.GetTypeByUUID(attributesOfType.DBTypeUUID);

                #endregion

                /* The DBO independent version */
                var beEdge = new EdgeKey(_graphDBType.UUID, attributesOfType.UUID);

                var runMT = DBConstants.RunMT;
                runMT = false;
                if (runMT)
                {

                    #region The parallel version

                    /**/
                    /* The parallel version */
                    Parallel.ForEach(((IReferenceEdge)aUserDefinedAttribute.Value).GetAllReferenceIDs(), (uuid) =>
                    {
                        var addExcept = _dbContext.DBObjectManager.AddBackwardEdge(uuid, attributesOfType.DBTypeUUID, beEdge, reference);

                        if (!addExcept.Success())
                        {
                            returnVal.PushIExceptional(addExcept);
                        }
                    });

                    if (!returnVal.Success())
                    {
                        return returnVal;
                    }
                    /**/

                    #endregion

                }
                else
                {

                    #region Single thread

                    foreach (var uuid in ((IReferenceEdge)aUserDefinedAttribute.Value).GetAllReferenceIDs())
                    {
                        var addExcept = _dbContext.DBObjectManager.AddBackwardEdge(uuid, attributesOfType.DBTypeUUID, beEdge, reference);

                        if (addExcept.Failed())
                        {
                            return new Exceptional(addExcept);
                        }
                    }

                    #endregion

                }
            }

            #endregion

            return Exceptional.OK;
        }

        private Exceptional AddMandatoryAttributes(DBContext myDBContext, GraphDBType myGraphDBType, ManipulationAttributes myManipulationAttributes)
        {
            Boolean mandatoryDefaults = (Boolean)myDBContext.DBSettingsManager.GetSettingValue((new SettingDefaultsOnMandatory()).ID, myDBContext, TypesSettingScope.TYPE, myGraphDBType).Value.Value;
            TypeAttribute typeAttr = null;
            GraphDBType typeOfAttr = null;
            var typeMandatoryAttribs = myGraphDBType.GetMandatoryAttributesUUIDs(myDBContext.DBTypeManager);

            if ((myManipulationAttributes.MandatoryAttributes.Count < typeMandatoryAttribs.Count()) && !mandatoryDefaults)
                return new Exceptional(new Error_MandatoryConstraintViolation(myGraphDBType.Name));

            foreach (var attrib in typeMandatoryAttribs)
            {
                if (!myManipulationAttributes.MandatoryAttributes.Contains(attrib))
                {
                    //if we have mandatory attributes in _graphDBType but not in the current statement and USE_DEFAULTS_ON_MANDATORY is true then do this
                    if (mandatoryDefaults)
                    {
                        typeAttr = myGraphDBType.GetTypeAttributeByUUID(attrib);

                        if (typeAttr == null)
                            return new Exceptional(new Error_AttributeIsNotDefined(myGraphDBType.Name, typeAttr.Name));

                        typeOfAttr = myDBContext.DBTypeManager.GetTypeByUUID(typeAttr.DBTypeUUID);

                        IObject defaultValue = typeAttr.DefaultValue;

                        if (defaultValue == null)
                            defaultValue = typeAttr.GetDefaultValue(myDBContext);

                        myManipulationAttributes.Attributes.Add(new TypeAndAttributeDefinition(typeAttr, typeOfAttr), defaultValue);
                    }
                    else
                    {
                        return new Exceptional(new Error_MandatoryConstraintViolation("Attribute \"" + myGraphDBType.GetTypeAttributeByUUID(attrib).Name + "\" of Type \"" + myGraphDBType.Name + "\" is mandatory."));
                    }
                }
            }

            return Exceptional.OK;
        }

        private Exceptional<Boolean> DeleteObjectReferences(ObjectUUID myObjectUUID, BackwardEdgeStream myObjectBackwardEdges)
        {
            foreach (var item in myObjectBackwardEdges)
            {
                var type = _dbContext.DBTypeManager.GetTypeByUUID(item.Key.TypeUUID);

                if (type == null)
                {
                    return new Exceptional<Boolean>(new Error_TypeDoesNotExist(""));
                }

                foreach (var objID in item.Value.GetAllEdgeDestinations(_dbContext.DBObjectCache))
                {
                    if (objID.Failed())
                    {
                        return new Exceptional<Boolean>(objID);
                    }

                    var attr = objID.Value.GetAttribute(item.Key.AttrUUID);

                    if (attr is IReferenceEdge)
                    {
                        var removeResult = ((IReferenceEdge)attr).RemoveUUID(myObjectUUID);
                        if (removeResult)
                        {
                            #region Sucessfully removed the single edge ref - so remove the attribute

                            if (attr is ASingleReferenceEdgeType)
                            {
                                objID.Value.RemoveAttribute(item.Key.AttrUUID);
                            }

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

                    var flushExcept = _dbContext.DBObjectManager.FlushDBObject(objID.Value);

                    if (!flushExcept.Success())
                        return new Exceptional<bool>(flushExcept.IErrors.First());
                }
            }

            return new Exceptional<bool>(true);
        }

        private Dictionary<TypeAndAttributeDefinition, IObject> ExtractDefinedAttributes(Dictionary<string, Tuple<TypeAttribute, IObject>> attrsForResult, DBTypeManager myTypeManager)
        {
            return attrsForResult.Where(item => !(item.Value.Item1 is UndefinedTypeAttribute)).ToDictionary(key => new TypeAndAttributeDefinition(key.Value.Item1, key.Value.Item1.GetDBType(myTypeManager)), value => value.Value.Item2);
        }

        private Dictionary<string, IObject> ExtractUndefindedAttributes(Dictionary<string, Tuple<TypeAttribute, IObject>> attrsForResult)
        {
            return attrsForResult.Where(item => (item.Value.Item1 is UndefinedTypeAttribute)).ToDictionary(key => key.Key, value => value.Value.Item2);
        }

        private AttributeUUID GetAttributesToCheckForUnique(AAttributeAssignOrUpdateOrRemove myAAttributeAssignOrUpdateOrRemove)
        {
            if (myAAttributeAssignOrUpdateOrRemove is AAttributeRemove)
                return null;

            if (myAAttributeAssignOrUpdateOrRemove.AttributeIDChain.IsUndefinedAttribute)
            {
                return null;
            }

            if (myAAttributeAssignOrUpdateOrRemove is AAttributeAssignOrUpdate)
            {
                return ((AAttributeAssignOrUpdate)myAAttributeAssignOrUpdateOrRemove).AttributeIDChain.LastAttribute.UUID;
            }

            if (myAAttributeAssignOrUpdateOrRemove is AttributeAssignOrUpdateList)
                return ((AttributeAssignOrUpdateList)myAAttributeAssignOrUpdateOrRemove).AttributeIDChain.LastAttribute.UUID;

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

        /// <summary>
        /// Create a readout based on the passed <paramref name="attributes"/>, <paramref name="undefinedAttributes"/>, <paramref name="specialTypeAttributes"/> which are all optional
        /// </summary>
        /// <param name="myDBObjectStreamExceptional"></param>
        /// <param name="attributes"></param>
        /// <param name="undefinedAttributes"></param>
        /// <param name="specialTypeAttributes"></param>
        /// <returns></returns>
        private Exceptional<Vertex> GetManipulationResultSet(Exceptional<DBObjectStream> myDBObjectStreamExceptional, Dictionary<TypeAndAttributeDefinition, IObject> attributes = null, Dictionary<String, IObject> undefinedAttributes = null, Dictionary<ASpecialTypeAttribute, Object> specialTypeAttributes = null)
        {
            Vertex _Vertex = null;

              #region Return inserted attributes

            #region attributes

            if (!attributes.IsNullOrEmpty())
            {
                _Vertex = new Vertex(attributes.ToDictionary(key => key.Key.Definition.Name, value => value.Value.GetReadoutValue()));
            }
            else
            {
                _Vertex = new Vertex();
            }

            #endregion

            #region UndefinedAttributes

            if (!undefinedAttributes.IsNullOrEmpty())
            {

                foreach (var undefAttr in undefinedAttributes)
                {
                    _Vertex.AddAttribute(undefAttr.Key, undefAttr.Value.GetReadoutValue());
                }

            }

            #endregion

            #region SpecialTypeAttributes

            if (!specialTypeAttributes.IsNullOrEmpty())
            {

                foreach (var specAttr in specialTypeAttributes)
                {
                    _Vertex.AddAttribute(specAttr.Key.Name, specAttr.Value);
                }

            }

            #endregion

            #region UUID

            if (!_Vertex.HasAttribute(SpecialTypeAttribute_UUID.AttributeName))
            {

                var extractedValue = new SpecialTypeAttribute_UUID().ExtractValue(myDBObjectStreamExceptional.Value, _graphDBType, _dbContext);

                if (extractedValue.Failed())
                {
                    return new Exceptional<Vertex>(extractedValue);
                }

                _Vertex.AddAttribute(SpecialTypeAttribute_UUID.AttributeName, extractedValue.Value.GetReadoutValue());

            }

            #endregion

            #region REVISION

            if (!_Vertex.HasAttribute(SpecialTypeAttribute_REVISION.AttributeName)) // If it was updated by SpecialTypeAttributes we do not need to add them again
            {

                var extractedValue = new SpecialTypeAttribute_REVISION().ExtractValue(myDBObjectStreamExceptional.Value, _graphDBType, _dbContext);
                if (extractedValue.Failed())
                {
                    return new Exceptional<Vertex>(extractedValue);
                }
                _Vertex.AddAttribute(SpecialTypeAttribute_REVISION.AttributeName, extractedValue.Value.GetReadoutValue());

            }

            #endregion

            #endregion

            return new Exceptional<Vertex>(_Vertex);
        }

        /// <summary>
        /// Get attribute assignments for new DBObjects.
        /// </summary>
        /// <param name="myAttributeAssigns">The interesting ParseTreeNode.</param>
        /// <param name="typeManager">The TypeManager of the GraphDB.</param>
        /// <returns>A Dictionary of AttributeAssignments</returns>
        private Exceptional<ManipulationAttributes> GetRecursiveAttributes(List<AAttributeAssignOrUpdate> myAttributeAssigns, DBContext myDBContext, GraphDBType myGraphDBType)
        {
            #region Data

            var manipulationAttributes = new ManipulationAttributes();
            var resultExcept = new Exceptional<ManipulationAttributes>();

            if (myAttributeAssigns == null)
            {
                return new Exceptional<ManipulationAttributes>(manipulationAttributes);
            }

            TypeAttribute attr;
            ADBBaseObject typedAttributeValue;
            BasicType correspondingCSharpType;
            Warning_UndefinedAttribute undefAttrWarning = null;

            var typeMandatoryAttribs = myGraphDBType.GetMandatoryAttributesUUIDs(myDBContext.DBTypeManager);

            var setExcept = myDBContext.DBSettingsManager.GetSetting(SettingUndefAttrBehaviour.UUID, myDBContext, TypesSettingScope.DB);

            if (!setExcept.Success())
            {
                return new Exceptional<ManipulationAttributes>(setExcept);
            }

            var undefAttrBehave = (SettingUndefAttrBehaviour)setExcept.Value;

            #endregion

            #region get Data

            #region proceed list

            foreach (var aAttributeAssign in myAttributeAssigns)
            {

                var validateResult = aAttributeAssign.AttributeIDChain.Validate(myDBContext, true);

                if (validateResult.Failed())
                {
                    return new Exceptional<ManipulationAttributes>(validateResult);
                }

                #region Undefined attributes - Refactor and add undefined logic into defined attribute AssignsOrUpdate

                System.Diagnostics.Debug.Assert(aAttributeAssign.AttributeIDChain != null);

                //in this case we have an undefined attribute
                if (aAttributeAssign.AttributeIDChain.IsUndefinedAttribute)
                {

                    var UndefAttrName = aAttributeAssign.AttributeIDChain.UndefinedAttribute;

                    switch (undefAttrBehave.Behaviour)
                    {
                        case UndefAttributeBehaviour.disallow:
                            return new Exceptional<ManipulationAttributes>(new Error_UndefinedAttributes());

                        case UndefAttributeBehaviour.warn:
                            resultExcept.PushIWarning(new Warning_UndefinedAttribute(aAttributeAssign.AttributeIDChain));
                            break;
                    }

                    if (aAttributeAssign is AttributeAssignOrUpdateList)
                    {

                        #region AttributeAssignCollection

                        var colDefinition = (aAttributeAssign as AttributeAssignOrUpdateList).CollectionDefinition;
                        EdgeTypeListOfBaseObjects valueList = new EdgeTypeListOfBaseObjects();

                        foreach (var tuple in colDefinition.TupleDefinition)
                        {
                            if (tuple.TypeOfValue == BasicType.Unknown)
                                valueList.Add((tuple.Value as ValueDefinition).Value);
                            else if (tuple.Value is ValueDefinition)
                                valueList.Add((tuple.Value as ValueDefinition).Value);
                            else
                                return new Exceptional<ManipulationAttributes>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
                        }

                        if (colDefinition.CollectionType == CollectionType.Set)
                            valueList.UnionWith(valueList);

                        manipulationAttributes.UndefinedAttributes.Add(UndefAttrName, valueList);
                        var undefAttr = new UndefinedAttributeDefinition() { AttributeName = UndefAttrName, AttributeValue = valueList };
                        var undefAttrAssign = new AttributeAssignOrUpdateUndefined((aAttributeAssign as AttributeAssignOrUpdateList).AttributeIDChain, undefAttr);
                        manipulationAttributes.AttributeToUpdateOrAssign.Add(undefAttrAssign);

                        #endregion
                    }
                    else if (aAttributeAssign is AttributeAssignOrUpdateValue)
                    {

                        #region AttributeAssignValue

                        var value = GraphDBTypeMapper.GetBaseObjectFromCSharpType((aAttributeAssign as AttributeAssignOrUpdateValue).Value);
                        manipulationAttributes.UndefinedAttributes.Add(UndefAttrName, value);
                        var undefAttr = new UndefinedAttributeDefinition() { AttributeName = UndefAttrName, AttributeValue = value };
                        var undefAttrAssign = new AttributeAssignOrUpdateUndefined((aAttributeAssign as AttributeAssignOrUpdateValue).AttributeIDChain, undefAttr);
                        manipulationAttributes.AttributeToUpdateOrAssign.Add(undefAttrAssign);

                        #endregion

                    }
                    else if (aAttributeAssign is AttributeAssignOrUpdateSetRef)
                    {
                        return new Exceptional<ManipulationAttributes>(new Error_InvalidReferenceAssignmentOfUndefAttr());
                    }
                    else
                    {
                        return new Exceptional<ManipulationAttributes>(new Error_InvalidUndefinedAttributeName());
                    }

                    continue;
                }

                #endregion

                attr = aAttributeAssign.AttributeIDChain.LastAttribute;

                manipulationAttributes.AttributeToUpdateOrAssign.Add(aAttributeAssign);

                #region checks

                if (aAttributeAssign.AttributeIDChain.LastType != myGraphDBType)
                {
                    return new Exceptional<ManipulationAttributes>(new Error_InvalidAttribute(aAttributeAssign.AttributeIDChain.ToString()));
                }

                if (attr.GetDBType(myDBContext.DBTypeManager).IsBackwardEdge)
                {
                    return new Exceptional<ManipulationAttributes>(new Error_Logic("Adding values to BackwardEdges Attributes are not allowed! (" + attr.Name + ") is an BackwardEdge Attribute of GraphType \"" + myGraphDBType.Name + "\"."));
                }

                #endregion

                #region SpecialTypeAttribute

                if (attr is ASpecialTypeAttribute)
                {

                    if (!(aAttributeAssign is AttributeAssignOrUpdateValue))
                    {
                        return new Exceptional<ManipulationAttributes>(new Error_InvalidAttributeValue((attr as ASpecialTypeAttribute).Name, aAttributeAssign.ToString()));
                    }

                    manipulationAttributes.SpecialTypeAttributes.Add((attr as ASpecialTypeAttribute), (aAttributeAssign as AttributeAssignOrUpdateValue).Value);

                    continue;

                }

                #endregion

                #region check & add

                if (aAttributeAssign.AttributeIDChain.Edges.Count > 1)
                {
                    //in case of those statements: INSERT INTO Flower VALUES (Colors.Name = 'red')
                    //Colors.Name is an IDNode with 2 Edges. This is not possible.

                    return new Exceptional<ManipulationAttributes>(new Error_Logic("Invalid attribute assignment : " + aAttributeAssign.AttributeIDChain.ToString() + " = " + aAttributeAssign));
                }

                if (aAttributeAssign is AttributeAssignOrUpdateList)
                {

                    #region SetOfDBObjects

                    #region Check, whether this is valid for SetOfDBObjects

                    if (attr.KindOfType != KindsOfType.SetOfReferences)
                    {
                        if (attr.KindOfType != KindsOfType.ListOfNoneReferences)
                        {
                            if (attr.KindOfType != KindsOfType.SetOfNoneReferences)
                            {
                                return new Exceptional<ManipulationAttributes>(new Error_ReferenceAssignmentExpected(attr));//"Please use SETREF keyword instead of REF/REFERENCE or LISTOF."));
                            }
                        }
                    }

                    #endregion

                    #region list stuff

                    #region process tuple

                    #region process as list

                    var collectionDefinition = ((AttributeAssignOrUpdateList)aAttributeAssign).CollectionDefinition;
                    var dbType = attr.GetDBType(myDBContext.DBTypeManager);

                    if (dbType.IsUserDefined)
                    {

                        #region List of references

                        var uuids = collectionDefinition.GetEdge(attr, dbType, myDBContext);
                        if (uuids.Failed())
                        {
                            return new Exceptional<ManipulationAttributes>(uuids);
                        }

                        manipulationAttributes.Attributes.Add(new TypeAndAttributeDefinition(attr, dbType), uuids.Value);

                        if (typeMandatoryAttribs.Contains(attr.UUID))
                        {
                            manipulationAttributes.MandatoryAttributes.Add(attr.UUID);
                        }

                        #endregion

                    }
                    else
                    {

                        #region List of ADBBaseObjects (Integer, String, etc)

                        var edge = (aAttributeAssign as AttributeAssignOrUpdateList).GetBasicList(myDBContext);
                        if (edge.Failed())
                        {
                            return new Exceptional<ManipulationAttributes>(edge);
                        }

                        // If the collection was declared as a SETOF insert
                        if (collectionDefinition.CollectionType == CollectionType.Set)
                            edge.Value.Distinction();

                        manipulationAttributes.Attributes.Add(new TypeAndAttributeDefinition(attr, attr.GetDBType(myDBContext.DBTypeManager)), edge.Value);

                        if (typeMandatoryAttribs.Contains(attr.UUID))
                        {
                            manipulationAttributes.MandatoryAttributes.Add(attr.UUID);
                        }

                        #endregion

                    }

                    #endregion

                    #endregion

                    #endregion

                    #endregion

                }
                else if (aAttributeAssign is AttributeAssignOrUpdateSetRef)
                {

                    #region reference

                    var aSetRefNode = ((AttributeAssignOrUpdateSetRef)aAttributeAssign).SetRefDefinition;

                    var singleedge = aSetRefNode.GetEdge(attr, myDBContext, attr.GetRelatedType(myDBContext.DBTypeManager));
                    if (singleedge.Failed())
                    {
                        return new Exceptional<ManipulationAttributes>(singleedge);
                    }

                    if (attr.GetRelatedType(myDBContext.DBTypeManager).IsUserDefined)
                    {
                        //a list which carries elements of userdefined types consists of GUIDS
                        manipulationAttributes.Attributes.Add(new TypeAndAttributeDefinition(attr, attr.GetDBType(myDBContext.DBTypeManager)), singleedge.Value);

                        if (typeMandatoryAttribs.Contains(attr.UUID))
                        {
                            manipulationAttributes.MandatoryAttributes.Add(attr.UUID);
                        }

                    }
                    else
                    {
                        return new Exceptional<ManipulationAttributes>(new Error_UnknownDBError("Reference types cannot be basic types."));
                    }

                    #endregion

                }
                else if (aAttributeAssign is AttributeAssignOrUpdateExpression)
                {

                    #region Expression

                    (aAttributeAssign as AttributeAssignOrUpdateExpression).BinaryExpressionDefinition.Validate(myDBContext);
                    var value = (aAttributeAssign as AttributeAssignOrUpdateExpression).BinaryExpressionDefinition.ResultValue;

                    if (value.Failed())
                    {
                        return new Exceptional<ManipulationAttributes>(value.IErrors.First());
                    }

                    if (value.Value is ValueDefinition)
                    {

                        #region AtomValue

                        if (attr.KindOfType == KindsOfType.SetOfReferences || attr.KindOfType == KindsOfType.ListOfNoneReferences || attr.KindOfType == KindsOfType.SetOfNoneReferences)
                            return new Exceptional<ManipulationAttributes>(new Error_InvalidTuple(aAttributeAssign.ToString()));

                        if (!(value.Value as ValueDefinition).IsDefined)
                        {
                            (value.Value as ValueDefinition).ChangeType(attr.GetDBType(myDBContext.DBTypeManager).UUID);
                        }
                        var val = (value.Value as ValueDefinition).Value.Value;

                        correspondingCSharpType = GraphDBTypeMapper.ConvertGraph2CSharp(attr, attr.GetDBType(myDBContext.DBTypeManager));
                        if (GraphDBTypeMapper.GetEmptyGraphObjectFromType(correspondingCSharpType).IsValidValue(val))
                        {
                            typedAttributeValue = GraphDBTypeMapper.GetGraphObjectFromType(correspondingCSharpType, val);
                            manipulationAttributes.Attributes.Add(new TypeAndAttributeDefinition(attr, attr.GetDBType(myDBContext.DBTypeManager)), typedAttributeValue);

                            if (typeMandatoryAttribs.Contains(attr.UUID))
                                manipulationAttributes.MandatoryAttributes.Add(attr.UUID);
                        }
                        else
                        {
                            return new Exceptional<ManipulationAttributes>(new Error_InvalidAttributeValue(attr.Name, (aAttributeAssign as AttributeAssignOrUpdateValue).Value));
                        }

                        #endregion

                    }
                    else // TupleValue!
                    {

                        #region TupleValue

                        if (attr.KindOfType != KindsOfType.SetOfReferences)
                            return new Exceptional<ManipulationAttributes>(new Error_InvalidTuple(aAttributeAssign.ToString()));

                        if (!(attr.EdgeType is IBaseEdge))
                            return new Exceptional<ManipulationAttributes>(new Error_InvalidEdgeType(attr.EdgeType.GetType(), typeof(IBaseEdge)));

                        correspondingCSharpType = GraphDBTypeMapper.ConvertGraph2CSharp(attr, attr.GetDBType(myDBContext.DBTypeManager));

                        if ((value.Value as TupleDefinition).TypeOfOperatorResult != correspondingCSharpType)
                            return new Exceptional<ManipulationAttributes>(new Error_DataTypeDoesNotMatch(correspondingCSharpType.ToString(), (value.Value as TupleDefinition).TypeOfOperatorResult.ToString()));

                        var edge = attr.EdgeType.GetNewInstance() as IBaseEdge;
                        edge.AddRange((value.Value as TupleDefinition).Select(te => (te.Value as ValueDefinition).Value));
                        manipulationAttributes.Attributes.Add(new TypeAndAttributeDefinition(attr, attr.GetDBType(myDBContext.DBTypeManager)), edge as IBaseEdge);

                        #endregion

                    }

                    #endregion

                }
                else if (aAttributeAssign is AttributeAssignOrUpdateValue)
                {

                    #region Simple value

                    var attrVal = aAttributeAssign as AttributeAssignOrUpdateValue;

                    if (attr.KindOfType == KindsOfType.ListOfNoneReferences)
                        return new Exceptional<ManipulationAttributes>(new Error_InvalidTuple(attrVal.ToString()));

                    if (attr.KindOfType != KindsOfType.SingleNoneReference)
                    {
                        return new Exceptional<ManipulationAttributes>(new Error_InvalidAttributeKind(attr.KindOfType, KindsOfType.SingleNoneReference));
                    }

                    correspondingCSharpType = GraphDBTypeMapper.ConvertGraph2CSharp(attr, attr.GetDBType(myDBContext.DBTypeManager));
                    if (GraphDBTypeMapper.GetEmptyGraphObjectFromType(correspondingCSharpType).IsValidValue(attrVal.Value))
                    {
                        typedAttributeValue = GraphDBTypeMapper.GetGraphObjectFromType(correspondingCSharpType, attrVal.Value);
                        manipulationAttributes.Attributes.Add(new TypeAndAttributeDefinition(attr, attr.GetDBType(myDBContext.DBTypeManager)), typedAttributeValue);

                        if (typeMandatoryAttribs.Contains(attr.UUID))
                            manipulationAttributes.MandatoryAttributes.Add(attr.UUID);
                    }
                    else
                    {
                        return new Exceptional<ManipulationAttributes>(new Error_InvalidAttributeValue(attr.Name, attrVal.Value));
                    }

                    #endregion

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

                #endregion

            }

            #endregion

            #endregion

            resultExcept.Value = manipulationAttributes;

            return resultExcept;
        }

        /// <summary>
        /// Inserts into all indices that are affected if a DBObject is updated on a certain attibute
        /// </summary>
        /// <param name="dBObjectStream"></param>
        /// <param name="attributeUUID"></param>
        /// <param name="_dbContext"></param>
        /// <returns></returns>
        private Exceptional InsertDBObjectIntoIndex(DBObjectStream dBObjectStream, AttributeUUID attributeUUID)
        {
            foreach (var aType in _dbContext.DBTypeManager.GetAllParentTypes(_dbContext.DBTypeManager.GetTypeByUUID(dBObjectStream.TypeUUID), true, false))
            {
                foreach (var aAttributeIdx in aType.GetAttributeIndices(_dbContext, attributeUUID))
                {
                    var result = aAttributeIdx.Insert(dBObjectStream, aType, _dbContext);

                    if (result.Failed())
                    {
                        return new Exceptional(result);
                    }
                }
            }

            return new Exceptional();
        }

        /// <summary>
        /// Removes index entries corresponding to a DBObject
        /// </summary>
        /// <param name="dBObjectStream"></param>
        /// <param name="attributeUUID"></param>
        /// <param name="_dbContext"></param>
        /// <returns></returns>
        private Exceptional RemoveDBObjectFromIndex(DBObjectStream dBObjectStream, AttributeUUID attributeUUID)
        {
            foreach (var aType in _dbContext.DBTypeManager.GetAllParentTypes(_dbContext.DBTypeManager.GetTypeByUUID(dBObjectStream.TypeUUID), true, false))
            {
                foreach (var aAttributeIdx in aType.GetAttributeIndices(_dbContext, attributeUUID))
                {
                    var result = aAttributeIdx.Remove(dBObjectStream, aType, _dbContext);

                    if (result.Failed())
                    {
                        return new Exceptional(result);
                    }
                }
            }

            return new Exceptional();
        }

        private Exceptional RemoveUndefAttrs(IEnumerable<Exceptional<DBObjectStream>> myDBObjStream, List<String> myUndefAttrs)
        {
            #region delete undefined attributes

            foreach (var objects in myDBObjStream)
            {
                var undefAttrsStream = myUndefAttrs.Where(item => objects.Value.GetUndefinedAttributePayload(_dbContext.DBObjectManager).Value.ContainsKey(item));

                foreach (var undefAttr in undefAttrsStream)
                {
                    var removeExcept = _dbContext.DBObjectManager.RemoveUndefinedAttribute(undefAttr, objects.Value);

                    if (removeExcept.Failed())
                        return new Exceptional(removeExcept);
                }
            }

            #endregion

            return Exceptional.OK;
        }

        /// <summary>
        /// setting the default value for the attribute
        /// </summary>
        /// <param name="myAttr">the attribute</param>
        /// <param name="myDBObjectCache">the object cache</param>
        /// <returns>true if the value was changed</returns>
        private Exceptional<Boolean> SetDefaultValue(TypeAttribute myAttr, Exceptional<DBObjectStream> myDBO)
        {
            if (myDBO.Success())
            {
                IObject defaultValue = myAttr.DefaultValue;

                if (defaultValue == null)
                    defaultValue = myAttr.GetDefaultValue(_dbContext);

                var alterExcept = myDBO.Value.AlterAttribute(myAttr.UUID, defaultValue);

                if (alterExcept.Failed())
                    return new Exceptional<Boolean>(alterExcept);

                if (!alterExcept.Value)
                {
                    return new Exceptional<bool>(false);
                }
            }
            else
            {
                return new Exceptional<bool>(false);
            }

            return new Exceptional<bool>(true);
        }

        /// <summary>
        /// This is the update method which will change some <paramref name="myDBObjects"/> on behalf of the <paramref name="myListOfUpdates"/>
        /// </summary>
        /// <param name="myDBObjects">Some dbobjects</param>
        /// <param name="myListOfUpdates">The list of update tasks (assign, delete, etc)</param>
        /// <param name="dbObjectCache"></param>
        /// <returns></returns>
        private QueryResult Update(IEnumerable<Exceptional<DBObjectStream>> myDBObjects, IEnumerable<AAttributeAssignOrUpdateOrRemove> myListOfUpdates)
        {
            #region Data

            var queryResultContent = new List<Vertex>();
            var queryResult = new QueryResult();

            #endregion

            #region check for undefined attributes setting

            var undefAttrSetting = _dbContext.DBSettingsManager.GetSetting(SettingUndefAttrBehaviour.UUID, _dbContext, TypesSettingScope.DB);

            if (!undefAttrSetting.Success())
            {
                return new QueryResult(undefAttrSetting);
            }

            var undefSettingVal = ((SettingUndefAttrBehaviour)undefAttrSetting.Value).Behaviour;

            #endregion

            #region Validate attributes

            var definedAttributeAssignments = new Dictionary<AttributeUUID, AAttributeAssignOrUpdate>();

            foreach (var updateOrAssign in myListOfUpdates)
            {
                System.Diagnostics.Debug.Assert(updateOrAssign != null);
                if (!(updateOrAssign is AttributeRemove))
                {
                    var result = updateOrAssign.AttributeIDChain.Validate(_dbContext, true);

                    if (result.Failed())
                    {
                        return new QueryResult(result);
                    }

                    if (updateOrAssign.IsUndefinedAttributeAssign)
                    {
                        #region handle undefined attributes
                        switch (undefSettingVal)
                        {
                            case UndefAttributeBehaviour.disallow:
                                return new QueryResult(new Error_UndefinedAttributes());
                            case UndefAttributeBehaviour.warn:
                                queryResult.PushIWarning(new Warning_UndefinedAttribute(updateOrAssign.AttributeIDChain));
                                break;
                        }
                        #endregion
                    }
                    else
                    {
                        //here a dictionary is used, because myListOfUpdates will be traversed many times now (maybe CachedEnumerator can be used instead)
                        if (updateOrAssign is AAttributeAssignOrUpdate)
                            definedAttributeAssignments[GetAttributesToCheckForUnique(updateOrAssign)] = updateOrAssign as AAttributeAssignOrUpdate;
                    }
                }
            }

            #endregion

            #region check unique constraint

            if (definedAttributeAssignments.CountIsGreater(0))
            {

                Exceptional<Boolean> CheckConstraint = null;

                IEnumerable<GraphDBType> parentTypes = _dbContext.DBTypeManager.GetAllParentTypes(_graphDBType, true, false);

                foreach (var entry in myDBObjects)
                {
                    //here all attributes are listed, that will change their value
                    var changingAttributes = (from CurrentAttribute in entry.Value.GetAttributes()
                                              join Update in definedAttributeAssignments on CurrentAttribute.Key equals Update.Key
                                              where !CurrentAttribute.Value.Equals(Update.Value.GetValueForAttribute(entry.Value, _dbContext, _graphDBType).Value)
                                              select new {Key = CurrentAttribute.Key, Value = CurrentAttribute.Value}).ToDictionary(x=>x.Key, x=>x.Value);

                    CheckConstraint = _dbContext.DBIndexManager.CheckUniqueConstraint(_graphDBType, parentTypes, changingAttributes);

                    if (CheckConstraint.Failed())
                        return new QueryResult(CheckConstraint.IErrors);

                }
            }

            #endregion

            #region regular update

            foreach (var aDBO in myDBObjects)
            {
                //key: attribute name
                //value: TypeAttribute, NewValue
                Dictionary<String, Tuple<TypeAttribute, IObject>> attrsForResult = new Dictionary<String, Tuple<TypeAttribute, IObject>>();

                if (aDBO.Failed())
                {
                    return new QueryResult(aDBO);
                }

                #region data

                Boolean sthChanged = false;

                #endregion

                #region iterate tasks

                //Exceptional<Boolean> partialResult;

                foreach (var attributeUpdateOrAssign in myListOfUpdates)
                {

                    var updateResult = attributeUpdateOrAssign.Update(_dbContext, aDBO.Value, _graphDBType);
                    if (updateResult.Failed())
                    {
                        return new QueryResult(updateResult);
                    }

                    if (updateResult.Value.Count > 0)
                    {
                        sthChanged = true;
                        attrsForResult.AddRange(updateResult.Value);
                    }

                }

                #endregion

                if (sthChanged)
                {
                    var definedAttributes = ExtractDefinedAttributes(attrsForResult, _dbContext.DBTypeManager);

                    #region update Idx

                    foreach (var _AttributeIndex in _graphDBType.GetAllAttributeIndices(_dbContext))
                    {
                        if(definedAttributes.Exists(item => _AttributeIndex.IndexKeyDefinition.IndexKeyAttributeUUIDs.Contains(item.Key.Definition.UUID)))
                        {
                            //execute update
                            _AttributeIndex.Update(aDBO.Value, _graphDBType, _dbContext);
                        }
                    }

                    #endregion

                    #region update dbobjects on fs

                    var flushResult = _dbContext.DBObjectManager.FlushDBObject(aDBO.Value);
                    if (!flushResult.Success())
                    {
                        return new QueryResult(flushResult);
                    }

                    #endregion

                    var resultSet = GetManipulationResultSet(aDBO, undefinedAttributes: ExtractUndefindedAttributes(attrsForResult), attributes: definedAttributes);
                    if (!resultSet.Success())
                    {
                        /*
                          what should happen now
                          this should not break the update
                        */
                    }

                    queryResultContent.Add(resultSet.Value);
                }
            }
コード例 #6
0
        internal Exceptional SetBackwardEdges(GraphDBType aType, Dictionary<AttributeUUID, IObject> userdefinedAttributes, ObjectUUID reference, DBContext dbContext)
        {
            var returnVal = new Exceptional();

            #region process attributes

            foreach (var aUserDefinedAttribute in userdefinedAttributes)
            {
                #region Data

                GraphDBType     typeOFAttribute     = null;
                TypeAttribute   attributesOfType    = null;

                #endregion

                #region get GraphType of Attribute

                //attributesOfType = aType.Attributes[aUserDefinedAttribute.Key];
                attributesOfType = aType.GetTypeAttributeByUUID(aUserDefinedAttribute.Key);

                typeOFAttribute = dbContext.DBTypeManager.GetTypeByUUID(attributesOfType.DBTypeUUID);

                #endregion

                /* The DBO independent version */
                var beEdge = new EdgeKey(aType.UUID, attributesOfType.UUID);

                var runMT = DBConstants.RunMT;
                runMT = false;
                if (runMT)
                {

                    #region The parallel version

                    /**/
                    /* The parallel version */
                    Parallel.ForEach(((IReferenceEdge)aUserDefinedAttribute.Value).GetAllReferenceIDs(), (uuid) =>
                    {
                        var addExcept = dbContext.DBObjectManager.AddBackwardEdge(uuid, attributesOfType.DBTypeUUID, beEdge, reference);

                        if (!addExcept.Success())
                        {
                            returnVal.PushIExceptional(addExcept);
                        }
                    });

                    if (!returnVal.Success())
                    {
                        return returnVal;
                    }
                    /**/

                    #endregion

                }
                else
                {

                    #region Single thread

                    foreach (var uuid in ((IReferenceEdge)aUserDefinedAttribute.Value).GetAllReferenceIDs())
                    {
                        var addExcept = dbContext.DBObjectManager.AddBackwardEdge(uuid, attributesOfType.DBTypeUUID, beEdge, reference);

                        if (addExcept.Failed())
                        {
                            return new Exceptional(addExcept);
                        }
                    }

                    #endregion

                }
            }

            #endregion

            return Exceptional.OK;
        }
コード例 #7
0
ファイル: AlterType_AddIndices.cs プロジェクト: Vadi/sones
        /// <summary>
        /// Add indices to a vertex
        /// <seealso cref=" AAlterTypeCommand"/>
        /// </summary>        
        public override Exceptional Execute(DBContext myDBContext, GraphDBType myGraphDBType)
        {
            var retExceptional = new Exceptional();

            foreach (var idxDef in _IdxDefinitionList)
            {

                var checkIdx = CheckIndexTypeReference(idxDef.IndexAttributeDefinitions, myGraphDBType);

                if (!checkIdx.Success())
                {
                    retExceptional.PushIExceptional(checkIdx);
                }
                else
                {
                    var result = myDBContext.DBIndexManager.CreateIndex(myDBContext, myGraphDBType.Name, idxDef.IndexName, idxDef.Edition, idxDef.IndexType, idxDef.IndexAttributeDefinitions);

                    if (!result.Success())
                    {
                        retExceptional.PushIExceptional(result);
                    }
                }

            }

            return retExceptional;
        }
コード例 #8
0
        public override Exceptional Execute(DBContext dbContext, GraphDBType graphDBType)
        {
            var listOfTypeAttrs = new List<TypeAttribute>();
            var retExcept = new Exceptional();

            foreach (var attr in _ListOfAttributes)
            {

                var typeAttr = graphDBType.GetTypeAttributeByName(attr);

                if (typeAttr == null)
                {
                    return new Exceptional(new Error_AttributeIsNotDefined(attr));
                }

                var attrType = dbContext.DBTypeManager.GetTypeByUUID(typeAttr.DBTypeUUID);

                if (attrType == null)
                    return new Exceptional(new Error_TypeDoesNotExist(""));

                if (attrType.IsUserDefined)
                    return new Exceptional(new Error_InvalidReferenceAssignmentOfUndefAttr());

                listOfTypeAttrs.Add(typeAttr);

            }

            var dbobjects = dbContext.DBObjectCache.SelectDBObjectsForLevelKey(new LevelKey(graphDBType, dbContext.DBTypeManager), dbContext);

            foreach (var item in dbobjects)
            {

                if (!item.Success())
                {
                    retExcept.PushIExceptional(item);
                }

                else
                {
                    foreach (var attr in listOfTypeAttrs)
                    {
                        if (item.Value.HasAttribute(attr.UUID, graphDBType))
                        {
                            var attrVal = item.Value.GetAttribute(attr.UUID);

                            var addExcept = item.Value.AddUndefinedAttribute(attr.Name, attrVal, dbContext.DBObjectManager);

                            if (!addExcept.Success())
                                retExcept.PushIExceptional(addExcept);

                            item.Value.RemoveAttribute(attr.UUID);

                            var saveExcept = dbContext.DBObjectManager.FlushDBObject(item.Value);

                            if (!saveExcept.Success())
                                retExcept.PushIExceptional(saveExcept);
                        }
                    }
                }
            }

            var indices = graphDBType.GetAllAttributeIndices();
            List<AAttributeIndex> idxToDelete = new List<AAttributeIndex>();

            //remove attributes from type
            foreach (var attr in listOfTypeAttrs)
            {

                foreach (var item in indices)
                {
                    var index = item.IndexKeyDefinition.IndexKeyAttributeUUIDs.Find(idx => idx == attr.UUID);

                    if (index != null && item.IndexKeyDefinition.IndexKeyAttributeUUIDs.Count == 1)
                    {
                        idxToDelete.Add(item);
                    }
                }

                //remove indices
                foreach (var idx in idxToDelete)
                {
                    var remExcept = graphDBType.RemoveIndex(idx.IndexName, idx.IndexEdition, dbContext.DBTypeManager);

                    if (!remExcept.Success())
                    {
                        retExcept.PushIExceptional(remExcept);
                    }
                }

                idxToDelete.Clear();
                graphDBType.RemoveAttribute(attr.UUID);

                var flushExcept = dbContext.DBTypeManager.FlushType(graphDBType);

                if (!flushExcept.Success())
                {
                    retExcept.PushIExceptional(flushExcept);
                }
            }

            return retExcept;
        }
コード例 #9
0
ファイル: GraphQueryLanguage.cs プロジェクト: ipbi/sones
        /// <summary>
        /// Create the GraphDML of all DBObjects in the database.
        /// </summary>
        /// <param name="myDumpFormat"></param>
        /// <param name="dbContext"></param>
        /// <param name="objectManager"></param>
        /// <returns></returns>
        public Exceptional<List<String>> ExportGraphDML(DumpFormats myDumpFormat, DBContext dbContext, IEnumerable<GraphDBType> myTypesToDump)
        {
            //var _StringBuilder  = new StringBuilder();
            var queries           = new List<String>();
            var exceptional       = new Exceptional<List<String>>();

            #region Go through each type

            foreach (var graphDBType in myTypesToDump)
            {

                var UUIDIdx = graphDBType.GetUUIDIndex(dbContext.DBTypeManager);

                #region Take UUID index

                foreach (var aDBO in dbContext.DBObjectCache.LoadListOfDBObjectStreams(graphDBType, UUIDIdx.GetAllUUIDs(graphDBType, dbContext)))
                {

                    if (!aDBO.Success())
                    {
                        exceptional.PushIExceptional(aDBO);
                    }
                    else
                    {

                        var gdmlExceptional = CreateGraphDMLforDBObject(myDumpFormat, dbContext, graphDBType, aDBO.Value);

                        if (!gdmlExceptional.Success())
                        {
                            exceptional.PushIExceptional(aDBO);
                        }
                        else
                        {
                            queries.Add(gdmlExceptional.Value);
                        }

                    }
                }

                #endregion

            }

            #endregion

            //_Exceptional.Value = _StringBuilder.ToString();
            exceptional.Value = queries;

            return exceptional;
        }
コード例 #10
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;
        }
コード例 #11
0
ファイル: IndexKeyDefinition.cs プロジェクト: Vadi/sones
 public static Exceptional<IndexKeyDefinition> CreateFromIDChainDefinitions(IEnumerable<IDChainDefinition> myIDChainDefinitions)
 {
     var indexKeyDefinition = new IndexKeyDefinition();
     var retVal = new Exceptional<IndexKeyDefinition>(indexKeyDefinition);
     foreach (var idChainDefinition in myIDChainDefinitions)
     {
         retVal.PushIExceptional(indexKeyDefinition.AddIDChainDefinition(idChainDefinition));
     }
     return retVal;
 }
コード例 #12
0
ファイル: IndexKeyDefinition.cs プロジェクト: Vadi/sones
 public static Exceptional<IndexKeyDefinition> CreateFromIDChainDefinition(IDChainDefinition myIDChainDefinition)
 {
     var indexKeyDefinition = new IndexKeyDefinition();
     var retVal = new Exceptional<IndexKeyDefinition>(indexKeyDefinition);
     retVal.PushIExceptional(indexKeyDefinition.AddIDChainDefinition(myIDChainDefinition));
     return retVal;
 }
コード例 #13
0
ファイル: DBTypeManager.cs プロジェクト: Vadi/sones
        /// <summary>
        /// This method adds a bunch of new GraphTypeDefinitions (comes from a CREATE TYPE(S) statement) to the TypeManager.
        /// If a certain PType can't be added (because of some inheritance or 
        /// attribute errors), this method tries to add it in a second 
        /// step.
        /// </summary>
        /// <param name="TypeList">List of GraphType definitions that should 
        /// be added to the TypeManager</param>
        /// <returns>List of GraphError</returns>
        public Exceptional<QueryResult> AddBulkTypes(List<GraphDBTypeDefinition> TypeList, DBContext currentContext)
        {
            #region Input Exceptions

            if (TypeList == null)
            {
                return new Exceptional<QueryResult>(new QueryResult());
            }

            if (TypeList.Count.Equals(0))
            {
                return new Exceptional<QueryResult>(new QueryResult());
            }

            #endregion

            #region Data

            var errors = new List<GraphDBError>();
            List<GraphDBType> addedTypes = new List<GraphDBType>();
            List<AttributeUUID> uniqueAttrIDs = new List<AttributeUUID>();
            QueryResult result = new QueryResult();

            #endregion

            try
            {

                #region Create the types without attributes

                foreach (GraphDBTypeDefinition aTypeDef in TypeList)
                {

                    #region Input validation

                    if (String.IsNullOrEmpty(aTypeDef.Name))
                        return new Exceptional<QueryResult>(new Error_ArgumentNullOrEmpty("myTypeName"));

                    if (String.IsNullOrEmpty(aTypeDef.ParentType))
                        return new Exceptional<QueryResult>(new Error_ArgumentNullOrEmpty("myParentType"));

                    if (aTypeDef.Attributes == null)
                        return new Exceptional<QueryResult>(new Error_ArgumentNullOrEmpty("myAttributes"));

                    #endregion

                    GraphDBType thisType = GetTypeByName(aTypeDef.Name);

                    #region Check if the name of the type is already used

                    if (thisType != null)
                    {
                        return new Exceptional<QueryResult>(new Error_TypeAlreadyExist(aTypeDef.Name));
                    }

                    #endregion

                    GraphDBType parentType = GetTypeByName(aTypeDef.ParentType);
                    Dictionary<AttributeUUID, TypeAttribute> attributes = new Dictionary<AttributeUUID, TypeAttribute>();

                    #region Add type

                    TypeUUID parentUUID = (parentType == null) ? null : parentType.UUID;

                    #region hack

                    GraphDBType _NewGraphType = new GraphDBType(null, new ObjectLocation(_DatabaseRootPath), aTypeDef.Name, parentUUID, attributes, true, aTypeDef.IsAbstract, aTypeDef.Comment);

                    #endregion

                    addedTypes.Add(_NewGraphType);

                    _UserDefinedTypes.Add(_NewGraphType.UUID, _NewGraphType);
                    _TypesNameLookUpTable.Add(_NewGraphType.Name, _NewGraphType);

                    #endregion

                }

                #endregion

                var backwardEdgesToBeAddedAfterwards = new Dictionary<GraphDBType, List<BackwardEdgeDefinition>>();

                #region Validate the previously added types and add the attributes and backwardEdges

                foreach (var aTypeDef in TypeList)
                {
                    GraphDBType aType = addedTypes.Where(item => item.Name == aTypeDef.Name).FirstOrDefault();

                    #region Check and set parent

                    GraphDBType parentType;

                    #region Verify base type existence

                    if (aType.ParentTypeUUID == null)
                    {
                        parentType = addedTypes.Where(item => item.Name == aTypeDef.ParentType).FirstOrDefault();

                        if (parentType == null)
                        {
                            RemoveRecentlyAddedTypes(addedTypes);
                            return new Exceptional<QueryResult>(new Error_ParentTypeDoesNotExist(aTypeDef.ParentType, aTypeDef.Name));
                        }
                        aType.SetParentTypeUUID(parentType.UUID);
                    }
                    else
                    {
                        parentType = aType.GetParentType(this);
                    }

                    #endregion

                    #region Verify that the type inherit DBReference

                    var parentTypeExcept = HasParentType(parentType.UUID, DBReference.UUID);

                    if (parentTypeExcept.Failed())
                    {
                        return new Exceptional<QueryResult>(parentTypeExcept);
                    }

                    if (!parentTypeExcept.Value)
                    {
                        RemoveRecentlyAddedTypes(addedTypes);
                        return new Exceptional<QueryResult>(new Error_InvalidBaseType(parentType.Name));
                    }

                    #endregion

                    #endregion

                    //add TypeAttributeLookuptable to current type
                    aType.AttributeLookupTable.AddRange(parentType.AttributeLookupTable);

                    #region check and set type of attributes

                    UInt16 attributeCounter = 0;

                    foreach (var attributeDef in aTypeDef.Attributes)
                    {
                        var attribute = attributeDef.Key.CreateTypeAttribute(currentContext, addedTypes, attributeCounter);

                        if (attribute.Failed())
                        {
                            return new Exceptional<QueryResult>(attribute);
                        }

                        if (attribute.Value.Name == aType.Name)
                        {
                            RemoveRecentlyAddedTypes(addedTypes);
                            return new Exceptional<QueryResult>(new Error_InvalidAttributeName("The attribute " + attribute.Value.Name + " can not be added, because it has the same name as its related type."));
                        }

                        GraphDBType attrType = GetTypeByName(attributeDef.Value);

                        if (attrType == null)
                        {
                            attrType = addedTypes.Where(item => item.Name == attributeDef.Value).FirstOrDefault();

                            if (attrType == null)
                            {
                                RemoveRecentlyAddedTypes(addedTypes);
                                return new Exceptional<QueryResult>(new Error_TypeDoesNotExist(attributeDef.Value));
                            }
                        }

                        attributeCounter++;

                        TypeAttribute newAttr = attribute.Value;

                        newAttr.DBTypeUUID = attrType.UUID;
                        newAttr.RelatedGraphDBTypeUUID = aType.UUID;

                        #region we had not defined a special EdgeType - for single reference attributes we need to set the EdgeTypeSingle NOW!

                        if (newAttr.KindOfType == KindsOfType.SingleReference && attrType.IsUserDefined && newAttr.EdgeType == null)
                            newAttr.EdgeType = new EdgeTypeSingleReference(null, newAttr.DBTypeUUID);

                        #endregion

                        #region Validate EdgeType in terms of List & Single

                        if (newAttr.KindOfType == KindsOfType.SingleReference && attrType.IsUserDefined && !(newAttr.EdgeType is ASingleReferenceEdgeType))
                        {
                            RemoveRecentlyAddedTypes(addedTypes);
                            return new Exceptional<QueryResult>(new Error_InvalidEdgeType(newAttr.EdgeType.GetType(), typeof(ASingleReferenceEdgeType)));
                        }
                        else if (newAttr.KindOfType == KindsOfType.SetOfReferences || newAttr.KindOfType == KindsOfType.SetOfNoneReferences)
                        {
                            if (attrType.IsUserDefined && !(newAttr.EdgeType is ASetOfReferencesEdgeType))
                            {
                                RemoveRecentlyAddedTypes(addedTypes);
                                return new Exceptional<QueryResult>(new Error_InvalidEdgeType(newAttr.EdgeType.GetType(), typeof(ASetOfReferencesEdgeType)));
                            }
                            else if (!attrType.IsUserDefined && !(newAttr.EdgeType is ASetOfBaseEdgeType))
                            {
                                RemoveRecentlyAddedTypes(addedTypes);
                                return new Exceptional<QueryResult>(new Error_InvalidEdgeType(newAttr.EdgeType.GetType(), typeof(AListOfBaseEdgeType)));
                            }
                        }

                        #endregion

                        aType.AddAttribute(newAttr, this, true);
                    }

                    #endregion

                    #region Set BackwardEdges

                    if (!aTypeDef.BackwardEdgeNodes.IsNullOrEmpty())
                    {
                        backwardEdgesToBeAddedAfterwards.Add(aType, aTypeDef.BackwardEdgeNodes);
                    }

                    #endregion
                }

                #endregion

                #region Add the BackwardEdges

                foreach (var beDefinition in backwardEdgesToBeAddedAfterwards)
                {
                    var aType = beDefinition.Key;
                    UInt16 beAttrCounter = 0;
                    foreach (var be in beDefinition.Value)
                    {

                        var bedgeAttribute = CreateBackwardEdgeAttribute(be, aType, beAttrCounter);

                        if (!bedgeAttribute.Success())
                        {
                            RemoveRecentlyAddedTypes(addedTypes);
                            return new Exceptional<QueryResult>(bedgeAttribute);
                        }

                        aType.AddAttribute(bedgeAttribute.Value, this, true);

                        beAttrCounter++;
                    }
                }

                #endregion

                #region Validate Attribute dependencies

                var _Vertices = new List<Vertex>();

                foreach (var _GraphDBType in addedTypes)
                {
                    foreach (var _GraphDBType2 in GetAllParentTypes(_GraphDBType, false, true))
                    {

                        var _MandatoryAttributes = _GraphDBType2.GetMandatoryAttributesUUIDs(this);
                        var _UniqueAttributes    = _GraphDBType2.GetAllUniqueAttributes(false, this);

                        foreach (var _TypeAttribute in _GraphDBType.Attributes.Values)
                        {

                            if (_GraphDBType2.GetTypeAttributeByName(_TypeAttribute.Name) != null)
                            {
                                // Todo: Use notification here
                                RemoveRecentlyAddedTypes(addedTypes);
                                return new Exceptional<QueryResult>(new Error_AttributeExistsInSupertype(_TypeAttribute.Name, _GraphDBType.Name));
                            }

                            #region unique and mandatory attributes

                            if (_TypeAttribute.TypeCharacteristics.IsUnique && !_UniqueAttributes.Contains(_TypeAttribute.UUID))
                            {
                                //if the attrbute has been marked unique and it is not contained in uniques of super types
                                if (!uniqueAttrIDs.Contains(_TypeAttribute.UUID))
                                {
                                    uniqueAttrIDs.Add(_TypeAttribute.UUID);
                                }
                            }

                            if (_TypeAttribute.TypeCharacteristics.IsMandatory && !_MandatoryAttributes.Contains(_TypeAttribute.UUID))
                            {
                                _GraphDBType.AddMandatoryAttribute(_TypeAttribute.UUID, this);
                            }

                            #endregion

                        }
                    }

                    //Add the unique attribute ids for the current type
                    var AddUniqueAttrExcept = _GraphDBType.AddUniqueAttributes(uniqueAttrIDs, currentContext);

                    if(AddUniqueAttrExcept.Failed())
                        return new Exceptional<QueryResult>(AddUniqueAttrExcept);

                    uniqueAttrIDs.Clear();
                }

                #endregion

                #region Create all default directories

                foreach (GraphDBType aType in addedTypes)
                {
                    //verzeichnisse für andere typen bei create Types wird nicht angelegt

                    var createDefaultDirectoriesResult = AddType_CreateDefaultDirectories(aType);
                    if (createDefaultDirectoriesResult.Failed())
                    {
                        RemoveRecentlyAddedTypes(addedTypes);
                        return new Exceptional<QueryResult>(createDefaultDirectoriesResult);
                    }
                }

                #endregion

                #region Create directories and indices

                foreach (GraphDBType aType in addedTypes)
                {

                    #region Create indices

                    #region Create userdefined Indices

                    var aTypeDef = TypeList.Where(item => item.Name == aType.Name).FirstOrDefault();

                    if (!aTypeDef.Indices.IsNullOrEmpty())
                    {

                        foreach (var index in aTypeDef.Indices)
                        {
                            Exceptional indexErrors = new Exceptional();
                            if (!index.IndexAttributeDefinitions.All(node => !indexErrors.PushIExceptional(node.IndexAttribute.Validate(currentContext, false, aType)).Failed()))
                            {
                                RemoveRecentlyAddedTypes(addedTypes);
                                return new Exceptional<QueryResult>(indexErrors);
                            }

                            var idxName = index.IndexName;

                            if (String.IsNullOrEmpty(index.IndexName))
                            {
                                idxName = index.IndexAttributeDefinitions.Aggregate(new StringBuilder(DBConstants.IndexKeyPrefix), (stringB, elem) => { stringB.Append(String.Concat(DBConstants.IndexKeySeperator, elem.IndexAttribute.LastAttribute.Name)); return stringB; }).ToString();
                            }

                            //List<AttributeUUID> indexAttrs = new List<AttributeUUID>(index.IndexAttributeDefinitions.Select(node => node.IndexAttribute.LastAttribute.UUID));
                            var indexAttrs = index.IndexAttributeDefinitions.Select(node => node.IndexAttribute);

                            foreach (var item in GetAllSubtypes(aType))
                            {
                                var IndexKeyDefinitionExcept = IndexKeyDefinition.CreateFromIDChainDefinitions(indexAttrs);
                                if (IndexKeyDefinitionExcept.Failed())
                                {
                                    RemoveRecentlyAddedTypes(addedTypes);
                                    return IndexKeyDefinitionExcept.Convert<QueryResult>();
                                }

                                var CreateIdxExcept = item.CreateAttributeIndex(currentContext, idxName, IndexKeyDefinitionExcept.Value, index.Edition, index.IndexType);

                                if (!CreateIdxExcept.Success())
                                {
                                    RemoveRecentlyAddedTypes(addedTypes);
                                    return new Exceptional<QueryResult>(CreateIdxExcept);
                                }
                            }
                        }
                    }

                    #endregion

                    //UUID index

                    var createIndexExcept = aType.CreateUUIDIndex(_DBContext, GetUUIDTypeAttribute().UUID, _IGraphFSSession.NumberOfSpecialDirectories);

                    if (!createIndexExcept.Success())
                    {
                        RemoveRecentlyAddedTypes(addedTypes);
                        return new Exceptional<QueryResult>(createIndexExcept);
                    }

                    List<AttributeUUID> UniqueIDs = aType.GetAllUniqueAttributes(true, this);

                    if (UniqueIDs.Count() > 0)
                    {
                        var idxName = _DBContext.DBIndexManager.GetUniqueIndexName(UniqueIDs, aType); // UniqueIDs.Aggregate<AttributeUUID, String>("Idx", (result, item) => result = result + "_" + aType.GetTypeAttributeByUUID(item).Name);
                        var createIdxExcept = aType.CreateUniqueAttributeIndex(currentContext, idxName, UniqueIDs, DBConstants.UNIQUEATTRIBUTESINDEX);

                        if (!createIdxExcept.Success())
                        {
                            RemoveRecentlyAddedTypes(addedTypes);
                            return new Exceptional<QueryResult>(createIdxExcept);
                        }
                    }

                    #endregion

                }

                #endregion

                #region flush to fs

                foreach (var item in addedTypes)
                {
                    var createException = CreateTypeOnFS(item);

                    if (!createException.Success())
                        return new Exceptional<QueryResult>(createException);

                    #region get system attributes from type

                    var readOut = GetVertexForType(item);

                    if (!readOut.Success())
                        return new Exceptional<QueryResult>(readOut.IErrors.First());

                    _Vertices.Add(readOut.Value);

                    #endregion
                }

                result.Vertices = _Vertices;

                #endregion

            }
            catch (GraphDBException ee)
            {
                RemoveRecentlyAddedTypes(addedTypes);

                var _Exceptional = new Exceptional<QueryResult>();
                foreach (var _ex in ee.GraphDBErrors)
                    _Exceptional.PushIError(_ex);

                return _Exceptional;

            }
            catch (GraphDBWarningException ee)
            {
                RemoveRecentlyAddedTypes(addedTypes);
                return new Exceptional<QueryResult>(ee.GraphDBWarning);
            }
            catch (Exception e)
            //finally
            {
                //if (!succeeded)
                //{
                addedTypes.ForEach(item =>
                {
                    _UserDefinedTypes.Remove(item.UUID);
                    _TypesNameLookUpTable.Remove(item.Name);
                });
                //}

                return new Exceptional<QueryResult>(new Error_UnknownDBError(e));

            }

            return new Exceptional<QueryResult>(result);
        }