/// <summary> /// Creates a new InvalidIndexAttributeException exception /// </summary> /// <param name="myInvalidIndexAttribute">The name of the invalid vertex type</param> /// <param name="myInfo"></param> /// <param name="innerException">The exception that is the cause of the current exception, this parameter can be NULL.</param> public IndexCreationException(IndexPredefinition myIndexPredef, String myInfo, Exception innerException = null) : base(innerException) { Info = myInfo; IndexPredef = myIndexPredef; _msg = String.Format("Could Not Create Index {0} type {1} on type {2}.\n\n{3}.", IndexPredef.Name, IndexPredef.TypeName, IndexPredef.VertexTypeName, Info); }
public override IQueryResult Execute(IGraphDB myGraphDB, IGraphQL myGraphQL, GQLPluginManager myPluginManager, String myQuery, SecurityToken mySecurityToken, Int64 myTransactionToken) { Query = myQuery; var indexDef = new IndexPredefinition(_IndexName, _DBType) .SetIndexType(_IndexType) .SetEdition(_IndexEdition); //to be indices attributes foreach (var aIndexedProperty in _AttributeList) { indexDef.AddProperty(aIndexedProperty.IndexAttribute.ContentString); } //options for the index if (_options != null) { foreach (var aKV in _options) { indexDef.AddOption(aKV.Key, aKV.Value); } } return(myGraphDB.CreateIndex <IQueryResult>(mySecurityToken, myTransactionToken, new RequestCreateIndex(indexDef), GenerateResult)); }
/// <summary> /// Generates a index predefinition /// </summary> /// <param name="aIndex">The index definition by the gql</param> /// <returns>An IndexPredefinition</returns> private IndexPredefinition GenerateIndex(IndexDefinition aIndex, String myVertexType) { IndexPredefinition result; if (String.IsNullOrEmpty(aIndex.IndexName)) { result = new IndexPredefinition(myVertexType); } else { result = new IndexPredefinition(aIndex.IndexName, myVertexType); } result.SetVertexType(myVertexType); if (!String.IsNullOrEmpty(aIndex.IndexType)) { result.SetIndexType(aIndex.IndexType); } foreach (var aIndexProperty in aIndex.IndexAttributeDefinitions) { result.AddProperty(aIndexProperty.IndexAttribute.ContentString); } if (aIndex.Options != null) { foreach (var aIndexOption in aIndex.Options) { result.AddOption(aIndexOption.Key, aIndexOption.Value); } } return(result); }
internal ServiceIndexPredefinition(IndexPredefinition myIndexPredefinition) { this.Edition = myIndexPredefinition.Edition; this.IndexTypeName = myIndexPredefinition.TypeName; this.Name = myIndexPredefinition.Name; this.IndexOptions = myIndexPredefinition.IndexOptions; this.Properties = myIndexPredefinition.Properties.ToArray(); this.VertexTypeName = myIndexPredefinition.VertexTypeName; this.Comment = myIndexPredefinition.Comment; }
/// <summary> /// Adds an index definition. /// </summary> /// <param name="myIndexDefinition">The index definition that is going to be added.</param> /// <returns>The reference of the current object. (fluent interface).</returns> public RequestAlterVertexType AddIndex(IndexPredefinition myIndexDefinition) { if (myIndexDefinition != null) { _toBeAddedIndices = (_toBeAddedIndices) ?? new List <IndexPredefinition>(); _toBeAddedIndices.Add(myIndexDefinition); AddIndicesCount++; } return(this); }
private string CreateIndexName(IndexPredefinition myIndexDefinition, IVertexType vertexType) { var propNames = string.Join("AND", myIndexDefinition.Properties); int count = 0; string result; do { result = string.Join("_", "sones", propNames, vertexType.Name, count++); } while (_ownIndex.ContainsKey(result)); return(result); }
public IndexPredefinition ToIndexPredefinition() { IndexPredefinition IndexPreDef = new IndexPredefinition(this.Name, this.VertexTypeName); IndexPreDef.SetComment(this.Comment); IndexPreDef.SetEdition(this.Edition); IndexPreDef.SetIndexType(this.IndexTypeName); if (this.IndexOptions != null) { IndexPreDef.AddOptions(this.IndexOptions); } if (this.Properties != null) { foreach (var Property in this.Properties) { IndexPreDef.AddProperty(Property); } } IndexPreDef.SetVertexType(this.VertexTypeName); return(IndexPreDef); }
/// <summary> /// Generates a index predefinition /// </summary> /// <param name="aIndex">The index definition by the gql</param> /// <returns>An IndexPredefinition</returns> private IndexPredefinition GenerateIndex(IndexDefinition aIndex) { IndexPredefinition result; if (String.IsNullOrEmpty(aIndex.IndexName)) { result = new IndexPredefinition(_TypeName); } else { result = new IndexPredefinition(aIndex.IndexName, _TypeName); } if (!String.IsNullOrEmpty(aIndex.IndexType)) { result.SetIndexType(aIndex.IndexType); } result.SetEdition(aIndex.Edition); //options for the index if (aIndex.Options != null) { foreach (var aKV in aIndex.Options) { result.AddOption(aKV.Key, aKV.Value); } } foreach (var aIndexProperty in aIndex.IndexAttributeDefinitions) { result.AddProperty(aIndexProperty.IndexAttribute.ContentString); } return(result); }
public RequestCreateIndex(IndexPredefinition myIndexDefinition) { IndexDefinition = myIndexDefinition; }
public IIndexDefinition CreateIndex(IndexPredefinition myIndexDefinition, SecurityToken mySecurity, Int64 myTransaction, bool myIsUserDefined = true) { myIndexDefinition.CheckNull("myIndexDefinition"); if (myIndexDefinition.Name != null && myIndexDefinition.Name.StartsWith("sones")) { throw new Exception("It is not allowed to add an index with a name, that starts with 'sones'."); } var vertexType = _vertexTypeManager.ExecuteManager.GetType(myIndexDefinition.VertexTypeName, myTransaction, mySecurity); var indexName = myIndexDefinition.Name ?? CreateIndexName(myIndexDefinition, vertexType); if (_ownIndex.ContainsKey(indexName)) { //TODO a better exception here. throw new Exception("An index with that name already exists."); } if (myIndexDefinition.Properties == null) { throw new Exception("Index without properties is not allowed."); } foreach (var prop in myIndexDefinition.Properties) { var propDef = vertexType.GetPropertyDefinition(prop); if (!vertexType.HasProperty(prop) || (propDef.RelatedType.ID != vertexType.ID && !HasIndex(propDef, mySecurity, myTransaction))) { //TODO a better exception here. throw new AttributeDoesNotExistException("The property is not defined on the vertex type " + vertexType.Name + ", it is defined on a parent type."); } } var indexID = _idManager.GetVertexTypeUniqeID((long)BaseTypes.Index).GetNextID(); var info = new VertexInformation((long)BaseTypes.Index, indexID, 0, myIndexDefinition.Edition); var typeClass = myIndexDefinition.TypeName ?? GetBestMatchingIndexName(false, false); var parameter = (_indexPluginParameter.ContainsKey(typeClass)) ? _indexPluginParameter[typeClass].PluginParameter : new Dictionary <string, object>(); var options = ValidateOptions(myIndexDefinition.IndexOptions, typeClass); // load propertyIDs for indexed properties var propertyIDs = myIndexDefinition.Properties.Select(prop => vertexType.GetPropertyDefinition(prop).ID).ToList(); // add propertyIDs for indexing parameter.Add(IndexConstants.PROPERTY_IDS_OPTIONS_KEY, propertyIDs); parameter = FillOptions(parameter, options); // HACK: manually inject eventuall existing PersistenceLocation (btk, 23.09.2011) #region Hack if (_applicationSettings.Get <PersistenceLocation>() != null) { // if not already, initialize if (parameter == null) { parameter = new Dictionary <string, object>(); } if (!parameter.ContainsKey("Path")) // only add when not already in there... { parameter.Add("Path", _applicationSettings.Get <PersistenceLocation>()); } } #endregion var index = _pluginManager.GetAndInitializePlugin <ISonesIndex>(typeClass, parameter, indexID); var props = myIndexDefinition.Properties.Select(prop => new VertexInformation((long)BaseTypes.Property, vertexType.GetPropertyDefinition(prop).ID)).ToList(); var date = DateTime.UtcNow.ToBinary(); var indexVertex = _baseStorageManager.StoreIndex( _vertexStore, info, indexName, myIndexDefinition.Comment, date, myIndexDefinition.TypeName, //GetIsSingleValue(index), GetIsRangeValue(index), GetIsVersionedValue(index), true, myIndexDefinition.IndexOptions, new VertexInformation((long)BaseTypes.VertexType, vertexType.ID), null, props, mySecurity, myTransaction); _ownIndex.Add(indexName, indexID); _indices.Add(indexID, index); foreach (var childType in vertexType.GetDescendantVertexTypes()) { var childID = _idManager.GetVertexTypeUniqeID((long)BaseTypes.Index).GetNextID(); var childName = CreateIndexName(myIndexDefinition, childType); var childIndex = _pluginManager.GetAndInitializePlugin <ISonesIndex>(typeClass, parameter, childID); _baseStorageManager.StoreIndex( _vertexStore, new VertexInformation((long)BaseTypes.Index, childID), childName, indexName, //we store the source index name as comment date, myIndexDefinition.TypeName, //GetIsSingleValue(index), GetIsRangeValue(index), GetIsVersionedValue(index), false, myIndexDefinition.IndexOptions, new VertexInformation((long)BaseTypes.VertexType, childType.ID), info, props, mySecurity, myTransaction); _ownIndex.Add(childName, childID); _indices.Add(childID, childIndex); } var indexDefinition = _baseStorageManager.CreateIndexDefinition(indexVertex, vertexType); _vertexTypeManager.ExecuteManager.CleanUpTypes(); var reloadedVertexType = _vertexTypeManager.ExecuteManager.GetType(vertexType.Name, myTransaction, mySecurity); foreach (var type in reloadedVertexType.GetDescendantVertexTypesAndSelf()) { RebuildIndices(type, myTransaction, mySecurity); } return(indexDefinition); }
public override QueryResult Execute(IGraphDB myGraphDB, IGraphQL myGraphQL, GQLPluginManager myPluginManager, String myQuery, SecurityToken mySecurityToken, TransactionToken myTransactionToken) { Query = myQuery; var indexDef = new IndexPredefinition(_IndexName); indexDef.SetIndexType(_IndexType); indexDef.SetVertexType(_DBType); indexDef.SetEdition(_IndexEdition); //to be indices attributes foreach (var aIndexedProperty in _AttributeList) { indexDef.AddProperty(aIndexedProperty.IndexAttribute.ContentString); } //options for the index if (_options != null) { foreach (var aKV in _options) { indexDef.AddOption(aKV.Key, aKV.Value); } } return myGraphDB.CreateIndex<QueryResult>(mySecurityToken, myTransactionToken, new RequestCreateIndex(indexDef), GenerateResult); }
/// <summary> /// Describes how to define a type with user defined properties and indices and create some instances by using GraphDB requests. /// </summary> private void GraphDBRequests() { #region define type "Tag" //create a VertexTypePredefinition var Tag_VertexTypePredefinition = new VertexTypePredefinition("Tag"); //create property var PropertyName = new PropertyPredefinition("Name", "String") .SetComment("This is a property on type 'Tag' named 'Name' and is of type 'String'"); //add property Tag_VertexTypePredefinition.AddProperty(PropertyName); //create outgoing edge to "Website" var OutgoingEdgesTaggedWebsites = new OutgoingEdgePredefinition("TaggedWebsites", "Website") .SetMultiplicityAsMultiEdge() .SetComment(@"This is an outgoing edge on type 'Tag' wich points to the type 'Website' (the AttributeType) and is defined as 'MultiEdge', which means that this edge can contain multiple single edges"); //add outgoing edge Tag_VertexTypePredefinition.AddOutgoingEdge(OutgoingEdgesTaggedWebsites); #endregion #region define type "Website" //create a VertexTypePredefinition var Website_VertexTypePredefinition = new VertexTypePredefinition("Website"); //create properties PropertyName = new PropertyPredefinition("Name", "String") .SetComment("This is a property on type 'Website' named 'Name' and is of type 'String'"); var PropertyUrl = new PropertyPredefinition("URL", "String") .SetAsMandatory(); //add properties Website_VertexTypePredefinition.AddProperty(PropertyName); Website_VertexTypePredefinition.AddProperty(PropertyUrl); #region create an index on type "Website" on property "Name" //there are three ways to set an index on property "Name" //Beware: Use just one of them! //1. create an index definition and specifie the property- and type name var MyIndex = new IndexPredefinition("MyIndex").SetIndexType("SonesIndex").AddProperty("Name").SetVertexType("Website"); //add index Website_VertexTypePredefinition.AddIndex((IndexPredefinition)MyIndex); //2. on creating the property definition of property "Name" call the SetAsIndexed() method, the GraphDB will create the index //PropertyName = new PropertyPredefinition("Name") // .SetAttributeType("String") // .SetComment("This is a property on type 'Website' with name 'Name' and is of type 'String'") // .SetAsIndexed(); //3. make a create index request, like creating a type //BEWARE: This statement must be execute AFTER the type "Website" is created. //var MyIndex = GraphDSServer.CreateIndex<IIndexDefinition>(SecToken, // TransToken, // new RequestCreateIndex( // new IndexPredefinition("MyIndex") // .SetIndexType("SonesIndex") // .AddProperty("Name") // .SetVertexType("Website")), (Statistics, Index) => Index); #endregion //add IncomingEdge "Tags", the related OutgoingEdge is "TaggedWebsites" on type "Tag" Website_VertexTypePredefinition.AddIncomingEdge(new IncomingEdgePredefinition("Tags", "Tag", "TaggedWebsites")); #endregion #region create types by sending requests //create the types "Tag" and "Website" var DBTypes = GraphDSServer.CreateVertexTypes <IEnumerable <IVertexType> >(SecToken, TransationID, new RequestCreateVertexTypes( new List <VertexTypePredefinition> { Tag_VertexTypePredefinition, Website_VertexTypePredefinition }), (Statistics, VertexTypes) => VertexTypes); /* * BEWARE: The following two operations won't work because the two types "Tag" and "Website" depending on each other, * because one type has an incoming edge to the other and the other one has an incoming edge, * so they cannot be created separate (by using create type), * they have to be created at the same time (by using create types) * * //create the type "Website" * var Website = GraphDSServer.CreateVertexType<IVertexType>(SecToken, * TransToken, * new RequestCreateVertexType(Website_VertexTypePredefinition), * (Statistics, VertexType) => VertexType); * * //create the type "Tag" * var Tag = GraphDSServer.CreateVertexType<IVertexType>(SecToken, * TransToken, * new RequestCreateVertexType(Tag_VertexTypePredefinition), * (Statistics, VertexType) => VertexType); */ var Tag = DBTypes.Where(type => type.Name == "Tag").FirstOrDefault(); var Website = DBTypes.Where(type => type.Name == "Website").FirstOrDefault(); #endregion #region insert some Websites by sending requests var cnn = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Website") .AddStructuredProperty("Name", "CNN") .AddStructuredProperty("URL", "http://cnn.com/"), (Statistics, Result) => Result); var xkcd = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Website") .AddStructuredProperty("Name", "xkcd") .AddStructuredProperty("URL", "http://xkcd.com/"), (Statistics, Result) => Result); var onion = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Website") .AddStructuredProperty("Name", "onion") .AddStructuredProperty("URL", "http://theonion.com/"), (Statistics, Result) => Result); //adding an unknown property means the property isn't defined before var test = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Website") .AddStructuredProperty("Name", "Test") .AddStructuredProperty("URL", "") .AddUnknownProperty("Unknown", "unknown property"), (Statistics, Result) => Result); #endregion #region insert some Tags by sending requests //insert a "Tag" with an OutgoingEdge to a "Website" include that the GraphDB creates an IncomingEdge on the given Website instances //(because we created an IncomingEdge on type "Website") --> as a consequence we never have to set any IncomingEdge var good = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Tag") .AddStructuredProperty("Name", "good") .AddEdge(new EdgePredefinition("TaggedWebsites") .AddVertexID(Website.ID, cnn.VertexID) .AddVertexID(Website.ID, xkcd.VertexID)), (Statistics, Result) => Result); var funny = GraphDSServer.Insert <IVertex>(SecToken, TransationID, new RequestInsertVertex("Tag") .AddStructuredProperty("Name", "funny") .AddEdge(new EdgePredefinition("TaggedWebsites") .AddVertexID(Website.ID, xkcd.VertexID) .AddVertexID(Website.ID, onion.VertexID)), (Statistics, Result) => Result); #endregion #region how to get a type from the DB, properties of the type, instances of a specific type and read out property values //how to get a type from the DB var TagDBType = GraphDSServer.GetVertexType <IVertexType>(SecToken, TransationID, new RequestGetVertexType(Tag.ID), (Statistics, Type) => Type); //read informations from type var typeName = TagDBType.Name; //are there other types wich extend the type "Tag" var hasChildTypes = TagDBType.HasChildTypes; //get the definition of the property "Name" var propName = TagDBType.GetPropertyDefinition("Name"); //how to get all instances of a type from the DB var TagInstances = GraphDSServer.GetVertices(SecToken, TransationID, new RequestGetVertices(TagDBType.ID), (Statistics, Vertices) => Vertices); foreach (var item in TagInstances) { //to get the value of a property of an instance, you need the property ID //(that's why we fetched the type from DB an read out the property definition of property "Name") var name = item.GetPropertyAsString(propName.ID); } #endregion }
/// <summary> /// Describes how to define a type with user defined properties and indices and create some instances by using GraphDB requests. /// </summary> private void GraphDBRequests() { #region define type "Tag" //create a VertexTypePredefinition var Tag_VertexTypePredefinition = new VertexTypePredefinition("Tag"); //create property var PropertyName = new PropertyPredefinition("Name") .SetAttributeType("String") .SetComment("This is a property on type 'Tag' named 'Name' and is of type 'String'"); //add property Tag_VertexTypePredefinition.AddProperty(PropertyName); //create outgoing edge to "Website" var OutgoingEdgesTaggedWebsites = new OutgoingEdgePredefinition("TaggedWebsites") .SetAttributeType("Website") .SetMultiplicityAsMultiEdge() .SetComment(@"This is an outgoing edge on type 'Tag' wich points to the type 'Website' (the AttributeType) and is defined as 'MultiEdge', which means that this edge can contain multiple single edges"); //add outgoing edge Tag_VertexTypePredefinition.AddOutgoingEdge(OutgoingEdgesTaggedWebsites); #endregion #region define type "Website" //create a VertexTypePredefinition var Website_VertexTypePredefinition = new VertexTypePredefinition("Website"); //create properties PropertyName = new PropertyPredefinition("Name") .SetAttributeType("String") .SetComment("This is a property on type 'Website' named 'Name' and is of type 'String'"); var PropertyUrl = new PropertyPredefinition("URL") .SetAttributeType("String") .SetAsMandatory(); //add properties Website_VertexTypePredefinition.AddProperty(PropertyName); Website_VertexTypePredefinition.AddProperty(PropertyUrl); #region create an index on type "Website" on property "Name" //there are three ways to set an index on property "Name" //Beware: Use just one of them! //1. create an index definition and specifie the property- and type name var MyIndex = new IndexPredefinition("MyIndex").SetIndexType("MultipleValueIndex").AddProperty("Name").SetVertexType("Website"); //add index Website_VertexTypePredefinition.AddIndex((IndexPredefinition)MyIndex); //2. on creating the property definition of property "Name" call the SetAsIndexed() method, the GraphDB will create the index //PropertyName = new PropertyPredefinition("Name") // .SetAttributeType("String") // .SetComment("This is a property on type 'Website' with name 'Name' and is of type 'String'") // .SetAsIndexed(); //3. make a create index request, like creating a type //BEWARE: This statement must be execute AFTER the type "Website" is created. //var MyIndex = GraphDSServer.CreateIndex<IIndexDefinition>(SecToken, // TransToken, // new RequestCreateIndex( // new IndexPredefinition("MyIndex") // .SetIndexType("MultipleValueIndex") // .AddProperty("Name") // .SetVertexType("Website")), (Statistics, Index) => Index); #endregion //add IncomingEdge "Tags", the related OutgoingEdge is "TaggedWebsites" on type "Tag" Website_VertexTypePredefinition.AddIncomingEdge(new IncomingEdgePredefinition("Tags") .SetOutgoingEdge("Tag", "TaggedWebsites")); #endregion #region create types by sending requests //create the types "Tag" and "Website" var DBTypes = GraphDSServer.CreateVertexTypes<IEnumerable<IVertexType>>(SecToken, TransToken, new RequestCreateVertexTypes( new List<VertexTypePredefinition> { Tag_VertexTypePredefinition, Website_VertexTypePredefinition }), (Statistics, VertexTypes) => VertexTypes); /* * BEWARE: The following two operations won't work because the two types "Tag" and "Website" depending on each other, * because one type has an incoming edge to the other and the other one has an incoming edge, * so they cannot be created separate (by using create type), * they have to be created at the same time (by using create types) * * //create the type "Website" * var Website = GraphDSServer.CreateVertexType<IVertexType>(SecToken, * TransToken, * new RequestCreateVertexType(Website_VertexTypePredefinition), * (Statistics, VertexType) => VertexType); * * //create the type "Tag" * var Tag = GraphDSServer.CreateVertexType<IVertexType>(SecToken, * TransToken, * new RequestCreateVertexType(Tag_VertexTypePredefinition), * (Statistics, VertexType) => VertexType); */ var Tag = DBTypes.Where(type => type.Name == "Tag").FirstOrDefault(); var Website = DBTypes.Where(type => type.Name == "Website").FirstOrDefault(); #endregion #region insert some Websites by sending requests var cnn = GraphDSServer.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website") .AddStructuredProperty("Name", "CNN") .AddStructuredProperty("URL", "http://cnn.com/"), (Statistics, Result) => Result); var xkcd = GraphDSServer.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website") .AddStructuredProperty("Name", "xkcd") .AddStructuredProperty("URL", "http://xkcd.com/"), (Statistics, Result) => Result); var onion = GraphDSServer.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website") .AddStructuredProperty("Name", "onion") .AddStructuredProperty("URL", "http://theonion.com/"), (Statistics, Result) => Result); //adding an unknown property means the property isn't defined before var test = GraphDSServer.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Website") .AddStructuredProperty("Name", "Test") .AddStructuredProperty("URL", "") .AddUnknownProperty("Unknown", "unknown property"), (Statistics, Result) => Result); #endregion #region insert some Tags by sending requests //insert a "Tag" with an OutgoingEdge to a "Website" include that the GraphDB creates an IncomingEdge on the given Website instances //(because we created an IncomingEdge on type "Website") --> as a consequence we never have to set any IncomingEdge var good = GraphDSServer.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Tag") .AddStructuredProperty("Name", "good") .AddEdge(new EdgePredefinition("TaggedWebsites") .AddVertexID(Website.ID, cnn.VertexID) .AddVertexID(Website.ID, xkcd.VertexID)), (Statistics, Result) => Result); var funny = GraphDSServer.Insert<IVertex>(SecToken, TransToken, new RequestInsertVertex("Tag") .AddStructuredProperty("Name", "funny") .AddEdge(new EdgePredefinition("TaggedWebsites") .AddVertexID(Website.ID, xkcd.VertexID) .AddVertexID(Website.ID, onion.VertexID)), (Statistics, Result) => Result); #endregion #region how to get a type from the DB, properties of the type, instances of a specific type and read out property values //how to get a type from the DB var TagDBType = GraphDSServer.GetVertexType<IVertexType>(SecToken, TransToken, new RequestGetVertexType(Tag.ID), (Statistics, Type) => Type); //read informations from type var typeName = TagDBType.Name; //are there other types wich extend the type "Tag" var hasChildTypes = TagDBType.HasChildTypes; //get the definition of the property "Name" var propName = TagDBType.GetPropertyDefinition("Name"); //how to get all instances of a type from the DB var TagInstances = GraphDSServer.GetVertices(SecToken, TransToken, new RequestGetVertices(TagDBType.ID), (Statistics, Vertices) => Vertices); foreach (var item in TagInstances) { //to get the value of a property of an instance, you need the property ID //(that's why we fetched the type from DB an read out the property definition of property "Name") var name = item.GetPropertyAsString(propName.ID); } #endregion }
/// <summary> /// Adds a unique constraint /// </summary> /// <param name="myToBeAddedUniques"></param> /// <param name="myTransactionToken"></param> /// <param name="mySecurityToken"></param> private IEnumerable<IIndexDefinition> AddUniqueConstraint(RequestAlterVertexType myAlterVertexTypeRequest, TransactionToken myTransactionToken, SecurityToken mySecurityToken) { var indexDefs = new List<IIndexDefinition>(); var uniques = myAlterVertexTypeRequest.ToBeAddedUniques; if (!uniques.IsNotNullOrEmpty()) return indexDefs; foreach (var aUniqueConstraint in uniques) { var predef = new IndexPredefinition(); predef.AddProperty(aUniqueConstraint.Properties); predef.SetVertexType(myAlterVertexTypeRequest.VertexTypeName); indexDefs.Add(_indexManager.CreateIndex(predef, mySecurityToken, myTransactionToken)); } return indexDefs; }
/// <summary> /// Generates a index predefinition /// </summary> /// <param name="aIndex">The index definition by the gql</param> /// <returns>An IndexPredefinition</returns> private IndexPredefinition GenerateIndex(IndexDefinition aIndex, String myVertexType) { IndexPredefinition result; if (String.IsNullOrEmpty(aIndex.IndexName)) { result = new IndexPredefinition(); } else { result = new IndexPredefinition(aIndex.IndexName); } result.SetVertexType(myVertexType); if (!String.IsNullOrEmpty(aIndex.IndexType)) { result.SetIndexType(aIndex.IndexType); } foreach (var aIndexProperty in aIndex.IndexAttributeDefinitions) { result.AddProperty(aIndexProperty.IndexAttribute.ContentString); } if (aIndex.Options != null) { foreach (var aIndexOption in aIndex.Options) { result.AddOption(aIndexOption.Key, aIndexOption.Value); } } return result; }
/// <summary> /// Generates a index predefinition /// </summary> /// <param name="aIndex">The index definition by the gql</param> /// <returns>An IndexPredefinition</returns> private IndexPredefinition GenerateIndex(IndexDefinition aIndex) { IndexPredefinition result; if (String.IsNullOrEmpty(aIndex.IndexName)) { result = new IndexPredefinition(); } else { result = new IndexPredefinition(aIndex.IndexName); } if (!String.IsNullOrEmpty(aIndex.IndexType)) { result.SetIndexType(aIndex.IndexType); } result.SetEdition(aIndex.Edition); foreach (var aIndexProperty in aIndex.IndexAttributeDefinitions) { result.AddProperty(aIndexProperty.IndexAttribute.ContentString); } return result; }
private string CreateIndexName(IndexPredefinition myIndexDefinition, IVertexType vertexType) { var propNames = string.Join("AND", myIndexDefinition.Properties); int count = 0; string result; do { result = string.Join("_", "sones", propNames, vertexType.Name, count++); } while (_ownIndex.ContainsKey(result)); return result; }
public IIndexDefinition CreateIndex(IndexPredefinition myIndexDefinition, SecurityToken mySecurity, TransactionToken myTransaction, bool myIsUserDefined = true) { myIndexDefinition.CheckNull("myIndexDefinition"); if (myIndexDefinition.Name != null && myIndexDefinition.Name.StartsWith("sones")) throw new Exception("It is not allowed to add an index with a name, that starts with 'sones'."); var vertexType = _vertexTypeManager.ExecuteManager.GetVertexType(myIndexDefinition.VertexTypeName, myTransaction, mySecurity); var indexName = myIndexDefinition.Name ?? CreateIndexName(myIndexDefinition, vertexType); if (_ownIndex.ContainsKey(indexName)) //TODO a better exception here. throw new Exception("An index with that name already exists."); if (myIndexDefinition.Properties == null) throw new Exception("Index without properties is not allowed."); foreach (var prop in myIndexDefinition.Properties) { var propDef = vertexType.GetPropertyDefinition(prop); if (!vertexType.HasProperty(prop) || (propDef.RelatedType.ID != vertexType.ID && !HasIndex(propDef, mySecurity, myTransaction))) //TODO a better exception here. throw new Exception("The property is not defined on the vertex type " + vertexType.Name + ", it is defined on a parent type."); } var indexID = _idManager[(long)BaseTypes.Index].GetNextID(); var info = new VertexInformation((long)BaseTypes.Index, indexID, 0, myIndexDefinition.Edition); var typeClass = myIndexDefinition.TypeName ?? GetBestMatchingIndexName(false, false, false); var parameter = (_indexPluginParameter.ContainsKey(typeClass)) ? _indexPluginParameter[typeClass].PluginParameter : null; var options = ValidateOptions(myIndexDefinition.IndexOptions, typeClass); parameter = FillOptions(parameter, options); var index = _pluginManager.GetAndInitializePlugin<IIndex<IComparable, Int64>>(typeClass, parameter, indexID); var props = myIndexDefinition.Properties.Select(prop => new VertexInformation((long)BaseTypes.Property, vertexType.GetPropertyDefinition(prop).ID)).ToList(); var date = DateTime.UtcNow.ToBinary(); var indexVertex = BaseGraphStorageManager.StoreIndex( _vertexStore, info, indexName, myIndexDefinition.Comment, date, myIndexDefinition.TypeName, GetIsSingleValue(index), GetIsRangeValue(index), GetIsVersionedValue(index), true, myIndexDefinition.IndexOptions, new VertexInformation((long)BaseTypes.VertexType, vertexType.ID), null, props, mySecurity, myTransaction); _ownIndex.Add(indexName, indexID); _indices.Add(indexID, index); foreach (var childType in vertexType.GetDescendantVertexTypes()) { var childID = _idManager[(long)BaseTypes.Index].GetNextID(); var childName = CreateIndexName(myIndexDefinition, childType); var childIndex = _pluginManager.GetAndInitializePlugin<IIndex<IComparable, Int64>>(typeClass, parameter, childID); BaseGraphStorageManager.StoreIndex( _vertexStore, new VertexInformation((long)BaseTypes.Index, childID), childName, indexName, //we store the source index name as comment date, myIndexDefinition.TypeName, GetIsSingleValue(index), GetIsRangeValue(index), GetIsVersionedValue(index), false, myIndexDefinition.IndexOptions, new VertexInformation((long)BaseTypes.VertexType, childType.ID), info, props, mySecurity, myTransaction); _ownIndex.Add(childName, childID); _indices.Add(childID, childIndex); } var indexDefinition = BaseGraphStorageManager.CreateIndexDefinition(indexVertex, vertexType); _vertexTypeManager.ExecuteManager.CleanUpTypes(); var reloadedVertexType = _vertexTypeManager.ExecuteManager.GetVertexType(vertexType.Name, myTransaction, mySecurity); foreach(var type in reloadedVertexType.GetDescendantVertexTypesAndSelf()) { RebuildIndices(type, myTransaction, mySecurity); } return indexDefinition; }
public RequestCreateIndex(IndexPredefinition myIndexDefinition) { IndexDefinition = myIndexDefinition; }