use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class TestGraphUnwindOut method testUwindLightweightEdges.
@Test
public void testUwindLightweightEdges() {
OrientGraph graph = new OrientGraph("memory:" + TestGraphUnwindOut.class.getSimpleName());
graph.setUseLightweightEdges(true);
try {
OrientVertexType type = graph.createVertexType("edgetest");
graph.createEdgeType("edgetestedge");
type.createEdgeProperty(Direction.IN, "edgetestedge");
type.createEdgeProperty(Direction.OUT, "edgetestedge");
OrientVertex test = graph.addVertex("class:edgetest");
test.setProperty("ida", "parentckt1");
test.save();
OrientVertex test1 = graph.addVertex("class:edgetest");
test1.setProperty("ida", "childckt2");
test1.save();
OrientVertex test2 = graph.addVertex("class:edgetest");
test2.setProperty("ida", "childckt3");
test2.save();
OrientVertex test3 = graph.addVertex("class:edgetest");
test3.setProperty("ida", "childckt4");
test3.save();
graph.commit();
graph.command(new OCommandSQL("create edge edgetestedge from (select from edgetest where ida='parentckt1') to (select from edgetest where ida like 'childckt%')")).execute();
graph.commit();
Iterable<OrientElement> res = graph.command(new OSQLSynchQuery("select out_edgetestedge[0] from v where out_edgetestedge.size() > 0 unwind out_edgetestedge ")).execute();
for (OrientElement oDocument : res) {
assertNotNull(oDocument.getRecord().field("out_edgetestedge"));
ODocument doc = oDocument.getRecord().field("out_edgetestedge");
assertEquals(doc.getClassName(), "edgetest");
}
} finally {
graph.drop();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class OGraphImporterSTAPITest method main.
public static void main(String[] args) throws IOException, InterruptedException {
// String dbUrl = "memory:amazonReviews";
String dbUrl = "plocal:/temp/databases/amazonReviews";
final File f = new File("/temp/databases/amazonReviews");
if (f.exists())
OFileUtils.deleteRecursively(f);
final OrientGraph roGraph = new OrientGraph(dbUrl, "admin", "admin");
final OrientGraph graph = new OrientGraph(dbUrl, "admin", "admin");
OrientVertexType user = graph.createVertexType("User");
user.createProperty("uid", OType.STRING);
final OIndex<?> userIndex = user.createIndex("User.uid", OClass.INDEX_TYPE.UNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "uid" });
OrientVertexType product = graph.createVertexType("Product");
product.createProperty("uid", OType.STRING);
final OIndex<?> productIndex = product.createIndex("Product.uid", OClass.INDEX_TYPE.UNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "uid" });
graph.createEdgeType("Reviewed");
final File file = new File("/Users/luca/Downloads/ratings_Books.csv");
final BufferedReader br = new BufferedReader(new FileReader(file));
Orient.instance().scheduleTask(new TimerTask() {
@Override
public void run() {
roGraph.makeActive();
final long vertexCount = roGraph.countVertices();
final long edgeCount = roGraph.countEdges();
System.out.println(String.format("%d vertices=%d %d/sec edges=%d %d/sec", row, vertexCount, ((vertexCount - lastVertexCount) * 1000 / 2000), edgeCount, ((edgeCount - lastEdgeCount) * 1000 / 2000)));
lastVertexCount = vertexCount;
lastEdgeCount = edgeCount;
}
}, 2000, 2000);
try {
for (String line; (line = br.readLine()) != null; ) {
row++;
final String[] parts = line.split(",");
if (parts.length != 4) {
// SKIP IT
System.out.print("Skipped invalid line " + row + ": " + line);
continue;
}
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("score", new Float(parts[2]).intValue());
properties.put("date", Long.parseLong(parts[3]));
final Object k1 = userIndex.get(parts[0]);
OrientVertex v1;
if (k1 == null) {
v1 = graph.addVertex("class:User", "uid", parts[0]);
} else
v1 = graph.getVertex(k1);
final Object k2 = productIndex.get(parts[1]);
OrientVertex v2;
if (k2 == null) {
v2 = graph.addVertex("class:Product", "uid", parts[1]);
} else
v2 = graph.getVertex(k2);
final OrientEdge edge = graph.addEdge(null, v1, v2, "Reviewed");
edge.setProperties(properties);
if (row % 2 == 0) {
graph.commit();
}
}
} finally {
br.close();
}
graph.shutdown();
roGraph.shutdown();
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class GraphValidationTest method testPropertyReadOnly.
@Test(expected = OValidationException.class)
public void testPropertyReadOnly() {
OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL);
OrientVertexType testType = graphNoTx.createVertexType("Test");
OProperty prop;
prop = testType.createProperty("name", OType.STRING).setReadonly(true);
graphNoTx.shutdown();
//this one passes
Assert.assertTrue(prop.isReadonly());
OrientGraph graph = new OrientGraph(URL);
try {
OrientVertex vert1 = graph.addVertex("class:Test", "name", "Sam");
graph.commit();
//should throw an exception
vert1.setProperty("name", "Ben");
graph.commit();
//fails
Assert.assertEquals(vert1.getProperty("name"), "Sam");
} finally {
graph.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class GraphValidationTest method setupSchema.
private void setupSchema() {
OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL, "admin", "admin");
try {
ODatabaseDocumentTx database = graphNoTx.getRawGraph();
OSchema oScchema = database.getMetadata().getSchema();
oScchema.getClass("V").setStrictMode(true);
oScchema.getClass("E").setStrictMode(true);
OrientVertexType CmVertexBaseType = graphNoTx.createVertexType("CmVertexBase", "V");
CmVertexBaseType.setStrictMode(true);
OrientVertexType CmEdgeBaseType = graphNoTx.createVertexType("CmEdgeBase", "V");
CmEdgeBaseType.setStrictMode(true);
OClass mOClass = database.getMetadata().getSchema().createClass("M", database.getMetadata().getSchema().getClass("V"));
mOClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true);
mOClass.setStrictMode(true);
graphNoTx.commit();
} finally {
graphNoTx.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.
the class GraphValidationTest method testNoTxGraphConstraints.
@Test
public void testNoTxGraphConstraints() {
OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL);
OrientVertexType testType = graphNoTx.createVertexType("Test");
testType.createProperty("age", OType.INTEGER).setMax("3");
OrientVertex vert1 = graphNoTx.addVertex("class:Test", "age", 2);
try {
vert1.setProperty("age", 4);
} catch (OValidationException e) {
//this fails
Assert.assertEquals(vert1.getProperty("age"), 2);
} finally {
graphNoTx.shutdown();
}
}
Aggregations