public void DeleteUserVertices() { using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true)) { session.BeginUpdate(); Graph g = Graph.Open(session); // it takes a while to open graph fresh from databases VertexType userType = g.FindVertexType("User"); VertexType locationType = g.FindVertexType("Location"); EdgeType friendEdgeType = g.FindEdgeType("Friend"); EdgeType userLocationEdgeType = g.FindEdgeType("UserLocation"); for (int i = 1; i < numberOfUserVertices; i++) { userType.RemoveVertex(new Vertex(g, userType, i)); } Assert.IsTrue(friendEdgeType.GetEdges().Count() == 0); session.Commit(); Validate(); } }
public void Create1Vertices(bool vertexIdSetPerVertexType) { DataCache.MaximumMemoryUse = 10000000000; // 10 GB bool dirExist = Directory.Exists(systemDir); try { if (Directory.Exists(systemDir)) { Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases. } Directory.CreateDirectory(systemDir); File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb")); } catch { File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb")); } using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true)) { session.BeginUpdate(); Graph g = new Graph(session, vertexIdSetPerVertexType); session.Persist(g); VertexType userType = g.NewVertexType("User"); VertexType otherType = g.NewVertexType("Other"); PropertyType userNamePropertyType = g.NewVertexProperty(userType, "NAME", DataType.String, PropertyKind.Indexed); VertexType powerUserType = g.NewVertexType("PowerUser", userType); EdgeType userFriendEdgeType = g.NewEdgeType("Friend", true, userType, userType); EdgeType userBestFriendEdgeType = g.NewEdgeType("Best Friend", true, userType, userType, userFriendEdgeType); EdgeType otherEdgeType = g.NewEdgeType("Other", true, userType, userType); PropertyType bestFriendPropertyType = g.NewEdgeProperty(userFriendEdgeType, "START", DataType.DateTime, PropertyKind.Indexed); Vertex kinga = userType.NewVertex(); Vertex robin = userType.NewVertex(); Vertex mats = powerUserType.NewVertex(); Vertex chiran = powerUserType.NewVertex(); Vertex other = otherType.NewVertex(); Edge bestFriend = kinga.AddEdge(userBestFriendEdgeType, robin); Edge otherEdge = kinga.AddEdge(otherEdgeType, robin); DateTime now = DateTime.Now; mats.SetProperty("Address", 1); bestFriend.SetProperty(bestFriendPropertyType, now); kinga.SetProperty(userNamePropertyType, "Kinga"); if (g.VertexIdSetPerType == false) { mats.SetProperty(userNamePropertyType, "Mats"); } else { try { mats.SetProperty(userNamePropertyType, "Mats"); Assert.Fail("Invalid property for VertexType not handled"); } catch (Exception) { } } try { other.SetProperty(userNamePropertyType, "Mats"); Assert.Fail("Invalid property for VertexType not handled"); } catch (Exception) { } try { otherEdge.SetProperty(bestFriendPropertyType, now); Assert.Fail("Invalid property for VertexType not handled"); } catch (Exception) { } Vertex findMats = userNamePropertyType.GetPropertyVertex("Mats", true); var list = userNamePropertyType.GetPropertyVertices("Mats", true).ToList(); //Edge findWhen = bestFriendPropertyType.GetPropertyEdge(now); //var list2 = bestFriendPropertyType.GetPropertyEdges(now); Console.WriteLine(findMats); // session.Commit(); // session.BeginRead(); PropertyType adressProperty = g.FindVertexProperty(powerUserType, "Address"); Vertex find1 = adressProperty.GetPropertyVertex(1, true); session.Abort(); /*session.BeginUpdate(); * g.Unpersist(session); * session.Commit(); * dirExist = Directory.Exists(systemDir); * try * { * if (Directory.Exists(systemDir)) * Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases. * Directory.CreateDirectory(systemDir); * File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb")); * } * catch * { * File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb")); * }*/ } using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true)) { session.BeginUpdate(); session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None; Graph g = new Graph(session, vertexIdSetPerVertexType); session.Persist(g); Graph g2 = new Graph(session); session.Persist(g2); Graph g3 = new Graph(session); session.Persist(g3); UInt32 dbNum = session.DatabaseNumberOf(typeof(Graph)); Graph g4 = (Graph)session.Open(dbNum, 2, 1, true); // g4 == g Graph g5 = (Graph)session.Open(dbNum, 2, 2, true); // g5 == g2 Graph g6 = (Graph)session.Open(dbNum, 2, 3, true); // g6 == g3 for (int i = 4; i < 8; i++) { Graph gt = new Graph(session); session.Persist(gt); } Graph g7 = new Graph(session); Placement place = new Placement(dbNum, 15); session.Persist(place, g7); // SCHEMA VertexType userType = g.NewVertexType("User"); VertexType locationType = g.NewVertexType("Location"); VertexType aVertexType = g.NewVertexType("A"); VertexType bVertexType = g.NewVertexType("B"); VertexType cVertexType = g.NewVertexType("C"); EdgeType uEdge = g.NewEdgeType("unrestricted", true); Vertex aVertex = g.NewVertex(aVertexType); Vertex bVertex = g.NewVertex(bVertexType); Vertex cVertex = g.NewVertex(cVertexType); Edge abEdge = (Edge)aVertex.AddEdge("unrestricted", bVertex); Edge bcEdge = (Edge)aVertex.AddEdge("unrestricted", cVertex); Dictionary <Vertex, HashSet <Edge> > traverse = aVertex.Traverse(uEdge, Direction.Out); abEdge.Remove(); Dictionary <Vertex, HashSet <Edge> > traverse2 = aVertex.Traverse(uEdge, Direction.Out); EdgeType friendEdgeType = g.NewEdgeType("Friend", true, userType, userType); EdgeType userLocationEdgeType = g.NewEdgeType("UserLocation", true, userType, locationType); // DATA Random rand = new Random(5); for (int i = 0; i < numberOfUserVertices / 100; i++) { int vId = rand.Next(numberOfUserVertices); try { if (g.VertexIdSetPerType) { userType.GetVertex(vId); } else { g.GetVertex(vId); } try { userType.NewVertex(vId); Assert.Fail(); } catch (VertexAllreadyExistException) { } } catch (VertexDoesNotExistException) { userType.NewVertex(vId); userType.GetVertex(vId); } } for (int i = 0; i < numberOfUserVertices / 10000; i++) { int vId = rand.Next(numberOfUserVertices); try { Vertex v = userType.GetVertex(vId); v.SetProperty("test", 1); } catch (VertexDoesNotExistException) { } } for (int i = 0; i < numberOfUserVertices / 10000; i++) { int vId = rand.Next(numberOfUserVertices); try { Vertex v = userType.GetVertex(vId); userType.RemoveVertex(v); } catch (VertexDoesNotExistException) { } } foreach (Vertex v in userType.GetVertices().ToArray()) { userType.RemoveVertex(v); } Assert.AreEqual(0, userType.GetVertices().Count()); for (int i = 100000; i < numberOfUserVertices; i++) { userType.NewVertex(); } for (int i = 1; i < 100000; i++) { userType.NewVertex(); } for (int i = 1; i < numberOfLocationVertices; i++) { locationType.NewVertex(); } session.Commit(); session.BeginRead(); foreach (var x in session.AllObjects <BTreeSet <Range <VertexId> > >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeSet <EdgeType> >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeSet <EdgeIdVertexId> >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeMap <EdgeId, VelocityDbList <ElementId> > >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeMap <string, PropertyType> >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeMap <string, EdgeType> >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeMap <string, VertexType> >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeMap <VertexId, BTreeSet <EdgeIdVertexId> > >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeMap <VertexType, BTreeMap <VertexId, BTreeSet <EdgeIdVertexId> > > >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } foreach (var x in session.AllObjects <BTreeMap <EdgeType, BTreeMap <VertexType, BTreeMap <VertexId, BTreeSet <EdgeIdVertexId> > > > >(false, true)) { Assert.True(x.ToDoBatchAddCount == 0); } session.Commit(); Validate(); } }
/// <summary> /// Removes this <see cref="Vertex"/> from the <see cref="Graph"/> /// </summary> public override void Remove() { m_vertexType.RemoveVertex(this); }