示例#1
0
        private void RebuildIndices(IVertexType myVertexType, Int64 myTransaction, SecurityToken mySecurity, bool myOnlyNonPersistent)
        {
            Dictionary <IList <IPropertyDefinition>, IEnumerable <ISonesIndex> > toRebuild = new Dictionary <IList <IPropertyDefinition>, IEnumerable <ISonesIndex> >();

            foreach (var indexDef in myVertexType.GetIndexDefinitions(false))
            {
                var indices = GetIndices(myVertexType, indexDef.IndexedProperties, mySecurity, myTransaction).Where(_ => !myOnlyNonPersistent || !GetIsPersistentIndex(_));
                toRebuild.Add(indexDef.IndexedProperties, indices);
            }

            if (toRebuild.Count > 0)
            {
                foreach (var aIdxCollection in toRebuild.Values)
                {
                    foreach (var aIdx in aIdxCollection)
                    {
                        aIdx.Clear();
                    }
                }

                var vertices = _vertexStore.GetVerticesByTypeID(mySecurity, myTransaction, myVertexType.ID);

                foreach (var vertex in vertices)
                {
                    foreach (var indexGroup in toRebuild)
                    {
                        foreach (var index in indexGroup.Value)
                        {
                            index.Add(CreateIndexKey(indexGroup.Key, vertex), vertex.VertexID);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// output for the type indices
        /// </summary>
        /// <param name="myType">The db type</param>
        /// <param name="myDBContext">The db context</param>
        /// <returns>a list of readouts, contains the attributes</returns>
        private IEnumerable <ISingleEdgeView> GenerateIndicesOutput(IVertexType myType)
        {
            var _AttributeReadout = new List <ISingleEdgeView>();

            foreach (var idx in myType.GetIndexDefinitions(true))
            {
                var Attributes = new Dictionary <String, Object>();

                Attributes.Add("ID", idx.ID);
                Attributes.Add("Type", idx.IndexTypeName);
                Attributes.Add("Name", idx.Name);
                Attributes.Add("Edition", idx.Edition);

                var list = new ListCollectionWrapper();
                foreach (var item in idx.IndexedProperties)
                {
                    list.Add(item.Name);
                }

                Attributes.Add("IndexedProperties", list);

                _AttributeReadout.Add(new SingleEdgeView(null, new VertexView(Attributes, new Dictionary <String, IEdgeView>())));
            }

            return(_AttributeReadout);
        }
示例#3
0
        public IEnumerable <ISonesIndex> GetIndices(IVertexType myVertexType, IList <IPropertyDefinition> myPropertyDefinition, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            myVertexType.CheckNull("myVertexType");
            myPropertyDefinition.CheckNull("myPropertyDefinition");

            if (myPropertyDefinition.Count == 0)
            {
                throw new ArgumentOutOfRangeException("myPropertyDefinition", "At least one property must be given.");
            }

            var propertyTypes = myPropertyDefinition.GroupBy(_ => _.RelatedType);

            foreach (var group in propertyTypes)
            {
                if (!myVertexType.IsDescendantOrSelf(group.Key))
                {
                    throw new ArgumentException(string.Format("The properties ({0}) defined on type {1} is not part of inheritance hierarchy of {2}.",
                                                              string.Join(",", group.Select(_ => _.Name)),
                                                              group.Key.Name,
                                                              myVertexType.Name));
                }
            }

            var result = myVertexType.GetIndexDefinitions(false).Where(_ => myPropertyDefinition.SequenceEqual(_.IndexedProperties)).Select(_ => _indices[_.ID]).ToArray();

            return(result);
        }
示例#4
0
        private void RebuildIndices(IVertexType myVertexType, Int64 myTransaction, SecurityToken mySecurity, bool myOnlyNonPersistent )
        {
            Dictionary<IList<IPropertyDefinition>, IEnumerable<ISonesIndex>> toRebuild = new Dictionary<IList<IPropertyDefinition>, IEnumerable<ISonesIndex>>();
            foreach (var indexDef in myVertexType.GetIndexDefinitions(false))
            {
                var indices = GetIndices(myVertexType, indexDef.IndexedProperties, mySecurity, myTransaction).Where(_=>!myOnlyNonPersistent || !GetIsPersistentIndex(_));
                toRebuild.Add(indexDef.IndexedProperties, indices);
            }

            if (toRebuild.Count > 0)
            {
                foreach (var aIdxCollection in toRebuild.Values)
                {
                    foreach (var aIdx in aIdxCollection)
                    {
                        aIdx.Clear();
                    }
                }

                var vertices = _vertexStore.GetVerticesByTypeID(mySecurity, myTransaction, myVertexType.ID);

                foreach (var vertex in vertices)
                {
                    foreach (var indexGroup in toRebuild)
                    {
                        foreach (var index in indexGroup.Value)
                        {
                            index.Add(CreateIndexKey(indexGroup.Key, vertex), vertex.VertexID);
                        }
                    }
                }
            }
        }
示例#5
0
 public IEnumerable<ISonesIndex> GetIndices(IVertexType myVertexType, IPropertyDefinition myPropertyDefinition, SecurityToken mySecurityToken, Int64 myTransactionToken)
 {
     myVertexType.CheckNull("myVertexType");
     return myVertexType.GetIndexDefinitions(false).Where(_=>_.IndexedProperties.Count == 1 && _.IndexedProperties.Contains(myPropertyDefinition)).Select(_ => _indices[_.ID]);
     //return myPropertyDefinition.InIndices.Where(_ => myVertexType.Equals(_.VertexType)).Select(_ => _indices[_.ID]);
 }
示例#6
0
        public IEnumerable<ISonesIndex> GetIndices(IVertexType myVertexType, IList<IPropertyDefinition> myPropertyDefinition, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            myVertexType.CheckNull("myVertexType");
            myPropertyDefinition.CheckNull("myPropertyDefinition");

            if (myPropertyDefinition.Count == 0)
                throw new ArgumentOutOfRangeException("myPropertyDefinition", "At least one property must be given.");

            var propertyTypes = myPropertyDefinition.GroupBy(_ => _.RelatedType);
            foreach (var group in propertyTypes)
            {
                if (!myVertexType.IsDescendantOrSelf(group.Key))
                {
                    throw new ArgumentException(string.Format("The properties ({0}) defined on type {1} is not part of inheritance hierarchy of {2}.",
                        string.Join(",", group.Select(_ => _.Name)),
                        group.Key.Name,
                        myVertexType.Name));
                }
            }

            var result = myVertexType.GetIndexDefinitions(false).Where(_ => myPropertyDefinition.SequenceEqual(_.IndexedProperties)).Select(_=>_indices[_.ID]).ToArray();

            return result;
        }
示例#7
0
        /// <summary>
        /// Creates the ddl of a type.
        /// </summary>
        /// <param name="myVertexType">The vertex type.</param>
        private String CreateGraphDDL_VertexType(IVertexType myVertexType)
        {
            var stringBuilder = new StringBuilder();
            String delimiter = ", ";
            stringBuilder.AppendFormat("{0} ", myVertexType.Name);

            #region parent type

            //EXTENDS ...
            if (myVertexType.HasParentType)
            {
                stringBuilder.AppendFormat("{0} {1} ", S_EXTENDS.ToUpperString(), myVertexType.ParentVertexType.Name);
            }

            #endregion

            #region attributes
            //are there attributes
            if (myVertexType.HasAttributes(false))
            {
                #region !incomingEdges

                if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind != AttributeType.IncomingEdge))
                {
                    //so, there are attributes that are no incoming edges
                    stringBuilder.Append(String.Concat(S_ATTRIBUTES.ToUpperString(), " ", S_BRACKET_LEFT));

                    #region properties

                    if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.Property))
                    {
                        stringBuilder.Append(String.Concat(CreateGraphDDLOfProperties(myVertexType.GetPropertyDefinitions(false))));
                    }

                    #endregion

                    #region outgoing edges

                    if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.OutgoingEdge))
                    {
                        stringBuilder.Append(String.Concat(CreateGraphDDLOfOutgoingEdges(myVertexType.GetOutgoingEdgeDefinitions(false), myVertexType)));
                    }

                    #endregion

                    if (stringBuilder.ToString().EndsWith(delimiter))
                        stringBuilder.RemoveSuffix(delimiter);

                    stringBuilder.Append(String.Concat(S_BRACKET_RIGHT, " "));

                }

                #endregion

                #region incomingEdges

                if (myVertexType.GetAttributeDefinitions(false).Any(aAttribute => aAttribute.Kind == AttributeType.IncomingEdge))
                {
                    stringBuilder.Append(
                        String.Concat(S_INCOMINGEDGES.ToUpperString(),
                                        " ",
                                        S_BRACKET_LEFT.ToUpperString(),
                                        CreateGraphDDLOfIncomingEdges(
                                            myVertexType.GetIncomingEdgeDefinitions(false)),
                                        S_BRACKET_RIGHT.ToUpperString(), " "));
                }

                #endregion
            }

            #endregion

            #region Uniques

            if (myVertexType.HasUniqueDefinitions(false))
            {
                if (myVertexType.GetUniqueDefinitions(false).Count() > 0)
                {
                    stringBuilder.Append(S_UNIQUE.ToUpperString() +
                                            " " +
                                            S_BRACKET_LEFT.Symbol +
                                            CreateGraphDDLOfUniqueAttributes(
                                                myVertexType
                                                    .GetUniqueDefinitions(false)) +
                                            S_BRACKET_RIGHT.Symbol + " ");
                }
            }

            #endregion

            #region Mandatory attributes

            if (myVertexType.HasProperties(false))
            {
                if (myVertexType.GetPropertyDefinitions(false).Any(aProperty => aProperty.IsMandatory))
                {
                    stringBuilder.Append(S_MANDATORY.ToUpperString() +
                                            " " +
                                            S_BRACKET_LEFT.Symbol +
                                            CreateGraphDDLOfMandatoryAttributes(
                                                myVertexType
                                                    .GetPropertyDefinitions(false)
                                                    .Where(aProperty => aProperty.IsMandatory)) +
                                            S_BRACKET_RIGHT.Symbol + " ");
                }
            }

            #endregion

            #region Indices

            var indices =
                myVertexType.GetIndexDefinitions(false).Except(
                    myVertexType.GetUniqueDefinitions(false).Select(_ => _.CorrespondingIndex));

            if (indices.Count() > 0)
            {
                stringBuilder.Append(S_INDICES.ToUpperString() +
                                        " " +
                                        S_BRACKET_LEFT.Symbol +
                                        CreateGraphDDLOfIndices(indices, myVertexType) +
                                        S_BRACKET_RIGHT.Symbol);
            }

            #endregion

            return stringBuilder.ToString();
        }
示例#8
0
        //private bool GetIsSingleValue(IIndex<IComparable, long> index)
        //{
        //    return index is ISingleValueIndex<IComparable, Int64>;
        //}

        #region IIndexManager Members


        public IEnumerable <ISonesIndex> GetIndices(IVertexType myVertexType, IPropertyDefinition myPropertyDefinition, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            myVertexType.CheckNull("myVertexType");
            return(myVertexType.GetIndexDefinitions(false).Where(_ => _.IndexedProperties.Count == 1 && _.IndexedProperties.Contains(myPropertyDefinition)).Select(_ => _indices[_.ID]));
            //return myPropertyDefinition.InIndices.Where(_ => myVertexType.Equals(_.VertexType)).Select(_ => _indices[_.ID]);
        }
示例#9
0
        /// <summary>
        /// output for the type indices
        /// </summary>
        /// <param name="myType">The db type</param>
        /// <param name="myDBContext">The db context</param>
        /// <returns>a list of readouts, contains the attributes</returns>
        private IEnumerable<ISingleEdgeView> GenerateIndicesOutput(IVertexType myType)
        {
            var _AttributeReadout = new List<ISingleEdgeView>();

            foreach (var idx in myType.GetIndexDefinitions(true))
            {

                var Attributes = new Dictionary<String, Object>();

                Attributes.Add("ID", idx.ID);
                Attributes.Add("Type", idx.IndexTypeName);
                Attributes.Add("Name", idx.Name);
                Attributes.Add("Edition", idx.Edition);

                var list = new ListCollectionWrapper();
                foreach (var item in idx.IndexedProperties)
                    list.Add(item.Name);

                Attributes.Add("IndexedProperties", list);

                _AttributeReadout.Add(new SingleEdgeView(null, new VertexView(Attributes, new Dictionary<String, IEdgeView>())));

            }

            return _AttributeReadout;
        }
示例#10
0
        /// <summary>
        /// Removes indices
        /// </summary>
        /// <param name="myToBeRemovedIndices"></param>
        /// <param name="vertexType"></param>
        /// <param name="myTransactionToken"></param>
        /// <param name="mySecurityToken"></param>
        private void RemoveIndices(Dictionary<string, string> myToBeRemovedIndices, IVertexType vertexType, TransactionToken myTransactionToken, SecurityToken mySecurityToken)
        {
            if (myToBeRemovedIndices.IsNotNullOrEmpty())
            {
                foreach (var aIndex in myToBeRemovedIndices)
                {
                    //find the source
                    IIndexDefinition sourceIndexDefinition = vertexType.GetIndexDefinitions(false).Where(_ => _.Name == aIndex.Key && (aIndex.Value == null || _.Edition == aIndex.Value)).FirstOrDefault();

                    foreach (var aVertexType in vertexType.GetDescendantVertexTypes())
                    {
                        foreach (var aInnerIndex in aVertexType.GetIndexDefinitions(false).Where(_=>_.SourceIndex.ID == sourceIndexDefinition.ID))
                        {
                            _indexManager.RemoveIndexInstance(aInnerIndex.ID, myTransactionToken, mySecurityToken);
                        }
                    }

                    if (sourceIndexDefinition != null)
                        _indexManager.RemoveIndexInstance(sourceIndexDefinition.ID, myTransactionToken, mySecurityToken);
                }
            }
        }
示例#11
0
        private void RebuildIndices(IVertexType myVertexType, TransactionToken myTransaction, SecurityToken mySecurity, bool myOnlyNonPersistent )
        {
            Dictionary<IList<IPropertyDefinition>, IEnumerable<IIndex<IComparable, Int64>>> toRebuild = new Dictionary<IList<IPropertyDefinition>, IEnumerable<IIndex<IComparable, long>>>();
            foreach (var indexDef in myVertexType.GetIndexDefinitions(false))
            {
                var indices = GetIndices(myVertexType, indexDef.IndexedProperties, mySecurity, myTransaction).Where(_=>!myOnlyNonPersistent || !_.IsPersistent);
                toRebuild.Add(indexDef.IndexedProperties, indices);
            }

            if (toRebuild.Count > 0)
            {
                foreach (var aIdxCollection in toRebuild.Values)
                {
                    foreach (var aIdx in aIdxCollection)
                    {
                        aIdx.ClearIndex();
                    }
                }

                var vertices = _vertexStore.GetVerticesByTypeID(mySecurity, myTransaction, myVertexType.ID);

                foreach (var vertex in vertices)
                {
                    foreach (var indexGroup in toRebuild)
                    {
                        foreach (var index in indexGroup.Value)
                        {
                            var key = CreateIndexKey(indexGroup.Key, vertex);
                            if (key != null)
                            {
                                if (index is ISingleValueIndex<IComparable, Int64>)
                                {
                                    (index as ISingleValueIndex<IComparable, Int64>).Add(key, vertex.VertexID);
                                }
                                else if (index is IMultipleValueIndex<IComparable, Int64>)
                                {
                                    //Perf: We do not need to add a set of values. Initializing a HashSet is to expensive for this operation.
                                    //TODO: Refactor IIndex structure
                                    (index as IMultipleValueIndex<IComparable, Int64>).Add(key, new HashSet<Int64> { vertex.VertexID });
                                }
                                else
                                {
                                    throw new NotImplementedException(
                                        "Indices other than single or multiple value indices are not supported yet.");
                                }
                            }
                        }
                    }
                }
            }
        }
示例#12
0
        /// <summary>
        /// Checks if the desired index are removable
        /// </summary>
        /// <param name="myToBeRemovedIndices"></param>
        /// <param name="vertexType"></param>
        private static void CheckToBeRemovedIndices(Dictionary<string, string> myToBeRemovedIndices, IVertexType vertexType)
        {
            if (myToBeRemovedIndices == null)
                return;

            var indexDefinitions = vertexType.GetIndexDefinitions(true).ToList();

            foreach (var aKV in myToBeRemovedIndices)
            {
                if (!indexDefinitions.Any(_ => _.Name == aKV.Key && (aKV.Value == null || _.Edition == aKV.Value)))
                {
                    throw new IndexRemoveException(aKV.Key, aKV.Value, "The desired index does not exist.");
                }
            }
        }
示例#13
0
        /// <summary>
        /// Checks if every to be added index is valid
        /// </summary>
        /// <param name="myToBeAddedIndices"></param>
        /// <param name="vertexType"></param>
        private static void CheckToBeAddedIndices(IEnumerable<IndexPredefinition> myToBeAddedIndices, IVertexType vertexType)
        {
            if (myToBeAddedIndices == null)
                return;

            var indexDefinitions = vertexType.GetIndexDefinitions(true).ToList();

            foreach (var aIndexPredefinition in myToBeAddedIndices)
            {
                #region check the properties

                foreach (var aProperty in aIndexPredefinition.Properties)
                {
                    if (!vertexType.HasProperty(aProperty))
                    {
                        throw new AttributeDoesNotExistException(aProperty, vertexType.Name);
                    }
                }

                #endregion

                #region check the idx name, etc

                if (indexDefinitions.Any(_ => _.Name == aIndexPredefinition.Name))
                {
                    throw new IndexCreationException(aIndexPredefinition, "This index definition is ambiguous.");
                }

                #endregion
            }
        }