将临时顶点添加到新的Tx

时间:2019-04-12 11:20:35

标签: java orientdb

我需要从一个TX添加一个临时顶点到另一个TX。 由于创建临时顶点和最终提交之间的时间太长,我想关闭第一个TX,并在保存时间到了,开始一个新的TX,并保存所有修改后的顶点。 可以在现有顶点上正常工作,但在临时上会失败。

查看以下代码:

private void testAttach() {
        OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/Test", "root", "toor").setupPool(10, 50);
        OrientGraph tx = factory.getTx();
        HashMap<String,String> hm = new HashMap<>();

        long ls = System.currentTimeMillis();
        System.out.println("timestamp: "+ls);
        hm.put("s", "test temporal "+ls);

        OrientVertex onew = tx.addVertex("SimpleVertex", hm);
        System.out.println("onew RID: "+onew.getId() + " isDetached: "+onew.isDetached() + " isLocked: "+onew.isLocked());
        System.out.println("detach...");
        onew.detach();
        System.out.println("onew RID: "+onew.getId() + " isDetached: "+onew.isDetached() + " isLocked: "+onew.isLocked());

        OrientVertex onew1 = tx.addVertex("SimpleVertex", hm);
        OrientVertex onew2 = tx.addVertex("SimpleVertex", hm);
        System.out.println(""+onew.getId()+" - "+onew1.getId()+" - "+onew2.getId());

        System.out.println("recupearndo existente ");
        OrientVertex oEx = tx.getVertex("#33:1665");
        System.out.println("Existente: "+oEx.getId().toString());

        System.out.println("cerrando la tx...");
        tx.shutdown(true, false);

        System.out.println("post shutdown tx: ");
        System.out.println("onew RID: "+onew.getId() + " isDetached: "+onew.isDetached() + " isLocked: "+onew.isLocked());

        System.out.println("abriendo tx...");
        tx = factory.getTx();

        OrientVertex onew3 = tx.addVertex("SimpleVertex", hm);
        OrientVertex onew4 = tx.addVertex("SimpleVertex", hm);
        System.out.println(""+onew.getId()+" - "+onew1.getId()+" - "+onew2.getId()+" - "+onew3.getId()+" - "+onew4.getId());


        System.out.println("oEx RID: "+oEx.getId() + " isDetached: "+oEx.isDetached() + " isLocked: "+oEx.isLocked());
        oEx.setProperty("s", oEx.getProperty("s")+"-");

        tx.attach(onew);
        System.out.println("onew RID: "+onew.getId() + " isDetached: "+onew.isDetached() + " isLocked: "+onew.isLocked());
        tx.commit();
        System.out.println("onew RID: "+onew.getId() + " isDetached: "+onew.isDetached() + " isLocked: "+onew.isLocked());

    }

这将产生以下输出:

timestamp: 1555066533622
onew RID: #-1:-2 isDetached: false isLocked: false
detach...
onew RID: #-1:-2 isDetached: true isLocked: false
#-1:-2 - #-1:-3 - #-1:-4
recuperando existente 
Existente: #33:1665
cerrando la tx...
post shutdown tx: 
onew RID: #-1:-2 isDetached: true isLocked: false
abriendo tx...
#-1:-2 - #-1:-3 - #-1:-4 - #-1:-2 - #-1:-3
oEx RID: #33:1665 isDetached: false isLocked: false
onew RID: #-1:-2 isDetached: false isLocked: false
onew RID: #-1:-2 isDetached: false isLocked: false

我看到的是每个Tx生成的临时ID。

现有对象会自动附加到新打开的Tx,并在提交时正确保存。

我还没有找到将临时顶点附加到新Tx的方法,提交tx时将其忽略。

有什么办法吗?

0 个答案:

没有答案