Skip to content

Commit

Permalink
Merge pull request #107 from velo/i93
Browse files Browse the repository at this point in the history
Fix for i93
  • Loading branch information
mpollmeier committed Nov 1, 2016
2 parents 4671879 + b8121d5 commit 09143cb
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 21 deletions.
@@ -1,5 +1,24 @@
package org.apache.tinkerpop.gremlin.orientdb;

import static org.apache.tinkerpop.gremlin.orientdb.StreamUtils.asStream;

import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.NotImplementedException;
import org.apache.tinkerpop.gremlin.orientdb.traversal.strategy.optimization.OrientGraphStepStrategy;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
import org.apache.tinkerpop.gremlin.structure.*;
import org.apache.tinkerpop.gremlin.structure.io.Io;
import org.apache.tinkerpop.gremlin.structure.io.Io.Builder;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.util.OCallable;
Expand All @@ -21,24 +40,6 @@
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.storage.OStorage;
import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.NotImplementedException;
import org.apache.tinkerpop.gremlin.orientdb.traversal.strategy.optimization.OrientGraphStepStrategy;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
import org.apache.tinkerpop.gremlin.structure.*;
import org.apache.tinkerpop.gremlin.structure.io.Io;
import org.apache.tinkerpop.gremlin.structure.io.Io.Builder;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;

import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static org.apache.tinkerpop.gremlin.orientdb.StreamUtils.asStream;

@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_STANDARD)
@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_INTEGRATE)
Expand Down Expand Up @@ -413,7 +414,10 @@ record = record.getRecord();
}

@Override
public Transaction tx() {
public OrientTransaction tx() {
if (!features.graph().supportsTransactions())
return new OrientNoTransaction(this);

makeActive();
return new OrientTransaction(this);
}
Expand Down Expand Up @@ -497,7 +501,7 @@ public Configuration configuration() {
}

@Override
public void close() throws Exception {
public void close() {
makeActive();
boolean commitTx = true;
String url = database.getURL();
Expand Down
@@ -0,0 +1,29 @@
package org.apache.tinkerpop.gremlin.orientdb;

public class OrientNoTransaction extends OrientTransaction {

public OrientNoTransaction(OrientGraph g) {
super(g);
}

@Override
public boolean isOpen() {
return false;
}

@Override
protected void doOpen() {
// do nothing, no transaction
}

@Override
protected void doCommit() throws TransactionException {
// do nothing, no transaction
}

@Override
protected void doRollback() throws TransactionException {
// do nothing, no transaction
}

}
Expand Up @@ -9,7 +9,7 @@ public class OrientTransaction extends AbstractThreadLocalTransaction {
public OrientTransaction(OrientGraph graph) {
super(graph);
this.graph = graph;
graph.begin();
doOpen();
}

@Override
Expand Down
@@ -0,0 +1,47 @@
package org.apache.tinkerpop.gremlin.orientdb;

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Test;

public class TransactionIdsTest {

@Test
public void withTransaction() {
final String labelVertex = "VertexLabel";
OrientGraph graph = new OrientGraphFactory("memory:myGraph").getTx();
Vertex v1 = graph.addVertex(labelVertex);
graph.tx().commit();

v1 = graph.traversal().V().next();

Vertex v2 = graph.addVertex(labelVertex);
graph.tx().commit();

GraphTraversal<Vertex, Edge> traversal = graph.traversal().V(v2.id()).outE().as("edge").otherV().hasId(v2)
.select("edge");
traversal.hasNext();

graph.close();
}

@Test
public void withoutTransaction() {
final String labelVertex = "VertexLabel";
OrientGraph graph = new OrientGraphFactory("memory:myGraph").getNoTx();
Vertex v1 = graph.addVertex(labelVertex);
graph.tx().commit();

v1 = graph.traversal().V().next();

Vertex v2 = graph.addVertex(labelVertex);

GraphTraversal<Vertex, Edge> traversal = graph.traversal().V(v2.id()).outE().as("edge").otherV().hasId(v2)
.select("edge");
traversal.hasNext();

graph.close();
}

}

0 comments on commit 09143cb

Please sign in to comment.