简体   繁体   English

Orientdb:将数据库导入内存中并将其用作图形

[英]Orientdb: Import database in memory and use it as graph

This is my Java DB class in which I open database and import database export file in memory graph database, where I define all database schema information for testing cases. 这是我的Java DB类,在其中打开数据库并在内存图数据库中导入数据库导出文件,在其中定义用于测试用例的所有数据库模式信息。

Operation going well but how can I access the imported database as graph instance and not document instance of database? 操作进行得很好,但是如何以图形实例而不是数据库的文档实例访问导入的数据库?

I try so many things but I have failed... 我尝试了很多事情,但是失败了...

Error : 错误:

The Person class exist in my schema so something else is going wrong. Person类存在于我的模式中,所以其他地方出了问题。

Caused by:
> com.orientechnologies.orient.core.exception.OCommandExecutionException:
> Class 'PERSON' was not found in current database

Code: 码:

import com.orientechnologies.orient.core.db.tool.ODatabaseExportException;
import com.orientechnologies.orient.core.db.tool.ODatabaseImport;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import lombok.Getter;

import java.io.IOException;

public class Db {

    @Getter private static OrientGraphFactory factory;
    @Getter private static OrientGraphNoTx graph;

    static public void main(String[] args){
        open("memory","database");
        importDB("/schemas/diary-11202016.gz");
        try {
            seed();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        closeDB();
    }

    public static void open(String dbType, String dbUrl) {

        String dbInfo = dbType + ":" + dbUrl;
        System.out.println(dbInfo);

        factory = new OrientGraphFactory(dbInfo, "root", "root").setupPool(1, 10);
        graph = factory.getNoTx();
    }

    public static void importDB(String path) {
        try {
            ODatabaseImport importDb = new ODatabaseImport(graph.getRawGraph(), Db.class.getResourceAsStream(path), (iText) -> {
                System.out.print(iText);
            });
            importDb.setMerge(true);
            importDb.importDatabase();
            importDb.close();
            System.out.println("\nImporting database: OK");
        } catch (ODatabaseExportException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void seed() throws InterruptedException {
        System.out.println("Starting to seed...");
        for (Vertex v : (Iterable<Vertex>) graph.command( new OCommandSQL("select from Person")).execute()) {
            System.out.println("- Bought: " + v.getProperty("name"));
        }
        System.out.println("Finish to seed...");
    }

    public static void closeDB() {
        factory.close();
    }
}

Replace the following piece of code 替换下面的代码

ODatabaseImport importDb = new ODatabaseImport(graph.getRawGraph(), Db.class.getResourceAsStream(path), (iText) -> {
                System.out.print(iText);
            });
importDb.setMerge(true);

with

ODatabaseImport importDb = new ODatabaseImport(graph.getRawGraph(), path, (iText) -> {
                System.out.print(iText);
            });
// importDb.setMerge(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM