I'm trying to use OrientDB in an JavaFX desktop app by connecting to a remote server.
I tried some code snippets first without JavaFX. They worked. I could connect, qurey and it print.out over console.
But inside of an JavaFX app there seems to be some issues related to the way threads are handeled.
I read the chapter about Multy-Threading for OrientDB but I don't seem to understand.
An example on how to use orientDB in a JavaFX would be very helpful!
In my last try I used a backgrooud Thread, here is the example:
@FXML
private void abfragenButtonClick(ActionEvent event) {
//Create a Runnable
Runnable task = () -> queryOrientDB();
//Run the task in a background thread
Thread backgroundThread = new Thread(task);
//Terminate the running thread if the application exits
backgroundThread.setDaemon(true);
//Start the thread
backgroundThread.start();
}
public void queryOrientDB() {
OrientGraphFactory factory = new OrientGraphFactory("remote:127.0.0.1:2424/Database", "admin", "admin").setupPool(1, 10);
OrientGraph graph = factory.getTx();
try {
for (Vertex v : (Iterable<Vertex>) graph.command(new OCommandSQL(
"SELECT FROM v LIMIT 10"
)).execute()) {
System.out.println(v.toString());
}
} finally {
graph.shutdown();
}
}
Exception
in thread "Thread-4"
com.orientechnologies.orient.core.exception.ODatabaseException: Error on
opening database 'remote:
127.0.0.1:2424/
Database
'
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:187)
at
com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPolled.<init>(OPartitionedDatabasePool.java:118)
at
com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPolled.<init>(OPartitionedDatabasePool.java:114)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.initQueue(OPartitionedDatabasePool.java:442)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.<init>(OPartitionedDatabasePool.java:217)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.<init>(OrientGraphFactory.java:78)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.<init>(OrientGraphFactory.java:55)
at com.mycompany.dmtest.FXMLController.queryOrientDB(FXMLController.java:48)
at com.mycompany.dmtest.FXMLController.lambda$abfragenButtonClick$0(FXMLController.java:34)
at java.lang.Thread.run(Thread.java:745)
Caused
by:
com.orientechnologies.orient.core.exception.OConfigurationException:
Error on opening database: the engine 'remote' was not found. URL was:
remote:
127.0.0.1:2424/
Database
. Registered engines are: [memory,
plocal]
DB name="remote:
127.0.0.1:2424/
Database
"
at com.orientechnologies.orient.core.Orient.loadStorage(Orient.java:476)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:167)
... 9 more
Thanks