use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class TestAsyncReplMode2ServersAddEdge method dbClient1.
protected void dbClient1() {
OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getLocalURL());
try {
OrientVertex parentV1 = graph.addVertex("vertextype", (String) null);
graph.commit();
assertEquals(1, parentV1.getRecord().getVersion());
parentV1Id = parentV1.getId();
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
Vertex childV = graph.addVertex("vertextype", (String) null);
graph.commit();
assertEquals(1, ((OrientVertex) childV).getRecord().getVersion());
parentV1.addEdge("edgetype", childV);
graph.commit();
OLogManager.instance().error(this, "parentV1 %s v%d should be v%d", parentV1.getIdentity(), parentV1.getRecord().getVersion(), i + 2);
assertEquals(i + 2, ((OrientVertex) parentV1).getRecord().getVersion());
assertEquals(2, ((OrientVertex) childV).getRecord().getVersion());
}
pause();
} catch (Throwable e) {
OLogManager.instance().error(this, "Exception", e);
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OGremlinConsole method importDatabase.
@Override
@ConsoleCommand(description = "Import a database into the current one", splitInWords = false)
public void importDatabase(@ConsoleParameter(name = "options", description = "Import options") String text) throws IOException {
checkForDatabase();
final List<String> items = OStringSerializerHelper.smartSplit(text, ' ');
final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1);
final String optionsAsString = fileName != null ? text.substring((items.get(0)).length() + (items.get(1)).length() + 1).trim() : text;
final Map<String, List<String>> options = parseOptions(optionsAsString);
final String format = options.containsKey("-format") ? options.get("-format").get(0) : null;
if ((format != null && format.equalsIgnoreCase("graphml")) || (fileName != null && (fileName.endsWith(".graphml") || fileName.endsWith(".xml")))) {
// GRAPHML
message("\nImporting GRAPHML database from " + fileName + " with options (" + optionsAsString + ")...");
try {
final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
g.setUseLog(false);
g.setWarnOnForceClosingTx(false);
final long totalEdges = g.countEdges();
final long totalVertices = g.countVertices();
final File file = new File(fileName);
if (!file.exists())
throw new ODatabaseImportException("Input file '" + fileName + "' not exists");
InputStream is = new FileInputStream(file);
if (fileName.endsWith(".zip"))
is = new ZipInputStream(is);
else if (fileName.endsWith(".gz"))
is = new GZIPInputStream(is);
try {
new OGraphMLReader(g).setOptions(options).setOutput(new OCommandOutputListener() {
@Override
public void onMessage(final String iText) {
System.out.print("\r" + iText);
}
}).inputGraph(is);
g.commit();
currentDatabase.commit();
message("\nDone: imported %d vertices and %d edges", g.countVertices() - totalVertices, g.countEdges() - totalEdges);
} finally {
is.close();
}
} catch (ODatabaseImportException e) {
printError(e);
}
} else if ((format != null && format.equalsIgnoreCase("graphson")) || (fileName != null && (fileName.endsWith(".graphson")))) {
// GRAPHSON
message("\nImporting GRAPHSON database from " + fileName + " with options (" + optionsAsString + ")...");
try {
final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
g.setUseLog(false);
g.setWarnOnForceClosingTx(false);
final long totalEdges = g.countEdges();
final long totalVertices = g.countVertices();
final File file = new File(fileName);
if (!file.exists())
throw new ODatabaseImportException("Input file '" + fileName + "' not exists");
InputStream is = new FileInputStream(file);
if (fileName.endsWith(".zip")) {
is = new ZipInputStream(is);
} else if (fileName.endsWith(".gz")) {
is = new GZIPInputStream(is);
}
try {
new OGraphSONReader(g).setOutput(new OCommandOutputListener() {
@Override
public void onMessage(final String iText) {
System.out.print("\r" + iText);
}
}).inputGraph(is, 10000);
// new OGraphMLReader(g).setOptions(options).inputGraph(g, fileName);
g.commit();
currentDatabase.commit();
message("\nDone: imported %d vertices and %d edges", g.countVertices() - totalVertices, g.countEdges() - totalEdges);
} finally {
is.close();
}
} catch (ODatabaseImportException e) {
printError(e);
}
} else if (format == null)
super.importDatabase(text);
else
throw new IllegalArgumentException("Format '" + format + "' is not supported");
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OETLBaseTest method setUp.
@Before
public void setUp() {
graph = new OrientGraph("memory:OETLBaseTest");
graph.setUseLightweightEdges(false);
proc = new OETLProcessor();
proc.getFactory().registerLoader(OETLStubLoader.class);
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OMergeTransformerTest method shouldUpdateExistingVertices.
@Test
public void shouldUpdateExistingVertices() throws Exception {
//prepare graph
graph.addVertex("class:Person", "num", 10000, "name", "FirstName");
graph.commit();
assertThat(graph.countVertices("Person")).isEqualTo(1);
Iterable<Vertex> vertices = graph.getVertices("Person.num", 10000);
assertThat(vertices).hasSize(1);
final Vertex inserted = vertices.iterator().next();
assertThat(inserted.getProperty("name")).isEqualTo("FirstName");
assertThat(inserted.getProperty("num")).isEqualTo(10000);
//update graph with CSV: avoid num to be casted to integer forcing string
process(" {source: { content: { value: 'num,name\n10000,FirstNameUpdated' } }, " + "extractor : { csv: {} }," + " transformers: [" + "{merge: { joinFieldName:'num', lookup:'Person.num'}}, " + "{vertex: { class:'Person', skipDuplicates: false}}" + "]," + "loader: { orientdb: { dbURL: 'memory:OETLBaseTest', dbType:'graph', tx: true} } }");
//verify
graph = new OrientGraph("memory:OETLBaseTest");
assertThat(graph.countVertices("Person")).isEqualTo(1);
vertices = graph.getVertices("Person.num", 10000);
assertThat(vertices).hasSize(1);
final Vertex updated = vertices.iterator().next();
ORecord load = graph.getRawGraph().load((ORID) updated.getId());
assertThat(updated.getProperty("name")).isEqualTo("FirstNameUpdated");
assertThat(updated.getProperty("num")).isEqualTo(10000);
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class DirtyManagerGraph method testLoopOfNew.
@Test
public void testLoopOfNew() {
OrientGraph graph = new OrientGraph("memory:" + DirtyManagerGraph.class.getSimpleName());
try {
graph.createEdgeType("next");
OrientVertex vertex = graph.addVertex(null);
OrientVertex vertex1 = graph.addVertex(null);
OrientVertex vertex2 = graph.addVertex(null);
OrientVertex vertex3 = graph.addVertex(null);
OrientEdge edge1 = (OrientEdge) vertex.addEdge("next", vertex1);
OrientEdge edge2 = (OrientEdge) vertex1.addEdge("next", vertex2);
OrientEdge edge3 = (OrientEdge) vertex2.addEdge("next", vertex3);
OrientEdge edge4 = (OrientEdge) vertex3.addEdge("next", vertex);
ODocument rec = vertex.getRecord();
ODirtyManager manager = ORecordInternal.getDirtyManager(rec);
List<OIdentifiable> pointed = manager.getPointed(vertex.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(edge1.getRecord()));
assertTrue(pointed.contains(edge4.getRecord()));
pointed = manager.getPointed(vertex1.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(edge1.getRecord()));
assertTrue(pointed.contains(edge2.getRecord()));
pointed = manager.getPointed(vertex2.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(edge2.getRecord()));
assertTrue(pointed.contains(edge3.getRecord()));
pointed = manager.getPointed(vertex3.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(edge3.getRecord()));
assertTrue(pointed.contains(edge4.getRecord()));
pointed = manager.getPointed(edge1.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(vertex.getRecord()));
assertTrue(pointed.contains(vertex1.getRecord()));
pointed = manager.getPointed(edge2.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(vertex1.getRecord()));
assertTrue(pointed.contains(vertex2.getRecord()));
pointed = manager.getPointed(edge3.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(vertex2.getRecord()));
assertTrue(pointed.contains(vertex3.getRecord()));
pointed = manager.getPointed(edge4.getRecord());
assertEquals(2, pointed.size());
assertTrue(pointed.contains(vertex3.getRecord()));
assertTrue(pointed.contains(vertex.getRecord()));
} finally {
graph.drop();
}
}
Aggregations