use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class GraphDatabaseTest method sqlNestedQueries.
@Test
public void sqlNestedQueries() {
Vertex vertex1 = database.addVertex(null, "driver", "John");
Vertex vertex2 = database.addVertex(null, "car", "ford");
Vertex targetVertex = database.addVertex(null, "car", "audi");
Edge edge = database.addEdge(null, vertex1, vertex2, "E");
edge.setProperty("color", "red");
edge.setProperty("action", "owns");
edge = database.addEdge(null, vertex1, targetVertex, "E");
edge.setProperty("color", "red");
edge.setProperty("action", "wants");
database.commit();
String query1 = "select driver from V where out().car contains 'ford'";
List<ODocument> result = database.getRawGraph().query(new OSQLSynchQuery<ODocument>(query1));
Assert.assertEquals(result.size(), 1);
String query2 = "select driver from V where outE()[color='red'].inV().car contains 'ford'";
result = database.getRawGraph().query(new OSQLSynchQuery<ODocument>(query2));
Assert.assertEquals(result.size(), 1);
//TODO these tests are broken, they should test "contains" instead of "="
String query3 = "select driver from V where outE()[action='owns'].inV().car = 'ford'";
result = database.getRawGraph().query(new OSQLSynchQuery<ODocument>(query3));
Assert.assertEquals(result.size(), 1);
String query4 = "select driver from V where outE()[color='red'][action='owns'].inV().car = 'ford'";
result = database.getRawGraph().query(new OSQLSynchQuery<ODocument>(query4));
Assert.assertEquals(result.size(), 1);
}
use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class TestDirtyTrackingTreeRidBagRemote method test.
@Test
public void test() {
final int max = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger() * 2;
OrientGraph graph = new OrientGraph("remote:localhost:3064/" + TestDirtyTrackingTreeRidBagRemote.class.getSimpleName(), "root", "root");
try {
graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
graph.createEdgeType("Edge");
OIdentifiable oneVertex = null;
Map<Object, Vertex> vertices = new HashMap<Object, Vertex>();
for (int i = 0; i < max; i++) {
Vertex v = graph.addVertex("class:V");
v.setProperty("key", "foo" + i);
graph.commit();
vertices.put(v.getProperty("key"), v);
if (i == max / 2 + 1)
oneVertex = ((OrientVertex) v).getIdentity();
}
graph.commit();
// Add the edges
for (int i = 0; i < max; i++) {
String codeUCD1 = "foo" + i;
// Take the first vertex
Vertex med1 = (Vertex) vertices.get(codeUCD1);
// For the 2nd term
for (int j = 0; j < max; j++) {
String key = "foo" + j;
// Take the second vertex
Vertex med2 = (Vertex) vertices.get(key);
// ((OrientVertex)med2).getRecord().reload();
OrientEdge eInteraction = graph.addEdge(null, med1, med2, "Edge");
assertNotNull(graph.getRawGraph().getTransaction().getRecordEntry(((OrientVertex) med2).getIdentity()));
}
// COMMIT
graph.commit();
}
graph.getRawGraph().getLocalCache().clear();
OrientVertex vertex = graph.getVertex(oneVertex);
assertEquals(new GremlinPipeline<Vertex, Long>().start(vertex).in("Edge").count(), max);
} finally {
graph.shutdown();
}
}
use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class OrientGraphSpecificTestSuite method testComplexMapProperty.
@Test
public void testComplexMapProperty() throws Exception {
// complex map properties have problems when unmarshalled from disk to
// an OTrackedMap
Graph graph = graphTest.generateGraph("complex-map");
final HashMap<String, Object> consignee = new HashMap<String, Object>();
consignee.put("name", "Company 4");
final ArrayList consigneeAddress = new ArrayList();
consigneeAddress.add("Lilla Bommen 6");
consignee.put("address", consigneeAddress);
consignee.put("zipCode", "41104");
consignee.put("city", "Göteborg");
final HashMap<String, Object> consigneeCountry = new HashMap<String, Object>();
consigneeCountry.put("name", "Sverige");
consigneeCountry.put("code", "SV");
consignee.put("country", consigneeCountry);
consignee.put("contactName", "Contact Person 4");
consignee.put("telephone", "0731123456");
consignee.put("telefax", null);
consignee.put("mobileTelephone", "072345678");
consignee.put("email", "test@company4.com");
consignee.put("hiflexId", null);
final HashMap<String, Object> delivery = new HashMap<String, Object>();
delivery.put("name", "Company 5");
final ArrayList deliveryAddress = new ArrayList();
deliveryAddress.add("Stora Enens Väg 38");
delivery.put("address", deliveryAddress);
delivery.put("zipCode", "43931");
delivery.put("city", "Onsala");
final HashMap<String, Object> deliveryCountry = new HashMap<String, Object>();
deliveryCountry.put("name", "Sverige");
deliveryCountry.put("code", "SV");
delivery.put("country", deliveryCountry);
delivery.put("contactName", "Contact Person 5");
delivery.put("telephone", "030060094");
delivery.put("telefax", null);
delivery.put("mobileTelephone", null);
delivery.put("email", "test@company5.com");
delivery.put("hiflexId", null);
final HashMap<String, Object> pickup = new HashMap<String, Object>();
pickup.put("name", "Pickup Company 2");
final ArrayList pickupAddress = new ArrayList();
pickupAddress.add("Drottninggatan 1");
pickup.put("address", pickupAddress);
pickup.put("zipCode", "41103");
pickup.put("city", "Göteborg");
final HashMap<String, Object> pickupCountry = new HashMap<String, Object>();
pickupCountry.put("name", "Sverige");
pickupCountry.put("code", "SV");
pickup.put("country", pickupCountry);
pickup.put("contactName", "Contact Person 6");
pickup.put("telephone", "071234567");
pickup.put("telefax", null);
pickup.put("mobileTelephone", null);
pickup.put("email", "test@pickupcompany2.com");
pickup.put("hiflexId", null);
final Map shipping = new HashMap();
shipping.put("name", "Posten MyPack");
shipping.put("code", "postenmypack");
shipping.put("templateName", "POSTENMYPACK");
shipping.put("rates", new ArrayList());
final Vertex v = graph.addVertex(null);
v.setProperty("weight", 20);
v.setProperty("height", 20);
v.setProperty("consigneeAddress", consignee);
v.setProperty("width", 10);
v.setProperty("sum", 400);
v.setProperty("shippingMethod", shipping);
v.setProperty("type", "shipment");
v.setProperty("depth", 30);
v.setProperty("estimatedCost", 200);
v.setProperty("deliveryAddress", delivery);
v.setProperty("pickupAddress", pickup);
((TransactionalGraph) graph).commit();
// have to shutdown the graph so that the map will read back out as an
// OTrackedMap. Maps that exist in memory
// do not show the problem.
graph.shutdown();
graph = graphTest.generateGraph("complex-map");
final Vertex v1 = graph.getVertex(v.getId());
assertNotNull(v1);
// check the delivery address. not sure if there should be other
// assertions here, but the basic issues
// is that the keys/values in the OTrackedMap appear like this:
// mobileTelephone=null:null
final Map d = v1.getProperty("deliveryAddress");
assertNotNull(d);
assertTrue(d.containsKey("telefax"));
graph.shutdown();
graphTest.dropGraph(((OrientGraphTest) graphTest).getWorkingDirectory() + File.separator + "complex-map");
}
use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class OrientGraphVertexInPropertyTest method testVertexInAProperty.
@Test
public void testVertexInAProperty() {
OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.setValue(ORecordSerializerSchemaAware2CSV.NAME);
final String url = "memory:" + this.getClass().getSimpleName();
OrientGraph graph = new OrientGraph(url);
graph.drop();
graph = new OrientGraph(url);
Vertex vertexa = graph.addVertex(null);
Object aid = vertexa.getId();
Vertex vertexb = graph.addVertex(null);
Object id = vertexb.getId();
vertexb.setProperty("test", vertexa);
graph.commit();
graph.getRawGraph().close();
graph.getRawGraph().open("admin", "admin");
Vertex vertb = graph.getVertex(id);
Assert.assertNotEquals(OType.CUSTOM, ((OrientVertex) vertb).getRecord().fieldType("test"));
Object val = vertb.getProperty("test");
if (val instanceof String) {
Assert.assertTrue(((String) val).contains(aid.toString()));
} else {
Assert.assertEquals(aid, ((Vertex) vertb.getProperty("test")).getId());
}
graph.drop();
}
use of com.tinkerpop.blueprints.Vertex in project orientdb by orientechnologies.
the class DatabaseConflictStategyTest method runTest.
public void runTest() {
OrientBaseGraph orientGraph = new OrientGraphNoTx(getDBURL());
log("Set database CONFLICTSTRATEGY to automerge");
orientGraph.command(new OCommandSQL("ALTER database CONFLICTSTRATEGY 'automerge'")).execute();
createVertexType(orientGraph, "Test");
orientGraph.shutdown();
OrientBaseGraph graph = getGraphFactory().getTx();
Vertex vertex = graph.addVertex("class:Test");
vertex.setProperty("prop1", "v1-1");
vertex.setProperty("prop2", "v2-1");
vertex.setProperty("prop3", "v3-1");
graph.shutdown();
Thread th1 = startThread(2, 1000, "prop1");
Thread th2 = startThread(3, 2000, "prop1");
Thread th3 = startThread(4, 3000, "prop1");
try {
th1.join();
th2.join();
th3.join();
} catch (Exception ex) {
ex.printStackTrace();
}
}
Aggregations