v.2.0M1 shows a WARNING when creating a Vertex in a transaction
I still have trouble beside my other issue https://github.com/orientechnologies/orientdb/issues/2814
I just ignored that bug and created a fresh graph db via Studio. The following is the try to import data on that fresh database:
First I tried it with this here:
void createClass(String className) {
OrientGraphNoTx txGraph = factoryGraph.getNoTx();
OSchema schema = db.getMetadata().getSchema();
if (!schema.existsClass(className)) {
txGraph.createVertexType(className);
}
txGraph.commit();
txGraph.shutdown();
}
but I got:
Exception in thread "main" java.lang.IllegalStateException: Cannot create a non-transactional graph instance after the pool has been set as transactional
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getNoTx(OrientGraphFactory.java:144)
at de.mapegy.graph.orientdb.OrientDB.createClass(OrientDB.java:186)
at de.mapegy.graph.orientdb.OrientDB.createObjectAppln(OrientDB.java:43)
at de.mapegy.graph.orientdb.OrientDBMain.main(OrientDBMain.java:10)
Well I can understand the error because it says to not mix up tx with NoTx. I don't know why this isn't working anymore in 2.0 but ok. Everything in Tx should be no problem :dancer:
But if I do it the tx way, it work's without error but an ugly WARNING:
void createEdge(String className) {
OrientGraph txGraph = factoryGraph.getTx();
OSchema schema = db.getMetadata().getSchema();
if (!schema.existsClass(className)) {
txGraph.createEdgeType(className);
}
txGraph.commit();
txGraph.shutdown();
}
Sep 19, 2014 4:17:40 PM com.orientechnologies.common.log.OLogManager log
WARNING: Requested command 'create vertex type 'Appln' as subclass of 'V'' must be executed outside active transaction: the transaction will be committed and reopen right after it. To avoid this behavior execute it outside a transaction
406 ms
0 sec
0 min
You can execute things outside a tx scope with:
graph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {
@Override
public Object call(OrientBaseGraph iArgument) {
customer = (OrientVertexType) graph.createVertexType("Customer").setClusterSelection("default");
customer.addCluster("Customer_genius");
customerGeniusCluster = graph.getRawGraph().getClusterIdByName("Customer_genius");
provider = (OrientVertexType) graph.createVertexType("Provider").setClusterSelection("default");
knows = graph.createEdgeType("Knows");
return null;
}
});
}
That works great. Thanks. Now just https://github.com/orientechnologies/orientdb/issues/2814 and my old code from 1.7.8 is working again =)
Hi,
I have tried the above but the code shows the below error: The method executeOutsideTx(OCallable<RET,OrientBaseGraph>, String...) from the type OrientBaseGraph is not visible
Any pointers?
Just curious to know why such a complex way to execute outside Tx? I mean it is common to always check the schema before initiating a transaction.
-Rao
Hey, well I use
void createClass(final String className) {
final OrientGraph txGraph = factoryGraph.getTx();
txGraph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {
public Object call(OrientBaseGraph iArgument) {
txGraph.createVertexType(className).setClusterSelection("default");
return null;
}
});
}
void createEdge(final String className) {
final OrientGraph txGraph = factoryGraph.getTx();
txGraph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {
public Object call(OrientBaseGraph iArgument) {
txGraph.createEdgeType(className).setClusterSelection("default");
return null;
}
});
}
void createProperty(String className, String propertyName, OType oType) {
OrientGraph txGraph = factoryGraph.getTx();
OSchema schema = db.getMetadata().getSchema();
if (!schema.existsClass(className)) {
txGraph.createVertexType(className);
}
txGraph.commit();
txGraph.shutdown();
db.getMetadata().getSchema().getClass(className).createProperty(propertyName, oType);
}
in my import code and it works great. Maybe you miss some librarys?
Thanks kwoxer for the pointer. I tried but it is still the same. BTW whats the db variable in your code? I have used the below libraries. Did I miss anything?
import com.orientechnologies.common.util.OCallable; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.index.OIndex; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.OCommandSQL; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OSchema; import com.orientechnologies.orient.core.metadata.schema.OType; import com.tinkerpop.blueprints.Parameter; import com.tinkerpop.blueprints.impls.orient.OrientBaseGraph; import com.tinkerpop.blueprints.impls.orient.OrientEdgeType; import com.tinkerpop.blueprints.impls.orient.OrientGraph; import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
import com.orientechnologies.orient.server.OServer; import com.orientechnologies.orient.server.OServerMain; import com.orientechnologies.orient.server.network.; import com.orientechnologies.orient.core.; import com.orientechnologies.orient.server.*; import com.orientechnologies.orient.core.db.ODatabase;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
Well I just see some small snippets of your code. And I already wanted to post my import code for OrientDB anyway. So here it is. Sorry for German but the two code files are in English. Feel free to take what you need. Tell me if it's working for you now.
http://www.kwoxer.de/2014/11/12/daten-import-via-java-orientdb-real-beispiel-tutorial/
Hmm..its strange!....i just copied your full exact code of OrientDB.java into a separate class. But still only those two calls to the executeOutsideTx method are showing the same error I mentioned above.
-Rao
Well maybe you have to add suppresswarnings. Is it a Maven proejct or a normal Java Project?
Do you use Eclipse?
And which Librarys are you using, the 2.0M2?