internal ServiceVertexInformation(VertexInformation myVertexInformation) { VertexTypeIDField = myVertexInformation.VertexTypeID; VertexIDField = myVertexInformation.VertexID; VertexRevisionIDField = myVertexInformation.VertexRevisionID; VertexEditionNameField = myVertexInformation.VertexEditionName ?? String.Empty; }
public Boolean Equals(VertexInformation p) { // If parameter is null return false: if ((object)p == null) { return(false); } return ((this.VertexID == p.VertexID) && (this.VertexTypeID == p.VertexTypeID) && (this.VertexEditionName == p.VertexEditionName) && (this.VertexRevisionID == p.VertexRevisionID)); }
/// <summary> /// Creates a new hyper edge definition /// </summary> /// <param name="myPropertyID">The property id of the edge</param> /// <param name="myEdgeTypeID">The id of this edge type</param> /// <param name="mySourceVertex">The source vertex of this hyper edge</param> /// <param name="myContainedSingleEdges">The single edges that are contained within this hyper edge</param> /// <param name="myComment">The comment on this graph element</param> /// <param name="myCreationDate">The creation date of this element</param> /// <param name="myModificationDate">The modification date of this element</param> /// <param name="myStructuredProperties">The structured properties of this element</param> /// <param name="myUnstructuredProperties">The unstructured properties of this element</param> public HyperEdgeAddDefinition( Int64 myPropertyID, Int64 myEdgeTypeID, VertexInformation mySourceVertex, IEnumerable <SingleEdgeAddDefinition> myContainedSingleEdges, String myComment, long myCreationDate, long myModificationDate, IDictionary <Int64, IComparable> myStructuredProperties, IDictionary <String, Object> myUnstructuredProperties) { PropertyID = myPropertyID; EdgeTypeID = myEdgeTypeID; SourceVertex = mySourceVertex; ContainedSingleEdges = myContainedSingleEdges; Comment = myComment; CreationDate = myCreationDate; ModificationDate = myModificationDate; StructuredProperties = myStructuredProperties; UnstructuredProperties = myUnstructuredProperties; }
/// <summary> /// Creates a new single edge definition /// </summary> /// <param name="myPropertyID">The id of the edge property</param> /// <param name="myEdgeTypeID">The id of this edge type</param> /// <param name="mySourceVertexInformation">The target vertex informantion</param> /// <param name="myTargetVertexInformation">The graph element properties</param> /// <param name="myComment">The comment on this graph element</param> /// <param name="myCreationDate">The creation date of this element</param> /// <param name="myModificationDate">The modification date of this element</param> /// <param name="myStructuredProperties">The structured properties of this element</param> /// <param name="myUnstructuredProperties">The unstructured properties of this element</param> public SingleEdgeAddDefinition( Int64 myPropertyID, Int64 myEdgeTypeID, VertexInformation mySourceVertexInformation, VertexInformation myTargetVertexInformation, String myComment, long myCreationDate, long myModificationDate, IDictionary <Int64, IComparable> myStructuredProperties, IDictionary <String, Object> myUnstructuredProperties) { PropertyID = myPropertyID; EdgeTypeID = myEdgeTypeID; SourceVertexInformation = mySourceVertexInformation; TargetVertexInformation = myTargetVertexInformation; Comment = myComment; CreationDate = myCreationDate; ModificationDate = myModificationDate; StructuredProperties = myStructuredProperties; UnstructuredProperties = myUnstructuredProperties; }
public void AddNodeAndBackwardEdge(LevelKey myPath, IVertex aVertex, EdgeKey backwardDirection, VertexInformation backwardDestination, IComparable EdgeWeight, IComparable NodeWeight) { lock (_Content) { var node = GenerateVertexInfoFromLevelKeyAndVertexID(aVertex.VertexTypeID, aVertex.VertexID); if (_Content.ContainsKey(myPath)) { //the level exists if (_Content[myPath].Nodes.ContainsKey(node)) { //Node exists _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight); } else { //Node does not exist _Content[myPath].Nodes.Add(node, new ExpressionNode(aVertex, NodeWeight, node)); _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight); } } else { HashSet<IExpressionEdge> backwardEdges = new HashSet<IExpressionEdge>() { new ExpressionEdge(backwardDestination, EdgeWeight, backwardDirection) }; _Content.Add(myPath, new ExpressionLevelEntry(myPath)); _Content[myPath].Nodes.Add(node, new ExpressionNode(aVertex, NodeWeight, node)); _Content[myPath].Nodes[node].AddBackwardEdge(backwardDirection, backwardDestination, EdgeWeight); } } }
/// <summary> /// Converts an enumerable of SingleLink into an enumerable of SingleEdgeAddDefinition. /// </summary> /// <param name="mySingleLinks">The enumerable of SingleLink instances to be converted.</param> /// <param name="myVertextype">The vertex type, that is used to get the property id.</param> /// <param name="mySource">The vertex information of the source vertex.</param> /// <returns>An enumerable of SingleEdgeAddDefinition one definition per SingleLink instance.</returns> /// <exception cref="NullReferenceException">If <paramref name="mySingleLinks"/> or <paramref name="myVertextype"/> is <c>Null</c>.</exception> private IEnumerable<SingleEdgeAddDefinition> ConvertSingleEdges(List<SingleLink> mySingleLinks, InternVertexType myVertextype, VertexInformation mySource) { List<SingleEdgeAddDefinition> result = new List<SingleEdgeAddDefinition>(); foreach (var singleLink in mySingleLinks) { var propID = myVertextype.Attributes[singleLink.Key]; result.Add(ConvertLink(singleLink.Link, propID, mySource)); } return result; }
private SingleEdgeAddDefinition? CreateSingleEdgeAddDefinition( Int64 myTransaction, SecurityToken mySecurity, long date, long myAttributeID, EdgePredefinition edgeDef, IEdgeType myEdgeType, VertexInformation source, IOutgoingEdgeDefinition attrDef) { AddDefaultPropertiesToEdgePredefinition(ref edgeDef, attrDef, date); var vertexIDs = GetResultingVertexIDs(myTransaction, mySecurity, edgeDef, attrDef.TargetVertexType); if (vertexIDs == null) return null; CheckTargetVertices(attrDef.TargetVertexType, vertexIDs); //adds the basic attributes like CreationDate, ModificationDate ... to the structured properties AddDefaultValues(ref edgeDef, myEdgeType); return new SingleEdgeAddDefinition(myAttributeID, myEdgeType.ID, source, vertexIDs.First(), edgeDef.Comment, date, date, ConvertStructuredProperties(edgeDef, myEdgeType), edgeDef.UnstructuredProperties); }
private HyperEdgeAddDefinition? CreateMultiEdgeAddDefinition( Int64 myTransaction, SecurityToken mySecurity, VertexInformation source, long date, EdgePredefinition edgeDef, IOutgoingEdgeDefinition attrDef) { var vertexIDs = GetResultingVertexIDs(myTransaction, mySecurity, edgeDef, attrDef.TargetVertexType); var contained = CreateContainedEdges(myTransaction, mySecurity, date, vertexIDs, edgeDef, attrDef, source); if (contained == null) return null; return new HyperEdgeAddDefinition(attrDef.ID, attrDef.EdgeType.ID, source, contained, edgeDef.Comment, date, date, ConvertStructuredProperties(edgeDef, attrDef.InnerEdgeType), edgeDef.UnstructuredProperties); }
private Tuple<long?, VertexAddDefinition> RequestInsertVertexToVertexAddDefinition(RequestInsertVertex myInsertDefinition, IVertexType myVertexType, Int64 myTransaction, SecurityToken mySecurity) { long vertexID = (myInsertDefinition.VertexUUID.HasValue) ? myInsertDefinition.VertexUUID.Value : _idManager.GetVertexTypeUniqeID(myVertexType.ID).GetNextID(); var source = new VertexInformation(myVertexType.ID, vertexID); long creationdate = DateTime.UtcNow.ToBinary(); long modificationDate = creationdate; String comment = myInsertDefinition.Comment; String edition = myInsertDefinition.Edition; long? revision = null; IEnumerable<SingleEdgeAddDefinition> singleEdges; IEnumerable<HyperEdgeAddDefinition> hyperEdges; CreateEdgeAddDefinitions(myInsertDefinition.OutgoingEdges, myVertexType, myTransaction, mySecurity, source, creationdate, out singleEdges, out hyperEdges); var binaries = (myInsertDefinition.BinaryProperties == null) ? null : myInsertDefinition.BinaryProperties.Select(x => new StreamAddDefinition(myVertexType.GetAttributeDefinition(x.Key).ID, x.Value)); var structured = ConvertStructuredProperties(myInsertDefinition, myVertexType); ExtractVertexProperties(ref edition, ref revision, ref comment, ref vertexID, ref creationdate, ref modificationDate, structured); //set id to maximum to allow user set UUIDs _idManager.GetVertexTypeUniqeID(myVertexType.ID).SetToMaxID(vertexID); return Tuple.Create(revision, new VertexAddDefinition(vertexID, myVertexType.ID, edition, hyperEdges, singleEdges, null, binaries, comment, creationdate, modificationDate, structured, myInsertDefinition.UnstructuredProperties)); }
private IEnumerable<SingleEdgeDeleteDefinition> CreateSingleEdgeDeleteDefinitions(VertexInformation mySource, Int64 myTransaction, SecurityToken mySecurity, EdgePredefinition myEdge, IOutgoingEdgeDefinition edgeDef) { List<SingleEdgeDeleteDefinition> result = new List<SingleEdgeDeleteDefinition>(); switch (edgeDef.Multiplicity) { case EdgeMultiplicity.HyperEdge: break; case EdgeMultiplicity.MultiEdge: var targets = GetResultingVertexIDs(myTransaction, mySecurity, myEdge, edgeDef.TargetVertexType); if (targets != null) foreach (var target in targets) { result.Add(new SingleEdgeDeleteDefinition(mySource, target)); } foreach (var innerEdge in myEdge.ContainedEdges) { targets = GetResultingVertexIDs(myTransaction, mySecurity, innerEdge, edgeDef.TargetVertexType); if (targets != null) foreach (var target in targets) { result.Add(new SingleEdgeDeleteDefinition(mySource, target)); } } break; default: throw new Exception("The EdgeMultiplicity enumeration was changed, but not this switch statement."); } return result; }
private SingleEdgeAddDefinition? CreateSingleEdgeAddDefinition( TransactionToken myTransaction, SecurityToken mySecurity, long date, long myAttributeID, EdgePredefinition edgeDef, IEdgeType myEdgeType, VertexInformation source, IVertexType myTargetType = null) { var vertexIDs = GetResultingVertexIDs(myTransaction, mySecurity, edgeDef, myTargetType); if (vertexIDs == null) return null; CheckMandatoryConstraint(edgeDef, myEdgeType); CheckTargetVertices(myTargetType, vertexIDs); AddDefaultValues(edgeDef, myEdgeType); return new SingleEdgeAddDefinition(myAttributeID, myEdgeType.ID, source, vertexIDs.First(), edgeDef.Comment, date, date, ConvertStructuredProperties(edgeDef, myEdgeType), edgeDef.UnstructuredProperties); }
/// <summary> /// /// </summary> /// <param name="myStore"></param> /// <param name="myVertexID"></param> /// <param name="myVertexTypeID"></param> /// <param name="myEdition"></param> /// <param name="myComment"></param> /// <param name="myEdges"></param> /// <param name="myStructuredProperties"></param> /// <param name="myUnstructuredProperties"></param> private static IVertex Store( IVertexStore myStore, VertexInformation mySource, String myComment, Int64 myCreationDate, IDictionary<Tuple<Int64, Int64>, VertexInformation> mySingleEdges, IDictionary<Tuple<Int64, Int64>, IEnumerable<VertexInformation>> myHyperEdges, IDictionary<Int64, IComparable> myStructuredProperties, IDictionary<String, Object> myUnstructuredProperties, SecurityToken mySecurity, TransactionToken myTransaction) { VertexAddDefinition def = new VertexAddDefinition( mySource.VertexID, mySource.VertexTypeID, mySource.VertexEditionName, CreateHyperEdgeDefinitions(myHyperEdges, mySource, myCreationDate), CreateSingleEdgeDefinitions(mySingleEdges, mySource, myCreationDate), null, null, myComment, myCreationDate, myCreationDate, myStructuredProperties, myUnstructuredProperties); return myStore.AddVertex(mySecurity, myTransaction, def); }
/// <summary> /// /// </summary> /// <param name="myEdges"></param> /// <param name="myVertexID"></param> /// <param name="myVertexTypeID"></param> /// <param name="myCreationDate"></param> /// <returns></returns> private static IEnumerable<HyperEdgeAddDefinition> CreateHyperEdgeDefinitions( IDictionary<Tuple<Int64, Int64>, IEnumerable<VertexInformation>> myEdges, VertexInformation mySource, Int64 myCreationDate) { if (myEdges == null) return null; List<HyperEdgeAddDefinition> result = new List<HyperEdgeAddDefinition>(myEdges.Count); long edgeID; long edgeTypeID; foreach (var edge in myEdges) { edgeID = edge.Key.Item1; edgeTypeID = edge.Key.Item2; var singleEdges = (edge.Value == null) ? null : edge.Value.Select((vertexInfo, pos) => new SingleEdgeAddDefinition( edgeID, edgeTypeID, mySource, vertexInfo, null, myCreationDate, myCreationDate, (edge.Value is IList<VertexInformation>) ? new Dictionary<long, IComparable> { { (long)AttributeDefinitions.OrderableEdgeDotOrder, pos }, } : null, null)).ToArray(); result.Add( new HyperEdgeAddDefinition( edgeID, edgeTypeID, mySource, singleEdges, null, myCreationDate, myCreationDate, null, null )); } return result; }
public static IVertex StoreVertexType( IVertexStore myStore, VertexInformation myVertex, BaseTypes myType, String myComment, Int64 myCreationDate, bool myIsAbstract, bool myIsSealed, bool myIsUserDefined, VertexInformation? myParent, IEnumerable<VertexInformation> myUniques, SecurityToken mySecurity, TransactionToken myTransaction) { return StoreVertexType(myStore, myVertex, myType.ToString(), myComment, myCreationDate, myIsAbstract, myIsSealed, myIsUserDefined, myParent, myUniques, mySecurity, myTransaction); }
/// <summary> /// Converts an enumerable of MultiLink into an enumerable of HyperEdgeAddDefinition. /// </summary> /// <param name="myMultiLinks">The enumerable of MultiLink instances that will be converted.</param> /// <param name="myVertextype">The vertex type, that is used to get the property id.</param> /// <param name="mySource">The vertex information of the source vertex.</param> /// <returns>An enumerable of HyperEdgeAddDefinition one definition per MultiLink instance.</returns> /// <exception cref="NullReferenceException">If <paramref name="myMultiLinks"/> or <paramref name="myVertextype"/> is <c>Null</c>.</exception> private IEnumerable<HyperEdgeAddDefinition> ConvertOutgoingEdges(List<MultiLink> myMultiLinks, InternVertexType myVertextype, VertexInformation mySource) { List<HyperEdgeAddDefinition> result = new List<HyperEdgeAddDefinition>(); foreach (var multiLink in myMultiLinks) { var propID = myVertextype.Attributes[multiLink.Key]; var date = DateTime.UtcNow.ToBinary(); var add = new HyperEdgeAddDefinition(propID, _edgeTypes[propID], mySource, multiLink.Links.Select(_ => ConvertLink(_, propID, mySource)), null, date, date, null, null); result.Add(add); } return result; }
/// <summary> /// Converts an instance of Link into an instance of SingleEdgeAddDefinition. /// </summary> /// <param name="myLink">An instance of Link that will be converted.</param> /// <param name="myPropertyID">The property id of the outgoing edge attribute.</param> /// <param name="mySource">The vertex information of the source vertex.</param> /// <returns>An instance of SingleEdgeAddDefinition.</returns> /// <exception cref="NullReferenceException">If <paramref name="myLink"/> is <c>Null</c>.</exception> private SingleEdgeAddDefinition ConvertLink(Link myLink, long myPropertyID, VertexInformation mySource) { var target = ConvertVertexID(myLink.TargetID); var comment = ExtractComment(myLink.Values); var creation = ExtractCreationDate(myLink.Values); var modification = ExtractModificationDate(myLink.Values); return new SingleEdgeAddDefinition(myPropertyID, _edgeTypes[myPropertyID], mySource, target, comment, creation, modification, null, null); }
private void AddNodeRecursiveBackward(IVertex myNewVertex, VertexInformation mySourceUUID, LevelKey mySourceLevelKey, LevelKey myNewNodeLevelKey, List<LevelKey> lowerLevelKeys, IExpressionGraph myGraph) { lock (myGraph) { //took the vertextype id of the levelkey, because it is possible that the vertextypeid of the vertex is something inheritated VertexInformation node = GenerateVertexInfoFromLevelKeyAndVertexID(myNewVertex.VertexTypeID, myNewVertex.VertexID); #region add node //add node and the node's backwardEdge //in this point we are shure that the level reall exists if (!myGraph.Levels[myNewNodeLevelKey.Level].ExpressionLevels[myNewNodeLevelKey].Nodes.ContainsKey(node)) { myGraph.Levels[myNewNodeLevelKey.Level].ExpressionLevels[myNewNodeLevelKey].Nodes.Add(node, new ExpressionNode(myNewVertex, null, node)); } myGraph.Levels[myNewNodeLevelKey.Level].AddForwardEdgeToNode(myNewNodeLevelKey, node, mySourceLevelKey.LastEdge, mySourceUUID, null); #endregion #region recursion if (lowerLevelKeys != null) { UpdateLowerLevels(myGraph.Levels[myNewNodeLevelKey.Level].ExpressionLevels[myNewNodeLevelKey].Nodes[node], myNewNodeLevelKey, lowerLevelKeys, myGraph); } #endregion } }
public static IVertex StoreVertexType( IVertexStore myStore, VertexInformation myVertex, String myName, String myComment, Int64 myCreationDate, bool myIsAbstract, bool myIsSealed, bool myIsUserDefined, VertexInformation? myParent, IEnumerable<VertexInformation> myUniques, SecurityToken mySecurity, TransactionToken myTransaction) { return Store( myStore, myVertex, myComment, myCreationDate, (myParent == null) ? null : new Dictionary<Tuple<long, long>, VertexInformation> { { _EdgeVertexTypeDotParent, myParent.Value }, }, myUniques == (null) ? null : new Dictionary<Tuple<long, long>, IEnumerable<Library.Commons.VertexStore.Definitions.VertexInformation>> { {_EdgeVertexTypeDotUniqueDefinitions, myUniques } }, new Dictionary<long, IComparable> { { (long) AttributeDefinitions.BaseTypeDotName, myName }, { (long) AttributeDefinitions.BaseTypeDotIsUserDefined, myIsUserDefined }, { (long) AttributeDefinitions.BaseTypeDotIsAbstract, myIsAbstract }, { (long) AttributeDefinitions.BaseTypeDotIsSealed, myIsSealed }, //{ (long) AttributeDefinitions.Behaviour, null }, }, null, mySecurity, myTransaction); }
/* /// <summary> /// The entry point for the execution of an <GQL> tag. /// </summary> /// <param name="myGQLReader">An XmlReader, that is positioned before an <GQL> tag.</param> private void ExecuteGql(XmlReader myGQLReader) { _logger.Log(Level.FINE, "ExecuteGql started."); // if no xml is available, we have nothing to do. if (myGQLReader == null) //TODO: log something; return; try { myGQLReader.MoveToContent(); if (!CheckIsGqlElement(myGQLReader)) return ; String gql = null; while (myGQLReader.MoveToNextAttribute()) { switch (myGQLReader.LocalName) { case "Query": gql = myGQLReader.ReadContentAsString(); break; default: //TODO: log something break; } } if (gql == null) //TODO log something; return; var result = _ql.Query(_security, _transaction, gql); } finally { if (!_closed) myGQLReader.Close(); _logger.Log(Level.FINE, "ExecuteGql finished."); } } /// <summary> /// Logs the result of the import as Info. /// </summary> /// <param name="myResult"></param> private void logQueryResult(IQueryResult myResult) { throw new NotImplementedException(); } */ /// <summary> /// The entry point for the execution of an <Insert> tag. /// </summary> /// <param name="myInsertReader">An XmlReader, that is positioned before an <Insert> tag.</param> private void ExecuteInsert(XmlReader myInsertReader) { _logger.Log(Level.FINE, "ExecuteInsert started."); // if no xml is available, we have nothing to do. if (myInsertReader == null) //TODO: log something; return; try { myInsertReader.MoveToContent(); if (!CheckIsInsertElement(myInsertReader)) return; String vertexTypeName = null; long? id = null; while (myInsertReader.MoveToNextAttribute()) { switch (myInsertReader.LocalName) { case VertexTypeAttribute: vertexTypeName = myInsertReader.ReadContentAsString(); break; case VertexIDAttribute: id = myInsertReader.ReadContentAsLong(); break; default: //TODO: log something break; } } if (vertexTypeName == null) //TODO: log something; return; if (!id.HasValue) //TODO: log something; return; IDictionary<String, String> values = new Dictionary<String, String>(); List<SingleLink> singleLinks = new List<SingleLink>(); List<MultiLink> multiLinks = new List<MultiLink>(); while (!_closed && myInsertReader.Read()) { if (CheckIsElement(myInsertReader)) { var nextReader = myInsertReader.ReadSubtree(); switch (myInsertReader.LocalName) { case SetValueTag: var value = ExecuteSetValue(nextReader); if (value.HasValue) values.Add(value.Value); break; case SingleLinkTag: var singleLink = ExecuteSingleLink(nextReader); if (singleLink != null) singleLinks.Add(singleLink); break; case MultiLinkTag: var multiLink = ExecuteMultiLink(nextReader); if (multiLink != null) multiLinks.Add(multiLink); break; default: //TODO: log something break; } } } var vertextype = RetrieveVertexType(vertexTypeName); var vertexTypeID = vertextype.ID; var vertexID = id.Value; var edition = ExtractEdition(values); var comment = ExtractComment(values); var creation = ExtractCreationDate(values); var modification = ExtractModificationDate(values); var structured = ConvertStructuredProperties(values, vertextype); var unstructured = ConvertUnstructuredProperties(values); var source = new VertexInformation(vertexTypeID, vertexID); var hyper = ConvertOutgoingEdges(multiLinks, vertextype, source); var single = ConvertSingleEdges(singleLinks, vertextype, source); var forResultingFS = new VertexAddDefinition(vertexID, vertexTypeID, edition, hyper, single, null, null, comment, creation, modification, structured, unstructured); if(!_autoCreateIncomingEdges) AddEdgesToSorter(hyper, single); _resultingFS.AddVertex(_security, _transaction, forResultingFS, myCreateAutoIncomingEdges: _autoCreateIncomingEdges); } catch (Exception ex) { IXmlLineInfo info = myInsertReader as IXmlLineInfo; if (info != null && info.HasLineInfo()) { var line = info.LineNumber; var pos = info.LinePosition; _logger.Log(Level.INFO, "Exception thrown while reading line {0} position {1}.", line, pos); } #if DEBUG for (var current = ex; current != null; current = current.InnerException) { _logger.Log(Level.SEVERE, "An exception was thrown:{0}\n{1}", current.GetType().FullName, current.StackTrace.ToString()); } #else _logger.Log(Level.SEVERE, "An exception was thrown:\n{0}", ex); #endif } finally { _logger.Log(Level.FINE, "ExecuteGql finished."); if (!_closed) myInsertReader.Close(); } }
private static IEnumerable<SingleEdgeAddDefinition> CreateSingleEdgeDefinitions( IDictionary<Tuple<long, long>, VertexInformation> mySingleEdges, VertexInformation mySource, long myCreationDate) { if (mySingleEdges == null) return null; List<SingleEdgeAddDefinition> result = new List<SingleEdgeAddDefinition>(mySingleEdges.Count); long edgeID; long edgeTypeID; foreach (var edge in mySingleEdges) { edgeID = edge.Key.Item1; edgeTypeID = edge.Key.Item2; result.Add( new SingleEdgeAddDefinition( edgeID, edgeTypeID, mySource, edge.Value, null, myCreationDate, myCreationDate, null, null)); } return result; }
private static void CleanLowerLevel(LevelKey myLevelKey, IExpressionGraph myGraph, IGraphDB myGraphDB, SecurityToken mySecurityToken, Int64 myTransactionToken) { if (myLevelKey.Level > 0) { var previousLevelKey = myLevelKey.GetPredecessorLevel(myGraphDB, mySecurityToken, myTransactionToken); HashSet<VertexInformation> toBeDeletedNodes = new HashSet<VertexInformation>(); foreach (var aLowerDBO in myGraph.Select(previousLevelKey, null, false)) { if (aLowerDBO.HasOutgoingEdge(myLevelKey.LastEdge.AttributeID)) { foreach (var aVertex in aLowerDBO.GetOutgoingEdge(myLevelKey.LastEdge.AttributeID).GetTargetVertices()) { //took the vertextype id of the levelkey, because it is possible that the vertextypeid of the vertex is something inheritated VertexInformation node = new VertexInformation(aVertex.VertexTypeID, aVertex.VertexID); if (!myGraph.GetLevel(myLevelKey.Level).ExpressionLevels[myLevelKey].Nodes.ContainsKey(node)) { //a reference occurred that is not in the higher level --> found a Zoidberg toBeDeletedNodes.Add(node); break; } } } } foreach (var aToBeDeletedNode in toBeDeletedNodes) { myGraph.GetLevel(previousLevelKey.Level).RemoveNode(previousLevelKey, aToBeDeletedNode); } } }
private IEnumerable<SingleEdgeAddDefinition> CreateContainedEdges( TransactionToken myTransaction, SecurityToken mySecurity, long myDate, IEnumerable<VertexInformation> vertexIDs, EdgePredefinition edgeDef, IOutgoingEdgeDefinition attrDef, VertexInformation mySource) { if ((vertexIDs == null || vertexIDs.Count() == 0) && (edgeDef.ContainedEdges == null || edgeDef.ContainedEdges.Count() == 0)) return null; List<SingleEdgeAddDefinition> result = new List<SingleEdgeAddDefinition>(); if (vertexIDs != null) { foreach (var vertex in vertexIDs) { //single edges from VertexIDs or expression does not have user properties //TODO they can have default values CheckMandatoryConstraint(null, attrDef.InnerEdgeType); result.Add(new SingleEdgeAddDefinition(Int64.MinValue, attrDef.InnerEdgeType.ID, mySource, vertex, null, myDate, myDate, null, null)); } } if (edgeDef.ContainedEdges != null) { foreach (var edge in edgeDef.ContainedEdges) { if (edge.ContainedEdges != null) //TODO a better exception here throw new Exception("An edge within a multi edge cannot have contained edges."); var toAdd = CreateSingleEdgeAddDefinition(myTransaction, mySecurity, myDate, Int64.MinValue, edge, attrDef.InnerEdgeType, mySource, attrDef.TargetVertexType); if (toAdd.HasValue) result.Add(toAdd.Value); } } return result; }
public static IVertex StoreBasicType( IVertexStore myStore, VertexInformation myVertex, String myName, bool myIsUserDefined, String myComment, Int64 myCreationDate, SecurityToken mySecurity, TransactionToken myTransaction) { return Store( myStore, myVertex, myComment, myCreationDate, null, null, new Dictionary<long, IComparable> { { (long) AttributeDefinitions.BaseTypeDotName, myName }, { (long) AttributeDefinitions.BaseTypeDotIsUserDefined, myIsUserDefined }, { (long) AttributeDefinitions.BaseTypeDotIsAbstract, false }, { (long) AttributeDefinitions.BaseTypeDotIsSealed, true }, //{ (long) AttributeDefinitions.Behaviour, null }, }, null, mySecurity, myTransaction); }
private Tuple<long?, String, VertexUpdateDefinition> CreateVertexUpdateDefinition( IVertex myVertex, IVertexType myVertexType, RequestUpdate myUpdate, IPropertyProvider myPropertyCopy, Int64 myTransaction, SecurityToken mySecurity) { #region get removes List<long> toBeDeletedSingle = null; List<long> toBeDeletedHyper = null; List<long> toBeDeletedStructured = null; List<String> toBeDeletedUnstructured = null; List<long> toBeDeletedBinaries = null; if (myUpdate.RemovedAttributes != null) { #region remove each defined attribute foreach (var name in myUpdate.RemovedAttributes) { if (myVertexType.HasAttribute(name)) { var attr = myVertexType.GetAttributeDefinition(name); switch (attr.Kind) { case AttributeType.Property: if ((attr as IPropertyDefinition).IsMandatory) throw new MandatoryConstraintViolationException(attr.Name); toBeDeletedStructured = toBeDeletedStructured ?? new List<long>(); toBeDeletedStructured.Add(attr.ID); break; case AttributeType.BinaryProperty: toBeDeletedBinaries = toBeDeletedBinaries ?? new List<long>(); toBeDeletedBinaries.Add(attr.ID); break; case AttributeType.IncomingEdge: //TODO: a better exception here. throw new Exception("The edges on an incoming edge attribute can not be removed."); case AttributeType.OutgoingEdge: switch ((attr as IOutgoingEdgeDefinition).Multiplicity) { case EdgeMultiplicity.HyperEdge: case EdgeMultiplicity.MultiEdge: toBeDeletedHyper = toBeDeletedHyper ?? new List<long>(); toBeDeletedHyper.Add(attr.ID); break; case EdgeMultiplicity.SingleEdge: toBeDeletedSingle = toBeDeletedSingle ?? new List<long>(); toBeDeletedSingle.Add(attr.ID); break; default: //TODO a better exception here throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement."); } break; default: //TODO: a better exception here. throw new Exception("The enumeration AttributeType was updated, but not this switch statement."); } } else { toBeDeletedUnstructured = toBeDeletedUnstructured ?? new List<String>(); toBeDeletedUnstructured.Add(name); } } #endregion } if (myUpdate.RemovedUnstructuredProperties != null) { #region remove each unstructured property foreach (var name in myUpdate.RemovedUnstructuredProperties) { if ((myVertexType.HasAttribute(name)) && (myVertexType.GetAttributeDefinition(name).Kind == AttributeType.Property)) { toBeDeletedUnstructured = toBeDeletedUnstructured ?? new List<String>(); toBeDeletedUnstructured.Add(name); } } #endregion } #endregion #region get update definitions IDictionary<Int64, HyperEdgeUpdateDefinition> toBeUpdatedHyper = null; IDictionary<Int64, SingleEdgeUpdateDefinition> toBeUpdatedSingle = null; IDictionary<Int64, IComparable> toBeUpdatedStructured = null; IDictionary<String, Object> toBeUpdatedUnstructured = null; IDictionary<Int64, StreamAddDefinition> toBeUpdatedBinaries = null; long? revision = null; string edition = myUpdate.UpdatedEdition; string comment = myUpdate.UpdatedComment; #region property copy things if (myPropertyCopy.StructuredProperties != null) { toBeUpdatedStructured = new Dictionary<long, IComparable>(); foreach (var prop in myPropertyCopy.StructuredProperties) { var propDef = myVertexType.GetPropertyDefinition(prop.Key); CheckPropertyType(myVertexType.Name, prop.Value, propDef); toBeUpdatedStructured.Add(propDef.ID, prop.Value); } } toBeUpdatedUnstructured = myPropertyCopy.UnstructuredProperties; #endregion #region binary properties if (myUpdate.UpdatedBinaryProperties != null) { foreach (var prop in myUpdate.UpdatedBinaryProperties) { var propDef = myVertexType.GetBinaryPropertyDefinition(prop.Key); toBeUpdatedBinaries = toBeUpdatedBinaries ?? new Dictionary<long, StreamAddDefinition>(); toBeUpdatedBinaries.Add(propDef.ID, new StreamAddDefinition(propDef.ID, prop.Value)); } } #endregion #region collections if (myUpdate.AddedElementsToCollectionProperties != null || myUpdate.RemovedElementsFromCollectionProperties != null) { if (myUpdate.AddedElementsToCollectionProperties != null && myUpdate.RemovedElementsFromCollectionProperties != null) { var keys = myUpdate.AddedElementsToCollectionProperties.Keys.Intersect(myUpdate.RemovedElementsFromCollectionProperties.Keys); if (keys.CountIsGreater(0)) { //TOTO a better exception here throw new Exception("You can not add and remove items simultaneously on a collection attribute."); } if (myUpdate.AddedElementsToCollectionProperties != null) { foreach (var added in myUpdate.AddedElementsToCollectionProperties) { var propDef = myVertexType.GetPropertyDefinition(added.Key); var hasValue = (propDef == null) ? myVertex.HasUnstructuredProperty(added.Key) : myVertex.HasProperty(propDef.ID); //if it is not ICollectionWrapper something wrong with deserialization var extractedValue = (!hasValue) ? null : (propDef == null) ? myVertex.GetUnstructuredProperty<ICollectionWrapper>(added.Key) : (ICollectionWrapper)propDef.GetValue(myVertex); PropertyMultiplicity mult; if (propDef != null) { //check types only for structured properties foreach (var element in added.Value) { CheckPropertyType(myVertexType.Name, element, propDef); } mult = propDef.Multiplicity; } else mult = (added.Value is SetCollectionWrapper) ? PropertyMultiplicity.Set : PropertyMultiplicity.List; var newValue = CreateNewCollectionWrapper( (hasValue) ? extractedValue.Union(added.Value) : added.Value, mult); if (propDef == null) { toBeUpdatedUnstructured = toBeUpdatedUnstructured ?? new Dictionary<String, object>(); toBeUpdatedUnstructured.Add(added.Key, newValue); } else { toBeUpdatedStructured = toBeUpdatedStructured ?? new Dictionary<long, IComparable>(); toBeUpdatedStructured.Add(propDef.ID, newValue); } } } if (myUpdate.RemovedElementsFromCollectionProperties != null) { foreach (var remove in myUpdate.RemovedElementsFromCollectionProperties) { var propDef = myVertexType.GetPropertyDefinition(remove.Key); var hasValue = (propDef == null) ? myVertex.HasUnstructuredProperty(remove.Key) : myVertex.HasProperty(propDef.ID); //no value, nothing to remove if (!hasValue) continue; //if it is not ICollectionWrapper something wrong with deserialization var extractedValue = (propDef == null) ? myVertex.GetUnstructuredProperty<ICollectionWrapper>(remove.Key) : (ICollectionWrapper)propDef.GetValue(myVertex); PropertyMultiplicity mult = (propDef != null) ? propDef.Multiplicity : (extractedValue is SetCollectionWrapper) ? PropertyMultiplicity.Set : PropertyMultiplicity.List; var newValue = CreateNewCollectionWrapper(extractedValue.Except(remove.Value), mult); toBeUpdatedStructured.Add(propDef.ID, newValue); if (propDef == null) { toBeUpdatedUnstructured = toBeUpdatedUnstructured ?? new Dictionary<String, object>(); toBeUpdatedUnstructured.Add(remove.Key, newValue); } else { toBeUpdatedStructured = toBeUpdatedStructured ?? new Dictionary<long, IComparable>(); toBeUpdatedStructured.Add(propDef.ID, newValue); } } } } } #endregion #region extract vertex properties #region will be ignored long vertexID = 0L; long creationDate = 0L; long modificationDate = 0L; #endregion ExtractVertexProperties(ref edition, ref revision, ref comment, ref vertexID, ref creationDate, ref modificationDate, toBeUpdatedStructured); #endregion #region edge magic if (myUpdate.AddedElementsToCollectionEdges != null || myUpdate.RemovedElementsFromCollectionEdges != null || myUpdate.UpdateOutgoingEdges != null || myUpdate.UpdateOutgoingEdgesProperties != null) { VertexInformation source = new VertexInformation(myVertex.VertexTypeID, myVertex.VertexID); #region update outgoing edges if (myUpdate.UpdateOutgoingEdges != null) { foreach (var edge in myUpdate.UpdateOutgoingEdges) { var edgeDef = myVertexType.GetOutgoingEdgeDefinition(edge.EdgeName); switch (edgeDef.Multiplicity) { case EdgeMultiplicity.SingleEdge: { #region SingleEdge var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType); if (targets == null || !targets.CountIsGreater(0)) { toBeDeletedSingle = toBeDeletedSingle ?? new List<long>(); toBeDeletedSingle.Add(edgeDef.ID); } else if (targets.CountIsGreater(1)) { throw new Exception("Single edge can not have more than one target."); } else { ConvertUnknownProperties(edge, edgeDef.EdgeType); var structured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType); var unstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties); toBeUpdatedSingle = toBeUpdatedSingle ?? new Dictionary<long, SingleEdgeUpdateDefinition>(); toBeUpdatedSingle.Add(edgeDef.ID, new SingleEdgeUpdateDefinition(source, targets.First(), edgeDef.EdgeType.ID, edge.Comment, structured, unstructured)); } #endregion } break; case EdgeMultiplicity.MultiEdge: { #region MultiEdge // Why deleting the edge instances ??? // they will never be inserted inside the update !!! // After delete the update will be needless because the edges are deleted !!! //List<SingleEdgeDeleteDefinition> internSingleDelete = null; //if (myVertex.HasOutgoingEdge(edgeDef.ID)) //{ // internSingleDelete = new List<SingleEdgeDeleteDefinition>(); // foreach (var edgeInstance in myVertex.GetOutgoingHyperEdge(edgeDef.ID).GetTargetVertices()) // { // internSingleDelete.Add( // new SingleEdgeDeleteDefinition(source, // new VertexInformation(edgeInstance.VertexTypeID, // edgeInstance.VertexID))); // } //} List<SingleEdgeUpdateDefinition> internSingleUpdate = null; var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType); if (targets != null) { foreach (var target in targets) { internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>(); internSingleUpdate.Add(new SingleEdgeUpdateDefinition(source, target, edgeDef.InnerEdgeType.ID)); } } if (edge.ContainedEdges != null) { foreach (var innerEdge in edge.ContainedEdges) { targets = GetResultingVertexIDs(myTransaction, mySecurity, innerEdge, edgeDef.TargetVertexType); if (targets != null && targets.CountIsGreater(0)) { ConvertUnknownProperties(innerEdge, edgeDef.InnerEdgeType); var structured = CreateStructuredUpdate(innerEdge.StructuredProperties, edgeDef.InnerEdgeType); var unstructured = CreateUnstructuredUpdate(innerEdge.UnstructuredProperties); foreach (var target in targets) { internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>(); internSingleUpdate.Add( new SingleEdgeUpdateDefinition(source, target, edgeDef.InnerEdgeType.ID, innerEdge.Comment, structured, unstructured)); } } } } ConvertUnknownProperties(edge, edgeDef.EdgeType); var outerStructured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType); var outerUnstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties); toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>(); toBeUpdatedHyper.Add(edgeDef.ID, new HyperEdgeUpdateDefinition(edgeDef.EdgeType.ID, edge.Comment, outerStructured, outerUnstructured, null,//internSingleDelete, internSingleUpdate)); #endregion } break; case EdgeMultiplicity.HyperEdge: break; default: throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement."); } } } #endregion #region update outgoing edges properties if (myUpdate.UpdateOutgoingEdgesProperties != null) { foreach (var edge in myUpdate.UpdateOutgoingEdgesProperties) { var edgeDef = myVertexType .GetOutgoingEdgeDefinitions(true) .Where(_ => _.ID.Equals(edge.EdgeTypeID) || _.InnerEdgeType.ID.Equals(edge.EdgeTypeID)).FirstOrDefault(); switch (edgeDef.Multiplicity) { case EdgeMultiplicity.SingleEdge: { #region SingleEdge //var targets = GetResultingVertexIDs(myTransaction, mySecurity, edge, edgeDef.TargetVertexType); //if (targets == null || !targets.CountIsGreater(0)) //{ // toBeDeletedSingle = toBeDeletedSingle ?? new List<long>(); // toBeDeletedSingle.Add(edgeDef.ID); //} //else if (targets.CountIsGreater(1)) //{ // throw new Exception("Single edge can not have more than one target."); //} //else //{ // ConvertUnknownProperties(edge, edgeDef.EdgeType); // var structured = CreateStructuredUpdate(edge.StructuredProperties, edgeDef.EdgeType); // var unstructured = CreateUnstructuredUpdate(edge.UnstructuredProperties); // toBeUpdatedSingle = toBeUpdatedSingle ?? new Dictionary<long, SingleEdgeUpdateDefinition>(); // toBeUpdatedSingle.Add(edgeDef.ID, // new SingleEdgeUpdateDefinition(source, // targets.First(), // edgeDef.EdgeType.ID, // edge.Comment, // structured, // unstructured)); //} #endregion } break; case EdgeMultiplicity.MultiEdge: { #region MultiEdge List<SingleEdgeUpdateDefinition> internSingleUpdate = null; var targets = myVertex .GetOutgoingEdge(edgeDef.ID) .GetTargetVertices() .Select(_ => new VertexInformation(_.VertexTypeID, _.VertexID)); if (targets != null && targets.CountIsGreater(0)) { var structured = edge.UpdatedStructuredProperties; var unstructured = edge.UpdatedUnstructuredProperties; foreach (var target in targets) { internSingleUpdate = internSingleUpdate ?? new List<SingleEdgeUpdateDefinition>(); internSingleUpdate.Add( new SingleEdgeUpdateDefinition(source, target, edgeDef.InnerEdgeType.ID, edge.CommentUpdate, structured, unstructured)); } } toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>(); if (toBeUpdatedHyper.ContainsKey(edgeDef.ID)) { var temp = toBeUpdatedHyper[edgeDef.ID]; toBeUpdatedHyper.Remove(edgeDef.ID); toBeUpdatedHyper.Add(edgeDef.ID, MergeToBeAddedHyperEdgeUpdates(temp, internSingleUpdate)); } else toBeUpdatedHyper.Add(edgeDef.ID, new HyperEdgeUpdateDefinition(edgeDef.EdgeType.ID, null, null, null, null, internSingleUpdate)); #endregion } break; case EdgeMultiplicity.HyperEdge: break; default: throw new Exception("The enumeration EdgeMultiplicity was changed, but not this switch statement."); } } } #endregion #region update AddedElementsToCollectionEdges if (myUpdate.AddedElementsToCollectionEdges != null) { foreach (var hyperEdge in myUpdate.AddedElementsToCollectionEdges) { var edgeDef = myVertexType.GetOutgoingEdgeDefinition(hyperEdge.Key); if (edgeDef == null) //TODO a better exception here throw new Exception("edge attribute not defined."); if (edgeDef.Multiplicity == EdgeMultiplicity.SingleEdge) //TODO a better exception here throw new Exception("Add edges is only defined on hyper/multi edges."); var edgeTypeID = edgeDef.ID; StructuredPropertiesUpdate structuredUpdate; UnstructuredPropertiesUpdate unstructuredUpdate; IEnumerable<SingleEdgeUpdateDefinition> singleUpdate; CheckIfToBeAddedElementAlreadyExist(myVertex, edgeDef, hyperEdge.Value, myTransaction, mySecurity); CreateSingleEdgeUpdateDefinitions(source, myTransaction, mySecurity, hyperEdge.Value, edgeDef, out structuredUpdate, out unstructuredUpdate, out singleUpdate); toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>(); toBeUpdatedHyper.Add(edgeTypeID, new HyperEdgeUpdateDefinition(edgeTypeID, null, structuredUpdate, unstructuredUpdate, null, singleUpdate)); } } #endregion #region update RemovedElementsFromCollectionEdges if (myUpdate.RemovedElementsFromCollectionEdges != null) { foreach (var hyperEdge in myUpdate.RemovedElementsFromCollectionEdges) { var edgeDef = myVertexType.GetOutgoingEdgeDefinition(hyperEdge.Key); if (edgeDef == null) //TODO a better exception here throw new Exception("Edge attribute not defined."); if (edgeDef.Multiplicity == EdgeMultiplicity.SingleEdge) //TODO a better exception here throw new Exception("Removing edges is only defined on hyper/multi edges."); var edgeTypeID = edgeDef.ID; var del = CreateSingleEdgeDeleteDefinitions(source, myTransaction, mySecurity, hyperEdge.Value, edgeDef); toBeUpdatedHyper = toBeUpdatedHyper ?? new Dictionary<long, HyperEdgeUpdateDefinition>(); toBeUpdatedHyper.Add(edgeTypeID, new HyperEdgeUpdateDefinition(edgeTypeID, null, null, null, del, null)); } } #endregion } #endregion #region create updates var updateSingle = (toBeUpdatedSingle != null || toBeDeletedSingle != null) ? new SingleEdgeUpdate(toBeUpdatedSingle, toBeDeletedSingle) : null; var updateHyper = (toBeUpdatedHyper != null || toBeDeletedHyper != null) ? new HyperEdgeUpdate(toBeUpdatedHyper, toBeDeletedHyper) : null; var updateStructured = (toBeUpdatedStructured != null || toBeDeletedStructured != null) ? new StructuredPropertiesUpdate(toBeUpdatedStructured, toBeDeletedStructured) : null; var updateUnstructured = (toBeUpdatedUnstructured != null || toBeDeletedUnstructured != null) ? new UnstructuredPropertiesUpdate(toBeUpdatedUnstructured, toBeDeletedUnstructured) : null; var updateBinaries = (toBeUpdatedBinaries != null || toBeDeletedBinaries != null) ? new BinaryPropertiesUpdate(toBeUpdatedBinaries, toBeDeletedBinaries) : null; #endregion return Tuple.Create(revision, edition, new VertexUpdateDefinition(comment, updateStructured, updateUnstructured, updateBinaries, updateSingle, updateHyper)); }
public static void StoreEdgeType( IVertexStore myStore, VertexInformation myVertex, String myName, String myComment, bool myIsUserDefined, Int64 myCreationDate, bool myIsAbstract, bool myIsSealed, VertexInformation? myParent, SecurityToken mySecurity, TransactionToken myTransaction) { Store( myStore, myVertex, myComment, myCreationDate, (myParent == null) ? null : new Dictionary<Tuple<long, long>, VertexInformation> { { _EdgeEdgeTypeDotParent, myParent.Value }, }, null, new Dictionary<long, IComparable> { { (long) AttributeDefinitions.BaseTypeDotName, myName }, { (long) AttributeDefinitions.BaseTypeDotIsUserDefined, myIsUserDefined }, { (long) AttributeDefinitions.BaseTypeDotIsAbstract, myIsAbstract }, { (long) AttributeDefinitions.BaseTypeDotIsSealed, myIsSealed }, //{ (long) AttributeDefinitions.Behaviour, null }, }, null, mySecurity, myTransaction); }
private void CreateSingleEdgeUpdateDefinitions(VertexInformation mySource, Int64 myTransaction, SecurityToken mySecurity, EdgePredefinition myEdge, IOutgoingEdgeDefinition edgeDef, out StructuredPropertiesUpdate outStructuredUpdate, out UnstructuredPropertiesUpdate outUnstructuredUpdate, out IEnumerable<SingleEdgeUpdateDefinition> outSingleUpdate) { #region predefine List<SingleEdgeUpdateDefinition> singleUpdate = new List<SingleEdgeUpdateDefinition>(); #endregion outStructuredUpdate = null; outUnstructuredUpdate = null; switch (edgeDef.Multiplicity) { case EdgeMultiplicity.HyperEdge: break; case EdgeMultiplicity.MultiEdge: var targets = GetResultingVertexIDs(myTransaction, mySecurity, myEdge, edgeDef.TargetVertexType); if (targets != null) foreach (var target in targets) { singleUpdate.Add(new SingleEdgeUpdateDefinition(mySource, target, Int64.MinValue)); } if (myEdge.ContainedEdges != null) { foreach (var innerEdge in myEdge.ContainedEdges) { targets = GetResultingVertexIDs(myTransaction, mySecurity, innerEdge, edgeDef.TargetVertexType); ConvertUnknownProperties(innerEdge, edgeDef.InnerEdgeType); var innerStructuredUpdate = CreateStructuredUpdate(innerEdge.StructuredProperties, edgeDef.InnerEdgeType); var innerUnstructuredUpdate = CreateUnstructuredUpdate(innerEdge.UnstructuredProperties); if (targets != null) foreach (var target in targets) { singleUpdate.Add(new SingleEdgeUpdateDefinition(mySource, target, Int64.MinValue, null, innerStructuredUpdate, innerUnstructuredUpdate)); } } } outStructuredUpdate = CreateStructuredUpdate(myEdge.StructuredProperties, edgeDef.InnerEdgeType); outUnstructuredUpdate = CreateUnstructuredUpdate(myEdge.UnstructuredProperties); break; default: throw new Exception("The EdgeMultiplicity enumeration was changed, but not this switch statement."); } #region return outSingleUpdate = singleUpdate; #endregion }
public static void StoreIncomingEdge( IVertexStore myStore, VertexInformation myVertex, String myName, String myComment, bool myIsUserDefined, Int64 myCreationDate, VertexInformation myDefiningType, VertexInformation myRelatedIncomingEdge, SecurityToken mySecurity, TransactionToken myTransaction) { Store( myStore, myVertex, myComment, myCreationDate, new Dictionary<Tuple<long, long>, VertexInformation> { { _EdgeAttributeDotDefiningType, myDefiningType }, { _EdgeIncomingEdgeDotRelatedEdge, myRelatedIncomingEdge} }, null, new Dictionary<long, IComparable> { { (long) AttributeDefinitions.AttributeDotName, myName }, { (long) AttributeDefinitions.AttributeDotIsUserDefined, myIsUserDefined }, }, null, mySecurity, myTransaction); }
private void CreateEdgeAddDefinitions( IEnumerable<EdgePredefinition> myOutgoingEdges, IVertexType myVertexType, Int64 myTransaction, SecurityToken mySecurity, VertexInformation source, long date, out IEnumerable<SingleEdgeAddDefinition> outSingleEdges, out IEnumerable<HyperEdgeAddDefinition> outHyperEdges) { outSingleEdges = null; outHyperEdges = null; if (myOutgoingEdges == null) return; var singleEdges = new Dictionary<String, SingleEdgeAddDefinition>(); var hyperEdges = new Dictionary<String, HyperEdgeAddDefinition>(); foreach (var edgeDef in myOutgoingEdges) { var attrDef = myVertexType.GetOutgoingEdgeDefinition(edgeDef.EdgeName); switch (attrDef.Multiplicity) { case EdgeMultiplicity.SingleEdge: { var edge = CreateSingleEdgeAddDefinition(myTransaction, mySecurity, date, attrDef.ID, edgeDef, attrDef.EdgeType, source, attrDef); if (edge.HasValue) singleEdges.Add(edgeDef.EdgeName, edge.Value); } break; case EdgeMultiplicity.HyperEdge: { break; } case EdgeMultiplicity.MultiEdge: { var edge = CreateMultiEdgeAddDefinition(myTransaction, mySecurity, source, date, edgeDef, attrDef); if (edge.HasValue) hyperEdges.Add(attrDef.Name, edge.Value); } break; default: throw new UnknownDBException("The EdgeMultiplicy enumeration was updated, but not this switch statement."); } } outSingleEdges = singleEdges.Select(x => x.Value); outHyperEdges = hyperEdges.Select(x => x.Value); }
public static IVertex StoreIndex( IVertexStore myStore, VertexInformation myVertex, String myName, String myComment, Int64 myCreationDate, String myIndexClass, bool myIsSingleValue, bool myIsRange, bool myIsVersioned, bool myIsUserDefined, IDictionary<String, object> myOptions, VertexInformation myDefiningVertexType, VertexInformation? mySourceIndex, IList<VertexInformation> myIndexedProperties, SecurityToken mySecurity, TransactionToken myTransaction) { var props = new Dictionary<long, IComparable> { { (long) AttributeDefinitions.IndexDotName, myName }, { (long) AttributeDefinitions.IndexDotIsUserDefined, myIsUserDefined }, { (long) AttributeDefinitions.IndexDotIsSingleValue, myIsSingleValue}, { (long) AttributeDefinitions.IndexDotIsRange, myIsRange }, { (long) AttributeDefinitions.IndexDotIsVersioned, myIsVersioned }, }; var single = new Dictionary<Tuple<long, long>, VertexInformation> { { _EdgeIndexDotDefiningVertexType, myDefiningVertexType } }; if (myIndexClass != null) props.Add((long) AttributeDefinitions.IndexDotIndexClass, myIndexClass); if (mySourceIndex.HasValue) single.Add( _EdgeIndexDotSource, mySourceIndex.Value); return Store( myStore, myVertex, myComment, myCreationDate, single, new Dictionary<Tuple<long, long>, IEnumerable<VertexInformation>> { { _EdgeIndexDotIndexedProperties, myIndexedProperties } }, props, myOptions, mySecurity, myTransaction); }
/// <summary> /// Creates SingleEdgeAddDefintions to create single edges. /// </summary> /// <param name="myTransaction">TransactionID</param> /// <param name="mySecurity">SecurityToken</param> /// <param name="myDate">Actual DateTime in long.</param> /// <param name="vertexIDs"></param> /// <param name="edgeDef">The EdgePredefnintion.</param> /// <param name="attrDef">The attribute defintion of the outgoing egde.</param> /// <param name="mySource">The source of the edge.</param> /// <returns></returns> private IEnumerable<SingleEdgeAddDefinition> CreateContainedEdges( Int64 myTransaction, SecurityToken mySecurity, long myDate, IEnumerable<VertexInformation> vertexIDs, EdgePredefinition edgeDef, IOutgoingEdgeDefinition attrDef, VertexInformation mySource) { if ((vertexIDs == null || vertexIDs.Count() == 0) && (edgeDef.ContainedEdges == null || edgeDef.ContainedEdges.Count() == 0)) return null; List<SingleEdgeAddDefinition> result = new List<SingleEdgeAddDefinition>(); if (vertexIDs != null) { foreach (var vertex in vertexIDs) { var toAdd = CreateSingleEdgeAddDefinition(myTransaction, mySecurity, myDate, Int64.MinValue, edgeDef, attrDef.InnerEdgeType, mySource, attrDef); if (toAdd.HasValue) result.Add(toAdd.Value); } } if (edgeDef.ContainedEdges != null) { foreach (var edge in edgeDef.ContainedEdges) { if (edge.ContainedEdges != null) //TODO a better exception here throw new Exception("An edge within a multi edge cannot have contained edges."); var toAdd = CreateSingleEdgeAddDefinition(myTransaction, mySecurity, myDate, Int64.MinValue, edge, attrDef.InnerEdgeType, mySource, attrDef); if (toAdd.HasValue) result.Add(toAdd.Value); } } return result; }
public static void StoreOutgoingEdge( IVertexStore myStore, VertexInformation myVertex, String myName, String myComment, bool myIsUserDefined, Int64 myCreationDate, EdgeMultiplicity myMultiplicity, VertexInformation myDefiningType, VertexInformation myEdgeType, VertexInformation? myInnerEdgeType, //not mandatory, might be null VertexInformation myTarget, SecurityToken mySecurity, TransactionToken myTransaction) { var singleEdges = new Dictionary<Tuple<long, long>, VertexInformation> { { _EdgeAttributeDotDefiningType, myDefiningType }, { _EdgeOutgoingEdgeDotSource, myDefiningType }, { _EdgeOutgoingEdgeDotEdgeType, myEdgeType }, { _EdgeOutgoingEdgeDotTarget, myTarget } }; if (myMultiplicity == EdgeMultiplicity.MultiEdge) { singleEdges.Add(_EdgeOutgoingEdgeDotInnerEdgeType, myInnerEdgeType.Value); } Store( myStore, myVertex, myComment, myCreationDate, singleEdges, null, new Dictionary<long, IComparable> { { (long) AttributeDefinitions.AttributeDotName, myName }, { (long) AttributeDefinitions.AttributeDotIsUserDefined, myIsUserDefined }, { (long) AttributeDefinitions.OutgoingEdgeDotMultiplicity, (byte) myMultiplicity }, }, null, mySecurity, myTransaction ); }
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 static void StoreProperty( IVertexStore myStore, VertexInformation myVertex, String myName, String myComment, Int64 myCreationDate, bool myIsMandatory, PropertyMultiplicity myMultiplicity, String myDefaultValue, bool myIsUserDefined, VertexInformation myDefiningType, VertexInformation myBasicType, SecurityToken mySecurity, TransactionToken myTransaction) { var props = new Dictionary<long, IComparable> { { (long) AttributeDefinitions.AttributeDotName, myName }, { (long) AttributeDefinitions.AttributeDotIsUserDefined, myIsUserDefined }, { (long) AttributeDefinitions.PropertyDotIsMandatory, myIsMandatory }, { (long) AttributeDefinitions.PropertyDotMultiplicity, (byte) myMultiplicity }, }; if (myDefaultValue != null) props.Add((long) AttributeDefinitions.PropertyDotDefaultValue, myDefaultValue); Store( myStore, myVertex, myComment, myCreationDate, new Dictionary<Tuple<long, long>, VertexInformation> { { _EdgeAttributeDotDefiningType, myDefiningType }, { _EdgePropertyDotBaseType, myBasicType }, }, null, props, null, mySecurity, myTransaction); }