.getGraph(ODatabaseRecordThreadLocal.instance().get());
new OGraphRepair().repair(OrientGraphFactory.getNoTxGraphImplFactory().getGraph(currentDatabase), this, options);
shouldBeShutDown.setValue(true); final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(database, false); if (autoStartTx && autoTxStartRequired(database)) g.begin();
@Override @ConsoleCommand(description = "Export a database", splitInWords = false, onlineHelp = "Console-Command-Export") public void exportDatabase(@ConsoleParameter(name = "options", description = "Export options") String iText) throws IOException { checkForDatabase(); final List<String> items = OStringSerializerHelper.smartSplit(iText, ' '); final String fileName = items.size() <= 1 || items.get(1).charAt(0) == '-' ? null : items.get(1); if (fileName != null && (fileName.endsWith(".graphml") || fileName.endsWith(".xml"))) { message("\nExporting database in GRAPHML format to " + iText + "..."); final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase); try { g.setUseLog(false); g.setWarnOnForceClosingTx(false); // CREATE THE EXPORT FILE IF NOT EXIST YET final File f = new File(fileName); if (f.getParentFile() != null) { f.getParentFile().mkdirs(); } f.createNewFile(); new GraphMLWriter(g).outputGraph(fileName); } catch (ODatabaseImportException e) { printError(e); }finally { g.shutdown(false, true); } } else // BASE EXPORT super.exportDatabase(iText); }
public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException { final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION); if (graphFile == null || graphFile.length() == 0) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION); } // get the <properties> section of the xml configuration final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties(); SubnodeConfiguration orientDbSpecificConfiguration; try { orientDbSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES); } catch (IllegalArgumentException iae) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES, iae); } try { final String username = orientDbSpecificConfiguration.getString("username", ""); final String password = orientDbSpecificConfiguration.getString("password", ""); // calling the open method opens the connection to graphdb. looks like the // implementation of shutdown will call the orientdb close method. return OrientGraphFactory.getTxGraphImplFactory().getGraph(graphFile, username, password); } catch (Exception ex) { throw new GraphConfigurationException(ex); } }
/** * @return any graph if available, otherwise a Non Transactional OrientGraph implementation from the current database in thread * local. */ public static OrientBaseGraph getAnyGraph(final OModifiableBoolean shouldBeShutDown) { final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.instance().get(); final OrientBaseGraph result = OrientBaseGraph.getActiveGraph(); if (result != null) { final ODatabaseDocument graphDb = result.getRawGraph(); // CHECK IF THE DATABASE + USER IN TL IS THE SAME IN ORDER TO USE IT if (canReuseActiveGraph(graphDb, database)) { if (!graphDb.isClosed()) { graphDb.activateOnCurrentThread(); shouldBeShutDown.setValue(false); return result; } } } // Set it again on ThreadLocal because the getRawGraph() may have set a closed db in the thread-local shouldBeShutDown.setValue(true); ODatabaseRecordThreadLocal.instance().set(database); return OrientGraphFactory.getNoTxGraphImplFactory().getGraph(database); }
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"); ODatabaseDocumentInternal db = new ODatabaseDocumentTx(dbURL); ODatabaseHelper.deleteDatabase(db, db.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(); } }
/** * @return a Non Transactional OrientGraph implementation from the current database in thread local. */ public static OrientGraphNoTx getGraphNoTx(final OModifiableBoolean shouldBeShutDown) { final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.instance().get(); final OrientBaseGraph result = OrientBaseGraph.getActiveGraph(); if (result != null && (result instanceof OrientGraphNoTx)) { final ODatabaseDocumentInternal graphDb = result.getRawGraph(); // CHECK IF THE DATABASE + USER IN TL IS THE SAME IN ORDER TO USE IT if (canReuseActiveGraph(graphDb, database)) { if (!graphDb.isClosed()) { ODatabaseRecordThreadLocal.instance().set(graphDb); shouldBeShutDown.setValue(false); return (OrientGraphNoTx) result; } } } // Set it again on ThreadLocal because the getRawGraph() may have set a closed db in the thread-local shouldBeShutDown.setValue(true); ODatabaseRecordThreadLocal.instance().set(database); return (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database); }
/** * Gets non transactional graph with the database from pool if pool is configured. Otherwise creates a graph with new db instance. * The Graph instance inherits the factory's configuration. * * @return non transactional graph */ public OrientGraphNoTx getNoTx() { final OrientGraphNoTx g; if (pool == null) { g = (OrientGraphNoTx) getNoTxGraphImplFactory().getGraph(getDatabase(), user, password, settings); } else { // USE THE POOL g = (OrientGraphNoTx) getNoTxGraphImplFactory().getGraph(pool, settings); } initGraph(g); return g; }
/** * Gets transactional graph with the database from pool if pool is configured. Otherwise creates a graph with new db instance. The * Graph instance inherits the factory's configuration. * * @return transactional graph */ public OrientGraph getTx() { final OrientGraph g; if (pool == null) { g = (OrientGraph) getTxGraphImplFactory().getGraph(getDatabase(), user, password, settings); } else { // USE THE POOL g = (OrientGraph) getTxGraphImplFactory().getGraph(pool, settings); } initGraph(g); return g; }
public OrientGraph acquireGraph(final ODatabaseDocumentInternal database) { return (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(database); }
@Override @ConsoleCommand(description = "Check database integrity", splitInWords = false) public void checkDatabase( @ConsoleParameter(name = "options", description = "Options: -v --skip-graph", optional = true) final String iOptions) throws IOException { final boolean fix_graph = iOptions == null || !iOptions.contains("--skip-graph"); if (fix_graph) { // REPAIR GRAPH final Map<String, List<String>> options = parseOptions(iOptions); new OGraphRepair().check(OrientGraphFactory.getNoTxGraphImplFactory().getGraph(currentDatabase), this, options); } super.checkDatabase(iOptions); }
protected OrientGraphNoTx getGraphNoTx(final ODatabaseIdentifier databaseIdentifier) { final ODatabase database = ODatabaseUtils.openDatabase(databaseIdentifier, connectionStrategy); if (database == null) throw new IllegalArgumentException("Error on opening database " + databaseIdentifier.getName()); return (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database); }
public OScriptGraphWrapper getGraph() { final ODatabaseDocumentInternal threadDatabase = (ODatabaseDocumentInternal) ODatabaseRecordThreadLocal.instance().get() .getDatabaseOwner(); return new OScriptGraphWrapper(OrientGraphFactory.getTxGraphImplFactory().getGraph(threadDatabase)); } }
public OScriptGraphWrapper getGraphNoTx() { final ODatabaseDocumentInternal threadDatabase = (ODatabaseDocumentInternal) ODatabaseRecordThreadLocal.instance().get() .getDatabaseOwner(); return new OScriptGraphWrapper(OrientGraphFactory.getNoTxGraphImplFactory().getGraph(threadDatabase)); }
@Override public OrientGraph rawTx() { ODatabaseSession db = context.open(DB_NAME, "admin", "admin"); return (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph((ODatabaseDocumentInternal) db); }
protected OrientGraph getGraph(final ODatabaseIdentifier databaseIdentifier) { final ODatabase database = ODatabaseUtils.openDatabase(databaseIdentifier, connectionStrategy); if (database == null) throw new IllegalArgumentException("Error on opening database " + databaseIdentifier.getName()); final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database); g.setAutoStartTx(false); return g; }
@Override public OrientGraphNoTx rawNoTx() { ODatabaseSession db = context.open(DB_NAME, "admin", "admin"); return (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentInternal) db); }