my question is simple (I hope the answer is simple too)
I want to return the RID when I create a vertex
client.command("create class Tag extends V") client.command("create vertex Tag set idTag=1, nomTag='tag1'")
Can I get the RID return? or if I cannot can I create the vertex with a RID I chose? like:
client.command("create vertex Tag set rid='#21:1234', idTag=1, nomTag='tag1'")
-Using orientdb 2.2
-Pyorient (python API)
thx for your help
just need to
RidReturn = client.command("create vertex Tag set idTag=1, nomTag='tag1'")
Rid = RidReturn[0]._rid
print(RidReturn)
[pyorient.otypes.OrientRecord object at 0x107e00a90]
print(Rid)
'#27:3077'
Related
I am working with orientDB using Java and I need to check if two vertices are connected, I tried to do a workaround be checking out and in edges for vertices and see if the other vertex in there, the solution works fine so far, i have seen that there is a method called "getEdgesBetweenVertexes()" but seems this method not existing in v 2.2 anymore
You can use the method called getEdges()
Example:
OrientVertex v1=graph.getVertex("#21:0");
OrientVertex v2=graph.getVertex("#26:1");
if(v2!=null){
Iterable<Edge> result=v1.getEdges(v2, Direction.BOTH, "E");
boolean connected=false;
for(Edge e:result){
connected=true;
break;
}
System.out.println(connected);
}
else{
System.out.println(false);
}
Hope it helps.
Graph created with Titan 0.4.4, we're getting a NPE on line 262 of com.thinkaurelias.titan.graphdb.database.EdgeSerializer (see below for offending line).
private static boolean hasGenericDataType(TitanKey key) {
return key.getDataType().equals(Object.class);
}
I'm not sure how, but none of the keys on any of the properties on any of our vertices have a datatype set. Is there something I can do to fix this? When retrieving any property on any vertex, I'm getting this null pointer.
I'm coding an editor for graphs (Graph Theory).Let's imagine vertex needs these properites :
class Vertex{
int ID {get;}
Color color {get; set;}
Point point{get; set;}
}
But it's violating of SRP(single responsibility principle). So I created somethink like :
class Vertex{
int ID {get;}
}
class Positions{
private Dict<Vertex,Point> _pos;
setPosition(Vertex v, Point pos);
Point getPosition(Vertex v);
}
//etc.
Right?
But ViewModel for vertex needs, all of these properties to be displayed.
class VertexVM
{
Vertex _v;
Positions _positions;
//...
Point position
{
get {return _positions.getPosition(_v); }
}
// same for color etc
}
Is it violationg of SRP? (In my opinion, it is.) Is there any way how to avoid it? Thanks.
I would say your initial vertex definition is violating SRP, but not for the reason you seem to imply by your re-factoring. On the other hand, your VertexVM is violating SRP.
A vertex in graph theory is a point or location within the graph. It by definition should be responsible for knowing its location. Therefore it should contain the point. Whether Color belongs in it or not is a different case. I'm guessing maybe not as this is likely more display related and doesn't belong in a model class. A vertex type that results in the view displaying the vertex in a particular color might be appropriate.
In VertexVM, the View Model is intended to represent a single Vertex to the view. It is not its responsibility to know the positions of all the vertices in the graph. This definitely violates SRP.
I am having trouble using a Class that I created as a property in another Class. I have two classes, one called Vertex and the other called Edge. Two of the properties of Edge, Parent and Child, are Vertex objects. Here is a method where I try to use them.
Option Explicit
Public Sub OrgChart()
Dim Vertices As Collection
Dim Edges As Collection
Dim vParent As Vertex
Dim vChild As Vertex
Dim eEdge As Edge
Dim rEdgeRow As Range
Set rEdgeRow = ActiveSheet.Range("A1:C1")
Do While Len(rEdgeRow(1, 1).Value) > 0
Set vChild = New Vertex
Set vParent = New Vertex
Set eEdge = New Edge
vChild.Name = rEdgeRow(1, 1).Value
vChild.Dummy = False
vParent.Name = rEdgeRow(2, 1).Value
vParent.Dummy = False
eEdge.Parent = vParent
eEdge.Child = vChild
eEdge.Percent = rEdgeRow(3, 1).Value
Set rEdgeRow = rEdgeRow.Offset(1, 0)
Loop
End Sub
When I run this, I get the error,
"Run-time error '91': Object variable or With block variable not set"
The debugger indicates that it is breaking at the line
eEdge.Parent = vParent
I assume that the issue has to do with the eEdge.Parent not being initialized, but I tried using
Set eEdge.Parent = New Vertex
and I got the same issue.
If it will help, I can post the class code as well, though they are fairly simple, only containing Property Get and Property Let functions.
I apologize if I did anything wrong when posting this; this is my first time posting anything on SO.
Thanks,
Eric
I might not be understanding this right, but did you try:
Set eEdge.Parent = vParent
Set eEdge.Child = vChild
If they're objects, you need to use a "Set"
... Also, if this doesn't fix it, can you post the code for your Vertex class - You may need to dim the Parent and Child objects differently in its constructor...
I've been looking into the topic of creating instances of a class within its own definition. Something like this:
public class myClass
{
public static myClass aObject = new myClass();
public static myClass bObject = new myClass();
}
I kind-of understand how this is possible, but I'm confused as to why it would be useful.
Also, my logic says that it should be possible to do something like this:
aObject.bObject.someMethod();
aObject is an instance of myClass, so it should contain bObject, right? I feel like I'm missing some fundamental understanding of how classes work, so I would really like to know what's going on here, and why someone would want to do this.
aObject.bObject.someMethod() would definitely work if someMethod() was defined as a part of myClass. As to why something like that would be done, I'll give an example that is used in java.
Say you have a class called Color that represents colors. You can make a new color of of its RGB value with the constructor Color(byte r, byte g, byte b). There are also constants in the Color class that represent commonly used colors, like red or green or pink. You can quickly access the pink color just by saying Color.PINK, since PINK is a Color variable that is inside the Color class. That way you don't have to construct a new color object each time you want to use pink in a method.
aObject.bObject.someMethod();
This is like saying "of object a's object b... do something." So its like a ball (called A) has a ball inside it (called B) which has a ball inside it (called C).. ect.
A linked list is a list does something like this, in that:
class Link {
public long data; // data item
public Link next; // next link in list
// =============================================================
public Link(long value){ // constructor
data = value; // assign parameter to data's data field
}
}
Link has inside of it a pointer to another link which does the same until you make a null object.
I think this is what you were asking...