Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Orientdb分区图java实现_Spring_Orientdb_Multi Tenant_Tinkerpop Blueprint_Ops4j - Fatal编程技术网

Spring Orientdb分区图java实现

Spring Orientdb分区图java实现,spring,orientdb,multi-tenant,tinkerpop-blueprint,ops4j,Spring,Orientdb,Multi Tenant,Tinkerpop Blueprint,Ops4j,我有一个后端Spring应用程序和Orientdb图形数据库。我使用Tinkerpop框架将orientdb顶点映射到java对象,并使用OPS4J进行spring事务管理。现在我想在那里实现一个多租户,其中多个客户(租户)使用这个应用程序实例。此应用程序完全基于REST原则,并且它对多个角度应用程序开放—每个客户都有。因此,前端Angle应用程序和我们的客户一样多,只有一个后端REST Spring应用程序。后端从HTTP请求中识别租户 现在我不确定最好的解决方案 第一个解决方案 当我阅读Or

我有一个后端Spring应用程序和Orientdb图形数据库。我使用Tinkerpop框架将orientdb顶点映射到java对象,并使用OPS4J进行spring事务管理。现在我想在那里实现一个多租户,其中多个客户(租户)使用这个应用程序实例。此应用程序完全基于REST原则,并且它对多个角度应用程序开放—每个客户都有。因此,前端Angle应用程序和我们的客户一样多,只有一个后端REST Spring应用程序。后端从HTTP请求中识别租户

现在我不确定最好的解决方案

第一个解决方案

当我阅读Orientdb文档时,我发现了一种在Orientdb-中实现多租户的方法。但是,我不知道如何通过JavaAPI使用它,除非我不想为每个请求创建新的数据库连接。因为现在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());
}
受保护的FramedGraph FramedGraph(){
返回framedGraphFactory.create(gdbf.graph());
}
第二种解决方案

另一个解决方案是使用修补匠

分区图

类,但我在Orientdb文档中没有找到任何关于这种可能性的句子。就这个在小叮当-。它可以工作,但最终只会在每个orientdb顶点中创建一个未索引属性,所以我担心这里的查询性能


有人有过这样的经历吗?有什么建议吗?

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

  • 获取连接(使用池重用数据库的距离)
  • 修改V类和E类;创建新用户,使其能够写入
  • 当您登录数据库时,user1可以写入对数据库不可见的顶点 用户2和相反

    //写入控制器:创建用户使能在DB上写入。。。。。。。。。。。。。。 连接con=新连接(); OrientGraph noTx=con.getConnection()

    //创建分区
    noTx.begin();
    命令(新的OCommandSQL(“ALTER CLASS V superclass orestricted”)).execute();
    命令(新的OCommandSQL(“ALTER CLASS E superclass orestricted”)).execute();
    noTx.commit();
    //创建不同的用户
    noTx.begin();
    字符串规则=”;
    Iterable rule=noTx.command(新的OCommandSQL(“从ORole中选择,其中name='writer')).execute();
    ridRule=rule.iterator().next().getId().toString();
    命令(新的OCommandSQL(“插入用户集名称='user1',状态='ACTIVE',密码='user1',角色=[“+ridRule+”])))。执行();
    命令(新的OCommandSQL(“插入用户集名称='user2',状态='ACTIVE',密码='user2',角色=[“+ridRule+”])))。执行();
    noTx.commit();
    //不会关闭图形实例,但将保持打开状态并可供下一个请求者使用
    noTx.shutdown();
    //最后,释放所有实例并释放所有资源
    con.clodealconnect();
    //写入控制器:使用适当的用户登录。。。。。。。。。。。。。。。。。。。。。
    //使用user1或user2登录的代码,创建顶点集标签='food',名称='Pizza'等。。。。
    }
    //豆子
    公共静态类连接{
    private OrientGraphFactory工厂=null;
    公共连接(){
    //可回收的实例池
    工厂=新的OrientGraphFactory(“远程:localhost/blog”)。设置池(1,10);
    }
    //返回连接
    公共方向图getConnection(){
    OrientGraph txGraph=factory.getTx();
    返回TX图;
    }
    公共无效ClodealConnect(){
    工厂关闭();
    }
    }
    

要调整这些步骤并将它们插入Spring中,这一链接可能非常有用。这并不多,但我希望能有所帮助。

是的,我知道当我使用user1(租户1)登录时,他可以编写其他用户(租户)看不到的顶点,我知道如何在如此低的java实现级别上完成。但我不想编写自己的事务管理器——它相当复杂,而且我没有太多时间。但我恐怕必须向OPS4J事务处理maanger发出拉取请求,这对一个租户来说效果很好,但还没有为更多租户做好准备并在那里实现它。我认为Spring Data Orientdb仍处于开发阶段,没有稳定的版本,不是吗?我将参与OPS4J项目(将Spring事务与Orientdb集成),并为Orientdb分区图实现解决方案-与您的类似或相同。现在没有人在做这件事。这不应该是个问题,这是个小图书馆。
//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();

    }
}