Exemplo n.º 1
0
        public UUIDIndex(string indexName, IndexKeyDefinition idxKey, GraphDBType correspondingType, string indexType = null, string indexEdition = DBConstants.DEFAULTINDEX)
        {
            IndexName          = indexName;
            IndexEdition       = indexEdition;
            IndexKeyDefinition = idxKey;
            IndexRelatedTypeUUID = correspondingType.UUID;

            if (indexEdition == null)
            {
                IndexEdition = DBConstants.DEFAULTINDEX;
            }
            else
            {
                IndexEdition = indexEdition;
            }

            if (String.IsNullOrEmpty(indexType))
            {
                IndexType = "UUIDIndex";
            }
            else
            {
                IndexType = indexType;
            }

            #region Workaround for current IndexOperation of InOperator - just follow the IsListOfBaseObjectsIndex property

            IsListOfBaseObjectsIndex = false;

            #endregion

            FileSystemLocation = (correspondingType.ObjectLocation + "Indices") + (IndexName + "#" + IndexEdition);
        }
Exemplo n.º 2
0
        public AttributeIndex(string indexName, IndexKeyDefinition idxKey, GraphDBType correspondingType, UInt16 myAttributeIdxShards, string indexType = null, string indexEdition = DBConstants.DEFAULTINDEX, UInt64 myKeyCount = 0, UInt64 myValueCount = 0)
        {
            IndexName          = indexName;
            IndexEdition       = indexEdition;
            IndexKeyDefinition = idxKey;
            IndexRelatedTypeUUID = correspondingType.UUID;
            AttributeIdxShards = myAttributeIdxShards;

            _keyCount = myKeyCount;
            _valueCount = myValueCount;

            if (indexEdition == null)
            {
                IndexEdition = DBConstants.DEFAULTINDEX;
            }
            else
            {
                IndexEdition = indexEdition;
            }

            if (String.IsNullOrEmpty(indexType))
            {
                IndexType = VersionedHashIndexObject.Name;
            }
            else
            {
                IndexType = indexType;
            }

            #region Workaround for current IndexOperation of InOperator - just follow the IsListOfBaseObjectsIndex property

            // better approach, use a special index key for a set of base objects
            if (idxKey.IndexKeyAttributeUUIDs.Any(a =>
            {
                var typeAttr = correspondingType.GetTypeAttributeByUUID(a);
                if (typeAttr != null && (typeAttr.EdgeType is IBaseEdge))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }))
            {
                IsListOfBaseObjectsIndex = true;
            }
            else
            {
                IsListOfBaseObjectsIndex = false;
            }

            #endregion

            FileSystemLocation = (correspondingType.ObjectLocation + "Indices") + (IndexName + "#" + IndexEdition);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds a single ADBBaseObject to the IndexKex
 /// </summary>
 /// <param name="myAttributeUUID">AttributeUUID corresponding to the ADBBaseObject</param>
 /// <param name="myIndexKeyPayload">The ADBBaseObject that is going to be added</param>
 /// <param name="myIndexDefinition">The corresponding IndexKeyDefinition</param>
 public IndexKey(AttributeUUID myAttributeUUID, ADBBaseObject myIndexKeyPayload, IndexKeyDefinition myIndexDefinition)
 {
     if (!myIndexDefinition.IndexKeyAttributeUUIDs.Contains(myAttributeUUID))
     {
         throw new GraphDBException(new Error_IndexKeyCreationError(myAttributeUUID, myIndexKeyPayload, myIndexDefinition));
     }
     else
     {
         AddAAKey(myAttributeUUID, myIndexKeyPayload);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Recommended way of creating a new IndexKey object.
 /// </summary>
 /// <param name="myIndexKeyValues">All ADBBaseObjects in relation with their AttributeUUID</param>
 /// <param name="myIndexDefinition">The corresponding IndexKeyDefinition</param>
 public IndexKey(Dictionary<AttributeUUID, ADBBaseObject> myIndexKeyValues, IndexKeyDefinition myIndexDefinition)
 {
     foreach (var aDefElement in myIndexDefinition.IndexKeyAttributeUUIDs)
     {
         if (!myIndexKeyValues.ContainsKey(aDefElement))
         {
             throw new GraphDBException(new Error_IndexKeyCreationError(aDefElement, null, myIndexDefinition));
         }
         else
         {
             AddAAKey(aDefElement, myIndexKeyValues[aDefElement]);
         }
     }
 }
        public Error_IndexAlreadyExistWithSameEditionAndAttribute(DBContext myDBContext, String myExistingIndexName , IndexKeyDefinition myIndexKeyDefinition, String myIndexEdition)
        {
            IndexEdition = myIndexEdition;
            IndexKeyDefinition = myIndexKeyDefinition;
            ExistingIndexName = myExistingIndexName;

            try
            {
                if (myDBContext != null)
                {
                    _IndexAttributes = IndexKeyDefinition.IndexKeyAttributeUUIDs.ToAggregatedString(a => a.ToString());
                }
                else
                {
                    _IndexAttributes = IndexKeyDefinition.IndexKeyAttributeUUIDs.ToAggregatedString(a => a.ToString());
                }
            }
            catch { }
        }
Exemplo n.º 6
0
        public UUIDIndex(string indexName, IndexKeyDefinition idxKey, GraphDBType correspondingType, UInt16 myAttributeIdxShards, string indexType = null, string indexEdition = DBConstants.DEFAULTINDEX, UInt64 myKeyCount = 0)
        {
            IndexName          = indexName;
            IndexEdition       = indexEdition;
            IndexKeyDefinition = idxKey;
            IndexRelatedTypeUUID = correspondingType.UUID;
            AttributeIdxShards = myAttributeIdxShards;

            _numberOfObjects = myKeyCount;
            //valueCount is irrellevant, because valueCount = keyCount

            if (indexEdition == null)
            {
                IndexEdition = DBConstants.DEFAULTINDEX;
            }
            else
            {
                IndexEdition = indexEdition;
            }

            if (String.IsNullOrEmpty(indexType))
            {
                IndexType = "UUIDIndex";
            }
            else
            {
                IndexType = indexType;
            }

            #region Workaround for current IndexOperation of InOperator - just follow the IsListOfBaseObjectsIndex property

            IsListOfBaseObjectsIndex = false;

            #endregion

            FileSystemLocation = (correspondingType.ObjectLocation + "Indices") + (IndexName + "#" + IndexEdition);
        }
Exemplo n.º 7
0
        public IEnumerable<AAttributeIndex> GetAttributeIndices(DBContext myDBContext, IndexKeyDefinition myIndexKeyDefinition)
        {
            if (_AttributeIndices.ContainsKey(myIndexKeyDefinition))
            {
                foreach (var aIdx in _AttributeIndices[myIndexKeyDefinition])
                {
                    yield return aIdx.Value;
                }

            }
            if (_AttributeIndexLocations.IsNotNullOrEmpty())
            {
                if (_AttributeIndexLocations.ContainsKey(myIndexKeyDefinition))
                {
                    foreach (var aIdxEdition in _AttributeIndexLocations[myIndexKeyDefinition])
                    {
                        yield return LoadAttributeIndexFromLocation(myDBContext, myIndexKeyDefinition, aIdxEdition.Key).Value;
                    }
                }
            }
            yield break;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns the index of the given attribute
        /// </summary>
        /// <param name="myAttributeName">The name of the attribute we want an index for.</param>
        /// <param name="myIndexEdition">The name of the index edition. May be null</param>
        /// <returns>The index for the given myAttributes if one exist. Else, null.</returns>
        public AAttributeIndex GetAttributeIndex(List<AttributeUUID> myAttributeNames, String myIndexEdition)
        {
            IndexKeyDefinition idxKey = new IndexKeyDefinition(myAttributeNames);
            if (_AttributeIndices.ContainsKey(idxKey) && _AttributeIndices[idxKey].ContainsKey(myIndexEdition))
                return _AttributeIndices[idxKey][myIndexEdition];

            throw new GraphDBException(new Error_IndexDoesNotExist(myAttributeNames.ToAggregatedString(mySeperator: ", "), myIndexEdition));
        }
Exemplo n.º 9
0
 public abstract Exceptional Initialize(DBContext myDBContext, string indexName, IndexKeyDefinition idxKey, GraphDBType correspondingType, string indexEdition = DBConstants.DEFAULTINDEX);
Exemplo n.º 10
0
        /// <summary>
        /// Returns the index of the given attribute
        /// </summary>
        /// <param name="myAttributeUUID">The name of the attribute we want an index for.</param>
        /// <param name="myIndexEdition">THe name of the index edition. May be null</param>
        /// <returns>The index for the given myAttributes if one exist. Else, null.</returns>
        public Exceptional<AAttributeIndex> GetAttributeIndex(DBContext myDBContext, IndexKeyDefinition idxKey, String myIndexEdition)
        {
            lock (_AttributeIndices)
            {

                if (_AttributeIndices.ContainsKey(idxKey))
                {

                    if (myIndexEdition == null)
                    {
                        if (_AttributeIndices[idxKey].ContainsKey(DBConstants.DEFAULTINDEX))
                            return new Exceptional<AAttributeIndex>(_AttributeIndices[idxKey][DBConstants.DEFAULTINDEX]);
                        else
                            return new Exceptional<AAttributeIndex>(_AttributeIndices[idxKey].First().Value);
                    }

                    else if (_AttributeIndices[idxKey].ContainsKey(myIndexEdition))
                    {
                        return new Exceptional<AAttributeIndex>(_AttributeIndices[idxKey][myIndexEdition]);
                    }

                }
                else
                {
                    if (_AttributeIndexLocations.IsNotNullOrEmpty())
                    {
                        if (_AttributeIndexLocations.ContainsKey(idxKey))
                        {
                            if (myIndexEdition == null)
                            {
                                if (_AttributeIndexLocations[idxKey].ContainsKey(DBConstants.DEFAULTINDEX))
                                {
                                    return LoadAttributeIndexFromLocation(myDBContext, idxKey, DBConstants.DEFAULTINDEX);
                                }
                                else
                                {
                                    return new Exceptional<AAttributeIndex>(new Error_IndexDoesNotExist(idxKey.ToString(), DBConstants.DEFAULTINDEX));
                                }
                            }

                            else if (_AttributeIndexLocations[idxKey].ContainsKey(myIndexEdition))
                            {
                                return LoadAttributeIndexFromLocation(myDBContext, idxKey, myIndexEdition);
                            }

                        }
                    }
                }

            }

            return new Exceptional<AAttributeIndex>(new Error_IndexAttributeDoesNotExist(idxKey.ToString()));
        }
Exemplo n.º 11
0
        public override void Deserialize(ref SerializationReader mySerializationReader)
        {
            UInt32 _Capacity;

            if (mySerializationReader != null)
            {
                try
                {
                    _UUID = new TypeUUID(this.ObjectUUID.GetByteArray());
                    ParentTypeUUID = new TypeUUID();
                    ParentTypeUUID.Deserialize(ref mySerializationReader);
                    _IsUserDefined = mySerializationReader.ReadBoolean();
                    _IsAbstract = mySerializationReader.ReadBoolean();
                    _Comment = mySerializationReader.ReadString();

                    _Capacity = mySerializationReader.ReadUInt32();

                    _Attributes = new Dictionary<AttributeUUID, TypeAttribute>();

                    _TypeAttributeLookupTable = new Dictionary<AttributeUUID, TypeAttribute>();

                    for (UInt32 i = 0; i < _Capacity; i++)
                    {
                        var _AttrAtrib = new AttributeUUID();
                        _AttrAtrib.Deserialize(ref mySerializationReader);
                        var _TypeObj = new TypeAttribute();
                        _TypeObj.Deserialize(ref mySerializationReader);
                        _Attributes.Add(_AttrAtrib, _TypeObj);
                        _TypeAttributeLookupTable.Add(_AttrAtrib, _TypeObj);
                    }

                    _Capacity = mySerializationReader.ReadUInt32();
                    _TypeSettings = new Dictionary<String, ADBSettingsBase>();

                    for (var i = 0; i < _Capacity; i++)
                    {
                        ADBSettingsBase _ADBSettingsBase = (ADBSettingsBase) mySerializationReader.ReadObject();
                        if(_ADBSettingsBase != null)
                            _TypeSettings.Add(_ADBSettingsBase.Name, _ADBSettingsBase);
                    }

                    _Capacity = mySerializationReader.ReadUInt32();
                    _UniqueAttributes = new List<AttributeUUID>();
                    AttributeUUID AttribID = null;

                    for (UInt32 i = 0; i < _Capacity; i++)
                    {
                        AttribID = new AttributeUUID(ref mySerializationReader);
                        _UniqueAttributes.Add(AttribID);
                    }

                    _Capacity = mySerializationReader.ReadUInt32();
                    _MandatoryAttributes = new HashSet<AttributeUUID>();

                    for (UInt32 i = 0; i < _Capacity; i++)
                    {
                        AttribID = new AttributeUUID(ref mySerializationReader);
                        _MandatoryAttributes.Add(AttribID);
                    }

                    ObjectDirectoryShards = mySerializationReader.ReadUInt16();

                    #region Indices

                    _AttributeIndices = new Dictionary<IndexKeyDefinition, Dictionary<String, AAttributeIndex>>();
                    _AttributeIndicesNameLookup = new Dictionary<String, IndexKeyDefinition>();

                    var idxCount = mySerializationReader.ReadUInt32();
                    for (var i = 0; i < idxCount; i++)
                    {

                        var idxKey = new IndexKeyDefinition();
                        idxKey.Deserialize(ref mySerializationReader);

                        //_AttributeIndices.Add(idxKey, new Dictionary<String, AttributeIndex>());

                        var idxVersionCount = mySerializationReader.ReadUInt32();

                        for (var j = 0; j < idxVersionCount; j++)
                        {

                            var key                 = mySerializationReader.ReadString();
                            var fileSystemLocation  = new ObjectLocation(mySerializationReader.ReadString());
                            var indexEdition        = mySerializationReader.ReadString();
                            var indexName           = mySerializationReader.ReadString();
                            var indexType           = mySerializationReader.ReadString();
                            var isUUIDIdx           = mySerializationReader.ReadBoolean();
                            var keyCount            = mySerializationReader.ReadUInt64();
                            var valueCount          = mySerializationReader.ReadUInt64();
                            var attributeIdxShards = mySerializationReader.ReadUInt16();

                            //var CreateIdxExcept = CreateAttributeIndex(indexName, idxKey.IndexKeyAttributeUUIDs, indexEdition, indexObjectType, fileSystemLocation);

                            if (isUUIDIdx)
                            {
                                AddAttributeIndex(new UUIDIndex(indexName, idxKey, this, attributeIdxShards, indexType, indexEdition, keyCount));
                            }
                            else
                            {
                                AddAttributeIndex(new AttributeIndex(indexName, idxKey, this, attributeIdxShards, indexType, indexEdition, keyCount, valueCount));
                            }

                            //if (CreateIdxExcept.Failed())
                            //    throw new GraphDBException(CreateIdxExcept.Errors);
                        }

                    }

                    #endregion

                }

                catch (Exception e)
                {
                    throw new SerializationException("The GraphDBType could not be deserialized!\n\n" + e);
                }

            }
        }
Exemplo n.º 12
0
        private IndexKey GenerateIndexKeyForUniqueConstraint(Dictionary<AttributeUUID, IObject> toBeCheckedForUniqueConstraint, IndexKeyDefinition myIndexKeyDefinition, GraphDBType myType)
        {
            var payload = new Dictionary<AttributeUUID, ADBBaseObject>();
            TypeAttribute currentAttribute;

            foreach (var aUnique in myIndexKeyDefinition.IndexKeyAttributeUUIDs)
            {
                currentAttribute = myType.GetTypeAttributeByUUID(aUnique);

                if (!currentAttribute.GetDBType(_DBContext.DBTypeManager).IsUserDefined)
                {
                    #region base attribute

                    if (toBeCheckedForUniqueConstraint.ContainsKey(aUnique))
                    {
                        switch (currentAttribute.KindOfType)
                        {
                            #region List/Set

                            case KindsOfType.ListOfNoneReferences:
                            case KindsOfType.SetOfNoneReferences:

                                throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), "Unique idx on list of base attributes is not implemented."));

                            #endregion

                            #region single/special

                            case KindsOfType.SpecialAttribute:
                            case KindsOfType.SingleNoneReference:
                            case KindsOfType.SingleReference:

                                payload.Add(aUnique, (ADBBaseObject)toBeCheckedForUniqueConstraint[aUnique]);

                                break;

                            #endregion

                            #region not implemented

                            case KindsOfType.SetOfReferences:
                            default:

                                throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), "Currently its not implemented to insert anything else than a List/Set/Single of base types"));

                            #endregion
                        }
                    }
                    else
                    {
                        //create default adbbaseobject

                        var defaultADBBAseObject = GraphDBTypeMapper.GetADBBaseObjectFromUUID(currentAttribute.DBTypeUUID);
                        defaultADBBAseObject.SetValue(DBObjectInitializeType.Default);

                        payload.Add(aUnique, defaultADBBAseObject);
                    }

                    #endregion
                }
                else
                {
                    #region reference attribute

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

                    #endregion
                }
            }

            return new IndexKey(payload, myIndexKeyDefinition);
        }
Exemplo n.º 13
0
        private Exceptional<AAttributeIndex> LoadAttributeIndexFromLocation(DBContext myDBContext, IndexKeyDefinition indexKeyDefinition, string indexEdition)
        {
            var idx = _AttributeIndexLocations[indexKeyDefinition][indexEdition];
            _AttributeIndexLocations[indexKeyDefinition].Remove(indexEdition);
            if (_AttributeIndexLocations[indexKeyDefinition].Count == 0)
            {
                _AttributeIndexLocations.Remove(indexKeyDefinition);
            }
            var loadResult = myDBContext.IGraphFSSession.GetFSObject<AAttributeIndex>(idx.Item2,
                        DBConstants.DBINDEXSTREAM,
                        () => myDBContext.DBPluginManager.GetIndex(idx.Item1).Value, indexEdition);

            if (!_AttributeIndices.ContainsKey(indexKeyDefinition))
            {
                _AttributeIndices.Add(indexKeyDefinition, new Dictionary<string, AAttributeIndex>());
            }
            _AttributeIndices[indexKeyDefinition][indexEdition] = loadResult.Value;

            _AttributeIndicesNameLookup.Add(loadResult.Value.IndexName, loadResult.Value.IndexKeyDefinition);

            return loadResult;
        }
Exemplo n.º 14
0
        public Exceptional<Boolean> RebuildIndices(IEnumerable<GraphDBType> myUserDefinedTypes)
        {
            #region Remove old attribute indices

            foreach (var _UserDefinedType in myUserDefinedTypes)
            {
                foreach (var _AttributeIndex in _UserDefinedType.GetAllAttributeIndices(_DBContext, includeUUIDIndices: false))
                {
                    // Clears the index and removes it from the file system!
                    _AttributeIndex.Clear(_DBContext, _UserDefinedType);
                }
            }

            #endregion

            foreach (var _UserDefinedType in myUserDefinedTypes)
            {

                var _DBObjectsLocation = new ObjectLocation(_UserDefinedType.ObjectLocation, DBConstants.DBObjectsLocation);
                IEnumerable<String> allDBOLocations = null;

                // Get all DBObjects from DirectoryListing
                try
                {
                    //this is the fasted way to get all UUIDs of a certain vertex type
                    allDBOLocations = _IGraphFSSession.GetDirectoryListing(_DBObjectsLocation).Value;
                }
                catch (Exception e)
                {
                    return new Exceptional<Boolean>(new Error_RebuildIndexFailed(DBConstants.UUIDIdxName, DBConstants.DEFAULTINDEX, e.Message));

                }

                var UUIDAttributeUUID = _DBContext.DBTypeManager.GetUUIDTypeAttribute().UUID;

                var UUIDIdxIndexKey = new IndexKeyDefinition(new List<AttributeUUID>() { UUIDAttributeUUID });

                foreach (var _DBObjectLocation in allDBOLocations)
                {
                    //the "allDBOLocations" are elements of a FS-directory-listing... so there might be default directory entries
                    if (!_DBObjectLocation.StartsWith(DBConstants.DefaultDirectoryEntryPrefix))
                    {
                        var _DBObjectExceptional = _DBContext.DBObjectManager.LoadDBObject(new ObjectLocation(_DBObjectsLocation, _DBObjectLocation));
                        if (_DBObjectExceptional.Failed())
                        {
                            return new Exceptional<Boolean>(_DBObjectExceptional);
                        }

                        //rebuild everything but the UUIDidx
                        foreach (var idx in _UserDefinedType.GetAllAttributeIndices(_DBContext, false))
                        {
                            //foreach (var _AttributeIndex in _KeyValuePair.Values)
                            {
                                idx.Insert(_DBObjectExceptional.Value, _UserDefinedType, _DBContext);
                            }
                        }
                    }
                }
            }

            return new Exceptional<bool>(true);
        }
Exemplo n.º 15
0
 public Boolean HasAttributeIndices(IndexKeyDefinition myIndexDefinition)
 {
     return _AttributeIndices.ContainsKey(myIndexDefinition) || (_AttributeIndexLocations.IsNotNullOrEmpty() && _AttributeIndexLocations.ContainsKey(myIndexDefinition));
 }
Exemplo n.º 16
0
 public override void Deserialize(ref Lib.NewFastSerializer.SerializationReader mySerializationReader)
 {
     FileSystemLocation  = new ObjectLocation(ObjectLocation.ParseString(mySerializationReader.ReadString()));
     IndexEdition        = mySerializationReader.ReadString();
     IndexName           = mySerializationReader.ReadString();
     _IsUUIDIndex        = mySerializationReader.ReadBoolean();
     IndexKeyDefinition = new IndexKeyDefinition();
     IndexKeyDefinition.Deserialize(ref mySerializationReader);
     IndexRelatedTypeUUID = new TypeUUID(ref mySerializationReader);
 }
Exemplo n.º 17
0
        public Exceptional<Boolean> RebuildIndices(IEnumerable<GraphDBType> myUserDefinedTypes)
        {
            #region Remove old attribute indices

            foreach (var _UserDefinedType in myUserDefinedTypes)
            {
                foreach (var _AttributeIndex in _UserDefinedType.GetAllAttributeIndices(includeUUIDIndices: false))
                {
                    // Clears the index and removes it from the file system!
                    _AttributeIndex.ClearAndRemoveFromDisc(this);
                }
            }

            #endregion

            foreach (var _UserDefinedType in myUserDefinedTypes)
            {

                var _DBObjectsLocation = new ObjectLocation(_UserDefinedType.ObjectLocation, DBConstants.DBObjectsLocation);

                // Get all DBObjects from DirectoryListing
                using (var _DBObjectsLocationsExceptional = _IGraphFSSession.GetFilteredDirectoryListing(_DBObjectsLocation, null, null, null, new List<String>(new String[] { DBConstants.DBOBJECTSTREAM }), null, null, null, null, null, null))
                {

                    if (_DBObjectsLocationsExceptional.IsValid())
                    {

                        var UUIDAttributeUUID = _DBContext.DBTypeManager.GetUUIDTypeAttribute().UUID;

                        var UUIDIdxIndexKey = new IndexKeyDefinition(new List<AttributeUUID>() { UUIDAttributeUUID });

                        foreach (var _DBObjectLocation in _DBObjectsLocationsExceptional.Value)
                        {

                            var _DBObjectExceptional = _DBContext.DBObjectManager.LoadDBObject(new ObjectLocation(_DBObjectsLocation, _DBObjectLocation));
                            if (_DBObjectExceptional.Failed())
                            {
                                return new Exceptional<Boolean>(_DBObjectExceptional);
                            }

                            //rebuild everything but the UUIDidx
                            foreach (var _KeyValuePair in _UserDefinedType.AttributeIndices.Where(aIDX => aIDX.Key != UUIDIdxIndexKey))
                            {
                                foreach (var _AttributeIndex in _KeyValuePair.Value.Values)
                                {
                                    _AttributeIndex.Insert(_DBObjectExceptional.Value, _UserDefinedType, _DBContext);
                                }
                            }

                        }

                    }

                    else
                        return new Exceptional<bool>(new Error_IndexRebuildError(_UserDefinedType, _DBObjectsLocation));

                }

            }

            return new Exceptional<bool>(true);
        }
Exemplo n.º 18
0
        public List<AAttributeIndex> GetAttributeIndices(IndexKeyDefinition IndexName)
        {
            if (_AttributeIndices.ContainsKey(IndexName))
                return new List<AAttributeIndex>(_AttributeIndices[IndexName].Values);

            return null;
        }
Exemplo n.º 19
0
        public override void Deserialize(ref SerializationReader mySerializationReader)
        {
            UInt32 _Capacity;

            if (mySerializationReader != null)
            {
                try
                {
                    _UUID = new TypeUUID(this.ObjectUUID.GetByteArray());
                    ParentTypeUUID = new TypeUUID();
                    ParentTypeUUID.Deserialize(ref mySerializationReader);
                    _IsUserDefined = mySerializationReader.ReadBoolean();
                    _IsAbstract = mySerializationReader.ReadBoolean();
                    _Comment = mySerializationReader.ReadString();

                    _Capacity = mySerializationReader.ReadUInt32();

                    _Attributes = new Dictionary<AttributeUUID, TypeAttribute>();

                    _TypeAttributeLookupTable = new Dictionary<AttributeUUID, TypeAttribute>();

                    for (UInt32 i = 0; i < _Capacity; i++)
                    {
                        var _AttrAtrib = new AttributeUUID();
                        _AttrAtrib.Deserialize(ref mySerializationReader);
                        var _TypeObj = new TypeAttribute();
                        _TypeObj.Deserialize(ref mySerializationReader);
                        _Attributes.Add(_AttrAtrib, _TypeObj);
                        _TypeAttributeLookupTable.Add(_AttrAtrib, _TypeObj);
                    }

                    _Capacity = mySerializationReader.ReadUInt32();
                    _TypeSettings = new Dictionary<String, ADBSettingsBase>();

                    for (var i = 0; i < _Capacity; i++)
                    {
                        ADBSettingsBase _ADBSettingsBase = (ADBSettingsBase) mySerializationReader.ReadObject();
                        if(_ADBSettingsBase != null)
                            _TypeSettings.Add(_ADBSettingsBase.Name, _ADBSettingsBase);
                    }

                    _Capacity = mySerializationReader.ReadUInt32();
                    _UniqueAttributes = new List<AttributeUUID>();
                    AttributeUUID AttribID = null;

                    for (UInt32 i = 0; i < _Capacity; i++)
                    {
                        AttribID = new AttributeUUID(ref mySerializationReader);
                        _UniqueAttributes.Add(AttribID);
                    }

                    _Capacity = mySerializationReader.ReadUInt32();
                    _MandatoryAttributes = new HashSet<AttributeUUID>();

                    for (UInt32 i = 0; i < _Capacity; i++)
                    {
                        AttribID = new AttributeUUID(ref mySerializationReader);
                        _MandatoryAttributes.Add(AttribID);
                    }

                    #region Indices

                    _AttributeIndices = new Dictionary<IndexKeyDefinition, Dictionary<String, AAttributeIndex>>();
                    _AttributeIndicesNameLookup = new Dictionary<String, IndexKeyDefinition>();
                    _AttributeIndexLocations = new Dictionary<IndexKeyDefinition, Dictionary<string, Tuple<string, ObjectLocation>>>();

                    var idxCount = mySerializationReader.ReadUInt32();
                    for (var i = 0; i < idxCount; i++)
                    {

                        var idxKey = new IndexKeyDefinition();
                        idxKey.Deserialize(ref mySerializationReader);

                        //_AttributeIndices.Add(idxKey, new Dictionary<String, AttributeIndex>());

                        var idxVersionCount = mySerializationReader.ReadUInt32();

                        _AttributeIndexLocations.Add(idxKey, new Dictionary<string, Tuple<string, ObjectLocation>>());
                        for (var j = 0; j < idxVersionCount; j++)
                        {

                            var key                 = mySerializationReader.ReadString();
                            var idxLocation         = mySerializationReader.ReadString();
                            var indexType           = mySerializationReader.ReadString();

                            _AttributeIndexLocations[idxKey][key] = new Tuple<string,ObjectLocation>(indexType, new ObjectLocation(idxLocation));

                            //idx.IndexKeyDefinition  = idxKey;
                            //AddAttributeIndex(idx as AAttributeIndex);

                        }

                    }

                    #endregion

                }

                catch (Exception e)
                {
                    throw new SerializationException("The GraphDBType could not be deserialized!\n\n" + e);
                }

            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Create a new Index
        /// </summary>
        /// <param name="myIndexName"></param>
        /// <param name="myAttributeDefinitions"></param>
        /// <param name="myIndexEdition"></param>
        /// <param name="myIndexType">The index type name</param>
        /// <param name="myFileSystemLocation"></param>
        /// <returns></returns>
        public Exceptional<AAttributeIndex> CreateAttributeIndex(DBContext myDBContext, String myIndexName, IndexKeyDefinition myIndexKeyDefinition, String myIndexEdition, String myIndexType = null)
        {
            if (!String.IsNullOrEmpty(myIndexType))
            {

                #region Verify IndexType

                if (!myDBContext.DBPluginManager.HasIndex(myIndexType))
                {
                    return new Exceptional<AAttributeIndex>(new Error_IndexTypeDoesNotExist(myIndexType));
                }

                #endregion

            }
            else
            {
                //if (myDBContext.IGraphFSSession is IPathBasedFS)
                //{
                //    myIndexType = "BPlusTree";
                //}
                //else
                //{
                //    myIndexType = HashTableIndex.INDEX_TYPE;
                //}
                myIndexType = myDBContext.GraphAppSettings.Get<AttributeIndexTypeSetting>();
            }

            if (String.IsNullOrEmpty(myIndexEdition))
            {
                myIndexEdition = DBConstants.DEFAULTINDEX;
            }

            var attributeIdxShards = UInt16.Parse(myDBContext.GraphAppSettings.Get<AttributeIdxShardsSetting>());

            var _NewAttributeIndex = myDBContext.DBPluginManager.GetIndex(myIndexType); //new HashTableIndex(myIndexName, myIndexEdition, myAttributeUUIDs, this);
            if (_NewAttributeIndex.Failed())
            {
                return _NewAttributeIndex;
            }

            var initializeResult = _NewAttributeIndex.Value.Initialize(myDBContext, myIndexName, myIndexKeyDefinition, this, indexEdition: myIndexEdition);
            if (initializeResult.Failed())
            {
                return new Exceptional<AAttributeIndex>(initializeResult);
            }

            var CreateExcept = AddAttributeIndex(_NewAttributeIndex.Value, myDBContext);

            if (CreateExcept.Failed())
            {
                return new Exceptional<AAttributeIndex>(CreateExcept);
            }

            return _NewAttributeIndex;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Returns the index of the given attribute
        /// </summary>
        /// <param name="myAttributeUUID">The name of the attribute we want an index for.</param>
        /// <param name="myIndexEdition">THe name of the index edition. May be null</param>
        /// <returns>The index for the given myAttributes if one exist. Else, null.</returns>
        public Exceptional<AAttributeIndex> GetAttributeIndex(AttributeUUID myAttributeUUID, String myIndexEdition)
        {
            IndexKeyDefinition idxKey = new IndexKeyDefinition(new List<AttributeUUID>() { myAttributeUUID });

            lock (_AttributeIndices)
            {

                if (_AttributeIndices.ContainsKey(idxKey))
                {

                    if (myIndexEdition == null)
                    {
                        if (_AttributeIndices[idxKey].ContainsKey(DBConstants.DEFAULTINDEX))
                            return new Exceptional<AAttributeIndex>(_AttributeIndices[idxKey][DBConstants.DEFAULTINDEX]);
                        else
                            return new Exceptional<AAttributeIndex>(_AttributeIndices[idxKey].First().Value);
                    }

                    else if (_AttributeIndices[idxKey].ContainsKey(myIndexEdition))
                    {
                        return new Exceptional<AAttributeIndex>(_AttributeIndices[idxKey][myIndexEdition]);
                    }

                }

            }

            return new Exceptional<AAttributeIndex>(new Error_IndexAttributeDoesNotExist(GetTypeAttributeByUUID(myAttributeUUID).Name));
        }
Exemplo n.º 22
0
 /// <summary>
 /// Returns the default edition index of the given attribute. If there is more than one (or empty) Edition then return the first.
 /// At some time, we could change this to take statistical information to get the best index
 /// </summary>
 /// <param name="myAttributeName">The name of the attribute we want an index for.</param>
 /// <returns>An exceptional that contains the index for the given myAttributes if one exist. Else, an error.</returns>
 public Exceptional<AAttributeIndex> GetDefaultAttributeIndex(DBContext myDBContext, AttributeUUID myAttributeUUID)
 {
     IndexKeyDefinition idxKey = new IndexKeyDefinition(new List<AttributeUUID>() { myAttributeUUID });
     return GetAttributeIndex(myDBContext, idxKey, DBConstants.DEFAULTINDEX);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Instantiates a new IndexKey on the base of another one. Additionally a AADBBaseObject is added.
        /// </summary>
        /// <param name="myStartingIndexKey">The base of the new IndexKey</param>
        /// <param name="myAttributeUUID">AttributeUUID corresponding to the ADBBaseObject</param>
        /// <param name="myIndexKeyPayload">The ADBBaseObject that is going to be added</param>
        /// <param name="myIndexDefinition">The corresponding IndexKeyDefinition</param>
        public IndexKey(IndexKey myStartingIndexKey, AttributeUUID myAttributeUUID, ADBBaseObject myIndexKeyPayload, IndexKeyDefinition myIndexDefinition)
        {
            _hashCode = myStartingIndexKey.GetHashCode();

            _indexKeyValues.AddRange(myStartingIndexKey.IndexKeyValues);

            if (!myIndexDefinition.IndexKeyAttributeUUIDs.Contains(myAttributeUUID))
            {
                throw new GraphDBException(new Error_IndexKeyCreationError(myAttributeUUID, myIndexKeyPayload, myIndexDefinition));
            }
            else
            {
                AddAAKey(myAttributeUUID, myIndexKeyPayload);
            }
        }
Exemplo n.º 24
0
        public IEnumerable<AAttributeIndex> GetAttributeIndices(IndexKeyDefinition IndexName)
        {
            if (_AttributeIndices.ContainsKey(IndexName))
            {
                foreach (var aIdx in _AttributeIndices[IndexName])
                {
                    yield return aIdx.Value;
                }

            }

            yield break;
        }
Exemplo n.º 25
0
        public Exceptional<Boolean> RebuildIndices(IEnumerable<GraphDBType> myUserDefinedTypes)
        {
            #region Remove old attribute indices

            foreach (var _UserDefinedType in myUserDefinedTypes)
            {
                foreach (var _AttributeIndex in _UserDefinedType.GetAllAttributeIndices(includeUUIDIndices: false))
                {
                    // Clears the index and removes it from the file system!
                    _AttributeIndex.ClearAndRemoveFromDisc(this);
                }
            }

            #endregion

            foreach (var _UserDefinedType in myUserDefinedTypes)
            {

                var _DBObjectsLocation = new ObjectLocation(_UserDefinedType.ObjectLocation, DBConstants.DBObjectsLocation);
                IEnumerable<String> allDBOLocations = null;

                // Get all DBObjects from DirectoryListing
                try
                {
                    allDBOLocations = _DBContext.DBObjectManager.GetAllStreamsRecursive(_DBObjectsLocation, DBConstants.DBOBJECTSTREAM);
                }
                catch (Exception e)
                {
                    return new Exceptional<Boolean>(new Error_RebuildIndexFailed(DBConstants.UUIDIdxName, DBConstants.DEFAULTINDEX, e.Message));

                }

                var UUIDAttributeUUID = _DBContext.DBTypeManager.GetUUIDTypeAttribute().UUID;

                var UUIDIdxIndexKey = new IndexKeyDefinition(new List<AttributeUUID>() { UUIDAttributeUUID });

                foreach (var _DBObjectLocation in allDBOLocations)
                {

                    var _DBObjectExceptional = _DBContext.DBObjectManager.LoadDBObject(new ObjectLocation(_DBObjectsLocation, _DBContext.DBObjectManager.GetDBObjectStreamShard(_UserDefinedType, new ObjectUUID(_DBObjectLocation)), _DBObjectLocation));
                    if (_DBObjectExceptional.Failed())
                    {
                        return new Exceptional<Boolean>(_DBObjectExceptional);
                    }

                    //rebuild everything but the UUIDidx
                    foreach (var _KeyValuePair in _UserDefinedType.AttributeIndices.Where(aIDX => aIDX.Key != UUIDIdxIndexKey))
                    {
                        foreach (var _AttributeIndex in _KeyValuePair.Value.Values)
                        {
                            _AttributeIndex.Insert(_DBObjectExceptional.Value, _UserDefinedType, _DBContext);
                        }
                    }

                }
            }

            return new Exceptional<bool>(true);
        }
Exemplo n.º 26
0
 public Boolean HasAttributeIndices(IndexKeyDefinition myIndexDefinition)
 {
     return _AttributeIndices.ContainsKey(myIndexDefinition);
 }
Exemplo n.º 27
0
        public override Exceptional Initialize(DBContext myDBContext, string indexName, IndexKeyDefinition idxKey, GraphDBType correspondingType, string indexEdition = DBConstants.DEFAULTINDEX)
        {
            IndexName = indexName;
            IndexEdition = indexEdition;
            IndexKeyDefinition = idxKey;
            IndexRelatedTypeUUID = correspondingType.UUID;
            AttributeIdxShards = Convert.ToUInt16(myDBContext.GraphAppSettings.Get<AttributeIdxShardsSetting>());

            _keyCount = 0;
            _valueCount = 0;

            if (indexEdition == null)
            {
                IndexEdition = DBConstants.DEFAULTINDEX;
            }
            else
            {
                IndexEdition = indexEdition;
            }

            _IsUUIDIndex = idxKey.IndexKeyAttributeUUIDs.Count == 1 && idxKey.IndexKeyAttributeUUIDs[0].Equals(myDBContext.DBTypeManager.GetUUIDTypeAttribute().UUID);

            #region Workaround for current IndexOperation of InOperator - just follow the IsListOfBaseObjectsIndex property

            // better approach, use a special index key for a set of base objects
            if (idxKey.IndexKeyAttributeUUIDs.Any(a =>
            {
                var typeAttr = correspondingType.GetTypeAttributeByUUID(a);
                if (typeAttr != null && (typeAttr.EdgeType is IBaseEdge))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }))
            {
                IsListOfBaseObjectsIndex = true;
            }
            else
            {
                IsListOfBaseObjectsIndex = false;
            }

            #endregion

            FileSystemLocation = (correspondingType.ObjectLocation + "Indices") + (IndexName + "#" + IndexEdition);

            return Exceptional.OK;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Returns the attribute index with the specified key and edition.
        /// </summary>
        /// <param name="idxKey">The index key.</param>
        /// <param name="edition">The index edition.</param>
        /// <returns>The index or null if no index was found.</returns>
        private AAttributeIndex GetAttributeIndex(IndexKeyDefinition idxKey, string edition)
        {
            if (_AttributeIndices.ContainsKey(idxKey) && _AttributeIndices[idxKey].ContainsKey(DBConstants.UNIQUEATTRIBUTESINDEX))
            {
                return _AttributeIndices[idxKey][DBConstants.UNIQUEATTRIBUTESINDEX];
            }

            return null;
        }
Exemplo n.º 29
0
 public Error_IndexKeyCreationError(AttributeUUID myAttributeUUID, ADBBaseObject myIndexKeyPayload, IndexKeyDefinition myIndexDefinition)
 {
     AttributeUUID = myAttributeUUID;
     IndexKeyPayload = myIndexKeyPayload;
     IndexDefinition = myIndexDefinition;
 }
Exemplo n.º 30
0
        /// <summary>
        /// add an unique attribute to type
        /// </summary>
        /// <param name="myAttribID"></param>
        public Exceptional<Boolean> AddUniqueAttributes(List<AttributeUUID> myAttribIDs, DBContext myDBContext)
        {
            if (!myAttribIDs.IsNullOrEmpty())
            {
                #region data

                AAttributeIndex AttribIndex = null;
                List<GraphDBType> SubTypes = myDBContext.DBTypeManager.GetAllSubtypes(this, false);
                IndexKeyDefinition idxKey = new IndexKeyDefinition(myAttribIDs);

                #endregion

                AttribIndex = GetAttributeIndex(idxKey, DBConstants.UNIQUEATTRIBUTESINDEX);

                if (!SubTypes.IsNullOrEmpty())
                {
                    string idxName = myDBContext.DBIndexManager.GetUniqueIndexName(myAttribIDs, this);

                    foreach (var aType in SubTypes)
                    {
                        foreach (var AttrID in myAttribIDs)
                        {
                            aType._UniqueAttributes.Add(AttrID);
                        }

                        if (AttribIndex != null)
                        {
                            var createIdxExcept = aType.CreateUniqueAttributeIndex(myDBContext, idxName, myAttribIDs, DBConstants.UNIQUEATTRIBUTESINDEX);

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

                _UniqueAttributes.AddRange(myAttribIDs);
            }

            return new Exceptional<Boolean>(true);
        }