Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.example.graph.orientdb;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.net.URI;
- import org.apache.log4j.Logger;
- import com.orientechnologies.orient.core.command.OCommandOutputListener;
- import com.orientechnologies.orient.core.db.record.ODatabaseRecord;
- import com.orientechnologies.orient.core.db.tool.ODatabaseExport;
- import com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph;
- /**
- * @author Salvatore Piccione
- *
- */
- public class GraphDatabaseExporter {
- protected static final Logger LOGGER = Logger.getLogger(GraphDatabaseExporter.class);
- private static final String DATABASE_URL = "remote:orientdb-host/tinkerpop";
- private static final String USERNAME = "admin";
- private static final String PASSWORD = "admin";
- /**
- * @param args
- */
- public static void main(String[] args) {
- final URI fileURI = new File("C:\\path\\to\\export\\dir\\exp_db.json").toURI();
- //check the parameters
- if (fileURI == null) {
- IllegalArgumentException topicNullExcep = new IllegalArgumentException(
- "The URI of the file exporting the database '" + DATABASE_URL +
- "' to cannot be null.");
- LOGGER.error(topicNullExcep.getMessage(),topicNullExcep);
- throw topicNullExcep;
- }
- File file = new File (fileURI);
- OutputStream fileStream = null;
- try {
- fileStream = new BufferedOutputStream(new FileOutputStream(file));
- } catch (FileNotFoundException e) {
- LOGGER.error("Error in opening the file " + fileURI.toString() + "(database export)", e);
- System.exit(1);
- }
- OrientGraph graph = new OrientGraph(
- DATABASE_URL, USERNAME,PASSWORD);
- ODatabaseExport exportManager = null;
- ODatabaseRecord database = null;
- try {
- database = graph.getRawGraph();
- exportManager = new ODatabaseExport(database ,fileStream,new OCommandOutputListener () {
- public void onMessage(String iText) {
- LOGGER.debug("Exporting database " + DATABASE_URL +
- " to " + fileURI.toString() + " - " + iText);
- }
- });
- exportManager.exportDatabase();
- /*
- exportManager.exportRecords();*/
- exportManager.close();
- database.close();
- } catch (IOException e) {
- LOGGER.error("Exception during the export of the database " + DATABASE_URL
- + " to the file " + fileURI.toString(), e);
- if (exportManager != null)
- exportManager.close();
- if (database != null)
- database.close();
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement