【问题标题】:Orientdb partitioned graph java implementationOrientdb分区图java实现
【发布时间】:2016-03-14 22:37:27
【问题描述】:

我有一个后端 Spring 应用程序和 Orientdb 图形数据库。我使用 Tinkerpop Frames 将 orientdb 顶点映射到 java 对象,并使用 OPS4J 进行 spring 事务管理。现在我想在那里实现一个多租户,其中几个客户(租户)使用这个应用程序实例。该应用程序完全按照 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 顶点中创建一个未索引的属性,所以我担心这里查询的性能。

有人有这方面的经验吗?有什么建议吗?

【问题讨论】:

    标签: spring orientdb multi-tenant tinkerpop-blueprint ops4j


    【解决方案1】:

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

    • 获取连接(使用池重用db的实例);
    • 修改V类和E类;创建新用户允许写入;
    • 当你登录db时,user1可以写Vertices,对 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 可能会很有用。不多,但我希望能有所帮助。

    【讨论】:

    • 是的,我知道当我用user1(tenant1)登录时,他可以写其他用户(租户)看不到的顶点,我知道如何在如此低的java级别上做到这一点执行。但我不想编写自己的事务管理器——它相当复杂,而且我没有太多时间。但恐怕我必须向 OPS4J 事务管理器发出拉取请求,这对一个租户来说效果很好,但还没有为更多租户做好准备并在那里实施。我认为 Spring Data Orientdb 仍处于开发阶段,没有稳定版本不是吗?
    • 我将分叉 OPS4J 项目(将 spring 事务与 orientdb 集成)并实现 Orientdb 分区图的解决方案 - 与您的类似或可能相同。无论如何,现在没有人在这方面工作。应该不是这样的问题,就是个小图书馆。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    • 2018-02-01
    • 2018-11-30
    • 2018-04-24
    • 2015-09-09
    相关资源
    最近更新 更多