我有一个后端Spring应用程序和Orientdb图形数据库。我使用Tinkerpop框架将orientdb顶点映射到java对象,并使用OPS4J进行春季事务管理。现在,我想在那里实现一个多租户,其中多个客户(租户)使用此一个应用程序实例。该应用程序完全按照REST原理工作,并且向多个Angular应用程序开放-每个客户都可以使用。因此,与我们的客户一样多的前端Angular应用程序,只有一个后端REST Spring应用程序。后端从HTTP请求中识别租户。

现在我不确定最佳解决方案...

第一个解决方案

当我阅读Orientdb文档时,我发现了一种在Orientdb中实现多租户的方法-http://orientdb.com/docs/2.1/Partitioned-Graphs.html。但是,除非我不想为每个请求创建新的数据库连接,否则我不知道如何通过Java API使用它。因为现在,Spring事务管理器从连接池中获取连接,而连接池是在Spring事务管理配置中集中设置的。我没有找到任何Java示例。

Spring事务管理配置:

@Configuration
@EnableTransactionManagement
public class TransactionConfig {

    @Bean
    @Qualifier("graphDbTx")
    public OrientTransactionManager graphDbTransactionManager() {
        OrientTransactionManager bean = new OrientTransactionManager();
        bean.setDatabaseManager(graphDatabaseFactory());
        return bean;
    }

    @Bean
    public OrientBlueprintsGraphFactory graphDatabaseFactory() {
        OrientBlueprintsGraphFactory dbf = new OrientBlueprintsGraphFactory();
        dbf.setMaxPoolSize(6);
        dbf.setUrl(DbConfig.DATABASE_URL);
        dbf.setUsername("admin");
        dbf.setPassword("admin");
        return dbf;
    }

    @Bean
    public FramedGraphFactory framedGraphFactory() {
        return new FramedGraphFactory(new JavaHandlerModule());
    }

}


建立连接:

protected FramedGraph<OrientGraph> framedGraph() {
    return framedGraphFactory.create(gdbf.graph());
}


第二解决方案

另一个解决方案是使用Tinkerpop


分区图


在Orientdb上有效的类,但是在Orientdb文档中没有找到关于这种可能性的任何句子。在Tinkerpop中就是这样-https://github.com/tinkerpop/blueprints/wiki/Partition-Implementation。它可以工作,但最后它只会在每个orientdb顶点中创建一个未索引的属性,因此我担心此处的查询性能。

有人对此有经验吗?有什么建议吗?

最佳答案

使用Java API创建分区数据库(如果我了解您的兴趣)的宏步骤为:


获取连接(使用池,db的位置被重用);
修改V和E类;创建新的用户启用写入;
当您登录数据库时,user1可以写入顶点,该顶点对于
user2相反;

//在您的控制器中写入:创建用户后可以在数据库上写入...........。
连接con = new Connection();
OrientGraph noTx = con.getConnection();

//create partition
    noTx.begin();
    noTx.command(new OCommandSQL("ALTER CLASS V superclass orestricted")).execute();
    noTx.command(new OCommandSQL("ALTER CLASS E superclass orestricted")).execute();
    noTx.commit();

    //create different users
    noTx.begin();
    String ridRule = "";
    Iterable<Vertex> rule = noTx.command(new OCommandSQL("select from ORole where name = 'writer'")).execute();
    ridRule = rule.iterator().next().getId().toString();
    noTx.command(new OCommandSQL("INSERT INTO ouser SET name = 'user1', status = 'ACTIVE', password = 'user1', roles = ["+ridRule+"]")).execute();
    noTx.command(new OCommandSQL("INSERT INTO ouser SET name = 'user2', status = 'ACTIVE', password = 'user2', roles = ["+ridRule+"]")).execute();
    noTx.commit();

    //will not close the graph instance, but will keep open and available for the next requester
    noTx.shutdown();

    //finally To release all the instances and free all the resources
    con.clodeAllConnect();


    //WRITE IN YOUR CONTROLLER: LOGIN WITH USER APPROPRIATE .....................
    //CODE to login with user1 or user2,  CREATE VERTEX SET label = 'food', name = 'Pizza' etc....
}


//beans
public static class Connection {

    private OrientGraphFactory factory = null;

    public Connection() {
        //recyclable pool of instances
        factory = new OrientGraphFactory("remote:localhost/blog").setupPool(1, 10);
    }

    //return the connection
    public OrientGraph getConnection() {
        OrientGraph txGraph = factory.getTx();
        return txGraph;
    }

    public void clodeAllConnect(){
        factory.close();

    }
}



要调整这些步骤并将其插入Spring,此链接OrientDB - spring implementation可能会很有用。数量不多,但希望对您有所帮助。

关于spring - OrientDB分区图Java实现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35999431/

10-11 02:21