use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class OInternalGraphImporter method runImport.
public void runImport(String inputFile, String dbURL) throws IOException, FileNotFoundException {
if (inputFile == null)
throw new OSystemException("needed an input file as first argument");
if (dbURL == null)
throw new OSystemException("needed an database location as second argument");
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbURL);
ODatabaseHelper.deleteDatabase(db, db.getStorage().getType());
OrientBaseGraph g = OrientGraphFactory.getNoTxGraphImplFactory().getGraph(dbURL);
System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "...");
final long startTime = System.currentTimeMillis();
OConsoleDatabaseApp console = new OGremlinConsole(new String[] { "import database " + inputFile }).setCurrentDatabase(g.getRawGraph());
console.run();
System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices());
g.command(new OCommandSQL("alter database TIMEZONE 'GMT'")).execute();
g.command(new OCommandSQL("alter database LOCALECOUNTRY 'UK'")).execute();
g.command(new OCommandSQL("alter database LOCALELANGUAGE 'EN'")).execute();
g.shutdown();
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class OGraphShortestPathWorkload method execute.
@Override
public void execute(final OStressTesterSettings settings, final ODatabaseIdentifier databaseIdentifier) {
connectionStrategy = settings.loadBalancing;
// RETRIEVE THE STARTING VERTICES
final OrientGraphNoTx g = getGraphNoTx(databaseIdentifier);
try {
for (OIdentifiable id : g.getRawGraph().browseClass("V")) {
startingVertices.add(id.getIdentity());
if (limit > -1 && startingVertices.size() >= limit)
break;
}
} finally {
g.shutdown();
}
result.total = startingVertices.size();
executeOperation(databaseIdentifier, result, settings, new OCallable<Void, OBaseWorkLoadContext>() {
@Override
public Void call(final OBaseWorkLoadContext context) {
final OWorkLoadContext graphContext = ((OWorkLoadContext) context);
final OrientBaseGraph graph = graphContext.graph;
for (int i = 0; i < startingVertices.size(); ++i) {
final Iterable<OrientVertex> commandResult = graph.command(new OCommandSQL("select shortestPath(?,?, 'both')")).execute(startingVertices.get(context.currentIdx), startingVertices.get(i));
for (OrientVertex v : commandResult) {
Collection depth = v.getRecord().field("shortestPath");
if (depth != null && !depth.isEmpty()) {
totalDepth.addAndGet(depth.size());
long max = maxDepth.get();
while (depth.size() > max) {
if (maxDepth.compareAndSet(max, depth.size()))
break;
max = maxDepth.get();
}
} else
notConnected.incrementAndGet();
}
}
result.current.incrementAndGet();
return null;
}
});
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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) {
try {
final OrientVertexType c = g.createVertexType(className);
c.createProperty("_id", OType.LONG);
c.createProperty("ts", OType.DATETIME);
} catch (OSchemaException e) {
// IGNORE IT, ALREADY CREATED
}
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class OGraphInsertWorkload method execute.
@Override
public void execute(final OStressTesterSettings settings, final ODatabaseIdentifier databaseIdentifier) {
connectionStrategy = settings.loadBalancing;
final List<OBaseWorkLoadContext> contexts = executeOperation(databaseIdentifier, resultVertices, settings, new OCallable<Void, OBaseWorkLoadContext>() {
@Override
public Void call(final OBaseWorkLoadContext context) {
final OWorkLoadContext graphContext = ((OWorkLoadContext) context);
final OrientBaseGraph graph = graphContext.graph;
final OrientVertex v = graph.addVertex("class:" + className, "_id", resultVertices.current.get(), "ts", System.currentTimeMillis());
if (graphContext.lastVertexToConnect != null) {
v.addEdge("E", graphContext.lastVertexToConnect);
resultEdges.current.incrementAndGet();
graphContext.lastVertexEdges++;
if (graphContext.lastVertexEdges > factor) {
graphContext.lastVertexEdges = 0;
if (strategy == STRATEGIES.LAST)
graphContext.lastVertexToConnect = v;
else if (strategy == STRATEGIES.RANDOM) {
do {
final int[] totalClusters = graph.getVertexBaseType().getClusterIds();
final int randomCluster = totalClusters[new Random().nextInt(totalClusters.length)];
long totClusterRecords = graph.getRawGraph().countClusterElements(randomCluster);
if (totClusterRecords > 0) {
final ORecordId randomRid = new ORecordId(randomCluster, new Random().nextInt((int) totClusterRecords));
graphContext.lastVertexToConnect = graph.getVertex(randomRid);
break;
}
} while (true);
} else if (strategy == STRATEGIES.SUPERNODE) {
final int[] totalClusters = graph.getVertexBaseType().getClusterIds();
final int firstCluster = totalClusters[0];
long totClusterRecords = graph.getRawGraph().countClusterElements(firstCluster);
if (totClusterRecords > 0) {
final ORecordId randomRid = new ORecordId(firstCluster, 0);
graphContext.lastVertexToConnect = graph.getVertex(randomRid);
}
}
}
} else
graphContext.lastVertexToConnect = v;
resultVertices.current.incrementAndGet();
return null;
}
});
final OrientBaseGraph graph = settings.operationsPerTransaction > 0 ? getGraph(databaseIdentifier) : getGraphNoTx(databaseIdentifier);
try {
// CONNECTED ALL THE SUB GRAPHS
OrientVertex lastVertex = null;
for (OBaseWorkLoadContext context : contexts) {
for (int retry = 0; retry < 100; ++retry) try {
if (lastVertex != null)
lastVertex.addEdge("E", ((OWorkLoadContext) context).lastVertexToConnect);
lastVertex = ((OWorkLoadContext) context).lastVertexToConnect;
} catch (ONeedRetryException e) {
if (lastVertex.getIdentity().isPersistent())
lastVertex.reload();
if (((OWorkLoadContext) context).lastVertexToConnect.getIdentity().isPersistent())
((OWorkLoadContext) context).lastVertexToConnect.reload();
}
}
} finally {
graph.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class TestGraphRecovering method testRecoverPerfectGraphNonLW.
@Test
public void testRecoverPerfectGraphNonLW() {
final OrientBaseGraph g = new OrientGraphNoTx("memory:testRecoverPerfectGraphNonLW");
try {
init(g, false);
final TestListener eventListener = new TestListener();
new OGraphRepair().setEventListener(eventListener).repair(g, null, null);
Assert.assertEquals(eventListener.scannedEdges, 3);
Assert.assertEquals(eventListener.removedEdges, 0);
Assert.assertEquals(eventListener.scannedVertices, 3);
Assert.assertEquals(eventListener.scannedLinks, 6);
Assert.assertEquals(eventListener.removedLinks, 0);
Assert.assertEquals(eventListener.repairedVertices, 0);
} finally {
g.shutdown();
}
}
Aggregations