use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class OGraphInsertWorkload method init.
@Override
protected void init(OBaseWorkLoadContext context) {
synchronized (getClass()) {
final OrientBaseGraph g = ((OWorkLoadContext) context).graph;
if (g.getVertexType(className) == null) {
final OrientVertexType c = g.createVertexType(className);
c.createProperty("_id", OType.LONG);
c.createProperty("ts", OType.DATETIME);
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class TestGraphIntentMassiveInsert method testIntent.
@Test
public void testIntent() {
final OrientGraph graph = new OrientGraph("memory:default", false);
graph.setUseLightweightEdges(true);
graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
final OrientVertexType c1 = graph.createVertexType("C1");
c1.createProperty("p1", OType.INTEGER);
graph.createEdgeType("parent");
graph.begin();
final OrientVertex first = graph.addVertex("class:C1");
first.setProperty("p1", -1);
for (int i = 0; i < 10; i++) {
final OrientVertex v = graph.addVertex("class:C1");
v.setProperty("p1", i);
first.addEdge("parent", v);
//this search fills _source
graph.command(new OSQLSynchQuery("SELECT from V where p1='" + i + "'")).execute();
}
graph.commit();
//here NPE will be thrown
final Iterable<Edge> edges = first.getEdges(Direction.BOTH);
Iterator<Edge> ter = edges.iterator();
for (int i = 0; i < 10; i++) {
assertTrue(ter.hasNext());
assertEquals(ter.next().getVertex(Direction.IN).getProperty("p1"), i);
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class GraphGetVertices method test.
@Test
public void test() {
Iterator<Vertex> iterator = null;
OrientGraphNoTx graph = new OrientGraphNoTx("memory:/TestDB", "admin", "admin");
OrientVertexType personType = graph.createVertexType("Person");
personType.createProperty("person_id", OType.STRING);
personType.createProperty("name", OType.STRING);
// Adding 3 vertices to the orient graph
OrientVertex p1 = graph.addVertex("class:Person");
p1.setProperty("person_id", "01");
p1.setProperty("name", "Gabriel");
OrientVertex p2 = graph.addVertex("class:Person");
p2.setProperty("person_id", "02");
p2.setProperty("name", "Daniel");
OrientVertex p3 = graph.addVertex("class:Person");
p3.setProperty("person_id", "03");
p3.setProperty("name", "Emanuel");
/*
* CASE 1 GetVertices call without indexes, query on one key and one value
*/
// String key and value
String[] singleKey = { "person_id" };
String[] singleValue = { "01" };
iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
int resultsAmount = 0;
while (iterator.hasNext()) {
iterator.next();
resultsAmount++;
}
assertEquals(1, resultsAmount);
iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
Vertex firstVertex = iterator.next();
assertEquals(firstVertex.getProperty("person_id"), "01");
assertEquals(firstVertex.getProperty("name"), "Gabriel");
/*
* CASE 2 GetVertices call with index built on a single property, query on one key and one value
*/
// Defining an index (unique_hash_index) on a single property
String statement = "create index Person.pkey on Person (person_id) unique_hash_index";
OCommandSQL sqlCommand = new OCommandSQL(statement);
graph.getRawGraph().command(sqlCommand).execute();
// String key and value
singleValue[0] = "02";
iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
resultsAmount = 0;
while (iterator.hasNext()) {
iterator.next();
resultsAmount++;
}
assertEquals(1, resultsAmount);
iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
firstVertex = iterator.next();
assertEquals(firstVertex.getProperty("person_id"), "02");
assertEquals(firstVertex.getProperty("name"), "Daniel");
/*
* CASE 3 GetVertices call with index built on two properties (composite key), query on two key and two values in order to test
* "composite key behaviour"
*/
// Dropping precedent index and defining a new index (unique_hash_index) on two properties
graph.dropIndex("Person.pkey");
statement = "create index Person.pkey on Person (person_id,name) unique_hash_index";
sqlCommand = new OCommandSQL(statement);
graph.getRawGraph().command(sqlCommand).execute();
// String key and value
String[] keys = { "person_id", "name" };
String[] values = { "03", "Emanuel" };
iterator = graph.getVertices("Person", keys, values).iterator();
resultsAmount = 0;
while (iterator.hasNext()) {
iterator.next();
resultsAmount++;
}
assertEquals(1, resultsAmount);
iterator = graph.getVertices("Person", keys, values).iterator();
firstVertex = iterator.next();
assertEquals(firstVertex.getProperty("person_id"), "03");
assertEquals(firstVertex.getProperty("name"), "Emanuel");
graph.createVertexType("PersonDummy");
Iterator<Vertex> personDummy = graph.getVertices("PersonDummy", singleKey, singleValue).iterator();
resultsAmount = 0;
while (personDummy.hasNext()) {
personDummy.next();
resultsAmount++;
}
assertEquals(0, resultsAmount);
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class SQLMoveVertexCommandTest method reinitVertexType.
private OrientVertexType reinitVertexType(String className) {
OrientVertexType clazz = graph.getVertexType(className);
if (clazz != null) {
graph.command(new OCommandSQL("delete vertex " + className)).execute();
graph.dropVertexType(className);
}
clazz = graph.createVertexType(className);
return clazz;
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class GraphEmbeddedTest method init.
@Before
public void init() {
graph = new OrientGraph(db, false);
OrientVertexType type = graph.createVertexType("City");
type.createProperty("latitude", OType.DOUBLE);
type.createProperty("longitude", OType.DOUBLE);
type.createProperty("name", OType.STRING);
db.command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE")).execute();
}
Aggregations